@@ -912,10 +912,24 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
912912                CStore :: from_tcx( tcx) . report_unused_deps( tcx) ; 
913913            } , 
914914            { 
915+                 // Prefetch this as it is used later by the loop below 
916+                 // to prevent multiple threads from blocking on it. 
917+                 tcx. ensure_done( ) . get_lang_items( ( ) ) ; 
918+ 
919+                 let  _timer = tcx. sess. timer( "misc_module_passes" ) ; 
915920                tcx. par_hir_for_each_module( |module| { 
916921                    tcx. ensure_ok( ) . check_mod_loops( module) ; 
917922                    tcx. ensure_ok( ) . check_mod_attrs( module) ; 
918923                    tcx. ensure_ok( ) . check_mod_naked_functions( module) ; 
924+                 } ) ; 
925+             } , 
926+             { 
927+                 // Prefetch this as it is used later by the loop below 
928+                 // to prevent multiple threads from blocking on it. 
929+                 tcx. ensure_done( ) . stability_index( ( ) ) ; 
930+ 
931+                 let  _timer = tcx. sess. timer( "check_unstable_api_usage" ) ; 
932+                 tcx. par_hir_for_each_module( |module| { 
919933                    tcx. ensure_ok( ) . check_mod_unstable_api_usage( module) ; 
920934                } ) ; 
921935            } , 
@@ -950,28 +964,45 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
950964    // This improves performance by allowing lock-free access to them. 
951965    tcx. untracked ( ) . definitions . freeze ( ) ; 
952966
953-     sess. time ( "MIR_borrow_checking" ,  || { 
954-         tcx. par_hir_body_owners ( |def_id| { 
955-             // Run unsafety check because it's responsible for stealing and 
956-             // deallocating THIR. 
957-             tcx. ensure_ok ( ) . check_unsafety ( def_id) ; 
958-             tcx. ensure_ok ( ) . mir_borrowck ( def_id) 
959-         } ) ; 
960-     } ) ; 
961-     sess. time ( "MIR_effect_checking" ,  || { 
962-         tcx. par_hir_body_owners ( |def_id| { 
963-             tcx. ensure_ok ( ) . has_ffi_unwind_calls ( def_id) ; 
964- 
965-             // If we need to codegen, ensure that we emit all errors from 
966-             // `mir_drops_elaborated_and_const_checked` now, to avoid discovering 
967-             // them later during codegen. 
968-             if  tcx. sess . opts . output_types . should_codegen ( ) 
969-                 || tcx. hir_body_const_context ( def_id) . is_some ( ) 
967+     sess. time ( "misc_checking_2" ,  || { 
968+         parallel ! ( 
969+             { 
970+                 // Prefetch this as it is used later by lint checking and privacy checking. 
971+                 tcx. ensure_done( ) . effective_visibilities( ( ) ) ; 
972+             } , 
973+             { 
974+                 sess. time( "MIR_borrow_checking" ,  || { 
975+                     tcx. par_hir_body_owners( |def_id| { 
976+                         // Run unsafety check because it's responsible for stealing and 
977+                         // deallocating THIR. 
978+                         tcx. ensure_ok( ) . check_unsafety( def_id) ; 
979+                         tcx. ensure_ok( ) . mir_borrowck( def_id) 
980+                     } ) ; 
981+                 } ) ; 
982+             } , 
970983            { 
971-                 tcx. ensure_ok ( ) . mir_drops_elaborated_and_const_checked ( def_id) ; 
984+                 sess. time( "MIR_effect_checking" ,  || { 
985+                     tcx. par_hir_body_owners( |def_id| { 
986+                         tcx. ensure_ok( ) . has_ffi_unwind_calls( def_id) ; 
987+ 
988+                         // If we need to codegen, ensure that we emit all errors from 
989+                         // `mir_drops_elaborated_and_const_checked` now, to avoid discovering 
990+                         // them later during codegen. 
991+                         if  tcx. sess. opts. output_types. should_codegen( ) 
992+                             || tcx. hir_body_const_context( def_id) . is_some( ) 
993+                         { 
994+                             tcx. ensure_ok( ) . mir_drops_elaborated_and_const_checked( def_id) ; 
995+                         } 
996+                     } ) ; 
997+                 } ) ; 
998+             } , 
999+             { 
1000+                 sess. time( "layout_testing" ,  || layout_test:: test_layout( tcx) ) ; 
1001+                 sess. time( "abi_testing" ,  || abi_test:: test_abi( tcx) ) ; 
9721002            } 
973-         } ) ; 
1003+         ) 
9741004    } ) ; 
1005+ 
9751006    sess. time ( "coroutine_obligations" ,  || { 
9761007        tcx. par_hir_body_owners ( |def_id| { 
9771008            if  tcx. is_coroutine ( def_id. to_def_id ( ) )  { 
@@ -988,9 +1019,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
9881019        } ) ; 
9891020    } ) ; 
9901021
991-     sess. time ( "layout_testing" ,  || layout_test:: test_layout ( tcx) ) ; 
992-     sess. time ( "abi_testing" ,  || abi_test:: test_abi ( tcx) ) ; 
993- 
9941022    // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item 
9951023    // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs 
9961024    // in MIR optimizations that may only be reachable through codegen, or other codepaths 
@@ -1026,26 +1054,18 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
10261054    sess. time ( "misc_checking_3" ,  || { 
10271055        parallel ! ( 
10281056            { 
1029-                 tcx. ensure_ok( ) . effective_visibilities( ( ) ) ; 
1030- 
1031-                 parallel!( 
1032-                     { 
1033-                         tcx. ensure_ok( ) . check_private_in_public( ( ) ) ; 
1034-                     } , 
1035-                     { 
1036-                         tcx. par_hir_for_each_module( |module| { 
1037-                             tcx. ensure_ok( ) . check_mod_deathness( module) 
1038-                         } ) ; 
1039-                     } , 
1040-                     { 
1041-                         sess. time( "lint_checking" ,  || { 
1042-                             rustc_lint:: check_crate( tcx) ; 
1043-                         } ) ; 
1044-                     } , 
1045-                     { 
1046-                         tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ; 
1047-                     } 
1048-                 ) ; 
1057+                 tcx. ensure_ok( ) . check_private_in_public( ( ) ) ; 
1058+             } , 
1059+             { 
1060+                 tcx. par_hir_for_each_module( |module| tcx. ensure_ok( ) . check_mod_deathness( module) ) ; 
1061+             } , 
1062+             { 
1063+                 sess. time( "lint_checking" ,  || { 
1064+                     rustc_lint:: check_crate( tcx) ; 
1065+                 } ) ; 
1066+             } , 
1067+             { 
1068+                 tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ; 
10491069            } , 
10501070            { 
10511071                sess. time( "privacy_checking_modules" ,  || { 
0 commit comments