@@ -956,10 +956,25 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
956956 {
957957 tcx. ensure_ok( ) . exportable_items( LOCAL_CRATE ) ;
958958 tcx. ensure_ok( ) . stable_order_of_exportable_impls( LOCAL_CRATE ) ;
959+
960+ // Prefetch this as it is used later by the loop below
961+ // to prevent multiple threads from blocking on it.
962+ tcx. ensure_done( ) . get_lang_items( ( ) ) ;
963+
964+ let _timer = tcx. sess. timer( "misc_module_passes" ) ;
959965 tcx. par_hir_for_each_module( |module| {
960966 tcx. ensure_ok( ) . check_mod_loops( module) ;
961967 tcx. ensure_ok( ) . check_mod_attrs( module) ;
962968 tcx. ensure_ok( ) . check_mod_naked_functions( module) ;
969+ } ) ;
970+ } ,
971+ {
972+ // Prefetch this as it is used later by the loop below
973+ // to prevent multiple threads from blocking on it.
974+ tcx. ensure_done( ) . stability_index( ( ) ) ;
975+
976+ let _timer = tcx. sess. timer( "check_unstable_api_usage" ) ;
977+ tcx. par_hir_for_each_module( |module| {
963978 tcx. ensure_ok( ) . check_mod_unstable_api_usage( module) ;
964979 } ) ;
965980 } ,
@@ -994,30 +1009,47 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
9941009 // This improves performance by allowing lock-free access to them.
9951010 tcx. untracked ( ) . definitions . freeze ( ) ;
9961011
997- sess. time ( "MIR_borrow_checking" , || {
998- tcx. par_hir_body_owners ( |def_id| {
999- // Run unsafety check because it's responsible for stealing and
1000- // deallocating THIR.
1001- tcx. ensure_ok ( ) . check_unsafety ( def_id) ;
1002- if !tcx. is_typeck_child ( def_id. to_def_id ( ) ) {
1003- tcx. ensure_ok ( ) . mir_borrowck ( def_id)
1004- }
1005- } ) ;
1006- } ) ;
1007- sess. time ( "MIR_effect_checking" , || {
1008- tcx. par_hir_body_owners ( |def_id| {
1009- tcx. ensure_ok ( ) . has_ffi_unwind_calls ( def_id) ;
1010-
1011- // If we need to codegen, ensure that we emit all errors from
1012- // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
1013- // them later during codegen.
1014- if tcx. sess . opts . output_types . should_codegen ( )
1015- || tcx. hir_body_const_context ( def_id) . is_some ( )
1012+ sess. time ( "misc_checking_2" , || {
1013+ parallel ! (
1014+ {
1015+ // Prefetch this as it is used later by lint checking and privacy checking.
1016+ tcx. ensure_done( ) . effective_visibilities( ( ) ) ;
1017+ } ,
10161018 {
1017- tcx. ensure_ok ( ) . mir_drops_elaborated_and_const_checked ( def_id) ;
1019+ sess. time( "MIR_borrow_checking" , || {
1020+ tcx. par_hir_body_owners( |def_id| {
1021+ // Run unsafety check because it's responsible for stealing and
1022+ // deallocating THIR.
1023+ tcx. ensure_ok( ) . check_unsafety( def_id) ;
1024+ if !tcx. is_typeck_child( def_id. to_def_id( ) ) {
1025+ tcx. ensure_ok( ) . mir_borrowck( def_id)
1026+ }
1027+ } ) ;
1028+ } ) ;
1029+ } ,
1030+ {
1031+ sess. time( "MIR_effect_checking" , || {
1032+ tcx. par_hir_body_owners( |def_id| {
1033+ tcx. ensure_ok( ) . has_ffi_unwind_calls( def_id) ;
1034+
1035+ // If we need to codegen, ensure that we emit all errors from
1036+ // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
1037+ // them later during codegen.
1038+ if tcx. sess. opts. output_types. should_codegen( )
1039+ || tcx. hir_body_const_context( def_id) . is_some( )
1040+ {
1041+ tcx. ensure_ok( ) . mir_drops_elaborated_and_const_checked( def_id) ;
1042+ }
1043+ } ) ;
1044+ } ) ;
1045+ } ,
1046+ {
1047+ sess. time( "layout_testing" , || layout_test:: test_layout( tcx) ) ;
1048+ sess. time( "abi_testing" , || abi_test:: test_abi( tcx) ) ;
10181049 }
1019- } ) ;
1050+ )
10201051 } ) ;
1052+
10211053 sess. time ( "coroutine_obligations" , || {
10221054 tcx. par_hir_body_owners ( |def_id| {
10231055 if tcx. is_coroutine ( def_id. to_def_id ( ) ) {
@@ -1036,9 +1068,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10361068 } ) ;
10371069 } ) ;
10381070
1039- sess. time ( "layout_testing" , || layout_test:: test_layout ( tcx) ) ;
1040- sess. time ( "abi_testing" , || abi_test:: test_abi ( tcx) ) ;
1041-
10421071 // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
10431072 // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
10441073 // in MIR optimizations that may only be reachable through codegen, or other codepaths
@@ -1074,26 +1103,18 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
10741103 sess. time ( "misc_checking_3" , || {
10751104 parallel ! (
10761105 {
1077- tcx. ensure_ok( ) . effective_visibilities( ( ) ) ;
1078-
1079- parallel!(
1080- {
1081- tcx. ensure_ok( ) . check_private_in_public( ( ) ) ;
1082- } ,
1083- {
1084- tcx. par_hir_for_each_module( |module| {
1085- tcx. ensure_ok( ) . check_mod_deathness( module)
1086- } ) ;
1087- } ,
1088- {
1089- sess. time( "lint_checking" , || {
1090- rustc_lint:: check_crate( tcx) ;
1091- } ) ;
1092- } ,
1093- {
1094- tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
1095- }
1096- ) ;
1106+ tcx. ensure_ok( ) . check_private_in_public( ( ) ) ;
1107+ } ,
1108+ {
1109+ tcx. par_hir_for_each_module( |module| tcx. ensure_ok( ) . check_mod_deathness( module) ) ;
1110+ } ,
1111+ {
1112+ sess. time( "lint_checking" , || {
1113+ rustc_lint:: check_crate( tcx) ;
1114+ } ) ;
1115+ } ,
1116+ {
1117+ tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
10971118 } ,
10981119 {
10991120 sess. time( "privacy_checking_modules" , || {
0 commit comments