@@ -319,7 +319,8 @@ impl<'test> TestCx<'test> {
319
319
320
320
fn run_cfail_test ( & self ) {
321
321
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 ( ) ) ;
323
324
self . check_if_test_should_compile ( & proc_res, pm) ;
324
325
self . check_no_compiler_crash ( & proc_res, self . props . should_ice ) ;
325
326
@@ -347,7 +348,7 @@ impl<'test> TestCx<'test> {
347
348
fn run_rfail_test ( & self ) {
348
349
let pm = self . pass_mode ( ) ;
349
350
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 ( ) ) ;
351
352
352
353
if !proc_res. status . success ( ) {
353
354
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
@@ -395,7 +396,7 @@ impl<'test> TestCx<'test> {
395
396
396
397
fn run_cpass_test ( & self ) {
397
398
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 ( ) ) ;
399
400
400
401
if !proc_res. status . success ( ) {
401
402
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
@@ -410,7 +411,7 @@ impl<'test> TestCx<'test> {
410
411
fn run_rpass_test ( & self ) {
411
412
let emit_metadata = self . should_emit_metadata ( self . pass_mode ( ) ) ;
412
413
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 ( ) ) ;
414
415
415
416
if !proc_res. status . success ( ) {
416
417
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
@@ -440,7 +441,7 @@ impl<'test> TestCx<'test> {
440
441
}
441
442
442
443
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 ( ) ) ;
444
445
445
446
if !proc_res. status . success ( ) {
446
447
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
@@ -686,7 +687,7 @@ impl<'test> TestCx<'test> {
686
687
687
688
// compile test file (it should have 'compile-flags:-g' in the header)
688
689
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 ( ) ) ;
690
691
if !compile_result. status . success ( ) {
691
692
self . fatal_proc_rec ( "compilation failed!" , & compile_result) ;
692
693
}
@@ -806,7 +807,7 @@ impl<'test> TestCx<'test> {
806
807
807
808
// compile test file (it should have 'compile-flags:-g' in the header)
808
809
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 ( ) ) ;
810
811
if !compiler_run_result. status . success ( ) {
811
812
self . fatal_proc_rec ( "compilation failed!" , & compiler_run_result) ;
812
813
}
@@ -1043,7 +1044,7 @@ impl<'test> TestCx<'test> {
1043
1044
fn run_debuginfo_lldb_test_no_opt ( & self ) {
1044
1045
// compile test file (it should have 'compile-flags:-g' in the header)
1045
1046
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 ( ) ) ;
1047
1048
if !compile_result. status . success ( ) {
1048
1049
self . fatal_proc_rec ( "compilation failed!" , & compile_result) ;
1049
1050
}
@@ -1482,15 +1483,16 @@ impl<'test> TestCx<'test> {
1482
1483
}
1483
1484
}
1484
1485
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 )
1487
1488
}
1488
1489
1489
1490
fn compile_test_general (
1490
1491
& self ,
1491
1492
will_execute : WillExecute ,
1492
1493
emit : Emit ,
1493
1494
local_pm : Option < PassMode > ,
1495
+ passes : Vec < String > ,
1494
1496
) -> ProcRes {
1495
1497
// Only use `make_exe_name` when the test ends up being executed.
1496
1498
let output_file = match will_execute {
@@ -1527,6 +1529,7 @@ impl<'test> TestCx<'test> {
1527
1529
emit,
1528
1530
allow_unused,
1529
1531
LinkToAux :: Yes ,
1532
+ passes,
1530
1533
) ;
1531
1534
1532
1535
self . compose_and_run_compiler ( rustc, None )
@@ -1777,6 +1780,7 @@ impl<'test> TestCx<'test> {
1777
1780
Emit :: None ,
1778
1781
AllowUnused :: No ,
1779
1782
LinkToAux :: No ,
1783
+ Vec :: new ( ) ,
1780
1784
) ;
1781
1785
1782
1786
for key in & aux_props. unset_rustc_env {
@@ -1908,6 +1912,7 @@ impl<'test> TestCx<'test> {
1908
1912
emit : Emit ,
1909
1913
allow_unused : AllowUnused ,
1910
1914
link_to_aux : LinkToAux ,
1915
+ passes : Vec < String > , // Vec of passes under mir-opt test to be dumped
1911
1916
) -> Command {
1912
1917
let is_aux = input_file. components ( ) . map ( |c| c. as_os_str ( ) ) . any ( |c| c == "auxiliary" ) ;
1913
1918
let is_rustdoc = self . is_rustdoc ( ) && !is_aux;
@@ -2008,9 +2013,18 @@ impl<'test> TestCx<'test> {
2008
2013
rustc. arg ( "-Cstrip=debuginfo" ) ;
2009
2014
}
2010
2015
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
+
2011
2025
rustc. args ( & [
2012
2026
"-Copt-level=1" ,
2013
- "-Zdump-mir=all" ,
2027
+ & zdump_arg ,
2014
2028
"-Zvalidate-mir" ,
2015
2029
"-Zdump-mir-exclude-pass-number" ,
2016
2030
"-Zmir-pretty-relative-line-numbers=yes" ,
@@ -2333,6 +2347,7 @@ impl<'test> TestCx<'test> {
2333
2347
Emit :: LlvmIr ,
2334
2348
AllowUnused :: No ,
2335
2349
LinkToAux :: Yes ,
2350
+ Vec :: new ( ) ,
2336
2351
) ;
2337
2352
2338
2353
self . compose_and_run_compiler ( rustc, None )
@@ -2364,8 +2379,14 @@ impl<'test> TestCx<'test> {
2364
2379
None => self . fatal ( "missing 'assembly-output' header" ) ,
2365
2380
}
2366
2381
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
+ ) ;
2369
2390
2370
2391
( self . compose_and_run_compiler ( rustc, None ) , output_path)
2371
2392
}
@@ -2496,6 +2517,7 @@ impl<'test> TestCx<'test> {
2496
2517
Emit :: None ,
2497
2518
AllowUnused :: Yes ,
2498
2519
LinkToAux :: Yes ,
2520
+ Vec :: new ( ) ,
2499
2521
) ;
2500
2522
new_rustdoc. build_all_auxiliary ( & mut rustc) ;
2501
2523
@@ -2769,7 +2791,7 @@ impl<'test> TestCx<'test> {
2769
2791
fn run_codegen_units_test ( & self ) {
2770
2792
assert ! ( self . revision. is_none( ) , "revisions not relevant here" ) ;
2771
2793
2772
- let proc_res = self . compile_test ( WillExecute :: No , Emit :: None ) ;
2794
+ let proc_res = self . compile_test ( WillExecute :: No , Emit :: None , Vec :: new ( ) ) ;
2773
2795
2774
2796
if !proc_res. status . success ( ) {
2775
2797
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
@@ -3310,14 +3332,15 @@ impl<'test> TestCx<'test> {
3310
3332
if let Some ( FailMode :: Build ) = self . props . fail_mode {
3311
3333
// Make sure a build-fail test cannot fail due to failing analysis (e.g. typeck).
3312
3334
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 ( ) ) ;
3314
3337
self . check_if_test_should_compile ( & proc_res, pm) ;
3315
3338
}
3316
3339
3317
3340
let pm = self . pass_mode ( ) ;
3318
3341
let should_run = self . should_run ( pm) ;
3319
3342
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 ( ) ) ;
3321
3344
self . check_if_test_should_compile ( & proc_res, pm) ;
3322
3345
3323
3346
// if the user specified a format in the ui test
@@ -3479,6 +3502,7 @@ impl<'test> TestCx<'test> {
3479
3502
emit_metadata,
3480
3503
AllowUnused :: No ,
3481
3504
LinkToAux :: Yes ,
3505
+ Vec :: new ( ) ,
3482
3506
) ;
3483
3507
let res = self . compose_and_run_compiler ( rustc, None ) ;
3484
3508
if !res. status . success ( ) {
@@ -3497,14 +3521,14 @@ impl<'test> TestCx<'test> {
3497
3521
let pm = self . pass_mode ( ) ;
3498
3522
let should_run = self . should_run ( pm) ;
3499
3523
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 ( ) ;
3501
3525
3526
+ let proc_res = self . compile_test ( should_run, emit_metadata, passes) ;
3527
+ self . check_mir_dump ( ) ;
3502
3528
if !proc_res. status . success ( ) {
3503
3529
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
3504
3530
}
3505
3531
3506
- self . check_mir_dump ( ) ;
3507
-
3508
3532
if let WillExecute :: Yes = should_run {
3509
3533
let proc_res = self . exec_compiled_test ( ) ;
3510
3534
@@ -3514,6 +3538,26 @@ impl<'test> TestCx<'test> {
3514
3538
}
3515
3539
}
3516
3540
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
+
3517
3561
fn check_mir_dump ( & self ) {
3518
3562
let test_file_contents = fs:: read_to_string ( & self . testpaths . file ) . unwrap ( ) ;
3519
3563
@@ -3543,8 +3587,9 @@ impl<'test> TestCx<'test> {
3543
3587
& self . testpaths . file ,
3544
3588
self . config . get_pointer_width ( ) ,
3545
3589
) ;
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
+ {
3548
3593
let dumped_string = if let Some ( after) = to_file {
3549
3594
self . diff_mir_files ( from_file. into ( ) , after. into ( ) )
3550
3595
} else {
0 commit comments