Skip to content

Commit d0e0f40

Browse files
committed
Remove old mir-opt test format.
1 parent ea4aca1 commit d0e0f40

File tree

2 files changed

+2
-244
lines changed

2 files changed

+2
-244
lines changed

src/test/mir-opt/README.md

+2-80
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
This folder contains tests for MIR optimizations.
22

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

86
# `--bless`able test format
97

@@ -39,79 +37,3 @@ This exists mainly for completeness and is rarely useful.
3937
```
4038
// EMIT_MIR $file_name_of_some_mir_dump.before.mir
4139
```
42-
43-
# Inline test format
44-
45-
```
46-
(arbitrary rust code)
47-
// END RUST SOURCE
48-
// START $file_name_of_some_mir_dump_0
49-
// $expected_line_0
50-
// (lines or elision)
51-
// $expected_line_N
52-
// END $file_name_of_some_mir_dump_0
53-
// (lines or elision)
54-
// START $file_name_of_some_mir_dump_N
55-
// $expected_line_0
56-
// (lines or elision)
57-
// $expected_line_N
58-
// END $file_name_of_some_mir_dump_N
59-
```
60-
61-
All the test information is in comments so the test is runnable.
62-
63-
For each $file_name, compiletest expects [$expected_line_0, ...,
64-
$expected_line_N] to appear in the dumped MIR in order. Currently it allows
65-
other non-matched lines before and after, but not between $expected_lines,
66-
should you want to skip lines, you must include an elision comment, of the form
67-
(as a regex) `//\s*...\s*`. The lines will be skipped lazily, that is, if there
68-
are two identical lines in the output that match the line after the elision
69-
comment, the first one will be matched.
70-
71-
Examples:
72-
73-
The following blocks will not match the one after it.
74-
75-
```
76-
bb0: {
77-
StorageLive(_1);
78-
_1 = const true;
79-
StorageDead(_1);
80-
}
81-
```
82-
83-
```
84-
bb0: {
85-
StorageLive(_1);
86-
_1 = const true;
87-
goto -> bb1
88-
}
89-
bb1: {
90-
StorageDead(_1);
91-
return;
92-
}
93-
```
94-
95-
But this will match the one above,
96-
97-
```
98-
bb0: {
99-
StorageLive(_1);
100-
_1 = const true;
101-
...
102-
StorageDead(_1);
103-
...
104-
}
105-
```
106-
107-
Lines match ignoring whitespace, and the prefix "//" is removed.
108-
109-
It also currently strips trailing comments -- partly because the full file path
110-
in "scope comments" is unpredictable and partly because tidy complains about
111-
the lines being too long.
112-
113-
compiletest handles dumping the MIR before and after every pass for you. The
114-
test writer only has to specify the file names of the dumped files (not the
115-
full path to the file) and what lines to expect. There is an option to rustc
116-
that tells it to dump the mir into some directly (rather then always dumping to
117-
the current directory).

src/tools/compiletest/src/runtest.rs

-164
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::collections::hash_map::DefaultHasher;
2121
use std::collections::{HashMap, HashSet, VecDeque};
2222
use std::env;
2323
use std::ffi::{OsStr, OsString};
24-
use std::fmt;
2524
use std::fs::{self, create_dir_all, File, OpenOptions};
2625
use std::hash::{Hash, Hasher};
2726
use std::io::prelude::*;
@@ -3156,36 +3155,6 @@ impl<'test> TestCx<'test> {
31563155
}
31573156
}
31583157
}
3159-
3160-
if let Some(idx) = test_file_contents.find("// END RUST SOURCE") {
3161-
let (_, tests_text) = test_file_contents.split_at(idx + "// END_RUST SOURCE".len());
3162-
let tests_text_str = String::from(tests_text);
3163-
let mut curr_test: Option<&str> = None;
3164-
let mut curr_test_contents = vec![ExpectedLine::Elision];
3165-
for l in tests_text_str.lines() {
3166-
debug!("line: {:?}", l);
3167-
if l.starts_with("// START ") {
3168-
let (_, t) = l.split_at("// START ".len());
3169-
curr_test = Some(t);
3170-
} else if l.starts_with("// END") {
3171-
let (_, t) = l.split_at("// END ".len());
3172-
if Some(t) != curr_test {
3173-
panic!("mismatched START END test name");
3174-
}
3175-
self.compare_mir_test_output(curr_test.unwrap(), &curr_test_contents);
3176-
curr_test = None;
3177-
curr_test_contents.clear();
3178-
curr_test_contents.push(ExpectedLine::Elision);
3179-
} else if l.is_empty() {
3180-
// ignore
3181-
} else if l.starts_with("//") && l.split_at("//".len()).1.trim() == "..." {
3182-
curr_test_contents.push(ExpectedLine::Elision)
3183-
} else if l.starts_with("// ") {
3184-
let (_, test_content) = l.split_at("// ".len());
3185-
curr_test_contents.push(ExpectedLine::Text(test_content));
3186-
}
3187-
}
3188-
}
31893158
}
31903159

31913160
fn check_mir_test_timestamp(&self, test_name: &str, output_file: &Path) {
@@ -3203,107 +3172,6 @@ impl<'test> TestCx<'test> {
32033172
}
32043173
}
32053174

