Skip to content

Commit

Permalink
change MIR dump filenames from nodeN to DefPath
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-m1 committed Nov 9, 2017
1 parent fd9ecfd commit 7a6832d
Show file tree
Hide file tree
Showing 41 changed files with 155 additions and 132 deletions.
20 changes: 20 additions & 0 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@ impl DefPath {

s
}

/// Return filename friendly string of the DefPah without
/// the crate-prefix. This method is useful if you don't have
/// a TyCtxt available.
pub fn to_filename_friendly_no_crate(&self) -> String {
let mut s = String::with_capacity(self.data.len() * 16);

for component in &self.data {
if component.disambiguator == 0 {
write!(s, ".{}", component.data.as_interned_str()).unwrap();
} else {
write!(s,
".{}[{}]",
component.data.as_interned_str(),
component.disambiguator)
.unwrap();
}
}
s
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable)]
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ where
let p = Path::new(file_dir);
file_path.push(p);
};

let _ = fs::create_dir_all(&file_path);
let file_name = format!("rustc.node{}{}{}.{}.{}.mir",
source.item_id(), promotion_id, pass_num, pass_name, disambiguator);
let function_name = tcx.hir.def_path_from_id(source.item_id())
.map(|d| d.to_filename_friendly_no_crate()) .unwrap_or(format!(".node{}", source.item_id()));
let file_name = format!("rustc{}{}{}.{}.{}.mir",
function_name, promotion_id, pass_num, pass_name, disambiguator);
file_path.push(&file_name);
let _ = fs::File::create(&file_path).and_then(|mut file| {
writeln!(file, "// MIR for `{}`", node_path)?;
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/basic_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-initial.after.mir
// START rustc.main.SimplifyCfg-initial.after.mir
// bb0: {
// StorageLive(_1);
// _1 = const false;
Expand Down Expand Up @@ -82,4 +82,4 @@ fn main() {
// StorageDead(_1);
// return;
// }
// END rustc.node4.SimplifyCfg-initial.after.mir
// END rustc.main.SimplifyCfg-initial.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/box_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Drop for S {
}

// END RUST SOURCE
// START rustc.node4.ElaborateDrops.before.mir
// START rustc.main.ElaborateDrops.before.mir
// let mut _0: ();
// scope 1 {
// let _1: std::boxed::Box<S>;
Expand Down Expand Up @@ -88,4 +88,4 @@ impl Drop for S {
// return;
// }
// }
// END rustc.node4.ElaborateDrops.before.mir
// END rustc.main.ElaborateDrops.before.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/copy_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node4.CopyPropagation.before.mir
// START rustc.test.CopyPropagation.before.mir
// bb0: {
// ...
// _3 = _1;
Expand All @@ -31,12 +31,12 @@ fn main() {
// ...
// return;
// }
// END rustc.node4.CopyPropagation.before.mir
// START rustc.node4.CopyPropagation.after.mir
// END rustc.test.CopyPropagation.before.mir
// START rustc.test.CopyPropagation.after.mir
// bb0: {
// ...
// _0 = _1;
// ...
// return;
// }
// END rustc.node4.CopyPropagation.after.mir
// END rustc.test.CopyPropagation.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/deaggregator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node13.Deaggregator.before.mir
// START rustc.bar.Deaggregator.before.mir
// bb0: {
// ...
// _2 = _1;
Expand All @@ -33,8 +33,8 @@ fn main() {
// ...
// return;
// }
// END rustc.node13.Deaggregator.before.mir
// START rustc.node13.Deaggregator.after.mir
// END rustc.bar.Deaggregator.before.mir
// START rustc.bar.Deaggregator.after.mir
// bb0: {
// ...
// _2 = _1;
Expand All @@ -45,4 +45,4 @@ fn main() {
// ...
// return;
// }
// END rustc.node13.Deaggregator.after.mir
// END rustc.bar.Deaggregator.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/deaggregator_test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node10.Deaggregator.before.mir
// START rustc.bar.Deaggregator.before.mir
// bb0: {
// StorageLive(_2);
// _2 = _1;
// _0 = Baz::Foo { x: _2 };
// StorageDead(_2);
// return;
// }
// END rustc.node10.Deaggregator.before.mir
// START rustc.node10.Deaggregator.after.mir
// END rustc.bar.Deaggregator.before.mir
// START rustc.bar.Deaggregator.after.mir
// bb0: {
// StorageLive(_2);
// _2 = _1;
Expand All @@ -44,4 +44,4 @@ fn main() {
// StorageDead(_2);
// return;
// }
// END rustc.node10.Deaggregator.after.mir
// END rustc.bar.Deaggregator.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/deaggregator_test_enum_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node12.Deaggregator.before.mir
// START rustc.test1.Deaggregator.before.mir
// bb1: {
// StorageLive(_4);
// _4 = _2;
Expand All @@ -44,8 +44,8 @@ fn main() {
// StorageDead(_5);
// goto -> bb3;
// }
// END rustc.node12.Deaggregator.before.mir
// START rustc.node12.Deaggregator.after.mir
// END rustc.test1.Deaggregator.before.mir
// START rustc.test1.Deaggregator.after.mir
// bb1: {
// StorageLive(_4);
// _4 = _2;
Expand All @@ -62,5 +62,5 @@ fn main() {
// StorageDead(_5);
// goto -> bb3;
// }
// END rustc.node12.Deaggregator.after.mir
// END rustc.test1.Deaggregator.after.mir
//
8 changes: 4 additions & 4 deletions src/test/mir-opt/deaggregator_test_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node10.Deaggregator.before.mir
// START rustc.test.Deaggregator.before.mir
// bb0: {
// ...
// _3 = _1;
Expand All @@ -39,8 +39,8 @@ fn main() {
// ...
// return;
// }
// END rustc.node10.Deaggregator.before.mir
// START rustc.node10.Deaggregator.after.mir
// END rustc.test.Deaggregator.before.mir
// START rustc.test.Deaggregator.after.mir
// bb0: {
// ...
// _3 = _1;
Expand All @@ -56,4 +56,4 @@ fn main() {
// ...
// return;
// }
// END rustc.node10.Deaggregator.after.mir
// END rustc.test.Deaggregator.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/end_region_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _1: i32;
Expand All @@ -37,4 +37,4 @@ fn main() {
// StorageDead(_1);
// return;
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/end_region_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _2: bool;
Expand Down Expand Up @@ -69,4 +69,4 @@ fn main() {
// StorageDead(_2);
// goto -> bb1;
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/end_region_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let mut _1: bool;
Expand Down Expand Up @@ -70,4 +70,4 @@ fn main() {
// StorageDead(_3);
// goto -> bb1;
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/end_region_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn foo(i: i32) {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _1: D;
Expand Down Expand Up @@ -76,4 +76,4 @@ fn foo(i: i32) {
// StorageDead(_1);
// return;
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/end_region_5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// ...
// let mut _0: ();
Expand Down Expand Up @@ -64,9 +64,9 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// return;
// }
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

// START rustc.node18.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(18) d:&'14s D]) -> i32 {
// let mut _0: i32;
// let mut _2: i32;
Expand All @@ -78,4 +78,4 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// StorageDead(_2);
// return;
// }
// END rustc.node18.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/end_region_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
Expand Down Expand Up @@ -62,9 +62,9 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// StorageDead(_1);
// return;
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

// START rustc.node22.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(22) d:&'19s D]) -> i32 {
// let mut _0: i32;
// ...
Expand All @@ -82,4 +82,4 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// StorageDead(_2);
// return;
// }
// END rustc.node22.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/end_region_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
Expand Down Expand Up @@ -70,9 +70,9 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// return;
// }
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

// START rustc.node22.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(22) d:D]) -> i32 {
// let mut _0: i32;
// ...
Expand All @@ -94,4 +94,4 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// return;
// }
// }
// END rustc.node22.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
8 changes: 4 additions & 4 deletions src/test/mir-opt/end_region_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
Expand Down Expand Up @@ -69,9 +69,9 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// return;
// }
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

// START rustc.node22.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(22) r:&'21_1rs D]) -> i32 {
// let mut _0: i32;
// let mut _2: i32;
Expand All @@ -84,4 +84,4 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// return;
// }
// }
// END rustc.node22.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.{{closure}}.SimplifyCfg-qualify-consts.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/end_region_9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
}

// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
Expand Down Expand Up @@ -84,4 +84,4 @@ fn main() {
// goto -> bb1;
// }
// }
// END rustc.node4.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/end_region_cyclic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
fn query() -> bool { true }

// END RUST SOURCE
// START rustc.node16.SimplifyCfg-qualify-consts.after.mir
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// scope 1 {
Expand Down Expand Up @@ -130,4 +130,4 @@ fn query() -> bool { true }
// goto -> bb1;
// }
// }
// END rustc.node16.SimplifyCfg-qualify-consts.after.mir
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
Loading

0 comments on commit 7a6832d

Please sign in to comment.