Skip to content

Commit cae6283

Browse files
committed
close parallel typeck and borrowck when use query caches
1 parent c8ff353 commit cae6283

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,20 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
237237
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
238238
});
239239

240-
// FIXME: Remove this when we implement creating `DefId`s
241-
// for anon constants during their parents' typeck.
242-
// Typeck all body owners in parallel will produce queries
243-
// cycle errors because it may typeck on anon constants directly.
244-
tcx.hir().par_body_owners(|item_def_id| {
245-
let def_kind = tcx.def_kind(item_def_id);
246-
if !matches!(def_kind, DefKind::AnonConst) {
247-
tcx.ensure().typeck(item_def_id);
248-
}
249-
});
240+
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
241+
242+
if !has_cache {
243+
// FIXME: Remove this when we implement creating `DefId`s
244+
// for anon constants during their parents' typeck.
245+
// Typeck all body owners in parallel will produce queries
246+
// cycle errors because it may typeck on anon constants directly.
247+
tcx.hir().par_body_owners(|item_def_id| {
248+
let def_kind = tcx.def_kind(item_def_id);
249+
if !matches!(def_kind, DefKind::AnonConst) {
250+
tcx.ensure().typeck(item_def_id);
251+
}
252+
});
253+
}
250254

251255
tcx.ensure().check_unused_traits(());
252256

compiler/rustc_interface/src/passes.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,16 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
790790
// passes are timed inside typeck
791791
rustc_hir_analysis::check_crate(tcx)?;
792792

793+
let has_cache = tcx.query_system.on_disk_cache.as_ref().map(|cache| cache.has_cache()).unwrap_or(false);
794+
793795
sess.time("MIR_borrow_checking", || {
794-
tcx.hir().par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
796+
if has_cache {
797+
for def_id in tcx.hir().body_owners() {
798+
tcx.ensure().mir_borrowck(def_id);
799+
}
800+
} else {
801+
tcx.hir().par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
802+
}
795803
});
796804

797805
sess.time("MIR_effect_checking", || {

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ impl<'sess> OnDiskCache<'sess> {
214214
}
215215
}
216216

217+
pub fn has_cache(&self) -> bool {
218+
self.serialized_data.read().is_some()
219+
}
220+
217221
/// Execute all cache promotions and release the serialized backing Mmap.
218222
///
219223
/// Cache promotions require invoking queries, which needs to read the serialized data.

0 commit comments

Comments
 (0)