2021-01-01 01:53:25 +01:00
|
|
|
use rustc_middle::mir::Body;
|
|
|
|
use rustc_middle::ty::TyCtxt;
|
2017-11-10 00:49:51 +02:00
|
|
|
use std::borrow::Cow;
|
2017-04-27 16:48:48 -04:00
|
|
|
|
2019-09-17 16:25:40 -07:00
|
|
|
pub mod check_consts;
|
2016-05-07 19:14:28 +03:00
|
|
|
pub mod promote_consts;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod rustc_peek;
|
2020-05-24 00:55:44 +02:00
|
|
|
pub mod validate;
|
2017-04-27 16:48:48 -04:00
|
|
|
|
2017-11-10 00:49:51 +02:00
|
|
|
/// Generates a default name for the pass based on the name of the
|
|
|
|
/// type `T`.
|
|
|
|
pub fn default_name<T: ?Sized>() -> Cow<'static, str> {
|
2020-10-13 10:17:05 +02:00
|
|
|
let name = std::any::type_name::<T>();
|
2020-02-26 13:03:46 +01:00
|
|
|
if let Some(tail) = name.rfind(':') { Cow::from(&name[tail + 1..]) } else { Cow::from(name) }
|
2017-11-10 00:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A streamlined trait that you can implement to create a pass; the
|
|
|
|
/// pass will be named after the type, and it will consist of a main
|
|
|
|
/// loop that goes over each available MIR and applies `run_pass`.
|
2019-08-04 16:20:00 -04:00
|
|
|
pub trait MirPass<'tcx> {
|
2019-06-21 18:12:39 +02:00
|
|
|
fn name(&self) -> Cow<'_, str> {
|
2017-11-10 00:49:51 +02:00
|
|
|
default_name::<Self>()
|
|
|
|
}
|
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>);
|
2017-11-10 00:49:51 +02:00
|
|
|
}
|