Skip to content

Commit

Permalink
Auto merge of #74837 - xldenis:mir-dump-crate-file, r=oli-obk
Browse files Browse the repository at this point in the history
Fix #70767

This PR changes the format of MIR dump filenames to include the crate name rather than `rustc` at the start.

As a result, we can now place mir-opt tests in the same directory as the source files, like with UI tests. I had to make sure that `compiletest` added a bit_width suffix to the expected files when appropriate but otherwise the change is only moving the files to the correct location and ensuring that the `EMIT_MIR` lines are correct.

Fixes #70767
cc @oli-obk
  • Loading branch information
bors committed Jul 29, 2020
2 parents 6fd4c3f + f07607f commit 8611e52
Show file tree
Hide file tree
Showing 306 changed files with 225 additions and 422 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Expand Up @@ -611,6 +611,7 @@ dependencies = [
"diff",
"env_logger 0.7.1",
"getopts",
"glob",
"lazy_static",
"libc",
"log",
Expand Down
12 changes: 10 additions & 2 deletions src/librustc_mir/util/pretty.rs
Expand Up @@ -177,6 +177,7 @@ fn dump_path(
let mut file_path = PathBuf::new();
file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));

let crate_name = tcx.crate_name(source.def_id().krate);
let item_name = tcx.def_path(source.def_id()).to_filename_friendly_no_crate();
// All drop shims have the same DefId, so we have to add the type
// to get unique file names.
Expand All @@ -196,8 +197,15 @@ fn dump_path(
};

let file_name = format!(
"rustc.{}{}{}{}.{}.{}.{}",
item_name, shim_disambiguator, promotion_id, pass_num, pass_name, disambiguator, extension,
"{}.{}{}{}{}.{}.{}.{}",
crate_name,
item_name,
shim_disambiguator,
promotion_id,
pass_num,
pass_name,
disambiguator,
extension,
);

file_path.push(&file_name);
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/address-of.rs
@@ -1,4 +1,4 @@
// EMIT_MIR rustc.address_of_reborrow.SimplifyCfg-initial.after.mir
// EMIT_MIR address_of.address_of_reborrow.SimplifyCfg-initial.after.mir

