From 8f0ca1d2536701a13f2df03ce2db2e235f8a3f75 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 26 Feb 2026 06:16:28 +1100 Subject: [PATCH 1/5] Remove `QUERY_KEY_HASH_VERIFY`. And also `query_key_hash_verify` for each query. This is done by generating `query_key_hash_verify_all` and having it do things more directly. --- compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/plumbing.rs | 32 +++++++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 1b93ffe945b3d..f1a4f3cad25ae 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -19,7 +19,7 @@ use rustc_span::Span; pub use crate::dep_kind_vtables::make_dep_kind_vtables; pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack}; -pub use crate::plumbing::{collect_active_jobs_from_all_queries, query_key_hash_verify_all}; +pub use crate::plumbing::collect_active_jobs_from_all_queries; use crate::plumbing::{encode_all_query_results, try_mark_green}; use crate::profiling_support::QueryKeyStringCache; pub use crate::profiling_support::alloc_self_profile_query_strings; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 8920f8dba38d1..7a69453e2aee8 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -134,16 +134,6 @@ pub(super) fn encode_all_query_results<'tcx>( } } -pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) { - if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) { - tcx.sess.time("query_key_hash_verify_all", || { - for verify in super::QUERY_KEY_HASH_VERIFY.iter() { - verify(tcx); - } - }) - } -} - macro_rules! cycle_error_handling { ([]) => {{ rustc_middle::query::CycleErrorHandling::Error @@ -689,13 +679,6 @@ macro_rules! define_queries { ) } } - - pub(crate) fn query_key_hash_verify<'tcx>(tcx: TyCtxt<'tcx>) { - $crate::plumbing::query_key_hash_verify( - &tcx.query_system.query_vtables.$name, - tcx, - ) - } })*} pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::QueryVTables<'tcx> { @@ -744,9 +727,18 @@ macro_rules! define_queries { ),* ]; - const QUERY_KEY_HASH_VERIFY: &[ - for<'tcx> fn(TyCtxt<'tcx>) - ] = &[$(query_impl::$name::query_key_hash_verify),*]; + pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) { + if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) { + tcx.sess.time("query_key_hash_verify_all", || { + $( + $crate::plumbing::query_key_hash_verify( + &tcx.query_system.query_vtables.$name, + tcx + ); + )* + }) + } + } /// Declares a dep-kind vtable constructor for each query. mod _dep_kind_vtable_ctors_for_queries { From 65cf5d73ab6854076086d510e3ab1f03d9872926 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 26 Feb 2026 06:42:56 +1100 Subject: [PATCH 2/5] Minimize `gather_active_jobs`. Currently `gather_active_jobs` and `gather_active_jobs_inner` do some of the work each. This commit changes things so that `gather_active_jobs` is just a thin wrapper around `gather_active_jobs_inner`. This paves the way for removing `gather_active_jobs` in the next commit. --- compiler/rustc_query_impl/src/execution.rs | 37 +++++++++++++++------- compiler/rustc_query_impl/src/plumbing.rs | 27 +++------------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index f4c1df145af35..856a6692adc91 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -3,13 +3,14 @@ use std::mem; use rustc_data_structures::hash_table::{Entry, HashTable}; use rustc_data_structures::stack::ensure_sufficient_stack; +use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::{outline, sharded, sync}; use rustc_errors::{Diag, FatalError, StashKey}; use rustc_middle::dep_graph::{DepGraphData, DepNodeKey}; use rustc_middle::query::plumbing::QueryVTable; use rustc_middle::query::{ ActiveKeyStatus, CycleError, CycleErrorHandling, EnsureMode, QueryCache, QueryJob, QueryJobId, - QueryLatch, QueryMode, QueryStackDeferred, QueryStackFrame, QueryState, + QueryKey, QueryLatch, QueryMode, QueryState, }; use rustc_middle::ty::TyCtxt; use rustc_middle::verify_ich::incremental_verify_ich; @@ -44,17 +45,20 @@ pub(crate) fn all_inactive<'tcx, K>(state: &QueryState<'tcx, K>) -> bool { /// Internal plumbing for collecting the set of active jobs for this query. /// /// Should only be called from `gather_active_jobs`. -pub(crate) fn gather_active_jobs_inner<'tcx, K: Copy>( - state: &QueryState<'tcx, K>, +pub(crate) fn gather_active_jobs_inner<'tcx, C>( + query: &'tcx QueryVTable<'tcx, C>, tcx: TyCtxt<'tcx>, - make_frame: fn(TyCtxt<'tcx>, K) -> QueryStackFrame>, require_complete: bool, job_map_out: &mut QueryJobMap<'tcx>, // Out-param; job info is gathered into this map -) -> Option<()> { +) -> Option<()> +where + C: QueryCache, + QueryVTable<'tcx, C>: DynSync, +{ let mut active = Vec::new(); // Helper to gather active jobs from a single shard. - let mut gather_shard_jobs = |shard: &HashTable<(K, ActiveKeyStatus<'tcx>)>| { + let mut gather_shard_jobs = |shard: &HashTable<(C::Key, ActiveKeyStatus<'tcx>)>| { for (k, v) in shard.iter() { if let ActiveKeyStatus::Started(ref job) = *v { active.push((*k, job.clone())); @@ -64,22 +68,33 @@ pub(crate) fn gather_active_jobs_inner<'tcx, K: Copy>( // Lock shards and gather jobs from each shard. if require_complete { - for shard in state.active.lock_shards() { + for shard in query.state.active.lock_shards() { gather_shard_jobs(&shard); } } else { // We use try_lock_shards here since we are called from the // deadlock handler, and this shouldn't be locked. - for shard in state.active.try_lock_shards() { - let shard = shard?; - gather_shard_jobs(&shard); + for shard in query.state.active.try_lock_shards() { + // This can be called during unwinding, and the function has a `try_`-prefix, so + // don't `unwrap()` here, just manually check for `None` and do best-effort error + // reporting. + match shard { + None => { + tracing::warn!( + "Failed to collect active jobs for query with name `{}`!", + query.name + ); + return None; + } + Some(shard) => gather_shard_jobs(&shard), + } } } // Call `make_frame` while we're not holding a `state.active` lock as `make_frame` may call // queries leading to a deadlock. for (key, job) in active { - let frame = make_frame(tcx, key); + let frame = crate::plumbing::create_deferred_query_stack_frame(tcx, query, key); job_map_out.insert(job.id, QueryJobInfo { frame, job }); } diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 7a69453e2aee8..8ac6b385b8894 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -303,8 +303,7 @@ pub(crate) fn create_deferred_query_stack_frame<'tcx, C>( key: C::Key, ) -> QueryStackFrame> where - C: QueryCache, - C::Key: QueryKey + DynSend + DynSync, + C: QueryCache, QueryVTable<'tcx, C>: DynSync, { let kind = vtable.dep_kind; @@ -627,30 +626,12 @@ macro_rules! define_queries { require_complete: bool, job_map_out: &mut QueryJobMap<'tcx>, ) -> Option<()> { - let make_frame = |tcx: TyCtxt<'tcx>, key| { - let vtable = &tcx.query_system.query_vtables.$name; - $crate::plumbing::create_deferred_query_stack_frame(tcx, vtable, key) - }; - - // Call `gather_active_jobs_inner` to do the actual work. - let res = crate::execution::gather_active_jobs_inner( - &tcx.query_system.query_vtables.$name.state, + crate::execution::gather_active_jobs_inner( + &tcx.query_system.query_vtables.$name, tcx, - make_frame, require_complete, job_map_out, - ); - - // this can be called during unwinding, and the function has a `try_`-prefix, so - // don't `unwrap()` here, just manually check for `None` and do best-effort error - // reporting. - if res.is_none() { - tracing::warn!( - "Failed to collect active jobs for query with name `{}`!", - stringify!($name) - ); - } - res + ) } pub(crate) fn alloc_self_profile_query_strings<'tcx>( From 6b0beecd9597153ddea2e00f4ce3fea4e63e93ab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 26 Feb 2026 08:23:04 +1100 Subject: [PATCH 3/5] Remove `PER_QUERY_GATHER_ACTIVE_JOBS_FNS`. And also `gather_active_jobs` for each query. This is done by generating `collect_active_jobs_from_all_queries` and having it do things more directly. --- compiler/rustc_query_impl/src/execution.rs | 13 ++-- compiler/rustc_query_impl/src/job.rs | 4 +- compiler/rustc_query_impl/src/lib.rs | 1 - compiler/rustc_query_impl/src/plumbing.rs | 89 ++++++++-------------- 4 files changed, 42 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index 856a6692adc91..ec67702507fbd 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -16,11 +16,10 @@ use rustc_middle::ty::TyCtxt; use rustc_middle::verify_ich::incremental_verify_ich; use rustc_span::{DUMMY_SP, Span}; +use crate::collect_active_jobs_from_all_queries; use crate::dep_graph::{DepNode, DepNodeIndex}; use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle}; -use crate::plumbing::{ - collect_active_jobs_from_all_queries, current_query_job, next_job_id, start_query, -}; +use crate::plumbing::{current_query_job, next_job_id, start_query}; #[inline] fn equivalent_key(k: &K) -> impl Fn(&(K, V)) -> bool + '_ { @@ -44,8 +43,12 @@ pub(crate) fn all_inactive<'tcx, K>(state: &QueryState<'tcx, K>) -> bool { /// Internal plumbing for collecting the set of active jobs for this query. /// -/// Should only be called from `gather_active_jobs`. -pub(crate) fn gather_active_jobs_inner<'tcx, C>( +/// Should only be called from `collect_active_jobs_from_all_queries`. +/// +/// (We arbitrarily use the word "gather" when collecting the jobs for +/// each individual query, so that we have distinct function names to +/// grep for.) +pub(crate) fn gather_active_jobs<'tcx, C>( query: &'tcx QueryVTable<'tcx, C>, tcx: TyCtxt<'tcx>, require_complete: bool, diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs index 2d9824a783ea5..228c611df3654 100644 --- a/compiler/rustc_query_impl/src/job.rs +++ b/compiler/rustc_query_impl/src/job.rs @@ -14,7 +14,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::{DUMMY_SP, Span}; -use crate::plumbing::collect_active_jobs_from_all_queries; +use crate::collect_active_jobs_from_all_queries; /// Map from query job IDs to job information collected by /// `collect_active_jobs_from_all_queries`. @@ -26,7 +26,7 @@ pub struct QueryJobMap<'tcx> { impl<'tcx> QueryJobMap<'tcx> { /// Adds information about a job ID to the job map. /// - /// Should only be called by `gather_active_jobs_inner`. + /// Should only be called by `gather_active_jobs`. pub(crate) fn insert(&mut self, id: QueryJobId, info: QueryJobInfo<'tcx>) { self.map.insert(id, info); } diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index f1a4f3cad25ae..cbaab61d3c7aa 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -19,7 +19,6 @@ use rustc_span::Span; pub use crate::dep_kind_vtables::make_dep_kind_vtables; pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack}; -pub use crate::plumbing::collect_active_jobs_from_all_queries; use crate::plumbing::{encode_all_query_results, try_mark_green}; use crate::profiling_support::QueryKeyStringCache; pub use crate::profiling_support::alloc_self_profile_query_strings; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 8ac6b385b8894..98985fd5f172e 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -29,9 +29,10 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::def_id::LOCAL_CRATE; +use crate::collect_active_jobs_from_all_queries; use crate::error::{QueryOverflow, QueryOverflowNote}; use crate::execution::{all_inactive, force_query}; -use crate::job::{QueryJobMap, find_dep_kind_root}; +use crate::job::find_dep_kind_root; fn depth_limit_error<'tcx>(tcx: TyCtxt<'tcx>, job: QueryJobId) { let job_map = @@ -94,32 +95,6 @@ pub(crate) fn start_query<'tcx, R>( }) } -/// Returns a map of currently active query jobs, collected from all queries. -/// -/// If `require_complete` is `true`, this function locks all shards of the -/// query results to produce a complete map, which always returns `Ok`. -/// Otherwise, it may return an incomplete map as an error if any shard -/// lock cannot be acquired. -/// -/// Prefer passing `false` to `require_complete` to avoid potential deadlocks, -/// especially when called from within a deadlock handler, unless a -/// complete map is needed and no deadlock is possible at this call site. -pub fn collect_active_jobs_from_all_queries<'tcx>( - tcx: TyCtxt<'tcx>, - require_complete: bool, -) -> Result, QueryJobMap<'tcx>> { - let mut job_map_out = QueryJobMap::default(); - let mut complete = true; - - for gather_fn in crate::PER_QUERY_GATHER_ACTIVE_JOBS_FNS.iter() { - if gather_fn(tcx, require_complete, &mut job_map_out).is_none() { - complete = false; - } - } - - if complete { Ok(job_map_out) } else { Err(job_map_out) } -} - pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool { tcx.dep_graph.try_mark_green(tcx, dep_node).is_some() } @@ -618,22 +593,6 @@ macro_rules! define_queries { } } - /// Internal per-query plumbing for collecting the set of active jobs for this query. - /// - /// Should only be called through `PER_QUERY_GATHER_ACTIVE_JOBS_FNS`. - pub(crate) fn gather_active_jobs<'tcx>( - tcx: TyCtxt<'tcx>, - require_complete: bool, - job_map_out: &mut QueryJobMap<'tcx>, - ) -> Option<()> { - crate::execution::gather_active_jobs_inner( - &tcx.query_system.query_vtables.$name, - tcx, - require_complete, - job_map_out, - ) - } - pub(crate) fn alloc_self_profile_query_strings<'tcx>( tcx: TyCtxt<'tcx>, string_cache: &mut QueryKeyStringCache @@ -672,21 +631,37 @@ macro_rules! define_queries { // These arrays are used for iteration and can't be indexed by `DepKind`. - /// Used by `collect_active_jobs_from_all_queries` to iterate over all - /// queries, and gather the active jobs for each query. + /// Returns a map of currently active query jobs, collected from all queries. /// - /// (We arbitrarily use the word "gather" when collecting the jobs for - /// each individual query, so that we have distinct function names to - /// grep for.) - const PER_QUERY_GATHER_ACTIVE_JOBS_FNS: &[ - for<'tcx> fn( - tcx: TyCtxt<'tcx>, - require_complete: bool, - job_map_out: &mut QueryJobMap<'tcx>, - ) -> Option<()> - ] = &[ - $( $crate::query_impl::$name::gather_active_jobs ),* - ]; + /// If `require_complete` is `true`, this function locks all shards of the + /// query results to produce a complete map, which always returns `Ok`. + /// Otherwise, it may return an incomplete map as an error if any shard + /// lock cannot be acquired. + /// + /// Prefer passing `false` to `require_complete` to avoid potential deadlocks, + /// especially when called from within a deadlock handler, unless a + /// complete map is needed and no deadlock is possible at this call site. + pub fn collect_active_jobs_from_all_queries<'tcx>( + tcx: TyCtxt<'tcx>, + require_complete: bool, + ) -> Result, QueryJobMap<'tcx>> { + let mut job_map_out = QueryJobMap::default(); + let mut complete = true; + + $( + let res = crate::execution::gather_active_jobs( + &tcx.query_system.query_vtables.$name, + tcx, + require_complete, + &mut job_map_out, + ); + if res.is_none() { + complete = false; + } + )* + + if complete { Ok(job_map_out) } else { Err(job_map_out) } + } const ALLOC_SELF_PROFILE_QUERY_STRINGS: &[ for<'tcx> fn(TyCtxt<'tcx>, &mut QueryKeyStringCache) From 7323750309424bea099e479db49cb2ad8be03b0f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 26 Feb 2026 08:39:59 +1100 Subject: [PATCH 4/5] Remove `ALLOC_SELF_PROFILE_QUERY_STRINGS`. And also `alloc_self_profile_query_strings` for each query. This is done by generating the top-level `alloc_self_profile_query_strings` and having it do things more directly. --- compiler/rustc_query_impl/src/lib.rs | 1 - compiler/rustc_query_impl/src/plumbing.rs | 42 ++++++++++++------- .../rustc_query_impl/src/profiling_support.rs | 24 +---------- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index cbaab61d3c7aa..34800096084cb 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -21,7 +21,6 @@ pub use crate::dep_kind_vtables::make_dep_kind_vtables; pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack}; use crate::plumbing::{encode_all_query_results, try_mark_green}; use crate::profiling_support::QueryKeyStringCache; -pub use crate::profiling_support::alloc_self_profile_query_strings; use crate::values::Value; #[macro_use] diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 98985fd5f172e..1f73277e88ff8 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -593,18 +593,6 @@ macro_rules! define_queries { } } - pub(crate) fn alloc_self_profile_query_strings<'tcx>( - tcx: TyCtxt<'tcx>, - string_cache: &mut QueryKeyStringCache - ) { - $crate::profiling_support::alloc_self_profile_query_strings_for_query_cache( - tcx, - stringify!($name), - &tcx.query_system.query_vtables.$name.cache, - string_cache, - ) - } - item_if_cache_on_disk! { [$($modifiers)*] pub(crate) fn encode_query_results<'tcx>( tcx: TyCtxt<'tcx>, @@ -663,9 +651,33 @@ macro_rules! define_queries { if complete { Ok(job_map_out) } else { Err(job_map_out) } } - const ALLOC_SELF_PROFILE_QUERY_STRINGS: &[ - for<'tcx> fn(TyCtxt<'tcx>, &mut QueryKeyStringCache) - ] = &[$(query_impl::$name::alloc_self_profile_query_strings),*]; + /// All self-profiling events generated by the query engine use + /// virtual `StringId`s for their `event_id`. This method makes all + /// those virtual `StringId`s point to actual strings. + /// + /// If we are recording only summary data, the ids will point to + /// just the query names. If we are recording query keys too, we + /// allocate the corresponding strings here. + pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { + if !tcx.prof.enabled() { + return; + } + + let _prof_timer = tcx.sess.prof.generic_activity("self_profile_alloc_query_strings"); + + let mut string_cache = QueryKeyStringCache::new(); + + $( + $crate::profiling_support::alloc_self_profile_query_strings_for_query_cache( + tcx, + stringify!($name), + &tcx.query_system.query_vtables.$name.cache, + &mut string_cache, + ); + )* + + tcx.sess.prof.store_query_cache_hits(); + } const ENCODE_QUERY_RESULTS: &[ Option fn( diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 679fee49b6c6d..cd6979a7c22ca 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -14,7 +14,7 @@ pub(crate) struct QueryKeyStringCache { } impl QueryKeyStringCache { - fn new() -> QueryKeyStringCache { + pub(crate) fn new() -> QueryKeyStringCache { QueryKeyStringCache { def_id_cache: Default::default() } } } @@ -239,25 +239,3 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>( } }); } - -/// All self-profiling events generated by the query engine use -/// virtual `StringId`s for their `event_id`. This method makes all -/// those virtual `StringId`s point to actual strings. -/// -/// If we are recording only summary data, the ids will point to -/// just the query names. If we are recording query keys too, we -/// allocate the corresponding strings here. -pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { - if !tcx.prof.enabled() { - return; - } - - let _prof_timer = tcx.sess.prof.generic_activity("self_profile_alloc_query_strings"); - - let mut string_cache = QueryKeyStringCache::new(); - - for alloc in super::ALLOC_SELF_PROFILE_QUERY_STRINGS.iter() { - alloc(tcx, &mut string_cache) - } - tcx.sess.prof.store_query_cache_hits(); -} From 90abedee9cd00939b26356166a0049171e43a845 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 26 Feb 2026 11:07:29 +1100 Subject: [PATCH 5/5] Remove `ENCODE_QUERY_RESULTS`. And also `encode_query_results` for each cacheable query. This is done by generating `encode_all_query_results` and having it do things more directly. --- compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/plumbing.rs | 59 +++++++---------------- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 34800096084cb..875dd07ff25f0 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -19,7 +19,7 @@ use rustc_span::Span; pub use crate::dep_kind_vtables::make_dep_kind_vtables; pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack}; -use crate::plumbing::{encode_all_query_results, try_mark_green}; +use crate::plumbing::try_mark_green; use crate::profiling_support::QueryKeyStringCache; use crate::values::Value; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 1f73277e88ff8..92a4b7ff2b659 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -99,16 +99,6 @@ pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> boo tcx.dep_graph.try_mark_green(tcx, dep_node).is_some() } -pub(super) fn encode_all_query_results<'tcx>( - tcx: TyCtxt<'tcx>, - encoder: &mut CacheEncoder<'_, 'tcx>, - query_result_index: &mut EncodedDepNodeIndex, -) { - for encode in super::ENCODE_QUERY_RESULTS.iter().copied().flatten() { - encode(tcx, encoder, query_result_index); - } -} - macro_rules! cycle_error_handling { ([]) => {{ rustc_middle::query::CycleErrorHandling::Error @@ -290,7 +280,7 @@ where QueryStackFrame::new(info, kind, def_id, def_id_for_ty_in_cycle) } -pub(crate) fn encode_query_results_inner<'a, 'tcx, C, V>( +pub(crate) fn encode_query_results<'a, 'tcx, C, V>( tcx: TyCtxt<'tcx>, query: &'tcx QueryVTable<'tcx, C>, encoder: &mut CacheEncoder<'a, 'tcx>, @@ -592,21 +582,6 @@ macro_rules! define_queries { &tcx.query_system.query_vtables.$name } } - - item_if_cache_on_disk! { [$($modifiers)*] - pub(crate) fn encode_query_results<'tcx>( - tcx: TyCtxt<'tcx>, - encoder: &mut CacheEncoder<'_, 'tcx>, - query_result_index: &mut EncodedDepNodeIndex - ) { - $crate::plumbing::encode_query_results_inner( - tcx, - &tcx.query_system.query_vtables.$name, - encoder, - query_result_index, - ) - } - } })*} pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::QueryVTables<'tcx> { @@ -617,8 +592,6 @@ macro_rules! define_queries { } } - // These arrays are used for iteration and can't be indexed by `DepKind`. - /// Returns a map of currently active query jobs, collected from all queries. /// /// If `require_complete` is `true`, this function locks all shards of the @@ -679,21 +652,23 @@ macro_rules! define_queries { tcx.sess.prof.store_query_cache_hits(); } - const ENCODE_QUERY_RESULTS: &[ - Option fn( - TyCtxt<'tcx>, - &mut CacheEncoder<'_, 'tcx>, - &mut EncodedDepNodeIndex) - > - ] = &[ + fn encode_all_query_results<'tcx>( + tcx: TyCtxt<'tcx>, + encoder: &mut CacheEncoder<'_, 'tcx>, + query_result_index: &mut EncodedDepNodeIndex, + ) { $( - if_cache_on_disk!([$($modifiers)*] { - Some(query_impl::$name::encode_query_results) - } { - None - }) - ),* - ]; + item_if_cache_on_disk! { + [$($modifiers)*] + $crate::plumbing::encode_query_results( + tcx, + &tcx.query_system.query_vtables.$name, + encoder, + query_result_index, + ) + } + )* + } pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) { if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) {