@@ -14,14 +14,16 @@ use rustc_crate_store::Untracked;
1414use rustc_data_structures:: indexmap:: IndexMap ;
1515use rustc_data_structures:: steal:: Steal ;
1616use rustc_data_structures:: sync:: {
17- AppendOnlyIndexVec , DynSend , DynSync , FreezeLock , WorkerLocal , par_fns, par_range,
17+ AppendOnlyIndexVec , DynSend , DynSync , FreezeLock , WorkerLocal , is_dyn_thread_safe, par_fns,
18+ par_range,
1819} ;
1920use rustc_data_structures:: thousands;
2021use rustc_errors:: timings:: TimingSection ;
2122use rustc_errors:: { Diag , DiagCtxtHandle , Diagnostic , Level } ;
2223use rustc_expand:: base:: { ExtCtxt , LintStoreExpand } ;
2324use rustc_feature:: Features ;
2425use rustc_fs_util:: try_canonicalize;
26+ use rustc_hir:: OwnerId ;
2527use rustc_hir:: def_id:: { DefIndex , LOCAL_CRATE , LocalDefId , StableCrateId , StableCrateIdMap } ;
2628use rustc_hir:: definitions:: Definitions ;
2729use rustc_incremental:: setup_dep_graph;
@@ -1090,17 +1092,24 @@ pub fn emit_delayed_lints(tcx: TyCtxt<'_>) {
10901092/// Runs all analyses that we guarantee to run, even if errors were reported in earlier analyses.
10911093/// This function never fails.
10921094fn run_required_analyses ( tcx : TyCtxt < ' _ > ) {
1093- tcx. untracked ( ) . definitions . write ( ) . commit_end_of_determinism ( ) ;
1094- tcx. ensure_done ( ) . resolve_type_relative_delegations ( ( ) ) ;
1095+ let is_parallel = is_dyn_thread_safe ( ) ;
10951096
1096- let index = tcx. index_ast ( ( ) ) ;
1097+ // There is no point in prefectching hir owners when parallel compiler is
1098+ // deisabled, `print_hir_stats`, `check_crate` or `hir_crate_items` below will do it.
1099+ if is_parallel {
1100+ tcx. untracked ( ) . definitions . write ( ) . commit_end_of_determinism ( ) ;
1101+ tcx. ensure_done ( ) . resolve_type_relative_delegations ( ( ) ) ;
10971102
1098- par_range ( 0 ..index. len ( ) , |idx| {
1099- let id = LocalDefId { local_def_index : DefIndex :: from_usize ( idx) } ;
1100- if index[ id] . is_some ( ) {
1101- tcx. ensure_done ( ) . lower_to_hir ( id) ;
1102- }
1103- } ) ;
1103+ let index = tcx. index_ast ( ( ) ) ;
1104+
1105+ par_range ( 0 ..index. len ( ) , |idx| {
1106+ let id = LocalDefId { local_def_index : DefIndex :: from_usize ( idx) } ;
1107+ if index[ id] . is_some ( ) {
1108+ tcx. ensure_done ( ) . hir_owner ( id) ;
1109+ tcx. ensure_done ( ) . hir_attr_map ( OwnerId { def_id : id } ) ;
1110+ }
1111+ } ) ;
1112+ }
11041113
11051114 if tcx. sess . opts . unstable_opts . input_stats {
11061115 rustc_passes:: input_stats:: print_hir_stats ( tcx) ;
@@ -1116,6 +1125,10 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
11161125 // to use `hir_crate_items`.
11171126 tcx. ensure_done ( ) . hir_crate_items ( ( ) ) ;
11181127
1128+ if !is_parallel {
1129+ tcx. untracked ( ) . definitions . write ( ) . commit_end_of_determinism ( ) ;
1130+ }
1131+
11191132 rustc_passes:: delegation:: check_glob_and_list_delegations_target_expr ( tcx) ;
11201133
11211134 let sess = tcx. sess ;
0 commit comments