@@ -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 {
0 commit comments