@@ -1063,8 +1063,19 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10631063 {
10641064 tcx. ensure_ok( ) . exportable_items( LOCAL_CRATE ) ;
10651065 tcx. ensure_ok( ) . stable_order_of_exportable_impls( LOCAL_CRATE ) ;
1066+
1067+ // Prefetch this as it is used later by the loop below
1068+ // to prevent multiple threads from blocking on it.
1069+ tcx. ensure_done( ) . get_lang_items( ( ) ) ;
1070+
1071+ let _timer = tcx. sess. timer( "misc_module_passes" ) ;
10661072 tcx. par_hir_for_each_module( |module| {
10671073 tcx. ensure_ok( ) . check_mod_attrs( module) ;
1074+ } ) ;
1075+ } ,
1076+ {
1077+ let _timer = tcx. sess. timer( "check_unstable_api_usage" ) ;
1078+ tcx. par_hir_for_each_module( |module| {
10681079 tcx. ensure_ok( ) . check_mod_unstable_api_usage( module) ;
10691080 } ) ;
10701081 } ,
@@ -1086,43 +1097,55 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10861097 // This improves performance by allowing lock-free access to them.
10871098 tcx. untracked ( ) . definitions . freeze ( ) ;
10881099
1089- sess. time ( "MIR_borrow_checking" , || {
1090- tcx. par_hir_body_owners ( |def_id| {
1091- if !tcx. is_typeck_child ( def_id. to_def_id ( ) ) {
1092- // Child unsafety and borrowck happens together with the parent
1093- tcx. ensure_ok ( ) . check_unsafety ( def_id) ;
1094- tcx. ensure_ok ( ) . mir_borrowck ( def_id) ;
1095- tcx. ensure_ok ( ) . check_transmutes ( def_id) ;
1096- }
1097- tcx. ensure_ok ( ) . has_ffi_unwind_calls ( def_id) ;
1100+ sess. time ( "misc_checking_2" , || {
1101+ parallel ! (
1102+ {
1103+ // Prefetch this as it is used later by lint checking and privacy checking.
1104+ tcx. ensure_done( ) . effective_visibilities( ( ) ) ;
1105+ } ,
1106+ {
1107+ sess. time( "misc_body_checking" , || {
1108+ tcx. par_hir_body_owners( |def_id| {
1109+ if !tcx. is_typeck_child( def_id. to_def_id( ) ) {
1110+ // Child unsafety and borrowck happens together with the parent
1111+ tcx. ensure_ok( ) . check_unsafety( def_id) ;
1112+ tcx. ensure_ok( ) . mir_borrowck( def_id) ;
1113+ tcx. ensure_ok( ) . check_transmutes( def_id) ;
1114+ }
1115+ tcx. ensure_ok( ) . has_ffi_unwind_calls( def_id) ;
1116+
1117+ // If we need to codegen, ensure that we emit all errors from
1118+ // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
1119+ // them later during codegen.
1120+ if tcx. sess. opts. output_types. should_codegen( )
1121+ || tcx. hir_body_const_context( def_id) . is_some( )
1122+ {
1123+ tcx. ensure_ok( ) . mir_drops_elaborated_and_const_checked( def_id) ;
1124+ }
10981125
1099- // If we need to codegen, ensure that we emit all errors from
1100- // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
1101- // them later during codegen.
1102- if tcx. sess . opts . output_types . should_codegen ( )
1103- || tcx. hir_body_const_context ( def_id) . is_some ( )
1126+ if tcx. is_coroutine( def_id. to_def_id( ) ) {
1127+ tcx. ensure_ok( ) . mir_coroutine_witnesses( def_id) ;
1128+ let _ = tcx. ensure_ok( ) . check_coroutine_obligations(
1129+ tcx. typeck_root_def_id( def_id. to_def_id( ) ) . expect_local( ) ,
1130+ ) ;
1131+ if !tcx. is_async_drop_in_place_coroutine( def_id. to_def_id( ) ) {
1132+ // Eagerly check the unsubstituted layout for cycles.
1133+ tcx. ensure_ok( ) . layout_of(
1134+ ty:: TypingEnv :: post_analysis( tcx, def_id. to_def_id( ) )
1135+ . as_query_input( tcx. type_of( def_id) . instantiate_identity( ) ) ,
1136+ ) ;
1137+ }
1138+ }
1139+ } ) ;
1140+ } ) ;
1141+ } ,
11041142 {
1105- tcx. ensure_ok ( ) . mir_drops_elaborated_and_const_checked ( def_id) ;
1143+ sess. time( "layout_testing" , || layout_test:: test_layout( tcx) ) ;
1144+ sess. time( "abi_testing" , || abi_test:: test_abi( tcx) ) ;
11061145 }
1107- if tcx. is_coroutine ( def_id. to_def_id ( ) ) {
1108- tcx. ensure_ok ( ) . mir_coroutine_witnesses ( def_id) ;
1109- let _ = tcx. ensure_ok ( ) . check_coroutine_obligations (
1110- tcx. typeck_root_def_id ( def_id. to_def_id ( ) ) . expect_local ( ) ,
1111- ) ;
1112- if !tcx. is_async_drop_in_place_coroutine ( def_id. to_def_id ( ) ) {
1113- // Eagerly check the unsubstituted layout for cycles.
1114- tcx. ensure_ok ( ) . layout_of (
1115- ty:: TypingEnv :: post_analysis ( tcx, def_id. to_def_id ( ) )
1116- . as_query_input ( tcx. type_of ( def_id) . instantiate_identity ( ) ) ,
1117- ) ;
1118- }
1119- }
1120- } ) ;
1146+ )
11211147 } ) ;
11221148
1123- sess. time ( "layout_testing" , || layout_test:: test_layout ( tcx) ) ;
1124- sess. time ( "abi_testing" , || abi_test:: test_abi ( tcx) ) ;
1125-
11261149 // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
11271150 // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
11281151 // in MIR optimizations that may only be reachable through codegen, or other codepaths
@@ -1158,28 +1181,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
11581181 sess. time ( "misc_checking_3" , || {
11591182 parallel ! (
11601183 {
1161- tcx. ensure_ok( ) . effective_visibilities( ( ) ) ;
1162-
1163- parallel!(
1164- {
1165- tcx. par_hir_for_each_module( |module| {
1166- tcx. ensure_ok( ) . check_private_in_public( module)
1167- } )
1168- } ,
1169- {
1170- tcx. par_hir_for_each_module( |module| {
1171- tcx. ensure_ok( ) . check_mod_deathness( module)
1172- } ) ;
1173- } ,
1174- {
1175- sess. time( "lint_checking" , || {
1176- rustc_lint:: check_crate( tcx) ;
1177- } ) ;
1178- } ,
1179- {
1180- tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
1181- }
1182- ) ;
1184+ tcx. par_hir_for_each_module( |module| {
1185+ tcx. ensure_ok( ) . check_private_in_public( module)
1186+ } )
1187+ } ,
1188+ {
1189+ tcx. par_hir_for_each_module( |module| tcx. ensure_ok( ) . check_mod_deathness( module) ) ;
1190+ } ,
1191+ {
1192+ sess. time( "lint_checking" , || {
1193+ rustc_lint:: check_crate( tcx) ;
1194+ } ) ;
1195+ } ,
1196+ {
1197+ tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
11831198 } ,
11841199 {
11851200 sess. time( "privacy_checking_modules" , || {
0 commit comments