fn address_of_reborrow() {
let y = &[0; 10];
Expand Down Expand Up @@ -37,7 +37,7 @@ fn address_of_reborrow() {
}

// The normal borrows here should be preserved
// EMIT_MIR rustc.borrow_and_cast.SimplifyCfg-initial.after.mir
// EMIT_MIR address_of.borrow_and_cast.SimplifyCfg-initial.after.mir
fn borrow_and_cast(mut x: i32) {
let p = &x as *const i32;
let q = &mut x as *const i32;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/array-index-is-temporary.rs
Expand Up @@ -8,7 +8,7 @@ unsafe fn foo(z: *mut usize) -> u32 {
}

// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR rustc.main.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir
fn main() {
let mut x = [42, 43, 44];
let mut y = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/basic_assignment.rs
@@ -1,6 +1,6 @@
// this tests move up progration, which is not yet implemented

// EMIT_MIR rustc.main.SimplifyCfg-initial.after.mir
// EMIT_MIR basic_assignment.main.SimplifyCfg-initial.after.mir

// Check codegen for assignments (`a = b`) where the left-hand-side is
// not yet initialized. Assignments tend to be absent in simple code,
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/box_expr.rs
Expand Up @@ -2,7 +2,7 @@

#![feature(box_syntax)]

// EMIT_MIR rustc.main.ElaborateDrops.before.mir
// EMIT_MIR box_expr.main.ElaborateDrops.before.mir
fn main() {
let x = box S::new();
drop(x);
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/byte_slice.rs
@@ -1,6 +1,6 @@
// compile-flags: -Z mir-opt-level=0

// EMIT_MIR rustc.main.SimplifyCfg-elaborate-drops.after.mir
// EMIT_MIR byte_slice.main.SimplifyCfg-elaborate-drops.after.mir
fn main() {
let x = b"foo";
let y = [5u8, b'x'];
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/combine_array_len.rs
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR rustc.norm2.InstCombine.diff
// EMIT_MIR combine_array_len.norm2.InstCombine.diff

fn norm2(x: [f32; 2]) -> f32 {
let a = x[0];
Expand Down
8 changes: 4 additions & 4 deletions src/test/mir-opt/const-promotion-extern-static.rs
Expand Up @@ -4,12 +4,12 @@ extern "C" {

static Y: i32 = 42;

// EMIT_MIR rustc.BAR.PromoteTemps.diff
// EMIT_MIR rustc.BAR-promoted[0].ConstProp.after.mir
// EMIT_MIR const_promotion_extern_static.BAR.PromoteTemps.diff
// EMIT_MIR const_promotion_extern_static.BAR-promoted[0].ConstProp.after.mir
static mut BAR: *const &i32 = [&Y].as_ptr();

// EMIT_MIR rustc.FOO.PromoteTemps.diff
// EMIT_MIR rustc.FOO-promoted[0].ConstProp.after.mir
// EMIT_MIR const_promotion_extern_static.FOO.PromoteTemps.diff
// EMIT_MIR const_promotion_extern_static.FOO-promoted[0].ConstProp.after.mir
static mut FOO: *const &i32 = [unsafe { &X }].as_ptr();

fn main() {}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_allocation.rs
Expand Up @@ -3,7 +3,7 @@
static FOO: &[(Option<i32>, &[&str])] =
&[(None, &[]), (None, &["foo", "bar"]), (Some(42), &["meh", "mop", "möp"])];

// EMIT_MIR rustc.main.ConstProp.after.mir
// EMIT_MIR const_allocation.main.ConstProp.after.mir
fn main() {
FOO;
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_allocation2.rs
@@ -1,6 +1,6 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH

// EMIT_MIR rustc.main.ConstProp.after.mir
// EMIT_MIR const_allocation2.main.ConstProp.after.mir
fn main() {
FOO;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_allocation3.rs
@@ -1,6 +1,6 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH

// EMIT_MIR rustc.main.ConstProp.after.mir
// EMIT_MIR const_allocation3.main.ConstProp.after.mir
fn main() {
FOO;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/aggregate.rs
@@ -1,6 +1,6 @@
// compile-flags: -O

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR aggregate.main.ConstProp.diff
fn main() {
let x = (0, 1, 2).1 + 0;
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/array_index.rs
@@ -1,6 +1,6 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR array_index.main.ConstProp.diff
fn main() {
let x: u32 = [0, 1, 2, 3][2];
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/bad_op_div_by_zero.rs
@@ -1,4 +1,4 @@
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR bad_op_div_by_zero.main.ConstProp.diff
#[allow(unconditional_panic)]
fn main() {
let y = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/bad_op_mod_by_zero.rs
@@ -1,4 +1,4 @@
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR bad_op_mod_by_zero.main.ConstProp.diff
#[allow(unconditional_panic)]
fn main() {
let y = 0;
Expand Down
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR bad_op_unsafe_oob_for_slices.main.ConstProp.diff
#[allow(unconditional_panic)]
fn main() {
let a: *const [_] = &[1, 2, 3];
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/boolean_identities.rs
@@ -1,6 +1,6 @@
// compile-flags: -O -Zmir-opt-level=3

// EMIT_MIR rustc.test.ConstProp.diff
// EMIT_MIR boolean_identities.test.ConstProp.diff
pub fn test(x: bool, y: bool) -> bool {
(y | true) & (x & false)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/boxes.rs
Expand Up @@ -7,7 +7,7 @@

// Note: this test verifies that we, in fact, do not const prop `box`

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR boxes.main.ConstProp.diff
fn main() {
let x = *(box 42) + 0;
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/cast.rs
@@ -1,4 +1,4 @@
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR cast.main.ConstProp.diff

fn main() {
let x = 42u8 as u32;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/checked_add.rs
@@ -1,6 +1,6 @@
// compile-flags: -C overflow-checks=on

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR checked_add.main.ConstProp.diff
fn main() {
let x: u32 = 1 + 1;
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs
@@ -1,7 +1,7 @@
#[inline(never)]
fn read(_: usize) { }

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR const_prop_fails_gracefully.main.ConstProp.diff
fn main() {
const FOO: &i32 = &1;
let x = FOO as *const i32 as usize;
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/control-flow-simplification.rs
Expand Up @@ -6,8 +6,8 @@ trait NeedsDrop:Sized{

impl<This> NeedsDrop for This{}

// EMIT_MIR rustc.hello.ConstProp.diff
// EMIT_MIR rustc.hello.PreCodegen.before.mir
// EMIT_MIR control_flow_simplification.hello.ConstProp.diff
// EMIT_MIR control_flow_simplification.hello.PreCodegen.before.mir
fn hello<T>(){
if <bool>::NEEDS {
panic!()
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/discriminant.rs
Expand Up @@ -6,7 +6,7 @@
// Fixing either of those will allow us to const-prop this away.

// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR discriminant.main.ConstProp.diff
fn main() {
let x = (if let Some(true) = Some(true) { 42 } else { 10 }) + 0;
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/indirect.rs
@@ -1,6 +1,6 @@
// compile-flags: -C overflow-checks=on

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR indirect.main.ConstProp.diff
fn main() {
let x = (2u32 as u8) + 1;
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/issue-66971.rs
Expand Up @@ -11,7 +11,7 @@ fn encode(this: ((), u8, u8)) {
assert!(this.2 == 0);
}

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR issue_66971.main.ConstProp.diff
fn main() {
encode(((), 0, 0));
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/issue-67019.rs
Expand Up @@ -6,7 +6,7 @@ fn test(this: ((u8, u8),)) {
assert!((this.0).0 == 1);
}

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR issue_67019.main.ConstProp.diff
fn main() {
test(((1, 2),));
}
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/mult_by_zero.rs
@@ -1,6 +1,6 @@
// compile-flags: -O -Zmir-opt-level=3

// EMIT_MIR rustc.test.ConstProp.diff
// EMIT_MIR mult_by_zero.test.ConstProp.diff
fn test(x : i32) -> i32 {
x * 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/mutable_variable.rs
@@ -1,6 +1,6 @@
// compile-flags: -O

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR mutable_variable.main.ConstProp.diff
fn main() {
let mut x = 42;
x = 99;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/mutable_variable_aggregate.rs
@@ -1,6 +1,6 @@
// compile-flags: -O

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR mutable_variable_aggregate.main.ConstProp.diff
fn main() {
let mut x = (42, 43);
x.1 = 99;
Expand Down
@@ -1,6 +1,6 @@
// compile-flags: -O

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR mutable_variable_aggregate_mut_ref.main.ConstProp.diff
fn main() {
let mut x = (42, 43);
let z = &mut x;
Expand Down
@@ -1,6 +1,6 @@
// compile-flags: -O

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR mutable_variable_aggregate_partial_read.main.ConstProp.diff
fn main() {
let mut x: (i32, i32) = foo();
x.1 = 99;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/mutable_variable_no_prop.rs
Expand Up @@ -2,7 +2,7 @@

static mut STATIC: u32 = 42;

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR mutable_variable_no_prop.main.ConstProp.diff
fn main() {
let mut x = 42;
unsafe {
Expand Down
@@ -1,6 +1,6 @@
// compile-flags: -O

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR mutable_variable_unprop_assign.main.ConstProp.diff
fn main() {
let a = foo();
let mut x: (i32, i32) = (1, 2);
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/optimizes_into_variable.rs
Expand Up @@ -6,8 +6,8 @@ struct Point {
}

// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR rustc.main.SimplifyLocals.after.mir
// EMIT_MIR optimizes_into_variable.main.ConstProp.diff
// EMIT_MIR optimizes_into_variable.main.SimplifyLocals.after.mir
fn main() {
let x = 2 + 2;
let y = [0, 1, 2, 3, 4, 5][3];
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/read_immutable_static.rs
Expand Up @@ -2,7 +2,7 @@

static FOO: u8 = 2;

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR read_immutable_static.main.ConstProp.diff
fn main() {
let x = FOO + FOO;
}
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/ref_deref.rs
@@ -1,5 +1,5 @@
// EMIT_MIR rustc.main.PromoteTemps.diff
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR ref_deref.main.PromoteTemps.diff
// EMIT_MIR ref_deref.main.ConstProp.diff

fn main() {
*(&4);
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/ref_deref_project.rs
@@ -1,5 +1,5 @@
// EMIT_MIR rustc.main.PromoteTemps.diff
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR ref_deref_project.main.PromoteTemps.diff
// EMIT_MIR ref_deref_project.main.ConstProp.diff

fn main() {
*(&(4, 5).1); // This does not currently propagate (#67862)
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/reify_fn_ptr.rs
@@ -1,4 +1,4 @@
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR reify_fn_ptr.main.ConstProp.diff

fn main() {
let _ = main as usize as *const fn();
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/repeat.rs
@@ -1,7 +1,7 @@
// compile-flags: -O

// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR repeat.main.ConstProp.diff
fn main() {
let x: u32 = [42; 8][2] + 0;
}
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/return_place.rs
@@ -1,7 +1,7 @@
// compile-flags: -C overflow-checks=on

// EMIT_MIR rustc.add.ConstProp.diff
// EMIT_MIR rustc.add.PreCodegen.before.mir
// EMIT_MIR return_place.add.ConstProp.diff
// EMIT_MIR return_place.add.PreCodegen.before.mir
fn add() -> u32 {
2 + 2
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/scalar_literal_propagation.rs
@@ -1,4 +1,4 @@
// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR scalar_literal_propagation.main.ConstProp.diff
fn main() {
let x = 1;
consume(x);
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/slice_len.rs
@@ -1,6 +1,6 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR slice_len.main.ConstProp.diff
fn main() {
(&[1u32, 2, 3] as &[u32])[1];
}
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/switch_int.rs
@@ -1,8 +1,8 @@
#[inline(never)]
fn foo(_: i32) { }

// EMIT_MIR rustc.main.ConstProp.diff
// EMIT_MIR rustc.main.SimplifyBranches-after-const-prop.diff
// EMIT_MIR switch_int.main.ConstProp.diff
// EMIT_MIR switch_int.main.SimplifyBranches-after-const-prop.diff
fn main() {
match 1 {
1 => foo(0),
Expand Down

0 comments on commit 8611e52

Please sign in to comment.