Skip to content

Commit de7e29e

Browse files
authored
Rollup merge of #110773 - mj10021:issue-109502-fix, r=oli-obk
Reduce MIR dump file count for MIR-opt tests As referenced in issue #109502 , mir-opt tests previously used the -Zdump-mir=all flag, which generates very large output. This PR only dumps the passes under test, greatly reducing dump output.
2 parents 4891f02 + c19959f commit de7e29e

8 files changed

+164
-102
lines changed

src/tools/compiletest/src/runtest.rs

+66-21
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ impl<'test> TestCx<'test> {
319319

320320
fn run_cfail_test(&self) {
321321
let pm = self.pass_mode();
322-
let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm));
322+
let proc_res =
323+
self.compile_test(WillExecute::No, self.should_emit_metadata(pm), Vec::new());
323324
self.check_if_test_should_compile(&proc_res, pm);
324325
self.check_no_compiler_crash(&proc_res, self.props.should_ice);
325326

@@ -347,7 +348,7 @@ impl<'test> TestCx<'test> {
347348
fn run_rfail_test(&self) {
348349
let pm = self.pass_mode();
349350
let should_run = self.run_if_enabled();
350-
let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm));
351+
let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm), Vec::new());
351352

352353
if !proc_res.status.success() {
353354
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -395,7 +396,7 @@ impl<'test> TestCx<'test> {
395396

396397
fn run_cpass_test(&self) {
397398
let emit_metadata = self.should_emit_metadata(self.pass_mode());
398-
let proc_res = self.compile_test(WillExecute::No, emit_metadata);
399+
let proc_res = self.compile_test(WillExecute::No, emit_metadata, Vec::new());
399400

400401
if !proc_res.status.success() {
401402
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -410,7 +411,7 @@ impl<'test> TestCx<'test> {
410411
fn run_rpass_test(&self) {
411412
let emit_metadata = self.should_emit_metadata(self.pass_mode());
412413
let should_run = self.run_if_enabled();
413-
let proc_res = self.compile_test(should_run, emit_metadata);
414+
let proc_res = self.compile_test(should_run, emit_metadata, Vec::new());
414415

415416
if !proc_res.status.success() {
416417
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -440,7 +441,7 @@ impl<'test> TestCx<'test> {
440441
}
441442

442443
let should_run = self.run_if_enabled();
443-
let mut proc_res = self.compile_test(should_run, Emit::None);
444+
let mut proc_res = self.compile_test(should_run, Emit::None, Vec::new());
444445

445446
if !proc_res.status.success() {
446447
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -686,7 +687,7 @@ impl<'test> TestCx<'test> {
686687

687688
// compile test file (it should have 'compile-flags:-g' in the header)
688689
let should_run = self.run_if_enabled();
689-
let compile_result = self.compile_test(should_run, Emit::None);
690+
let compile_result = self.compile_test(should_run, Emit::None, Vec::new());
690691
if !compile_result.status.success() {
691692
self.fatal_proc_rec("compilation failed!", &compile_result);
692693
}
@@ -806,7 +807,7 @@ impl<'test> TestCx<'test> {
806807

807808
// compile test file (it should have 'compile-flags:-g' in the header)
808809
let should_run = self.run_if_enabled();
809-
let compiler_run_result = self.compile_test(should_run, Emit::None);
810+
let compiler_run_result = self.compile_test(should_run, Emit::None, Vec::new());
810811
if !compiler_run_result.status.success() {
811812
self.fatal_proc_rec("compilation failed!", &compiler_run_result);
812813
}
@@ -1043,7 +1044,7 @@ impl<'test> TestCx<'test> {
10431044
fn run_debuginfo_lldb_test_no_opt(&self) {
10441045
// compile test file (it should have 'compile-flags:-g' in the header)
10451046
let should_run = self.run_if_enabled();
1046-
let compile_result = self.compile_test(should_run, Emit::None);
1047+
let compile_result = self.compile_test(should_run, Emit::None, Vec::new());
10471048
if !compile_result.status.success() {
10481049
self.fatal_proc_rec("compilation failed!", &compile_result);
10491050
}
@@ -1482,15 +1483,16 @@ impl<'test> TestCx<'test> {
14821483
}
14831484
}
14841485

1485-
fn compile_test(&self, will_execute: WillExecute, emit: Emit) -> ProcRes {
1486-
self.compile_test_general(will_execute, emit, self.props.local_pass_mode())
1486+
fn compile_test(&self, will_execute: WillExecute, emit: Emit, passes: Vec<String>) -> ProcRes {
1487+
self.compile_test_general(will_execute, emit, self.props.local_pass_mode(), passes)
14871488
}
14881489

14891490
fn compile_test_general(
14901491
&self,
14911492
will_execute: WillExecute,
14921493
emit: Emit,
14931494
local_pm: Option<PassMode>,
1495+
passes: Vec<String>,
14941496
) -> ProcRes {
14951497
// Only use `make_exe_name` when the test ends up being executed.
14961498
let output_file = match will_execute {
@@ -1527,6 +1529,7 @@ impl<'test> TestCx<'test> {
15271529
emit,
15281530
allow_unused,
15291531
LinkToAux::Yes,
1532+
passes,
15301533
);
15311534

15321535
self.compose_and_run_compiler(rustc, None)
@@ -1777,6 +1780,7 @@ impl<'test> TestCx<'test> {
17771780
Emit::None,
17781781
AllowUnused::No,
17791782
LinkToAux::No,
1783+
Vec::new(),
17801784
);
17811785

17821786
for key in &aux_props.unset_rustc_env {
@@ -1908,6 +1912,7 @@ impl<'test> TestCx<'test> {
19081912
emit: Emit,
19091913
allow_unused: AllowUnused,
19101914
link_to_aux: LinkToAux,
1915+
passes: Vec<String>, // Vec of passes under mir-opt test to be dumped
19111916
) -> Command {
19121917
let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
19131918
let is_rustdoc = self.is_rustdoc() && !is_aux;
@@ -2008,9 +2013,18 @@ impl<'test> TestCx<'test> {
20082013
rustc.arg("-Cstrip=debuginfo");
20092014
}
20102015
MirOpt => {
2016+
// We check passes under test to minimize the mir-opt test dump
2017+
// if files_for_miropt_test parses the passes, we dump only those passes
2018+
// otherwise we conservatively pass -Zdump-mir=all
2019+
let zdump_arg = if !passes.is_empty() {
2020+
format!("-Zdump-mir={}", passes.join(" | "))
2021+
} else {
2022+
"-Zdump-mir=all".to_string()
2023+
};
2024+
20112025
rustc.args(&[
20122026
"-Copt-level=1",
2013-
"-Zdump-mir=all",
2027+
&zdump_arg,
20142028
"-Zvalidate-mir",
20152029
"-Zdump-mir-exclude-pass-number",
20162030
"-Zmir-pretty-relative-line-numbers=yes",
@@ -2333,6 +2347,7 @@ impl<'test> TestCx<'test> {
23332347
Emit::LlvmIr,
23342348
AllowUnused::No,
23352349
LinkToAux::Yes,
2350+
Vec::new(),
23362351
);
23372352

23382353
self.compose_and_run_compiler(rustc, None)
@@ -2364,8 +2379,14 @@ impl<'test> TestCx<'test> {
23642379
None => self.fatal("missing 'assembly-output' header"),
23652380
}
23662381

2367-
let rustc =
2368-
self.make_compile_args(input_file, output_file, emit, AllowUnused::No, LinkToAux::Yes);
2382+
let rustc = self.make_compile_args(
2383+
input_file,
2384+
output_file,
2385+
emit,
2386+
AllowUnused::No,
2387+
LinkToAux::Yes,
2388+
Vec::new(),
2389+
);
23692390

23702391
(self.compose_and_run_compiler(rustc, None), output_path)
23712392
}
@@ -2496,6 +2517,7 @@ impl<'test> TestCx<'test> {
24962517
Emit::None,
24972518
AllowUnused::Yes,
24982519
LinkToAux::Yes,
2520+
Vec::new(),
24992521
);
25002522
new_rustdoc.build_all_auxiliary(&mut rustc);
25012523

@@ -2769,7 +2791,7 @@ impl<'test> TestCx<'test> {
27692791
fn run_codegen_units_test(&self) {
27702792
assert!(self.revision.is_none(), "revisions not relevant here");
27712793

2772-
let proc_res = self.compile_test(WillExecute::No, Emit::None);
2794+
let proc_res = self.compile_test(WillExecute::No, Emit::None, Vec::new());
27732795

27742796
if !proc_res.status.success() {
27752797
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -3310,14 +3332,15 @@ impl<'test> TestCx<'test> {
33103332
if let Some(FailMode::Build) = self.props.fail_mode {
33113333
// Make sure a build-fail test cannot fail due to failing analysis (e.g. typeck).
33123334
let pm = Some(PassMode::Check);
3313-
let proc_res = self.compile_test_general(WillExecute::No, Emit::Metadata, pm);
3335+
let proc_res =
3336+
self.compile_test_general(WillExecute::No, Emit::Metadata, pm, Vec::new());
33143337
self.check_if_test_should_compile(&proc_res, pm);
33153338
}
33163339

33173340
let pm = self.pass_mode();
33183341
let should_run = self.should_run(pm);
33193342
let emit_metadata = self.should_emit_metadata(pm);
3320-
let proc_res = self.compile_test(should_run, emit_metadata);
3343+
let proc_res = self.compile_test(should_run, emit_metadata, Vec::new());
33213344
self.check_if_test_should_compile(&proc_res, pm);
33223345

33233346
// if the user specified a format in the ui test
@@ -3479,6 +3502,7 @@ impl<'test> TestCx<'test> {
34793502
emit_metadata,
34803503
AllowUnused::No,
34813504
LinkToAux::Yes,
3505+
Vec::new(),
34823506
);
34833507
let res = self.compose_and_run_compiler(rustc, None);
34843508
if !res.status.success() {
@@ -3497,14 +3521,14 @@ impl<'test> TestCx<'test> {
34973521
let pm = self.pass_mode();
34983522
let should_run = self.should_run(pm);
34993523
let emit_metadata = self.should_emit_metadata(pm);
3500-
let proc_res = self.compile_test(should_run, emit_metadata);
3524+
let passes = self.get_passes();
35013525

3526+
let proc_res = self.compile_test(should_run, emit_metadata, passes);
3527+
self.check_mir_dump();
35023528
if !proc_res.status.success() {
35033529
self.fatal_proc_rec("compilation failed!", &proc_res);
35043530
}
35053531

3506-
self.check_mir_dump();
3507-
35083532
if let WillExecute::Yes = should_run {
35093533
let proc_res = self.exec_compiled_test();
35103534

@@ -3514,6 +3538,26 @@ impl<'test> TestCx<'test> {
35143538
}
35153539
}
35163540

3541+
fn get_passes(&self) -> Vec<String> {
3542+
let files = miropt_test_tools::files_for_miropt_test(
3543+
&self.testpaths.file,
3544+
self.config.get_pointer_width(),
3545+
);
3546+
3547+
let mut out = Vec::new();
3548+
3549+
for miropt_test_tools::MiroptTestFiles {
3550+
from_file: _,
3551+
to_file: _,
3552+
expected_file: _,
3553+
passes,
3554+
} in files
3555+
{
3556+
out.extend(passes);
3557+
}
3558+
out
3559+
}
3560+
35173561
fn check_mir_dump(&self) {
35183562
let test_file_contents = fs::read_to_string(&self.testpaths.file).unwrap();
35193563

@@ -3543,8 +3587,9 @@ impl<'test> TestCx<'test> {
35433587
&self.testpaths.file,
35443588
self.config.get_pointer_width(),
35453589
);
3546-
3547-
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file } in files {
3590+
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file, passes: _ } in
3591+
files
3592+
{
35483593
let dumped_string = if let Some(after) = to_file {
35493594
self.diff_mir_files(from_file.into(), after.into())
35503595
} else {

src/tools/miropt-test-tools/src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pub struct MiroptTestFiles {
44
pub expected_file: std::path::PathBuf,
55
pub from_file: String,
66
pub to_file: Option<String>,
7+
/// Vec of passes under test to be dumped
8+
pub passes: Vec<String>,
79
}
810

911
pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<MiroptTestFiles> {
@@ -28,17 +30,26 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
2830
let mut expected_file;
2931
let from_file;
3032
let to_file;
33+
let mut passes = Vec::new();
3134

3235
if test_name.ends_with(".diff") {
3336
let trimmed = test_name.trim_end_matches(".diff");
37+
passes.push(trimmed.split('.').last().unwrap().to_owned());
3438
let test_against = format!("{}.after.mir", trimmed);
3539
from_file = format!("{}.before.mir", trimmed);
3640
expected_file = format!("{}{}.diff", trimmed, bit_width);
3741
assert!(test_names.next().is_none(), "two mir pass names specified for MIR diff");
3842
to_file = Some(test_against);
3943
} else if let Some(first_pass) = test_names.next() {
4044
let second_pass = test_names.next().unwrap();
45+
if let Some((first_pass_name, _)) = first_pass.split_once('.') {
46+
passes.push(first_pass_name.to_owned());
47+
}
48+
if let Some((second_pass_name, _)) = second_pass.split_once('.') {
49+
passes.push(second_pass_name.to_owned());
50+
}
4151
assert!(test_names.next().is_none(), "three mir pass names specified for MIR diff");
52+
4253
expected_file =
4354
format!("{}{}.{}-{}.diff", test_name, bit_width, first_pass, second_pass);
4455
let second_file = format!("{}.{}.mir", test_name, second_pass);
@@ -51,18 +62,24 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
5162
.next()
5263
.expect("test_name has an invalid extension");
5364
let extension = cap.get(1).unwrap().as_str();
65+
5466
expected_file =
5567
format!("{}{}{}", test_name.trim_end_matches(extension), bit_width, extension,);
5668
from_file = test_name.to_string();
5769
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
5870
to_file = None;
71+
// the pass name is the third to last string in the test name
72+
// this gets pushed into passes
73+
passes.push(
74+
test_name.split('.').rev().nth(2).expect("invalid test format").to_string(),
75+
);
5976
};
6077
if !expected_file.starts_with(&test_crate) {
6178
expected_file = format!("{}.{}", test_crate, expected_file);
6279
}
6380
let expected_file = test_dir.join(expected_file);
6481

65-
out.push(MiroptTestFiles { expected_file, from_file, to_file });
82+
out.push(MiroptTestFiles { expected_file, from_file, to_file, passes });
6683
}
6784
}
6885

tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir

+16-16
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ fn main() -> () {
2121
}
2222

2323
alloc1 (static: FOO, size: 8, align: 4) {
24-
╾─alloc18─╼ 03 00 00 00 │ ╾──╼....
24+
╾─alloc19─╼ 03 00 00 00 │ ╾──╼....
2525
}
2626

27-
alloc18 (size: 48, align: 4) {
28-
0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc5──╼ 00 00 00 00 │ ....░░░░╾──╼....
29-
0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc8──╼ 02 00 00 00 │ ....░░░░╾──╼....
30-
0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc13─╼ 03 00 00 00 │ ....*...╾──╼....
27+
alloc19 (size: 48, align: 4) {
28+
0x00 │ 00 00 00 00 __ __ __ __ ╾─alloc6──╼ 00 00 00 00 │ ....░░░░╾──╼....
29+
0x10 │ 00 00 00 00 __ __ __ __ ╾─alloc9──╼ 02 00 00 00 │ ....░░░░╾──╼....
30+
0x20 │ 01 00 00 00 2a 00 00 00 ╾─alloc14─╼ 03 00 00 00 │ ....*...╾──╼....
3131
}
3232

33-
alloc5 (size: 0, align: 4) {}
33+
alloc6 (size: 0, align: 4) {}
3434

35-
alloc8 (size: 16, align: 4) {
36-
╾─alloc9──╼ 03 00 00 00 ╾─alloc10─╼ 03 00 00 00 │ ╾──╼....╾──╼....
35+
alloc9 (size: 16, align: 4) {
36+
╾─alloc10─╼ 03 00 00 00 ╾─alloc11─╼ 03 00 00 00 │ ╾──╼....╾──╼....
3737
}
3838

39-
alloc9 (size: 3, align: 1) {
39+
alloc10 (size: 3, align: 1) {
4040
66 6f 6f │ foo
4141
}
4242

43-
alloc10 (size: 3, align: 1) {
43+
alloc11 (size: 3, align: 1) {
4444
62 61 72 │ bar
4545
}
4646

47-
alloc13 (size: 24, align: 4) {
48-
0x00 │ ╾─alloc14─╼ 03 00 00 00 ╾─alloc15─╼ 03 00 00 00 │ ╾──╼....╾──╼....
49-
0x10 │ ╾─alloc16─╼ 04 00 00 00 │ ╾──╼....
47+
alloc14 (size: 24, align: 4) {
48+
0x00 │ ╾─alloc15─╼ 03 00 00 00 ╾─alloc16─╼ 03 00 00 00 │ ╾──╼....╾──╼....
49+
0x10 │ ╾─alloc17─╼ 04 00 00 00 │ ╾──╼....
5050
}
5151

52-
alloc14 (size: 3, align: 1) {
52+
alloc15 (size: 3, align: 1) {
5353
6d 65 68 │ meh
5454
}
5555

56-
alloc15 (size: 3, align: 1) {
56+
alloc16 (size: 3, align: 1) {
5757
6d 6f 70 │ mop
5858
}
5959

60-
alloc16 (size: 4, align: 1) {
60+
alloc17 (size: 4, align: 1) {
6161
6d c3 b6 70 │ m..p
6262
}

0 commit comments

Comments
 (0)