Skip to content

Commit

Permalink
Auto merge of #70721 - anyska:bless-all-mir-opt, r=oli-obk
Browse files Browse the repository at this point in the history
--bless all mir-opt tests.

r? @oli-obk
  • Loading branch information
bors committed Apr 8, 2020
2 parents 485c5fb + 82d6e07 commit 1edcfc8
Show file tree
Hide file tree
Showing 208 changed files with 10,198 additions and 4,304 deletions.
82 changes: 2 additions & 80 deletions src/test/mir-opt/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
This folder contains tests for MIR optimizations.

There are two test formats. One allows specifying a pattern to look for in the MIR, which also
permits leaving placeholders, but requires you to manually change the pattern if anything changes.
The other emits MIR to extra files that you can automatically update by specifying `--bless` on
the command line (just like `ui` tests updating `.stderr` files).
The `mir-opt` test format emits MIR to extra files that you can automatically update by specifying
`--bless` on the command line (just like `ui` tests updating `.stderr` files).

# `--bless`able test format

Expand Down Expand Up @@ -39,79 +37,3 @@ This exists mainly for completeness and is rarely useful.
```
// EMIT_MIR $file_name_of_some_mir_dump.before.mir
```

# Inline test format

```
(arbitrary rust code)
// END RUST SOURCE
// START $file_name_of_some_mir_dump_0
// $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_0
// (lines or elision)
// START $file_name_of_some_mir_dump_N
// $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_N
```

All the test information is in comments so the test is runnable.

For each $file_name, compiletest expects [$expected_line_0, ...,
$expected_line_N] to appear in the dumped MIR in order. Currently it allows
other non-matched lines before and after, but not between $expected_lines,
should you want to skip lines, you must include an elision comment, of the form
(as a regex) `//\s*...\s*`. The lines will be skipped lazily, that is, if there
are two identical lines in the output that match the line after the elision
comment, the first one will be matched.

Examples:

The following blocks will not match the one after it.

```
bb0: {
StorageLive(_1);
_1 = const true;
StorageDead(_1);
}
```

```
bb0: {
StorageLive(_1);
_1 = const true;
goto -> bb1
}
bb1: {
StorageDead(_1);
return;
}
```

But this will match the one above,

```
bb0: {
StorageLive(_1);
_1 = const true;
...
StorageDead(_1);
...
}
```

Lines match ignoring whitespace, and the prefix "//" is removed.

It also currently strips trailing comments -- partly because the full file path
in "scope comments" is unpredictable and partly because tidy complains about
the lines being too long.

compiletest handles dumping the MIR before and after every pass for you. The
test writer only has to specify the file names of the dumped files (not the
full path to the file) and what lines to expect. There is an option to rustc
that tells it to dump the mir into some directly (rather then always dumping to
the current directory).
71 changes: 3 additions & 68 deletions src/test/mir-opt/address-of.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// EMIT_MIR rustc.address_of_reborrow.SimplifyCfg-initial.after.mir

fn address_of_reborrow() {
let y = &[0; 10];
let mut z = &mut [0; 10];
Expand Down Expand Up @@ -35,78 +37,11 @@ fn address_of_reborrow() {
}

// The normal borrows here should be preserved
// EMIT_MIR rustc.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;
let r = &mut x as *mut i32;
}

fn main() {}

// START rustc.address_of_reborrow.SimplifyCfg-initial.after.mir
// bb0: {
// ...
// _5 = &raw const (*_1); // & to *const casts
// ...
// _7 = &raw const (*_1);
// ...
// _11 = &raw const (*_1);
// ...
// _14 = &raw const (*_1);
// ...
// _16 = &raw const (*_1);
// ...
// _17 = &raw const (*_1); // & to *const coercions
// ...
// _18 = &raw const (*_1);
// ...
// _20 = &raw const (*_1);
// ...
// _22 = &raw const (*_1);
// ...
// _24 = &raw const (*_2); // &mut to *const casts
// ...
// _26 = &raw const (*_2);
// ...
// _30 = &raw const (*_2);
// ...
// _33 = &raw const (*_2);
// ...
// _34 = &raw const (*_2); // &mut to *const coercions
// ...
// _35 = &raw const (*_2);
// ...
// _37 = &raw const (*_2);
// ...
// _39 = &raw const (*_2);
// ...
// _41 = &raw mut (*_2); // &mut to *mut casts
// ...
// _43 = &raw mut (*_2);
// ...
// _47 = &raw mut (*_2);
// ...
// _50 = &raw mut (*_2);
// ...
// _51 = &raw mut (*_2); // &mut to *mut coercions
// ...
// _52 = &raw mut (*_2);
// ...
// _54 = &raw mut (*_2);
// ...
// _56 = &raw mut (*_2);
// ...
// }
// END rustc.address_of_reborrow.SimplifyCfg-initial.after.mir

// START rustc.borrow_and_cast.EraseRegions.after.mir
// bb0: {
// ...
// _4 = &_1;
// ...
// _7 = &mut _1;
// ...
// _10 = &mut _1;
// ...
// }
// END rustc.borrow_and_cast.EraseRegions.after.mir
Loading

0 comments on commit 1edcfc8

Please sign in to comment.