@@ -913,10 +913,24 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
913913 CStore :: from_tcx( tcx) . report_unused_deps( tcx) ;
914914 } ,
915915 {
916+ // Prefetch this as it is used later by the loop below
917+ // to prevent multiple threads from blocking on it.
918+ tcx. ensure_done( ) . get_lang_items( ( ) ) ;
919+
920+ let _timer = tcx. sess. timer( "misc_module_passes" ) ;
916921 tcx. par_hir_for_each_module( |module| {
917922 tcx. ensure_ok( ) . check_mod_loops( module) ;
918923 tcx. ensure_ok( ) . check_mod_attrs( module) ;
919924 tcx. ensure_ok( ) . check_mod_naked_functions( module) ;
925+ } ) ;
926+ } ,
927+ {
928+ // Prefetch this as it is used later by the loop below
929+ // to prevent multiple threads from blocking on it.
930+ tcx. ensure_done( ) . stability_index( ( ) ) ;
931+
932+ let _timer = tcx. sess. timer( "check_unstable_api_usage" ) ;
933+ tcx. par_hir_for_each_module( |module| {
920934 tcx. ensure_ok( ) . check_mod_unstable_api_usage( module) ;
921935 } ) ;
922936 } ,
@@ -951,30 +965,47 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
951965 // This improves performance by allowing lock-free access to them.
952966 tcx. untracked ( ) . definitions . freeze ( ) ;
953967
954- sess. time ( "MIR_borrow_checking" , || {
955- tcx. par_hir_body_owners ( |def_id| {
956- // Run unsafety check because it's responsible for stealing and
957- // deallocating THIR.
958- tcx. ensure_ok ( ) . check_unsafety ( def_id) ;
959- if !tcx. is_typeck_child ( def_id. to_def_id ( ) ) {
960- tcx. ensure_ok ( ) . mir_borrowck ( def_id)
961- }
962- } ) ;
963- } ) ;
964- sess. time ( "MIR_effect_checking" , || {
965- tcx. par_hir_body_owners ( |def_id| {
966- tcx. ensure_ok ( ) . has_ffi_unwind_calls ( def_id) ;
967-
968- // If we need to codegen, ensure that we emit all errors from
969- // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
970- // them later during codegen.
971- if tcx. sess . opts . output_types . should_codegen ( )
972- || tcx. hir_body_const_context ( def_id) . is_some ( )
968+ sess. time ( "misc_checking_2" , || {
969+ parallel ! (
970+ {
971+ // Prefetch this as it is used later by lint checking and privacy checking.
972+ tcx. ensure_done( ) . effective_visibilities( ( ) ) ;
973+ } ,
974+ {
975+ sess. time( "MIR_borrow_checking" , || {
976+ tcx. par_hir_body_owners( |def_id| {
977+ // Run unsafety check because it's responsible for stealing and
978+ // deallocating THIR.
979+ tcx. ensure_ok( ) . check_unsafety( def_id) ;
980+ if !tcx. is_typeck_child( def_id. to_def_id( ) ) {
981+ tcx. ensure_ok( ) . mir_borrowck( def_id)
982+ }
983+ } ) ;
984+ } ) ;
985+ } ,
986+ {
987+ sess. time( "MIR_effect_checking" , || {
988+ tcx. par_hir_body_owners( |def_id| {
989+ tcx. ensure_ok( ) . has_ffi_unwind_calls( def_id) ;
990+
991+ // If we need to codegen, ensure that we emit all errors from
992+ // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
993+ // them later during codegen.
994+ if tcx. sess. opts. output_types. should_codegen( )
995+ || tcx. hir_body_const_context( def_id) . is_some( )
996+ {
997+ tcx. ensure_ok( ) . mir_drops_elaborated_and_const_checked( def_id) ;
998+ }
999+ } ) ;
1000+ } ) ;
1001+ } ,
9731002 {
974- tcx. ensure_ok ( ) . mir_drops_elaborated_and_const_checked ( def_id) ;
1003+ sess. time( "layout_testing" , || layout_test:: test_layout( tcx) ) ;
1004+ sess. time( "abi_testing" , || abi_test:: test_abi( tcx) ) ;
9751005 }
976- } ) ;
1006+ )
9771007 } ) ;
1008+
9781009 sess. time ( "coroutine_obligations" , || {
9791010 tcx. par_hir_body_owners ( |def_id| {
9801011 if tcx. is_coroutine ( def_id. to_def_id ( ) ) {
@@ -991,9 +1022,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
9911022 } ) ;
9921023 } ) ;
9931024
994- sess. time ( "layout_testing" , || layout_test:: test_layout ( tcx) ) ;
995- sess. time ( "abi_testing" , || abi_test:: test_abi ( tcx) ) ;
996-
9971025 // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
9981026 // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
9991027 // in MIR optimizations that may only be reachable through codegen, or other codepaths
@@ -1029,26 +1057,18 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
10291057 sess. time ( "misc_checking_3" , || {
10301058 parallel ! (
10311059 {
1032- tcx. ensure_ok( ) . effective_visibilities( ( ) ) ;
1033-
1034- parallel!(
1035- {
1036- tcx. ensure_ok( ) . check_private_in_public( ( ) ) ;
1037- } ,
1038- {
1039- tcx. par_hir_for_each_module( |module| {
1040- tcx. ensure_ok( ) . check_mod_deathness( module)
1041- } ) ;
1042- } ,
1043- {
1044- sess. time( "lint_checking" , || {
1045- rustc_lint:: check_crate( tcx) ;
1046- } ) ;
1047- } ,
1048- {
1049- tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
1050- }
1051- ) ;
1060+ tcx. ensure_ok( ) . check_private_in_public( ( ) ) ;
1061+ } ,
1062+ {
1063+ tcx. par_hir_for_each_module( |module| tcx. ensure_ok( ) . check_mod_deathness( module) ) ;
1064+ } ,
1065+ {
1066+ sess. time( "lint_checking" , || {
1067+ rustc_lint:: check_crate( tcx) ;
1068+ } ) ;
1069+ } ,
1070+ {
1071+ tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
10521072 } ,
10531073 {
10541074 sess. time( "privacy_checking_modules" , || {
0 commit comments