Skip to content

Modify MIR testing to require consecutive lines #45162

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 2 commits into from
Oct 14, 2017
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
33 changes: 24 additions & 9 deletions src/test/mir-opt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ The test format is:
// 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
```
Expand All @@ -22,10 +22,15 @@ 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, after and in-between. Note that this includes
lines that end basic blocks or begin new ones; it is good practice
in your tests to include the terminator for each of your basic blocks as an
internal sanity check guarding against a test like:
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 wil be matched.

Examples:

The following blocks will not match the one after it.

```
bb0: {
Expand All @@ -35,8 +40,6 @@ bb0: {
}
```

that will inadvertantly pattern-matching against:

```
bb0: {
StorageLive(_1);
Expand All @@ -49,6 +52,18 @@ bb1: {
}
```

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
Expand Down
5 changes: 4 additions & 1 deletion src/test/mir-opt/box_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ impl Drop for S {
// END RUST SOURCE
// START rustc.node4.ElaborateDrops.before.mir
// let mut _0: ();
// let _1: std::boxed::Box<S>;
// scope 1 {
// let _1: std::boxed::Box<S>;
// }
// ...
// let mut _2: std::boxed::Box<S>;
// let mut _3: ();
// let mut _4: std::boxed::Box<S>;
Expand Down
6 changes: 6 additions & 0 deletions src/test/mir-opt/copy_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ fn main() { }
// END RUST SOURCE
// START rustc.node4.CopyPropagation.before.mir
// bb0: {
// ...
// _2 = _1;
// ...
// _4 = _2;
// _3 = _4;
// ...
// _5 = _3;
// _0 = _5;
// ...
// return;
// }
// END rustc.node4.CopyPropagation.before.mir
// START rustc.node4.CopyPropagation.after.mir
// bb0: {
// ...
// _0 = _1;
// ...
// return;
// }
// END rustc.node4.CopyPropagation.after.mir
6 changes: 6 additions & 0 deletions src/test/mir-opt/deaggregator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ fn main() {}
// END RUST SOURCE
// START rustc.node13.Deaggregator.before.mir
// bb0: {
// ...
// _2 = _1;
// ...
// _3 = _2;
// _0 = Baz { x: _3, y: const 0f32, z: const false };
// ...
// return;
// }
// END rustc.node13.Deaggregator.before.mir
// START rustc.node13.Deaggregator.after.mir
// bb0: {
// ...
// _2 = _1;
// ...
// _3 = _2;
// (_0.0: usize) = _3;
// (_0.1: f32) = const 0f32;
// (_0.2: bool) = const false;
// ...
// return;
// }
// END rustc.node13.Deaggregator.after.mir
8 changes: 8 additions & 0 deletions src/test/mir-opt/deaggregator_test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@ fn main() {
// END RUST SOURCE
// START rustc.node10.Deaggregator.before.mir
// bb0: {
// StorageLive(_2);
// _2 = _1;
// StorageLive(_3);
// _3 = _2;
// _0 = Baz::Foo { x: _3 };
// StorageDead(_3);
// StorageDead(_2);
// return;
// }
// END rustc.node10.Deaggregator.before.mir
// START rustc.node10.Deaggregator.after.mir
// bb0: {
// StorageLive(_2);
// _2 = _1;
// StorageLive(_3);
// _3 = _2;
// ((_0 as Foo).0: usize) = _3;
// discriminant(_0) = 1;
// StorageDead(_3);
// StorageDead(_2);
// return;
// }
// END rustc.node10.Deaggregator.after.mir
10 changes: 8 additions & 2 deletions src/test/mir-opt/deaggregator_test_enum_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,35 @@ fn main() {}
// END RUST SOURCE
// START rustc.node12.Deaggregator.before.mir
// bb1: {
// StorageLive(_6);
// _6 = _4;
// _0 = Foo::A(_6,);
// StorageDead(_6);
// goto -> bb3;
// }
//
// bb2: {
// StorageLive(_7);
// _7 = _4;
// _0 = Foo::B(_7,);
// StorageDead(_7);
// goto -> bb3;
// }
// END rustc.node12.Deaggregator.before.mir
// START rustc.node12.Deaggregator.after.mir
// bb1: {
// StorageLive(_6);
// _6 = _4;
// ((_0 as A).0: i32) = _6;
// discriminant(_0) = 0;
// StorageDead(_6);
// goto -> bb3;
// }
//
// bb2: {
// StorageLive(_7);
// _7 = _4;
// ((_0 as B).0: i32) = _7;
// discriminant(_0) = 1;
// StorageDead(_7);
// goto -> bb3;
// }
// END rustc.node12.Deaggregator.after.mir
Expand Down
10 changes: 10 additions & 0 deletions src/test/mir-opt/deaggregator_test_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,35 @@ fn main() { }
// END RUST SOURCE
// START rustc.node10.Deaggregator.before.mir
// bb0: {
// ...
// _2 = _1;
// ...
// _4 = _2;
// _3 = Foo::A(_4,);
// ...
// _6 = _2;
// _5 = Foo::A(_6,);
// ...
// _0 = [_3, _5];
// ...
// return;
// }
// END rustc.node10.Deaggregator.before.mir
// START rustc.node10.Deaggregator.after.mir
// bb0: {
// ...
// _2 = _1;
// ...
// _4 = _2;
// ((_3 as A).0: i32) = _4;
// discriminant(_3) = 0;
// ...
// _6 = _2;
// ((_5 as A).0: i32) = _6;
// discriminant(_5) = 0;
// ...
// _0 = [_3, _5];
// ...
// return;
// }
// END rustc.node10.Deaggregator.after.mir
4 changes: 3 additions & 1 deletion src/test/mir-opt/end_region_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ fn main() {
// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _1: i32;
// ...
// let _2: &'10_1rs i32;
//
// ...
// bb0: {
// StorageLive(_1);
// _1 = const 3i32;
Expand Down
6 changes: 6 additions & 0 deletions src/test/mir-opt/end_region_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ fn main() {
// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _2: bool;
// ...
// let _3: &'23_1rs bool;
// ...
// let _7: &'23_3rs bool;
// ...
// let mut _4: ();
// let mut _5: bool;
// ...
// bb0: {
// goto -> bb1;
// }
Expand All @@ -52,6 +57,7 @@ fn main() {
// return;
// }
// bb3: {
// _4 = ();
// StorageDead(_5);
// StorageLive(_7);
// _7 = &'23_3rs _2;
Expand Down
6 changes: 5 additions & 1 deletion src/test/mir-opt/end_region_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ fn main() {
// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let mut _1: bool;
// ...
// let _3: &'26_1rs bool;
// ...
// let _7: &'26_3rs bool;
// ...
// let mut _2: ();
// let mut _4: ();
// let mut _5: bool;
//
// let mut _6: !;
// bb0: {
// StorageLive(_1);
// goto -> bb1;
Expand Down
5 changes: 5 additions & 0 deletions src/test/mir-opt/end_region_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ fn foo(i: i32) {
// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _1: D;
// ...
// let _2: i32;
// ...
// let _3: &'26_2rs i32;
// ...
// let _6: &'26_4rs i32;
// ...
// let mut _4: ();
// let mut _5: i32;
// bb0: {
Expand Down
3 changes: 3 additions & 0 deletions src/test/mir-opt/end_region_5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// END RUST SOURCE
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// ...
// let mut _0: ();
// ...
// let _1: D;
// ...
// let mut _2: ();
// let mut _3: [closure@NodeId(18) d:&'14s D];
// let mut _4: &'14s D;
Expand Down
5 changes: 4 additions & 1 deletion src/test/mir-opt/end_region_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
// let _1: D;
// ...
// let mut _2: ();
// let mut _3: [closure@NodeId(22) d:&'19s D];
// let mut _4: &'19s D;
Expand Down Expand Up @@ -65,9 +67,10 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// START rustc.node22.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(22) d:&'19s D]) -> i32 {
// let mut _0: i32;
// ...
// let _2: &'15_0rs D;
// ...
// let mut _3: i32;
//
// bb0: {
// StorageLive(_2);
// _2 = &'15_0rs (*(_1.0: &'19s D));
Expand Down
6 changes: 4 additions & 2 deletions src/test/mir-opt/end_region_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
// let _1: D;
// ...
// let mut _2: ();
// let mut _3: [closure@NodeId(22) d:D];
// let mut _4: D;
//
// bb0: {
// StorageLive(_1);
// _1 = D::{{constructor}}(const 0i32,);
Expand Down Expand Up @@ -74,9 +75,10 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// START rustc.node22.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(22) d:D]) -> i32 {
// let mut _0: i32;
// ...
// let _2: &'15_0rs D;
// ...
// let mut _3: i32;
//
// bb0: {
// StorageLive(_2);
// _2 = &'15_0rs (_1.0: D);
Expand Down
3 changes: 3 additions & 0 deletions src/test/mir-opt/end_region_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// START rustc.node4.SimplifyCfg-qualify-consts.after.mir
// fn main() -> () {
// let mut _0: ();
// ...
// let _1: D;
// ...
// let _2: &'21_1rs D;
// ...
// let mut _3: ();
// let mut _4: [closure@NodeId(22) r:&'21_1rs D];
// let mut _5: &'21_1rs D;
Expand Down
Loading