mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #34306 - arielb1:mir-dump-fixes, r=eddyb
Fixes for `-Z dump-mir` Do not overwrite the parent MIR when dumping promoted MIR. r? @eddyb
This commit is contained in:
commit
be203ac258
@ -13,7 +13,7 @@ use hir;
|
||||
use hir::map::DefPathData;
|
||||
use hir::def_id::DefId;
|
||||
use mir::mir_map::MirMap;
|
||||
use mir::repr::Mir;
|
||||
use mir::repr::{Mir, Promoted};
|
||||
use ty::TyCtxt;
|
||||
use syntax::ast::NodeId;
|
||||
|
||||
@ -32,7 +32,7 @@ pub enum MirSource {
|
||||
Static(NodeId, hir::Mutability),
|
||||
|
||||
/// Promoted rvalues within a function.
|
||||
Promoted(NodeId, usize)
|
||||
Promoted(NodeId, Promoted)
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> MirSource {
|
||||
@ -77,7 +77,12 @@ pub trait Pass {
|
||||
DepNode::MirPass(def_id)
|
||||
}
|
||||
fn name(&self) -> &str {
|
||||
unsafe { ::std::intrinsics::type_name::<Self>() }
|
||||
let name = unsafe { ::std::intrinsics::type_name::<Self>() };
|
||||
if let Some(tail) = name.rfind(":") {
|
||||
&name[tail+1..]
|
||||
} else {
|
||||
name
|
||||
}
|
||||
}
|
||||
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> { None }
|
||||
}
|
||||
@ -104,11 +109,6 @@ pub trait MirPassHook<'tcx>: Pass {
|
||||
|
||||
/// A pass which inspects Mir of functions in isolation.
|
||||
pub trait MirPass<'tcx>: Pass {
|
||||
fn run_pass_on_promoted<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
item_id: NodeId, index: usize,
|
||||
mir: &mut Mir<'tcx>) {
|
||||
self.run_pass(tcx, MirSource::Promoted(item_id, index), mir);
|
||||
}
|
||||
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
src: MirSource, mir: &mut Mir<'tcx>);
|
||||
}
|
||||
@ -133,11 +133,12 @@ impl<'tcx, T: MirPass<'tcx>> MirMapPass<'tcx> for T {
|
||||
hook.on_mir_pass(tcx, src, mir, self, true);
|
||||
}
|
||||
|
||||
for (i, mir) in mir.promoted.iter_mut().enumerate() {
|
||||
for (i, mir) in mir.promoted.iter_enumerated_mut() {
|
||||
let src = MirSource::Promoted(id, i);
|
||||
for hook in &mut *hooks {
|
||||
hook.on_mir_pass(tcx, src, mir, self, false);
|
||||
}
|
||||
self.run_pass_on_promoted(tcx, id, i, mir);
|
||||
MirPass::run_pass(self, tcx, src, mir);
|
||||
for hook in &mut *hooks {
|
||||
hook.on_mir_pass(tcx, src, mir, self, true);
|
||||
}
|
||||
|
@ -61,8 +61,13 @@ pub fn dump_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
return;
|
||||
}
|
||||
|
||||
let file_name = format!("rustc.node{}.{}.{}.mir",
|
||||
node_id, pass_name, disambiguator);
|
||||
let promotion_id = match src {
|
||||
MirSource::Promoted(_, id) => format!("-{:?}", id),
|
||||
_ => String::new()
|
||||
};
|
||||
|
||||
let file_name = format!("rustc.node{}{}.{}.{}.mir",
|
||||
node_id, promotion_id, pass_name, disambiguator);
|
||||
let _ = fs::File::create(&file_name).and_then(|mut file| {
|
||||
try!(writeln!(file, "// MIR for `{}`", node_path));
|
||||
try!(writeln!(file, "// node_id = {}", node_id));
|
||||
@ -93,7 +98,7 @@ pub fn write_mir_pretty<'a, 'b, 'tcx, I>(tcx: TyCtxt<'b, 'tcx, 'tcx>,
|
||||
let src = MirSource::from_node(tcx, id);
|
||||
write_mir_fn(tcx, src, mir, w, None)?;
|
||||
|
||||
for (i, mir) in mir.promoted.iter().enumerate() {
|
||||
for (i, mir) in mir.promoted.iter_enumerated() {
|
||||
writeln!(w, "")?;
|
||||
write_mir_fn(tcx, MirSource::Promoted(id, i), mir, w, None)?;
|
||||
}
|
||||
@ -287,7 +292,7 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
|
||||
MirSource::Const(_) => write!(w, "const")?,
|
||||
MirSource::Static(_, hir::MutImmutable) => write!(w, "static")?,
|
||||
MirSource::Static(_, hir::MutMutable) => write!(w, "static mut")?,
|
||||
MirSource::Promoted(_, i) => write!(w, "promoted{} in", i)?
|
||||
MirSource::Promoted(_, i) => write!(w, "{:?} in", i)?
|
||||
}
|
||||
|
||||
write!(w, " {}", tcx.node_path_str(src.item_id()))?;
|
||||
|
@ -13,8 +13,6 @@ use rustc::mir::repr::*;
|
||||
use rustc::mir::transform::{MirPass, MirSource, Pass};
|
||||
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||
|
||||
use pretty;
|
||||
|
||||
pub struct AddCallGuards;
|
||||
|
||||
/**
|
||||
@ -38,7 +36,7 @@ pub struct AddCallGuards;
|
||||
*/
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for AddCallGuards {
|
||||
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &mut Mir<'tcx>) {
|
||||
fn run_pass<'a>(&mut self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource, mir: &mut Mir<'tcx>) {
|
||||
let pred_count: IndexVec<_, _> =
|
||||
mir.predecessors().iter().map(|ps| ps.len()).collect();
|
||||
|
||||
@ -75,7 +73,6 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards {
|
||||
}
|
||||
}
|
||||
|
||||
pretty::dump_mir(tcx, "break_cleanup_edges", &0, src, mir, None);
|
||||
debug!("Broke {} N edges", new_blocks.len());
|
||||
|
||||
mir.basic_blocks_mut().extend(new_blocks);
|
||||
|
@ -60,4 +60,7 @@ impl<'l> Pass for SimplifyBranches<'l> {
|
||||
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> {
|
||||
Some(Box::new(self.label))
|
||||
}
|
||||
|
||||
// avoid calling `type_name` - it contains `<'static>`
|
||||
fn name(&self) -> &str { "SimplifyBranches" }
|
||||
}
|
||||
|
@ -62,6 +62,9 @@ impl<'l> Pass for SimplifyCfg<'l> {
|
||||
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> {
|
||||
Some(Box::new(self.label))
|
||||
}
|
||||
|
||||
// avoid calling `type_name` - it contains `<'static>`
|
||||
fn name(&self) -> &str { "SimplifyCfg" }
|
||||
}
|
||||
|
||||
pub struct CfgSimplifier<'a, 'tcx: 'a> {
|
||||
|
Loading…
Reference in New Issue
Block a user