Skip to content

Commit a6d694e

Browse files
author
Ariel Ben-Yehuda
committed
fix MirSource::Promoted handling
1 parent 5da8bf8 commit a6d694e

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn dump_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6262
}
6363

6464
let promotion_id = match src {
65-
MirSource::Promoted(_, id) => format!("-promoted{}", id),
65+
MirSource::Promoted(_, id) => format!("-{:?}", id),
6666
_ => String::new()
6767
};
6868

@@ -98,7 +98,7 @@ pub fn write_mir_pretty<'a, 'b, 'tcx, I>(tcx: TyCtxt<'b, 'tcx, 'tcx>,
9898
let src = MirSource::from_node(tcx, id);
9999
write_mir_fn(tcx, src, mir, w, None)?;
100100

101-
for (i, mir) in mir.promoted.iter().enumerate() {
101+
for (i, mir) in mir.promoted.iter_enumerated() {
102102
writeln!(w, "")?;
103103
write_mir_fn(tcx, MirSource::Promoted(id, i), mir, w, None)?;
104104
}
@@ -292,7 +292,7 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
292292
MirSource::Const(_) => write!(w, "const")?,
293293
MirSource::Static(_, hir::MutImmutable) => write!(w, "static")?,
294294
MirSource::Static(_, hir::MutMutable) => write!(w, "static mut")?,
295-
MirSource::Promoted(_, i) => write!(w, "promoted{} in", i)?
295+
MirSource::Promoted(_, i) => write!(w, "{:?} in", i)?
296296
}
297297

298298
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);

0 commit comments

Comments
 (0)