Skip to content

Commit 55ccbd0

Browse files
committed
Auto merge of #90065 - cjgillot:novalcache, r=Mark-Simulacrum
Do not depend on the stored value when trying to cache on disk. Having different criteria for loading and saving of query results can lead to saved results that may never be loaded. Since the on-disk cache is discarded as soon as a compilation error is issued, there should not be any need for an exclusion mecanism based on errors. As a result, the possibility to condition the storage on the value itself does not appear useful.
2 parents cf70855 + 0a5666b commit 55ccbd0

File tree

6 files changed

+12
-25
lines changed

6 files changed

+12
-25
lines changed

compiler/rustc_macros/src/query.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum QueryModifier {
3636
Storage(Type),
3737

3838
/// Cache the query to disk if the `Expr` returns true.
39-
Cache(Option<(IdentOrWild, IdentOrWild)>, Block),
39+
Cache(Option<IdentOrWild>, Block),
4040

4141
/// Custom code to load the query from disk.
4242
LoadCached(Ident, Ident, Block),
@@ -87,9 +87,7 @@ impl Parse for QueryModifier {
8787
let args;
8888
parenthesized!(args in input);
8989
let tcx = args.parse()?;
90-
args.parse::<Token![,]>()?;
91-
let value = args.parse()?;
92-
Some((tcx, value))
90+
Some(tcx)
9391
} else {
9492
None
9593
};
@@ -197,7 +195,7 @@ struct QueryModifiers {
197195
storage: Option<Type>,
198196

199197
/// Cache the query to disk if the `Block` returns true.
200-
cache: Option<(Option<(IdentOrWild, IdentOrWild)>, Block)>,
198+
cache: Option<(Option<IdentOrWild>, Block)>,
201199

202200
/// Custom code to load the query from disk.
203201
load_cached: Option<(Ident, Ident, Block)>,
@@ -375,14 +373,7 @@ fn add_query_description_impl(
375373
let tcx = args
376374
.as_ref()
377375
.map(|t| {
378-
let t = &(t.0).0;
379-
quote! { #t }
380-
})
381-
.unwrap_or_else(|| quote! { _ });
382-
let value = args
383-
.as_ref()
384-
.map(|t| {
385-
let t = &(t.1).0;
376+
let t = &t.0;
386377
quote! { #t }
387378
})
388379
.unwrap_or_else(|| quote! { _ });
@@ -394,7 +385,6 @@ fn add_query_description_impl(
394385
fn cache_on_disk(
395386
#tcx: QueryCtxt<'tcx>,
396387
#key: &Self::Key,
397-
#value: Option<&Self::Value>
398388
) -> bool {
399389
#expr
400390
}

compiler/rustc_middle/src/query/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,7 @@ rustc_queries! {
765765
/// additional requirements that the closure's creator must verify.
766766
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
767767
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
768-
cache_on_disk_if(tcx, opt_result) {
769-
tcx.is_closure(key.to_def_id())
770-
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
771-
}
768+
cache_on_disk_if(tcx) { tcx.is_closure(key.to_def_id()) }
772769
}
773770
query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
774771
desc {

compiler/rustc_query_impl/src/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ where
10331033
if res.is_err() {
10341034
return;
10351035
}
1036-
if Q::cache_on_disk(tcx, &key, Some(value)) {
1036+
if Q::cache_on_disk(tcx, &key) {
10371037
let dep_node = SerializedDepNodeIndex::new(dep_node.index());
10381038

10391039
// Record position of the cache entry.

compiler/rustc_query_impl/src/plumbing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ macro_rules! define_queries {
418418

419419
let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
420420
let tcx = QueryCtxt::from_tcx(tcx);
421-
if queries::$name::cache_on_disk(tcx, &key, None) {
421+
if queries::$name::cache_on_disk(tcx, &key) {
422422
let _ = tcx.$name(key);
423423
}
424424
}

compiler/rustc_query_system/src/query/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
2727
pub compute: fn(CTX::DepContext, K) -> V,
2828
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
2929
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
30-
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
30+
pub cache_on_disk: fn(CTX, &K) -> bool,
3131
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
3232
}
3333

@@ -43,8 +43,8 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
4343
(self.compute)(tcx, key)
4444
}
4545

46-
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool {
47-
(self.cache_on_disk)(tcx, key, value)
46+
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K) -> bool {
47+
(self.cache_on_disk)(tcx, key)
4848
}
4949

5050
pub(crate) fn try_load_from_disk(&self, tcx: CTX, index: SerializedDepNodeIndex) -> Option<V> {
@@ -82,7 +82,7 @@ pub trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
8282
fn describe(tcx: CTX, key: Self::Key) -> String;
8383

8484
#[inline]
85-
fn cache_on_disk(_: CTX, _: &Self::Key, _: Option<&Self::Value>) -> bool {
85+
fn cache_on_disk(_: CTX, _: &Self::Key) -> bool {
8686
false
8787
}
8888

compiler/rustc_query_system/src/query/plumbing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ where
512512

513513
// First we try to load the result from the on-disk cache.
514514
// Some things are never cached on disk.
515-
if query.cache_on_disk(tcx, key, None) {
515+
if query.cache_on_disk(tcx, key) {
516516
let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
517517
let result = query.try_load_from_disk(tcx, prev_dep_node_index);
518518
prof_timer.finish_with_query_invocation_id(dep_node_index.into());

0 commit comments

Comments
 (0)