Skip to content

Commit be203ac

Browse files
authored
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
2 parents 114be1e + a6d694e commit be203ac

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

src/librustc/mir/transform.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use hir;
1313
use hir::map::DefPathData;
1414
use hir::def_id::DefId;
1515
use mir::mir_map::MirMap;
16-
use mir::repr::Mir;
16+
use mir::repr::{Mir, Promoted};
1717
use ty::TyCtxt;
1818
use syntax::ast::NodeId;
1919

@@ -32,7 +32,7 @@ pub enum MirSource {
3232
Static(NodeId, hir::Mutability),
3333

3434
/// Promoted rvalues within a function.
35-
Promoted(NodeId, usize)
35+
Promoted(NodeId, Promoted)
3636
}
3737

3838
impl<'a, 'tcx> MirSource {
@@ -77,7 +77,12 @@ pub trait Pass {
7777
DepNode::MirPass(def_id)
7878
}
7979
fn name(&self) -> &str {
80-
unsafe { ::std::intrinsics::type_name::<Self>() }
80+
let name = unsafe { ::std::intrinsics::type_name::<Self>() };
81+
if let Some(tail) = name.rfind(":") {
82+
&name[tail+1..]
83+
} else {
84+
name
85+
}
8186
}
8287
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> { None }
8388
}
@@ -104,11 +109,6 @@ pub trait MirPassHook<'tcx>: Pass {
104109

105110
/// A pass which inspects Mir of functions in isolation.
106111
pub trait MirPass<'tcx>: Pass {
107-
fn run_pass_on_promoted<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
108-
item_id: NodeId, index: usize,
109-
mir: &mut Mir<'tcx>) {
110-
self.run_pass(tcx, MirSource::Promoted(item_id, index), mir);
111-
}
112112
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
113113
src: MirSource, mir: &mut Mir<'tcx>);
114114
}
@@ -133,11 +133,12 @@ impl<'tcx, T: MirPass<'tcx>> MirMapPass<'tcx> for T {
133133
hook.on_mir_pass(tcx, src, mir, self, true);
134134
}
135135

136-
for (i, mir) in mir.promoted.iter_mut().enumerate() {
136+
for (i, mir) in mir.promoted.iter_enumerated_mut() {
137+
let src = MirSource::Promoted(id, i);
137138
for hook in &mut *hooks {
138139
hook.on_mir_pass(tcx, src, mir, self, false);
139140
}
140-
self.run_pass_on_promoted(tcx, id, i, mir);
141+
MirPass::run_pass(self, tcx, src, mir);
141142
for hook in &mut *hooks {
142143
hook.on_mir_pass(tcx, src, mir, self, true);
143144
}

src/librustc_mir/pretty.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ pub fn dump_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6161
return;
6262
}
6363

64-
let file_name = format!("rustc.node{}.{}.{}.mir",
65-
node_id, pass_name, disambiguator);
64+
let promotion_id = match src {
65+
MirSource::Promoted(_, id) => format!("-{:?}", id),
66+
_ => String::new()
67+
};
68+
69+
let file_name = format!("rustc.node{}{}.{}.{}.mir",
70+
node_id, promotion_id, pass_name, disambiguator);
6671
let _ = fs::File::create(&file_name).and_then(|mut file| {
6772
try!(writeln!(file, "// MIR for `{}`", node_path));
6873
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>,
9398
let src = MirSource::from_node(tcx, id);
9499
write_mir_fn(tcx, src, mir, w, None)?;
95100

96-
for (i, mir) in mir.promoted.iter().enumerate() {
101+
for (i, mir) in mir.promoted.iter_enumerated() {
97102
writeln!(w, "")?;
98103
write_mir_fn(tcx, MirSource::Promoted(id, i), mir, w, None)?;
99104
}
@@ -287,7 +292,7 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
287292
MirSource::Const(_) => write!(w, "const")?,
288293
MirSource::Static(_, hir::MutImmutable) => write!(w, "static")?,
289294
MirSource::Static(_, hir::MutMutable) => write!(w, "static mut")?,
290-
MirSource::Promoted(_, i) => write!(w, "promoted{} in", i)?
295+
MirSource::Promoted(_, i) => write!(w, "{:?} in", i)?
291296
}
292297

293298
write!(w, " {}", tcx.node_path_str(src.item_id()))?;

src/librustc_mir/transform/add_call_guards.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use rustc::mir::repr::*;
1313
use rustc::mir::transform::{MirPass, MirSource, Pass};
1414
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1515

16-
use pretty;
17-
1816
pub struct AddCallGuards;
1917

2018
/**
@@ -38,7 +36,7 @@ pub struct AddCallGuards;
3836
*/
3937

4038
impl<'tcx> MirPass<'tcx> for AddCallGuards {
41-
fn run_pass<'a>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &mut Mir<'tcx>) {
39+
fn run_pass<'a>(&mut self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource, mir: &mut Mir<'tcx>) {
4240
let pred_count: IndexVec<_, _> =
4341
mir.predecessors().iter().map(|ps| ps.len()).collect();
4442

@@ -75,7 +73,6 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards {
7573
}
7674
}
7775

78-
pretty::dump_mir(tcx, "break_cleanup_edges", &0, src, mir, None);
7976
debug!("Broke {} N edges", new_blocks.len());
8077

8178
mir.basic_blocks_mut().extend(new_blocks);

src/librustc_mir/transform/simplify_branches.rs

+3
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ impl<'l> Pass for SimplifyBranches<'l> {
6060
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> {
6161
Some(Box::new(self.label))
6262
}
63+
64+
// avoid calling `type_name` - it contains `<'static>`
65+
fn name(&self) -> &str { "SimplifyBranches" }
6366
}

src/librustc_mir/transform/simplify_cfg.rs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ impl<'l> Pass for SimplifyCfg<'l> {
6262
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> {
6363
Some(Box::new(self.label))
6464
}
65+
66+
// avoid calling `type_name` - it contains `<'static>`
67+
fn name(&self) -> &str { "SimplifyCfg" }
6568
}
6669

6770
pub struct CfgSimplifier<'a, 'tcx: 'a> {

0 commit comments

Comments
 (0)