diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index f2d3154bf8950..d09df8e158439 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -91,6 +91,8 @@ pub struct OnDiskCache { // we try to map an `ExpnHash` to its value in the current // compilation session. foreign_expn_data: UnhashMap, + + fresh: bool, } // This type is used only for serialization and deserialization. @@ -175,6 +177,7 @@ impl OnDiskCache { expn_data: footer.expn_data, foreign_expn_data: footer.foreign_expn_data, hygiene_context: Default::default(), + fresh: false, }) } @@ -190,9 +193,14 @@ impl OnDiskCache { expn_data: UnhashMap::default(), foreign_expn_data: UnhashMap::default(), hygiene_context: Default::default(), + fresh: true, } } + pub fn is_fresh(&self) -> bool { + self.fresh + } + /// Release the serialized backing `Mmap`. pub fn close_serialized_data_mmap(&self) { // Obtain a write lock, and replace the mmap with None to drop it. diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index b614bc14b4539..ad25225704504 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -19,7 +19,7 @@ use tracing::warn; use crate::dep_graph::{DepNode, DepNodeIndex}; use crate::handle_cycle_error; use crate::job::{QueryJobInfo, QueryJobMap, create_cycle_error, find_cycle_in_stack}; -use crate::plumbing::{current_query_job, loadable_from_disk, next_job_id, start_query}; +use crate::plumbing::{current_query_job, loadable_from_disk_incr, next_job_id, start_query}; use crate::query_impl::for_each_query_vtable; #[inline] @@ -604,7 +604,7 @@ fn ensure_can_skip_execution<'tcx, C: QueryCache>( // for this key. EnsureMode::Done => { (query.will_cache_on_disk_for_key_fn)(key) - && loadable_from_disk(tcx, serialized_dep_node_index) + && loadable_from_disk_incr(tcx, serialized_dep_node_index) } } } diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 11f960598c387..25de2a557e9cd 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -173,9 +173,11 @@ pub(crate) fn promote_from_disk_inner<'tcx, C: QueryCache>( } } -pub(crate) fn loadable_from_disk<'tcx>(tcx: TyCtxt<'tcx>, id: SerializedDepNodeIndex) -> bool { - if let Some(cache) = tcx.query_system.on_disk_cache.as_ref() { - cache.loadable_from_disk(id) +pub(crate) fn loadable_from_disk_incr<'tcx>(tcx: TyCtxt<'tcx>, id: SerializedDepNodeIndex) -> bool { + let cache = tcx.query_system.on_disk_cache.as_ref().unwrap(); + if !cache.is_fresh() { + assert!(cache.loadable_from_disk(id)); + true } else { false }