Skip to content

Commit 1e137bd

Browse files
committed
close some parallel when using cache
1 parent 7b50e05 commit 1e137bd

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ pub fn provide(providers: &mut Providers) {
187187
pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
188188
let _prof_timer = tcx.sess.timer("type_check_crate");
189189

190+
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
191+
190192
// this ensures that later parts of type checking can assume that items
191193
// have valid types and not error
192194
// FIXME(matthewjasper) We shouldn't need to use `track_errors`.
@@ -228,7 +230,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
228230

229231
tcx.sess.track_errors(|| {
230232
tcx.sess.time("wf_checking", || {
231-
tcx.hir().par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
233+
if has_cache {
234+
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
235+
} else {
236+
tcx.hir().par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
237+
}
232238
});
233239
})?;
234240

@@ -237,8 +243,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
237243
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
238244
});
239245

240-
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
241-
242246
if !has_cache {
243247
// FIXME: Remove this when we implement creating `DefId`s
244248
// for anon constants during their parents' typeck.

compiler/rustc_interface/src/passes.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
746746
tcx.ensure().hir_crate_items(());
747747
tcx.ensure().stability_index(());
748748

749+
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
750+
749751
rustc_passes::hir_id_validator::check_crate(tcx);
750752

751753
let sess = tcx.sess;
@@ -763,13 +765,24 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
763765
CStore::from_tcx(tcx).report_unused_deps(tcx);
764766
},
765767
{
766-
tcx.hir().par_for_each_module(|module| {
768+
if has_cache {
769+
tcx.hir().for_each_module(|module| {
770+
tcx.ensure().check_mod_loops(module);
771+
tcx.ensure().check_mod_attrs(module);
772+
tcx.ensure().check_mod_naked_functions(module);
773+
tcx.ensure().check_mod_unstable_api_usage(module);
774+
tcx.ensure().check_mod_const_bodies(module);
775+
});
776+
} else {
777+
tcx.hir().par_for_each_module(|module| {
767778
tcx.ensure().check_mod_loops(module);
768779
tcx.ensure().check_mod_attrs(module);
769780
tcx.ensure().check_mod_naked_functions(module);
770781
tcx.ensure().check_mod_unstable_api_usage(module);
771782
tcx.ensure().check_mod_const_bodies(module);
772783
});
784+
}
785+
773786
},
774787
{
775788
sess.time("unused_lib_feature_checking", || {
@@ -790,8 +803,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
790803
// passes are timed inside typeck
791804
rustc_hir_analysis::check_crate(tcx)?;
792805

793-
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
794-
795806
sess.time("MIR_borrow_checking", || {
796807
if has_cache {
797808
for def_id in tcx.hir().body_owners() {
@@ -872,7 +883,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
872883
});
873884
}
874885
);
875-
876886
// This check has to be run after all lints are done processing. We don't
877887
// define a lint filter, as all lint checks should have finished at this point.
878888
sess.time("check_lint_expectations", || tcx.check_expectations(None));

compiler/rustc_lint/src/late.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,14 @@ pub fn check_crate<'tcx, T: LateLintPass<'tcx> + 'tcx>(
445445
},
446446
|| {
447447
tcx.sess.time("module_lints", || {
448+
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
449+
448450
// Run per-module lints
449-
tcx.hir().par_for_each_module(|module| tcx.ensure().lint_mod(module));
451+
if has_cache {
452+
tcx.hir().for_each_module(|module| tcx.ensure().lint_mod(module));
453+
} else {
454+
tcx.hir().par_for_each_module(|module| tcx.ensure().lint_mod(module));
455+
}
450456
});
451457
},
452458
);

compiler/rustc_query_system/src/query/job.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ pub(crate) fn report_cycle<'a, D: DepKind>(
615615
}
616616

617617
pub fn print_query_stack<Qcx: QueryContext>(
618-
qcx: Qcx,
618+
_qcx: Qcx,
619619
mut current_query: Option<QueryJobId>,
620620
handler: &Handler,
621621
num_frames: Option<usize>,
@@ -627,7 +627,11 @@ pub fn print_query_stack<Qcx: QueryContext>(
627627
let mut count_printed = 0;
628628
let mut count_total = 0;
629629

630-
let query_map = qcx.try_collect_active_jobs();
630+
#[cfg(not(parallel_compiler))]
631+
let query_map = _qcx.try_collect_active_jobs();
632+
633+
#[cfg(parallel_compiler)]
634+
let query_map: Option<QueryMap<Qcx::DepKind>> = None;
631635

632636
if let Some(ref mut file) = file {
633637
let _ = writeln!(file, "\n\nquery stack during panic:");

0 commit comments

Comments
 (0)