From ef2fa8ad3a5083941eccca528f90a89e9f7bc224 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Fri, 15 May 2026 12:21:22 +0300 Subject: [PATCH 1/2] Assert redundant incremental check --- compiler/rustc_query_impl/src/plumbing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 11f960598c387..5f36423f21542 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -175,7 +175,8 @@ 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) + assert!(cache.loadable_from_disk(id)); + true } else { false } From c23ce2e17f523d667ee25fd0dd48c85b742896f1 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Tue, 26 May 2026 11:16:03 +0300 Subject: [PATCH 2/2] Check if on_disk_cache was loaded or created fresh empty --- compiler/rustc_middle/src/query/on_disk_cache.rs | 8 ++++++++ compiler/rustc_query_impl/src/execution.rs | 4 ++-- compiler/rustc_query_impl/src/plumbing.rs | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) 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 5f36423f21542..25de2a557e9cd 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -173,8 +173,9 @@ 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() { +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 {