From a5e8a0ea7c337225ba96248387b343f044205b7e Mon Sep 17 00:00:00 2001 From: Christopher Vittal Date: Mon, 9 Oct 2017 21:12:11 -0400 Subject: [PATCH 1/2] Modify MIR testing to require continuous lines Mir testing now requires that lines be continuous. To achive this, instead of collecting the expected mir as a string, it is now wrapped in an `ExpectedLine` enum, that is either `Elision` or `Text(T)` where `T: AsRef`. `Text` lines must be matched in order, unless separated by `Elision` lines. Matches occur greedily, that is, an Elision will skip as few lines as possible. To add a new elision marker. Put a comment containing only "..." and whitespace in any MIR testing block. Like so: ``` // fn write_42(_1: *mut i32) -> bool { // ... // bb0: { // Validate(Acquire, [_1: *mut i32]); // Validate(Release, [_1: *mut i32]); // ... // return; // } // } ``` Right now, all input before the line right after `// START` is elided, and all input after the line right before `// END` is also not tested. Many tests need to be updated. That will follow in the next commit. cc #45153 --- src/tools/compiletest/src/runtest.rs | 130 ++++++++++++++++++++------- 1 file changed, 96 insertions(+), 34 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 10ef326d9db..400599923ff 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -25,6 +25,7 @@ use std::collections::HashSet; use std::env; use std::ffi::OsString; use std::fs::{self, File, create_dir_all}; +use std::fmt; use std::io::prelude::*; use std::io::{self, BufReader}; use std::path::{Path, PathBuf}; @@ -2237,7 +2238,7 @@ actual:\n\ let (_, tests_text) = test_file_contents.split_at(idx + "// END_RUST SOURCE".len()); let tests_text_str = String::from(tests_text); let mut curr_test : Option<&str> = None; - let mut curr_test_contents = Vec::new(); + let mut curr_test_contents = vec![ExpectedLine::Elision]; for l in tests_text_str.lines() { debug!("line: {:?}", l); if l.starts_with("// START ") { @@ -2251,11 +2252,14 @@ actual:\n\ self.compare_mir_test_output(curr_test.unwrap(), &curr_test_contents); curr_test = None; curr_test_contents.clear(); + curr_test_contents.push(ExpectedLine::Elision); } else if l.is_empty() { // ignore + } else if l.starts_with("//") && l.split_at("//".len()).1.trim() == "..." { + curr_test_contents.push(ExpectedLine::Elision) } else if l.starts_with("// ") { let (_, test_content) = l.split_at("// ".len()); - curr_test_contents.push(test_content); + curr_test_contents.push(ExpectedLine::Text(test_content)); } } } @@ -2273,7 +2277,7 @@ actual:\n\ } } - fn compare_mir_test_output(&self, test_name: &str, expected_content: &[&str]) { + fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedLine<&str>]) { let mut output_file = PathBuf::new(); output_file.push(self.get_mir_dump_dir()); output_file.push(test_name); @@ -2285,38 +2289,77 @@ actual:\n\ let mut dumped_string = String::new(); dumped_file.read_to_string(&mut dumped_string).unwrap(); let mut dumped_lines = dumped_string.lines().filter(|l| !l.is_empty()); - let mut expected_lines = expected_content.iter().filter(|l| !l.is_empty()); - - // We expect each non-empty line from expected_content to appear - // in the dump in order, but there may be extra lines interleaved - while let Some(expected_line) = expected_lines.next() { - let e_norm = normalize_mir_line(expected_line); - if e_norm.is_empty() { - continue; - }; - let mut found = false; - while let Some(dumped_line) = dumped_lines.next() { - let d_norm = normalize_mir_line(dumped_line); - debug!("found: {:?}", d_norm); - debug!("expected: {:?}", e_norm); - if e_norm == d_norm { - found = true; - break; - }; + let mut expected_lines = expected_content.iter().filter(|&l| { + if let &ExpectedLine::Text(l) = l { + !l.is_empty() + } else { + true } - if !found { - let normalize_all = dumped_string.lines() - .map(nocomment_mir_line) - .filter(|l| !l.is_empty()) - .collect::>() - .join("\n"); - panic!("ran out of mir dump output to match against.\n\ - Did not find expected line: {:?}\n\ - Expected:\n{}\n\ - Actual:\n{}", - expected_line, - expected_content.join("\n"), - normalize_all); + }).peekable(); + + let compare = |expected_line, dumped_line| { + let e_norm = normalize_mir_line(expected_line); + let d_norm = normalize_mir_line(dumped_line); + debug!("found: {:?}", d_norm); + debug!("expected: {:?}", e_norm); + e_norm == d_norm + }; + + let error = |expected_line, extra_msg| { + let normalize_all = dumped_string.lines() + .map(nocomment_mir_line) + .filter(|l| !l.is_empty()) + .collect::>() + .join("\n"); + let f = |l: &ExpectedLine<_>| match l { + &ExpectedLine::Elision => "... (elided)".into(), + &ExpectedLine::Text(t) => t + }; + let expected_content = expected_content.iter() + .map(|l| f(l)) + .collect::>() + .join("\n"); + panic!("Did not find expected line, error: {}\n\ + Actual Line: {:?}\n\ + Expected:\n{}\n\ + Actual:\n{}", + extra_msg, + expected_line, + expected_content, + normalize_all); + }; + + // We expect each non-empty line to appear consecutively, non-consecutive lines + // must be separated by at least one Elision + while let Some(dumped_line) = dumped_lines.next() { + match expected_lines.next() { + Some(&ExpectedLine::Text(expected_line)) => + if !compare(expected_line, dumped_line) { + error(expected_line, + format!("Mismatch in lines\nExpected Line: {:?}", dumped_line)); + }, + Some(&ExpectedLine::Elision) => { + // skip any number of elisions in a row. + while let Some(&&ExpectedLine::Elision) = expected_lines.peek() { + expected_lines.next(); + } + if let Some(&ExpectedLine::Text(expected_line)) = expected_lines.next() { + let mut found = compare(expected_line, dumped_line); + if found { + continue; + } + while let Some(dumped_line) = dumped_lines.next() { + found = compare(expected_line, dumped_line); + if found { + break; + } + } + if !found { + error(expected_line, "ran out of mir dump to match against".into()); + } + } + }, + None => {}, } } } @@ -2439,6 +2482,25 @@ enum TargetLocation { ThisDirectory(PathBuf), } +#[derive(Clone, PartialEq, Eq)] +enum ExpectedLine> { + Elision, + Text(T) +} + +impl fmt::Debug for ExpectedLine +where + T: AsRef + fmt::Debug +{ + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + if let &ExpectedLine::Text(ref t) = self { + write!(formatter, "{:?}", t) + } else { + write!(formatter, "\"...\" (Elision)") + } + } +} + fn normalize_mir_line(line: &str) -> String { nocomment_mir_line(line).replace(char::is_whitespace, "") } From 426183c01bbaf398e8ae68bd554488af23e49dbd Mon Sep 17 00:00:00 2001 From: Christopher Vittal Date: Mon, 9 Oct 2017 23:14:13 -0400 Subject: [PATCH 2/2] Update README and tests for new infrastructure --- src/test/mir-opt/README.md | 33 ++- src/test/mir-opt/box_expr.rs | 5 +- src/test/mir-opt/copy_propagation.rs | 6 + src/test/mir-opt/deaggregator_test.rs | 6 + src/test/mir-opt/deaggregator_test_enum.rs | 8 + src/test/mir-opt/deaggregator_test_enum_2.rs | 10 +- .../mir-opt/deaggregator_test_multiple.rs | 10 + src/test/mir-opt/end_region_1.rs | 4 +- src/test/mir-opt/end_region_2.rs | 6 + src/test/mir-opt/end_region_3.rs | 6 +- src/test/mir-opt/end_region_4.rs | 5 + src/test/mir-opt/end_region_5.rs | 3 + src/test/mir-opt/end_region_6.rs | 5 +- src/test/mir-opt/end_region_7.rs | 6 +- src/test/mir-opt/end_region_8.rs | 3 + src/test/mir-opt/end_region_9.rs | 7 +- src/test/mir-opt/end_region_cyclic.rs | 1 + src/test/mir-opt/issue-41110.rs | 10 +- .../mir-opt/storage_live_dead_in_statics.rs | 200 +++++++++++++----- src/test/mir-opt/storage_ranges.rs | 1 + src/test/mir-opt/validate_1.rs | 5 + src/test/mir-opt/validate_2.rs | 8 + src/test/mir-opt/validate_3.rs | 15 ++ src/test/mir-opt/validate_4.rs | 9 + src/test/mir-opt/validate_5.rs | 5 + 25 files changed, 304 insertions(+), 73 deletions(-) diff --git a/src/test/mir-opt/README.md b/src/test/mir-opt/README.md index d999ff97551..b00b35aa29f 100644 --- a/src/test/mir-opt/README.md +++ b/src/test/mir-opt/README.md @@ -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 ``` @@ -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: { @@ -35,8 +40,6 @@ bb0: { } ``` -that will inadvertantly pattern-matching against: - ``` bb0: { StorageLive(_1); @@ -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 diff --git a/src/test/mir-opt/box_expr.rs b/src/test/mir-opt/box_expr.rs index 4015930ef76..5c3b418e950 100644 --- a/src/test/mir-opt/box_expr.rs +++ b/src/test/mir-opt/box_expr.rs @@ -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; +// scope 1 { +// let _1: std::boxed::Box; +// } +// ... // let mut _2: std::boxed::Box; // let mut _3: (); // let mut _4: std::boxed::Box; diff --git a/src/test/mir-opt/copy_propagation.rs b/src/test/mir-opt/copy_propagation.rs index 26b042d0343..0b0d2f45f1c 100644 --- a/src/test/mir-opt/copy_propagation.rs +++ b/src/test/mir-opt/copy_propagation.rs @@ -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 diff --git a/src/test/mir-opt/deaggregator_test.rs b/src/test/mir-opt/deaggregator_test.rs index 81dd1932894..ce2b13ecda7 100644 --- a/src/test/mir-opt/deaggregator_test.rs +++ b/src/test/mir-opt/deaggregator_test.rs @@ -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 diff --git a/src/test/mir-opt/deaggregator_test_enum.rs b/src/test/mir-opt/deaggregator_test_enum.rs index 25fa0e90835..d77dcb62781 100644 --- a/src/test/mir-opt/deaggregator_test_enum.rs +++ b/src/test/mir-opt/deaggregator_test_enum.rs @@ -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 diff --git a/src/test/mir-opt/deaggregator_test_enum_2.rs b/src/test/mir-opt/deaggregator_test_enum_2.rs index 02d496b2901..e65830bddc4 100644 --- a/src/test/mir-opt/deaggregator_test_enum_2.rs +++ b/src/test/mir-opt/deaggregator_test_enum_2.rs @@ -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 diff --git a/src/test/mir-opt/deaggregator_test_multiple.rs b/src/test/mir-opt/deaggregator_test_multiple.rs index a180a69be55..ed68d3bf5f7 100644 --- a/src/test/mir-opt/deaggregator_test_multiple.rs +++ b/src/test/mir-opt/deaggregator_test_multiple.rs @@ -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 diff --git a/src/test/mir-opt/end_region_1.rs b/src/test/mir-opt/end_region_1.rs index 1941d1bc7be..a0edcc82fe1 100644 --- a/src/test/mir-opt/end_region_1.rs +++ b/src/test/mir-opt/end_region_1.rs @@ -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; diff --git a/src/test/mir-opt/end_region_2.rs b/src/test/mir-opt/end_region_2.rs index d8dd4aeadf4..69042fecc7d 100644 --- a/src/test/mir-opt/end_region_2.rs +++ b/src/test/mir-opt/end_region_2.rs @@ -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; // } @@ -52,6 +57,7 @@ fn main() { // return; // } // bb3: { +// _4 = (); // StorageDead(_5); // StorageLive(_7); // _7 = &'23_3rs _2; diff --git a/src/test/mir-opt/end_region_3.rs b/src/test/mir-opt/end_region_3.rs index e404af838ce..da423163e84 100644 --- a/src/test/mir-opt/end_region_3.rs +++ b/src/test/mir-opt/end_region_3.rs @@ -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; diff --git a/src/test/mir-opt/end_region_4.rs b/src/test/mir-opt/end_region_4.rs index d51c627d14b..2087485b913 100644 --- a/src/test/mir-opt/end_region_4.rs +++ b/src/test/mir-opt/end_region_4.rs @@ -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: { diff --git a/src/test/mir-opt/end_region_5.rs b/src/test/mir-opt/end_region_5.rs index 6299ec3815c..4663b71bd7c 100644 --- a/src/test/mir-opt/end_region_5.rs +++ b/src/test/mir-opt/end_region_5.rs @@ -28,8 +28,11 @@ fn foo(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; diff --git a/src/test/mir-opt/end_region_6.rs b/src/test/mir-opt/end_region_6.rs index 13ab3e4f2dd..7d2868ee4ba 100644 --- a/src/test/mir-opt/end_region_6.rs +++ b/src/test/mir-opt/end_region_6.rs @@ -29,7 +29,9 @@ fn foo(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; @@ -65,9 +67,10 @@ fn foo(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)); diff --git a/src/test/mir-opt/end_region_7.rs b/src/test/mir-opt/end_region_7.rs index 826d3749167..0156c1be7ed 100644 --- a/src/test/mir-opt/end_region_7.rs +++ b/src/test/mir-opt/end_region_7.rs @@ -29,11 +29,12 @@ fn foo(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,); @@ -74,9 +75,10 @@ fn foo(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); diff --git a/src/test/mir-opt/end_region_8.rs b/src/test/mir-opt/end_region_8.rs index 6438484fcfa..6e8cf4204ee 100644 --- a/src/test/mir-opt/end_region_8.rs +++ b/src/test/mir-opt/end_region_8.rs @@ -30,8 +30,11 @@ fn foo(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; diff --git a/src/test/mir-opt/end_region_9.rs b/src/test/mir-opt/end_region_9.rs index 59d5d934391..fd23d813452 100644 --- a/src/test/mir-opt/end_region_9.rs +++ b/src/test/mir-opt/end_region_9.rs @@ -40,15 +40,18 @@ fn main() { // START rustc.node4.SimplifyCfg-qualify-consts.after.mir // fn main() -> () { // let mut _0: (); +// ... // let mut _1: bool; +// ... // let _2: i32; +// ... // let mut _4: &'33_0rs i32; +// ... // let mut _3: (); // let mut _5: !; // let mut _6: (); // let mut _7: bool; // let mut _8: !; -// // bb0: { // StorageLive(_1); // _1 = const false; @@ -63,7 +66,6 @@ fn main() { // _7 = _1; // switchInt(_7) -> [0u8: bb3, otherwise: bb2]; // } -// // bb2: { // _0 = (); // StorageDead(_7); @@ -73,7 +75,6 @@ fn main() { // StorageDead(_1); // return; // } -// // bb3: { // _4 = &'33_0rs _2; // _6 = (); diff --git a/src/test/mir-opt/end_region_cyclic.rs b/src/test/mir-opt/end_region_cyclic.rs index 8f9dd79cd75..f70f6519275 100644 --- a/src/test/mir-opt/end_region_cyclic.rs +++ b/src/test/mir-opt/end_region_cyclic.rs @@ -45,6 +45,7 @@ fn query() -> bool { true } // scope 1 { // let _2: S<'35_0rs>; // } +// ... // let mut _1: (); // let mut _3: std::cell::Cell>>; // let mut _4: std::option::Option<&'35_0rs S<'35_0rs>>; diff --git a/src/test/mir-opt/issue-41110.rs b/src/test/mir-opt/issue-41110.rs index 3a8b5c449c2..384201b7c12 100644 --- a/src/test/mir-opt/issue-41110.rs +++ b/src/test/mir-opt/issue-41110.rs @@ -35,22 +35,26 @@ impl S { // END RUST SOURCE // START rustc.node4.ElaborateDrops.after.mir // let mut _0: (); -// let _1: (); +// scope 1 { +// let _1: (); +// } +// ... // let mut _2: S; // let mut _3: S; // let mut _4: S; // let mut _5: bool; -// // bb0: { // END rustc.node4.ElaborateDrops.after.mir // START rustc.node13.ElaborateDrops.after.mir // let mut _0: (); +// ... // let _1: S; +// ... // let mut _2: S; +// ... // let mut _3: (); // let mut _4: S; // let mut _5: S; // let mut _6: bool; -// // bb0: { // END rustc.node13.ElaborateDrops.after.mir diff --git a/src/test/mir-opt/storage_live_dead_in_statics.rs b/src/test/mir-opt/storage_live_dead_in_statics.rs index 9fb725a980e..370ab599eca 100644 --- a/src/test/mir-opt/storage_live_dead_in_statics.rs +++ b/src/test/mir-opt/storage_live_dead_in_statics.rs @@ -45,56 +45,156 @@ fn main() { // END RUST SOURCE // START rustc.node4.mir_map.0.mir +// let mut _0: &'static Foo; +// let mut _1: &'static Foo; +// let mut _2: Foo; +// let mut _3: &'static [(u32, u32)]; +// let mut _4: &'static [(u32, u32); 42]; +// let mut _5: &'static [(u32, u32); 42]; +// let mut _6: [(u32, u32); 42]; +// let mut _7: (u32, u32); +// let mut _8: (u32, u32); +// let mut _9: (u32, u32); +// let mut _10: (u32, u32); +// let mut _11: (u32, u32); +// let mut _12: (u32, u32); +// let mut _13: (u32, u32); +// let mut _14: (u32, u32); +// let mut _15: (u32, u32); +// let mut _16: (u32, u32); +// let mut _17: (u32, u32); +// let mut _18: (u32, u32); +// let mut _19: (u32, u32); +// let mut _20: (u32, u32); +// let mut _21: (u32, u32); +// let mut _22: (u32, u32); +// let mut _23: (u32, u32); +// let mut _24: (u32, u32); +// let mut _25: (u32, u32); +// let mut _26: (u32, u32); +// let mut _27: (u32, u32); +// let mut _28: (u32, u32); +// let mut _29: (u32, u32); +// let mut _30: (u32, u32); +// let mut _31: (u32, u32); +// let mut _32: (u32, u32); +// let mut _33: (u32, u32); +// let mut _34: (u32, u32); +// let mut _35: (u32, u32); +// let mut _36: (u32, u32); +// let mut _37: (u32, u32); +// let mut _38: (u32, u32); +// let mut _39: (u32, u32); +// let mut _40: (u32, u32); +// let mut _41: (u32, u32); +// let mut _42: (u32, u32); +// let mut _43: (u32, u32); +// let mut _44: (u32, u32); +// let mut _45: (u32, u32); +// let mut _46: (u32, u32); +// let mut _47: (u32, u32); +// let mut _48: (u32, u32); // bb0: { -// _7 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:29:9: 29:15 -// _8 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:29:17: 29:23 -// _9 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:29:25: 29:31 -// _10 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:30:9: 30:15 -// _11 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:30:17: 30:23 -// _12 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:30:25: 30:31 -// _13 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:31:9: 31:15 -// _14 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:31:17: 31:23 -// _15 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:31:25: 31:31 -// _16 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:32:9: 32:15 -// _17 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:32:17: 32:23 -// _18 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:32:25: 32:31 -// _19 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:33:9: 33:15 -// _20 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:33:17: 33:23 -// _21 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:33:25: 33:31 -// _22 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:34:9: 34:15 -// _23 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:34:17: 34:23 -// _24 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:34:25: 34:31 -// _25 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:35:9: 35:15 -// _26 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:35:17: 35:23 -// _27 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:35:25: 35:31 -// _28 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:36:9: 36:15 -// _29 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:36:17: 36:23 -// _30 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:36:25: 36:31 -// _31 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:37:9: 37:15 -// _32 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:37:17: 37:23 -// _33 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:37:25: 37:31 -// _34 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:38:9: 38:15 -// _35 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:38:17: 38:23 -// _36 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:38:25: 38:31 -// _37 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:39:9: 39:15 -// _38 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:39:17: 39:23 -// _39 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:39:25: 39:31 -// _40 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:40:9: 40:15 -// _41 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:40:17: 40:23 -// _42 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:40:25: 40:31 -// _43 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:41:9: 41:15 -// _44 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:41:17: 41:23 -// _45 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:41:25: 41:31 -// _46 = (const 0u32, const 1u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:42:9: 42:15 -// _47 = (const 0u32, const 2u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:42:17: 42:23 -// _48 = (const 0u32, const 3u32); // scope 0 at src/test/mir-opt/basic_assignment.rs:42:25: 42:31 -// _6 = [_7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48]; // scope 0 at src/test/mir-opt/basic_assignment.rs:28:12: 43:6 -// _5 = &_6; // scope 0 at src/test/mir-opt/basic_assignment.rs:28:11: 43:6 -// _4 = &(*_5); // scope 0 at src/test/mir-opt/basic_assignment.rs:28:11: 43:6 -// _3 = _4 as &'static [(u32, u32)] (Unsize); // scope 0 at src/test/mir-opt/basic_assignment.rs:28:11: 43:6 -// _2 = Foo { tup: const "hi", data: _3 }; // scope 0 at src/test/mir-opt/basic_assignment.rs:26:29: 44:2 -// _1 = &_2; // scope 0 at src/test/mir-opt/basic_assignment.rs:26:28: 44:2 -// _0 = &(*_1); // scope 0 at src/test/mir-opt/basic_assignment.rs:26:28: 44:2 -// return; // scope 0 at src/test/mir-opt/basic_assignment.rs:26:1: 44:3 +// StorageLive(_1); +// StorageLive(_2); +// StorageLive(_3); +// StorageLive(_4); +// StorageLive(_5); +// StorageLive(_6); +// StorageLive(_7); +// _7 = (const 0u32, const 1u32); +// StorageLive(_8); +// _8 = (const 0u32, const 2u32); +// StorageLive(_9); +// _9 = (const 0u32, const 3u32); +// StorageLive(_10); +// _10 = (const 0u32, const 1u32); +// StorageLive(_11); +// _11 = (const 0u32, const 2u32); +// StorageLive(_12); +// _12 = (const 0u32, const 3u32); +// StorageLive(_13); +// _13 = (const 0u32, const 1u32); +// StorageLive(_14); +// _14 = (const 0u32, const 2u32); +// StorageLive(_15); +// _15 = (const 0u32, const 3u32); +// StorageLive(_16); +// _16 = (const 0u32, const 1u32); +// StorageLive(_17); +// _17 = (const 0u32, const 2u32); +// StorageLive(_18); +// _18 = (const 0u32, const 3u32); +// StorageLive(_19); +// _19 = (const 0u32, const 1u32); +// StorageLive(_20); +// _20 = (const 0u32, const 2u32); +// StorageLive(_21); +// _21 = (const 0u32, const 3u32); +// StorageLive(_22); +// _22 = (const 0u32, const 1u32); +// StorageLive(_23); +// _23 = (const 0u32, const 2u32); +// StorageLive(_24); +// _24 = (const 0u32, const 3u32); +// StorageLive(_25); +// _25 = (const 0u32, const 1u32); +// StorageLive(_26); +// _26 = (const 0u32, const 2u32); +// StorageLive(_27); +// _27 = (const 0u32, const 3u32); +// StorageLive(_28); +// _28 = (const 0u32, const 1u32); +// StorageLive(_29); +// _29 = (const 0u32, const 2u32); +// StorageLive(_30); +// _30 = (const 0u32, const 3u32); +// StorageLive(_31); +// _31 = (const 0u32, const 1u32); +// StorageLive(_32); +// _32 = (const 0u32, const 2u32); +// StorageLive(_33); +// _33 = (const 0u32, const 3u32); +// StorageLive(_34); +// _34 = (const 0u32, const 1u32); +// StorageLive(_35); +// _35 = (const 0u32, const 2u32); +// StorageLive(_36); +// _36 = (const 0u32, const 3u32); +// StorageLive(_37); +// _37 = (const 0u32, const 1u32); +// StorageLive(_38); +// _38 = (const 0u32, const 2u32); +// StorageLive(_39); +// _39 = (const 0u32, const 3u32); +// StorageLive(_40); +// _40 = (const 0u32, const 1u32); +// StorageLive(_41); +// _41 = (const 0u32, const 2u32); +// StorageLive(_42); +// _42 = (const 0u32, const 3u32); +// StorageLive(_43); +// _43 = (const 0u32, const 1u32); +// StorageLive(_44); +// _44 = (const 0u32, const 2u32); +// StorageLive(_45); +// _45 = (const 0u32, const 3u32); +// StorageLive(_46); +// _46 = (const 0u32, const 1u32); +// StorageLive(_47); +// _47 = (const 0u32, const 2u32); +// StorageLive(_48); +// _48 = (const 0u32, const 3u32); +// _6 = [_7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48]; +// _5 = &_6; +// _4 = &(*_5); +// _3 = _4 as &'static [(u32, u32)] (Unsize); +// _2 = Foo { tup: const "hi", data: _3 }; +// _1 = &_2; +// _0 = &(*_1); +// StorageDead(_1); +// StorageDead(_5); +// return; // } +//} // END rustc.node4.mir_map.0.mir diff --git a/src/test/mir-opt/storage_ranges.rs b/src/test/mir-opt/storage_ranges.rs index 3fbd1a36f2f..7dbcf82af34 100644 --- a/src/test/mir-opt/storage_ranges.rs +++ b/src/test/mir-opt/storage_ranges.rs @@ -38,5 +38,6 @@ fn main() { // _0 = (); // StorageDead(_6); // StorageDead(_1); +// return; // } // END rustc.node4.TypeckMir.before.mir diff --git a/src/test/mir-opt/validate_1.rs b/src/test/mir-opt/validate_1.rs index d2ca65775a4..0c570deae24 100644 --- a/src/test/mir-opt/validate_1.rs +++ b/src/test/mir-opt/validate_1.rs @@ -31,12 +31,15 @@ fn main() { // START rustc.node12.EraseRegions.after.mir // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:5) => validate_1[8cd8]::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:5) => validate_1[8cd8]::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]); +// ... // return; // } // END rustc.node12.EraseRegions.after.mir // START rustc.node23.EraseRegions.after.mir // fn main() -> () { +// ... // bb0: { +// ... // Validate(Suspend(ReScope(Node(ItemLocalId(10)))), [_1: i32]); // _6 = &ReErased mut _1; // Validate(Acquire, [(*_6): i32/ReScope(Node(ItemLocalId(10)))]); @@ -50,12 +53,14 @@ fn main() { // bb1: { // Validate(Acquire, [_2: ()]); // EndRegion(ReScope(Node(ItemLocalId(10)))); +// ... // return; // } // } // END rustc.node23.EraseRegions.after.mir // START rustc.node50.EraseRegions.after.mir // fn main::{{closure}}(_1: &ReErased [closure@NodeId(50)], _2: &ReErased mut i32) -> i32 { +// ... // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:11) => validate_1[8cd8]::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:11) => validate_1[8cd8]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); // StorageLive(_3); diff --git a/src/test/mir-opt/validate_2.rs b/src/test/mir-opt/validate_2.rs index 37ebd720d52..aacf5a5ed0f 100644 --- a/src/test/mir-opt/validate_2.rs +++ b/src/test/mir-opt/validate_2.rs @@ -18,10 +18,18 @@ fn main() { // END RUST SOURCE // START rustc.node4.EraseRegions.after.mir // fn main() -> () { +// ... // bb1: { +// Validate(Acquire, [_2: std::boxed::Box<[i32; 3]>]); // Validate(Release, [_2: std::boxed::Box<[i32; 3]>]); // _1 = _2 as std::boxed::Box<[i32]> (Unsize); // Validate(Acquire, [_1: std::boxed::Box<[i32]>]); +// StorageDead(_2); +// StorageDead(_3); +// _0 = (); +// Validate(Release, [_1: std::boxed::Box<[i32]>]); +// drop(_1) -> bb2; // } +// ... // } // END rustc.node4.EraseRegions.after.mir diff --git a/src/test/mir-opt/validate_3.rs b/src/test/mir-opt/validate_3.rs index 116e35b2d6f..d7d3e023c9e 100644 --- a/src/test/mir-opt/validate_3.rs +++ b/src/test/mir-opt/validate_3.rs @@ -30,8 +30,17 @@ fn main() { // END RUST SOURCE // START rustc.node16.EraseRegions.after.mir // fn main() -> () { +// ... // let mut _5: &ReErased i32; // bb0: { +// StorageLive(_1); +// _1 = Test { x: const 0i32 }; +// StorageLive(_2); +// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 }))), [_1: Test]); +// _2 = &ReErased _1; +// Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })) (imm)]); +// StorageLive(_4); +// StorageLive(_5); // Validate(Suspend(ReScope(Node(ItemLocalId(17)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 })) (imm)]); // _5 = &ReErased ((*_2).0: i32); // Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(17))) (imm)]); @@ -42,8 +51,14 @@ fn main() { // _3 = const foo(_4) -> bb1; // } // bb1: { +// Validate(Acquire, [_3: ()]); // EndRegion(ReScope(Node(ItemLocalId(17)))); +// StorageDead(_4); +// StorageDead(_5); +// _0 = (); // EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(19), first_statement_index: 3 }))); +// StorageDead(_2); +// StorageDead(_1); // return; // } // } diff --git a/src/test/mir-opt/validate_4.rs b/src/test/mir-opt/validate_4.rs index d240b51e222..da9a4c7e455 100644 --- a/src/test/mir-opt/validate_4.rs +++ b/src/test/mir-opt/validate_4.rs @@ -38,15 +38,18 @@ fn main() { // END RUST SOURCE // START rustc.node4.EraseRegions.after.mir // fn write_42(_1: *mut i32) -> bool { +// ... // bb0: { // Validate(Acquire, [_1: *mut i32]); // Validate(Release, [_1: *mut i32]); +// ... // return; // } // } // END rustc.node4.EraseRegions.after.mir // START rustc.node22.EraseRegions.after.mir // fn write_42::{{closure}}(_1: &ReErased [closure@NodeId(22)], _2: *mut i32) -> () { +// ... // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_4[8cd8]::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]); // Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_4[8cd8]::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]); @@ -60,24 +63,30 @@ fn main() { // END rustc.node22.EraseRegions.after.mir // START rustc.node31.EraseRegions.after.mir // fn test(_1: &ReErased mut i32) -> () { +// ... // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_4[8cd8]::test[0] }, BrAnon(0)) mut i32]); // Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_4[8cd8]::test[0] }, BrAnon(0)) mut i32]); +// ... // _3 = const write_42(_4) -> bb1; // } // bb1: { // Validate(Acquire, [_3: bool]); // Validate(Release, [_3: bool]); +// ... // } // } // END rustc.node31.EraseRegions.after.mir // START rustc.node60.EraseRegions.after.mir // fn main::{{closure}}(_1: &ReErased [closure@NodeId(60)], _2: &ReErased mut i32) -> bool { +// ... // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[8cd8]::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[8cd8]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); // Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[8cd8]::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[8cd8]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); // StorageLive(_3); +// ... // _0 = const write_42(_4) -> bb1; // } +// ... // } // END rustc.node60.EraseRegions.after.mir diff --git a/src/test/mir-opt/validate_5.rs b/src/test/mir-opt/validate_5.rs index e1eeb2102d1..0ece83afa13 100644 --- a/src/test/mir-opt/validate_5.rs +++ b/src/test/mir-opt/validate_5.rs @@ -35,15 +35,19 @@ fn main() { // END RUST SOURCE // START rustc.node17.EraseRegions.after.mir // fn test(_1: &ReErased mut i32) -> () { +// ... // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_5[8cd8]::test[0] }, BrAnon(0)) mut i32]); +// ... // Validate(Release, [_3: bool, _4: *mut i32]); // _3 = const write_42(_4) -> bb1; // } +// ... // } // END rustc.node17.EraseRegions.after.mir // START rustc.node46.EraseRegions.after.mir // fn main::{{closure}}(_1: &ReErased [closure@NodeId(46)], _2: &ReErased mut i32) -> bool { +// ... // bb0: { // Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[8cd8]::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[8cd8]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); // StorageLive(_3); @@ -59,5 +63,6 @@ fn main() { // Validate(Release, [_0: bool, _4: *mut i32]); // _0 = const write_42(_4) -> bb1; // } +// ... // } // END rustc.node46.EraseRegions.after.mir