rust/compiler/rustc_mir/src/transform/mod.rs

27 lines
822 B
Rust
Raw Normal View History

use rustc_middle::mir::Body;
use rustc_middle::ty::TyCtxt;
use std::borrow::Cow;
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;
/// Generates a default name for the pass based on the name of the
/// type `T`.
pub fn default_name<T: ?Sized>() -> Cow<'static, str> {
let name = std::any::type_name::<T>();
if let Some(tail) = name.rfind(':') { Cow::from(&name[tail + 1..]) } else { Cow::from(name) }
}
/// 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> {
default_name::<Self>()
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>);
}