From 90abedee9cd00939b26356166a0049171e43a845 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 26 Feb 2026 11:07:29 +1100 Subject: [PATCH] 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 34800096084c..875dd07ff25f 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -19,7 +19,7 @@ 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 1f73277e88ff..92a4b7ff2b65 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 @@ pub(crate) fn create_deferred_query_stack_frame<'tcx, C>( 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 @@ fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache> { &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 @@ pub fn make_query_vtables<'tcx>(incremental: bool) -> queries::QueryVTables<'tcx } } - // 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 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { 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) {