Move the cache_on_disk check out of try_load_from_disk_fn.

It doesn't need to be in there, it can instead be at the single call
site. Removing it eliminates one parameter, makes `define_queries!`
smaller (which is always good), and also enables the next commit which
tidies up profiling.

This commit also changes how `value` and `verify` are initialized,
because I don't like the current way of doing it after the declaration.
This commit is contained in:
Nicholas Nethercote
2026-04-10 13:47:27 +10:00
parent 9004856428
commit 3afb618592
3 changed files with 17 additions and 17 deletions
+12 -9
View File
@@ -477,16 +477,17 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
debug_assert!(dep_graph_data.is_index_green(prev_index));
// First try to load the result from the on-disk cache. Some things are never cached on disk.
let value;
let verify;
match (query.try_load_from_disk_fn)(tcx, key, prev_index, dep_node_index) {
Some(loaded_value) => {
let try_value = if (query.will_cache_on_disk_for_key_fn)(key) {
(query.try_load_from_disk_fn)(tcx, prev_index, dep_node_index)
} else {
None
};
let (value, verify) = match try_value {
Some(value) => {
if std::intrinsics::unlikely(tcx.sess.opts.unstable_opts.query_dep_graph) {
dep_graph_data.mark_debug_loaded_from_disk(*dep_node)
}
value = loaded_value;
let prev_fingerprint = dep_graph_data.prev_value_fingerprint_of(prev_index);
// If `-Zincremental-verify-ich` is specified, re-hash results from
// the cache and make sure that they have the expected fingerprint.
@@ -495,17 +496,19 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
// from disk. Re-hashing results is fairly expensive, so we can't
// currently afford to verify every hash. This subset should still
// give us some coverage of potential bugs.
verify = prev_fingerprint.split().1.as_u64().is_multiple_of(32)
let verify = prev_fingerprint.split().1.as_u64().is_multiple_of(32)
|| tcx.sess.opts.unstable_opts.incremental_verify_ich;
(value, verify)
}
None => {
// We could not load a result from the on-disk cache, so recompute. The dep-graph for
// this computation is already in-place, so we can just call the query provider.
let prof_timer = tcx.prof.query_provider();
value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, key));
let value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, key));
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
verify = true;
(value, true)
}
};
+2 -7
View File
@@ -160,14 +160,9 @@ pub(crate) fn make_query_vtable<'tcx>(incremental: bool)
$crate::query_impl::$name::will_cache_on_disk_for_key,
#[cfg($cache_on_disk)]
try_load_from_disk_fn: |tcx, key, prev_index, index| {
try_load_from_disk_fn: |tcx, prev_index, index| {
use rustc_middle::queries::$name::{ProvidedValue, provided_to_erased};
// Check the cache-on-disk condition for this key.
if !$crate::query_impl::$name::will_cache_on_disk_for_key(key) {
return None;
}
let loaded_value: ProvidedValue<'tcx> =
$crate::plumbing::try_load_from_disk(tcx, prev_index, index)?;
@@ -175,7 +170,7 @@ pub(crate) fn make_query_vtable<'tcx>(incremental: bool)
Some(provided_to_erased(tcx, loaded_value))
},
#[cfg(not($cache_on_disk))]
try_load_from_disk_fn: |_tcx, _key, _prev_index, _index| None,
try_load_from_disk_fn: |_tcx, _prev_index, _index| None,
#[cfg($handle_cycle_error)]
handle_cycle_error_fn: |tcx, key, cycle, err| {