Remove cache_on_disk from QueryVTable

This is not only simpler, but removes a generic function and unwrap.
I have hope it will see compile time and bootstrap time improvements.
This commit is contained in:
Joshua Nelson 2022-09-01 22:26:03 -05:00
parent b164dbc271
commit 7208bdee33
3 changed files with 6 additions and 13 deletions

View file

@ -442,8 +442,7 @@ fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) ->
hash_result: hash_result!([$($modifiers)*]),
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
compute,
cache_on_disk,
try_load_from_disk: Self::TRY_LOAD_FROM_DISK,
try_load_from_disk: if cache_on_disk { Self::TRY_LOAD_FROM_DISK } else { None },
}
}

View file

@ -25,11 +25,12 @@ pub struct QueryVTable<CTX: QueryContext, K, V> {
pub dep_kind: CTX::DepKind,
pub eval_always: bool,
pub depth_limit: bool,
pub cache_on_disk: bool,
pub compute: fn(CTX::DepContext, K) -> V,
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
pub handle_cycle_error: HandleCycleError,
// NOTE: this is not quite the same as `Q::TRY_LOAD_FROM_DISK`; it can also be `None` if
// `cache_on_disk` returned false for this key.
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
}
@ -44,13 +45,6 @@ pub(crate) fn to_dep_node(&self, tcx: CTX::DepContext, key: &K) -> DepNode<CTX::
pub(crate) fn compute(&self, tcx: CTX::DepContext, key: K) -> V {
(self.compute)(tcx, key)
}
pub(crate) fn try_load_from_disk(&self, tcx: CTX, index: SerializedDepNodeIndex) -> Option<V> {
self.try_load_from_disk
.expect("QueryDescription::load_from_disk() called for an unsupported query.")(
tcx, index,
)
}
}
pub trait QueryDescription<CTX: QueryContext>: QueryConfig {

View file

@ -488,14 +488,14 @@ fn try_load_from_disk_and_cache_in_memory<CTX, K, V>(
// First we try to load the result from the on-disk cache.
// Some things are never cached on disk.
if query.cache_on_disk {
if let Some(try_load_from_disk) = query.try_load_from_disk {
let prof_timer = tcx.dep_context().profiler().incr_cache_loading();
// The call to `with_query_deserialization` enforces that no new `DepNodes`
// are created during deserialization. See the docs of that method for more
// details.
let result = dep_graph
.with_query_deserialization(|| query.try_load_from_disk(tcx, prev_dep_node_index));
let result =
dep_graph.with_query_deserialization(|| try_load_from_disk(tcx, prev_dep_node_index));
prof_timer.finish_with_query_invocation_id(dep_node_index.into());