@@ -1068,8 +1068,19 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10681068 {
10691069 tcx. ensure_ok( ) . exportable_items( LOCAL_CRATE ) ;
10701070 tcx. ensure_ok( ) . stable_order_of_exportable_impls( LOCAL_CRATE ) ;
1071+
1072+ // Prefetch this as it is used later by the loop below
1073+ // to prevent multiple threads from blocking on it.
1074+ tcx. ensure_done( ) . get_lang_items( ( ) ) ;
1075+
1076+ let _timer = tcx. sess. timer( "misc_module_passes" ) ;
10711077 tcx. par_hir_for_each_module( |module| {
10721078 tcx. ensure_ok( ) . check_mod_attrs( module) ;
1079+ } ) ;
1080+ } ,
1081+ {
1082+ let _timer = tcx. sess. timer( "check_unstable_api_usage" ) ;
1083+ tcx. par_hir_for_each_module( |module| {
10731084 tcx. ensure_ok( ) . check_mod_unstable_api_usage( module) ;
10741085 } ) ;
10751086 } ,
@@ -1091,49 +1102,56 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10911102 // This improves performance by allowing lock-free access to them.
10921103 tcx. untracked ( ) . definitions . freeze ( ) ;
10931104
1094- sess. time ( "MIR_borrow_checking" , || {
1095- tcx. par_hir_body_owners ( |def_id| {
1096- let not_typeck_child = !tcx. is_typeck_child ( def_id. to_def_id ( ) ) ;
1097- if not_typeck_child {
1098- // Child unsafety and borrowck happens together with the parent
1099- tcx. ensure_ok ( ) . check_unsafety ( def_id) ;
1100- }
1101- if tcx. is_trivial_const ( def_id) {
1102- return ;
1103- }
1104- if not_typeck_child {
1105- tcx. ensure_ok ( ) . mir_borrowck ( def_id) ;
1106- tcx. ensure_ok ( ) . check_transmutes ( def_id) ;
1107- }
1108- tcx. ensure_ok ( ) . has_ffi_unwind_calls ( def_id) ;
1109- tcx. ensure_ok ( ) . check_liveness ( def_id) ;
1110-
1111- // If we need to codegen, ensure that we emit all errors from
1112- // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
1113- // them later during codegen.
1114- if tcx. sess . opts . output_types . should_codegen ( )
1115- || tcx. hir_body_const_context ( def_id) . is_some ( )
1105+ sess. time ( "misc_checking_2" , || {
1106+ parallel ! (
11161107 {
1117- tcx. ensure_ok ( ) . mir_drops_elaborated_and_const_checked ( def_id) ;
1118- }
1119- if tcx. is_coroutine ( def_id. to_def_id ( ) ) {
1120- tcx. ensure_ok ( ) . mir_coroutine_witnesses ( def_id) ;
1121- let _ = tcx. ensure_ok ( ) . check_coroutine_obligations (
1122- tcx. typeck_root_def_id ( def_id. to_def_id ( ) ) . expect_local ( ) ,
1123- ) ;
1124- if !tcx. is_async_drop_in_place_coroutine ( def_id. to_def_id ( ) ) {
1125- // Eagerly check the unsubstituted layout for cycles.
1126- tcx. ensure_ok ( ) . layout_of (
1127- ty:: TypingEnv :: post_analysis ( tcx, def_id. to_def_id ( ) )
1128- . as_query_input ( tcx. type_of ( def_id) . instantiate_identity ( ) ) ,
1129- ) ;
1130- }
1108+ // Prefetch this as it is used later by lint checking and privacy checking.
1109+ tcx. ensure_done( ) . effective_visibilities( ( ) ) ;
1110+ } ,
1111+ {
1112+ sess. time( "misc_body_checking" , || {
1113+ tcx. par_hir_body_owners( |def_id| {
1114+ if !tcx. is_typeck_child( def_id. to_def_id( ) ) {
1115+ // Child unsafety and borrowck happens together with the parent
1116+ tcx. ensure_ok( ) . check_unsafety( def_id) ;
1117+ tcx. ensure_ok( ) . mir_borrowck( def_id) ;
1118+ tcx. ensure_ok( ) . check_transmutes( def_id) ;
1119+ }
1120+ tcx. ensure_ok( ) . has_ffi_unwind_calls( def_id) ;
1121+
1122+ // If we need to codegen, ensure that we emit all errors from
1123+ // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
1124+ // them later during codegen.
1125+ if tcx. sess. opts. output_types. should_codegen( )
1126+ || tcx. hir_body_const_context( def_id) . is_some( )
1127+ {
1128+ tcx. ensure_ok( ) . mir_drops_elaborated_and_const_checked( def_id) ;
1129+ }
1130+
1131+ if tcx. is_coroutine( def_id. to_def_id( ) ) {
1132+ tcx. ensure_ok( ) . mir_coroutine_witnesses( def_id) ;
1133+ let _ = tcx. ensure_ok( ) . check_coroutine_obligations(
1134+ tcx. typeck_root_def_id( def_id. to_def_id( ) ) . expect_local( ) ,
1135+ ) ;
1136+ if !tcx. is_async_drop_in_place_coroutine( def_id. to_def_id( ) ) {
1137+ // Eagerly check the unsubstituted layout for cycles.
1138+ tcx. ensure_ok( ) . layout_of(
1139+ ty:: TypingEnv :: post_analysis( tcx, def_id. to_def_id( ) )
1140+ . as_query_input( tcx. type_of( def_id) . instantiate_identity( ) ) ,
1141+ ) ;
1142+ }
1143+ }
1144+ } ) ;
1145+ } ) ;
1146+ } ,
1147+ {
1148+ sess. time( "layout_testing" , || layout_test:: test_layout( tcx) ) ;
1149+ sess. time( "abi_testing" , || abi_test:: test_abi( tcx) ) ;
11311150 }
1132- } ) ;
1151+ )
11331152 } ) ;
11341153
1135- sess. time ( "layout_testing" , || layout_test:: test_layout ( tcx) ) ;
1136- sess. time ( "abi_testing" , || abi_test:: test_abi ( tcx) ) ;
1154+ }
11371155}
11381156
11391157/// Runs the type-checking, region checking and other miscellaneous analysis
@@ -1158,28 +1176,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
11581176 sess. time ( "misc_checking_3" , || {
11591177 parallel ! (
11601178 {
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- ) ;
1179+ tcx. par_hir_for_each_module( |module| {
1180+ tcx. ensure_ok( ) . check_private_in_public( module)
1181+ } )
1182+ } ,
1183+ {
1184+ tcx. par_hir_for_each_module( |module| tcx. ensure_ok( ) . check_mod_deathness( module) ) ;
1185+ } ,
1186+ {
1187+ sess. time( "lint_checking" , || {
1188+ rustc_lint:: check_crate( tcx) ;
1189+ } ) ;
1190+ } ,
1191+ {
1192+ tcx. ensure_ok( ) . clashing_extern_declarations( ( ) ) ;
11831193 } ,
11841194 {
11851195 sess. time( "privacy_checking_modules" , || {
0 commit comments