3206-
fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedLine<&str>]) {
3207-
let mut output_file = PathBuf::new();
3208-
output_file.push(self.get_mir_dump_dir());
3209-
output_file.push(test_name);
3210-
debug!("comparing the contents of: {:?}", output_file);
3211-
debug!("with: {:?}", expected_content);
3212-
if !output_file.exists() {
3213-
panic!("Output file `{}` from test does not exist", output_file.display());
3214-
}
3215-
self.check_mir_test_timestamp(test_name, &output_file);
3216-
3217-
let dumped_string = fs::read_to_string(&output_file).unwrap();
3218-
let mut dumped_lines =
3219-
dumped_string.lines().map(|l| nocomment_mir_line(l)).filter(|l| !l.is_empty());
3220-
let mut expected_lines = expected_content
3221-
.iter()
3222-
.filter(|&l| if let &ExpectedLine::Text(l) = l { !l.is_empty() } else { true })
3223-
.peekable();
3224-
3225-
let compare = |expected_line, dumped_line| {
3226-
let e_norm = normalize_mir_line(expected_line);
3227-
let d_norm = normalize_mir_line(dumped_line);
3228-
debug!("found: {:?}", d_norm);
3229-
debug!("expected: {:?}", e_norm);
3230-
e_norm == d_norm
3231-
};
3232-
3233-
let error = |expected_line, extra_msg| {
3234-
let normalize_all = dumped_string
3235-
.lines()
3236-
.map(nocomment_mir_line)
3237-
.filter(|l| !l.is_empty())
3238-
.collect::<Vec<_>>()
3239-
.join("\n");
3240-
let f = |l: &ExpectedLine<_>| match l {
3241-
&ExpectedLine::Elision => "... (elided)".into(),
3242-
&ExpectedLine::Text(t) => t,
3243-
};
3244-
let expected_content =
3245-
expected_content.iter().map(|l| f(l)).collect::<Vec<_>>().join("\n");
3246-
panic!(
3247-
"Did not find expected line, error: {}\n\
3248-
Expected Line: {:?}\n\
3249-
Test Name: {}\n\
3250-
Expected:\n{}\n\
3251-
Actual:\n{}",
3252-
extra_msg, expected_line, test_name, expected_content, normalize_all
3253-
);
3254-
};
3255-
3256-
// We expect each non-empty line to appear consecutively, non-consecutive lines
3257-
// must be separated by at least one Elision
3258-
let mut start_block_line = None;
3259-
while let Some(dumped_line) = dumped_lines.next() {
3260-
match expected_lines.next() {
3261-
Some(&ExpectedLine::Text(expected_line)) => {
3262-
let normalized_expected_line = normalize_mir_line(expected_line);
3263-
if normalized_expected_line.contains(":{") {
3264-
start_block_line = Some(expected_line);
3265-
}
3266-
3267-
if !compare(expected_line, dumped_line) {
3268-
error!("{:?}", start_block_line);
3269-
error(
3270-
expected_line,
3271-
format!(
3272-
"Mismatch in lines\n\
3273-
Current block: {}\n\
3274-
Actual Line: {:?}",
3275-
start_block_line.unwrap_or("None"),
3276-
dumped_line
3277-
),
3278-
);
3279-
}
3280-
}
3281-
Some(&ExpectedLine::Elision) => {
3282-
// skip any number of elisions in a row.
3283-
while let Some(&&ExpectedLine::Elision) = expected_lines.peek() {
3284-
expected_lines.next();
3285-
}
3286-
if let Some(&ExpectedLine::Text(expected_line)) = expected_lines.next() {
3287-
let mut found = compare(expected_line, dumped_line);
3288-
if found {
3289-
continue;
3290-
}
3291-
while let Some(dumped_line) = dumped_lines.next() {
3292-
found = compare(expected_line, dumped_line);
3293-
if found {
3294-
break;
3295-
}
3296-
}
3297-
if !found {
3298-
error(expected_line, "ran out of mir dump to match against".into());
3299-
}
3300-
}
3301-
}
3302-
None => {}
3303-
}
3304-
}
3305-
}
3306-
33073175
fn get_mir_dump_dir(&self) -> PathBuf {
33083176
let mut mir_dump_dir = PathBuf::from(self.config.build_base.as_path());
33093177
debug!("input_file: {:?}", self.testpaths.file);
@@ -3589,43 +3457,11 @@ enum TargetLocation {
35893457
ThisDirectory(PathBuf),
35903458
}
35913459

3592-
#[derive(Clone, PartialEq, Eq)]
3593-
enum ExpectedLine<T: AsRef<str>> {
3594-
Elision,
3595-
Text(T),
3596-
}
3597-
35983460
enum AllowUnused {
35993461
Yes,
36003462
No,
36013463
}
36023464

3603-
impl<T> fmt::Debug for ExpectedLine<T>
3604-
where
3605-
T: AsRef<str> + fmt::Debug,
3606-
{
3607-
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
3608-
if let &ExpectedLine::Text(ref t) = self {
3609-
write!(formatter, "{:?}", t)
3610-
} else {
3611-
write!(formatter, "\"...\" (Elision)")
3612-
}
3613-
}
3614-
}
3615-
3616-
fn normalize_mir_line(line: &str) -> String {
3617-
nocomment_mir_line(line).replace(char::is_whitespace, "")
3618-
}
3619-
3620-
fn nocomment_mir_line(line: &str) -> &str {
3621-
if let Some(idx) = line.find("//") {
3622-
let (l, _) = line.split_at(idx);
3623-
l.trim_end()
3624-
} else {
3625-
line
3626-
}
3627-
}
3628-
36293465
fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
36303466
use crate::read2::read2;
36313467
use std::mem::replace;

0 commit comments

Comments
 (0)