Do not depend on the stored value when trying to cache on disk.
This commit is contained in:
parent
e015ef5b26
commit
0a5666b838
6 changed files with 12 additions and 25 deletions
|
@ -36,7 +36,7 @@ enum QueryModifier {
|
||||||
Storage(Type),
|
Storage(Type),
|
||||||
|
|
||||||
/// Cache the query to disk if the `Expr` returns true.
|
/// Cache the query to disk if the `Expr` returns true.
|
||||||
Cache(Option<(IdentOrWild, IdentOrWild)>, Block),
|
Cache(Option<IdentOrWild>, Block),
|
||||||
|
|
||||||
/// Custom code to load the query from disk.
|
/// Custom code to load the query from disk.
|
||||||
LoadCached(Ident, Ident, Block),
|
LoadCached(Ident, Ident, Block),
|
||||||
|
@ -87,9 +87,7 @@ impl Parse for QueryModifier {
|
||||||
let args;
|
let args;
|
||||||
parenthesized!(args in input);
|
parenthesized!(args in input);
|
||||||
let tcx = args.parse()?;
|
let tcx = args.parse()?;
|
||||||
args.parse::<Token![,]>()?;
|
Some(tcx)
|
||||||
let value = args.parse()?;
|
|
||||||
Some((tcx, value))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -197,7 +195,7 @@ struct QueryModifiers {
|
||||||
storage: Option<Type>,
|
storage: Option<Type>,
|
||||||
|
|
||||||
/// Cache the query to disk if the `Block` returns true.
|
/// Cache the query to disk if the `Block` returns true.
|
||||||
cache: Option<(Option<(IdentOrWild, IdentOrWild)>, Block)>,
|
cache: Option<(Option<IdentOrWild>, Block)>,
|
||||||
|
|
||||||
/// Custom code to load the query from disk.
|
/// Custom code to load the query from disk.
|
||||||
load_cached: Option<(Ident, Ident, Block)>,
|
load_cached: Option<(Ident, Ident, Block)>,
|
||||||
|
@ -375,14 +373,7 @@ fn add_query_description_impl(
|
||||||
let tcx = args
|
let tcx = args
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|t| {
|
.map(|t| {
|
||||||
let t = &(t.0).0;
|
let t = &t.0;
|
||||||
quote! { #t }
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| quote! { _ });
|
|
||||||
let value = args
|
|
||||||
.as_ref()
|
|
||||||
.map(|t| {
|
|
||||||
let t = &(t.1).0;
|
|
||||||
quote! { #t }
|
quote! { #t }
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| quote! { _ });
|
.unwrap_or_else(|| quote! { _ });
|
||||||
|
@ -394,7 +385,6 @@ fn add_query_description_impl(
|
||||||
fn cache_on_disk(
|
fn cache_on_disk(
|
||||||
#tcx: QueryCtxt<'tcx>,
|
#tcx: QueryCtxt<'tcx>,
|
||||||
#key: &Self::Key,
|
#key: &Self::Key,
|
||||||
#value: Option<&Self::Value>
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
#expr
|
#expr
|
||||||
}
|
}
|
||||||
|
|
|
@ -765,10 +765,7 @@ rustc_queries! {
|
||||||
/// additional requirements that the closure's creator must verify.
|
/// additional requirements that the closure's creator must verify.
|
||||||
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
|
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
|
||||||
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
|
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
|
||||||
cache_on_disk_if(tcx, opt_result) {
|
cache_on_disk_if(tcx) { tcx.is_closure(key.to_def_id()) }
|
||||||
tcx.is_closure(key.to_def_id())
|
|
||||||
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
|
query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
|
||||||
desc {
|
desc {
|
||||||
|
|
|
@ -1033,7 +1033,7 @@ where
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if Q::cache_on_disk(tcx, &key, Some(value)) {
|
if Q::cache_on_disk(tcx, &key) {
|
||||||
let dep_node = SerializedDepNodeIndex::new(dep_node.index());
|
let dep_node = SerializedDepNodeIndex::new(dep_node.index());
|
||||||
|
|
||||||
// Record position of the cache entry.
|
// Record position of the cache entry.
|
||||||
|
|
|
@ -418,7 +418,7 @@ macro_rules! define_queries {
|
||||||
|
|
||||||
let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
|
let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
|
||||||
let tcx = QueryCtxt::from_tcx(tcx);
|
let tcx = QueryCtxt::from_tcx(tcx);
|
||||||
if queries::$name::cache_on_disk(tcx, &key, None) {
|
if queries::$name::cache_on_disk(tcx, &key) {
|
||||||
let _ = tcx.$name(key);
|
let _ = tcx.$name(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
|
||||||
pub compute: fn(CTX::DepContext, K) -> V,
|
pub compute: fn(CTX::DepContext, K) -> V,
|
||||||
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
||||||
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
||||||
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
pub cache_on_disk: fn(CTX, &K) -> bool,
|
||||||
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
|
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
|
||||||
(self.compute)(tcx, key)
|
(self.compute)(tcx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool {
|
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K) -> bool {
|
||||||
(self.cache_on_disk)(tcx, key, value)
|
(self.cache_on_disk)(tcx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn try_load_from_disk(&self, tcx: CTX, index: SerializedDepNodeIndex) -> Option<V> {
|
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> {
|
||||||
fn describe(tcx: CTX, key: Self::Key) -> String;
|
fn describe(tcx: CTX, key: Self::Key) -> String;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cache_on_disk(_: CTX, _: &Self::Key, _: Option<&Self::Value>) -> bool {
|
fn cache_on_disk(_: CTX, _: &Self::Key) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -512,7 +512,7 @@ where
|
||||||
|
|
||||||
// First we try to load the result from the on-disk cache.
|
// First we try to load the result from the on-disk cache.
|
||||||
// Some things are never cached on disk.
|
// Some things are never cached on disk.
|
||||||
if query.cache_on_disk(tcx, key, None) {
|
if query.cache_on_disk(tcx, key) {
|
||||||
let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
|
let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
|
||||||
let result = query.try_load_from_disk(tcx, prev_dep_node_index);
|
let result = query.try_load_from_disk(tcx, prev_dep_node_index);
|
||||||
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
|
||||||
|
|
Loading…
Add table
Reference in a new issue