Skip to content

Fixes for -Z dump-mir #34306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/librustc/mir/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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 }
}
Expand All @@ -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>);
}
Expand All @@ -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);
}
Expand Down
13 changes: 9 additions & 4 deletions src/librustc_mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -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()))?;
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_mir/transform/add_call_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_mir/transform/simplify_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
3 changes: 3 additions & 0 deletions src/librustc_mir/transform/simplify_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down