diff --git a/compiler/rustc_query_impl/src/dep_kind_vtables.rs b/compiler/rustc_query_impl/src/dep_kind_vtables.rs index 882e59cfa1f3a..f892ff05214f9 100644 --- a/compiler/rustc_query_impl/src/dep_kind_vtables.rs +++ b/compiler/rustc_query_impl/src/dep_kind_vtables.rs @@ -2,7 +2,7 @@ use rustc_middle::bug; use rustc_middle::dep_graph::{DepKindVTable, DepNodeKey, KeyFingerprintStyle}; use rustc_middle::query::QueryCache; -use crate::QueryDispatcherUnerased; +use crate::GetQueryVTable; use crate::plumbing::{force_from_dep_node_inner, try_load_from_on_disk_cache_inner}; /// [`DepKindVTable`] constructors for special dep kinds that aren't queries. @@ -102,18 +102,17 @@ mod non_query { /// Shared implementation of the [`DepKindVTable`] constructor for queries. /// Called from macro-generated code for each query. -pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q, Cache>( +pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q>( is_anon: bool, is_eval_always: bool, ) -> DepKindVTable<'tcx> where - Q: QueryDispatcherUnerased<'tcx, Cache>, - Cache: QueryCache + 'tcx, + Q: GetQueryVTable<'tcx>, { let key_fingerprint_style = if is_anon { KeyFingerprintStyle::Opaque } else { - >::key_fingerprint_style() + ::Key::key_fingerprint_style() }; if is_anon || !key_fingerprint_style.reconstructible() { diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 41a947bb4a84c..63cba4bb6172b 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -37,22 +37,18 @@ mod job; mod profiling_support; mod values; -/// Provides access to vtable-like operations for a query (by obtaining a -/// `QueryVTable`), but also keeps track of the "unerased" value type of the -/// query (i.e. the actual result type in the query declaration). +/// Trait that knows how to look up the [`QueryVTable`] for a particular query. /// /// This trait allows some per-query code to be defined in generic functions /// with a trait bound, instead of having to be defined inline within a macro /// expansion. /// /// There is one macro-generated implementation of this trait for each query, -/// on the type `rustc_query_impl::query_impl::$name::QueryType`. -trait QueryDispatcherUnerased<'tcx, C: QueryCache> { - type UnerasedValue; +/// on the type `rustc_query_impl::query_impl::$name::VTableGetter`. +trait GetQueryVTable<'tcx> { + type Cache: QueryCache + 'tcx; - fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, C>; - - fn restore_val(value: C::Value) -> Self::UnerasedValue; + fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache>; } pub fn query_system<'tcx>( diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 11077e8e0ee20..a25be9bb0156d 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -13,12 +13,13 @@ use rustc_middle::bug; #[expect(unused_imports, reason = "used by doc comments")] use rustc_middle::dep_graph::DepKindVTable; use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeIndex, DepNodeKey, SerializedDepNodeIndex}; +use rustc_middle::query::erase::{Erasable, Erased}; use rustc_middle::query::on_disk_cache::{ AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex, }; use rustc_middle::query::plumbing::QueryVTable; use rustc_middle::query::{ - Key, QueryCache, QueryJobId, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, + Key, QueryCache, QueryJobId, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, erase, }; use rustc_middle::ty::codec::TyEncoder; use rustc_middle::ty::print::with_reduced_queries; @@ -27,7 +28,6 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::def_id::LOCAL_CRATE; -use crate::QueryDispatcherUnerased; use crate::error::{QueryOverflow, QueryOverflowNote}; use crate::execution::{all_inactive, force_query}; use crate::job::{QueryJobMap, find_dep_kind_root}; @@ -324,14 +324,14 @@ where QueryStackFrame::new(info, kind, def_id, def_id_for_ty_in_cycle) } -pub(crate) fn encode_query_results<'a, 'tcx, Q, C: QueryCache>( - query: &'tcx QueryVTable<'tcx, C>, +pub(crate) fn encode_query_results_inner<'a, 'tcx, C, V>( tcx: TyCtxt<'tcx>, + query: &'tcx QueryVTable<'tcx, C>, encoder: &mut CacheEncoder<'a, 'tcx>, query_result_index: &mut EncodedDepNodeIndex, ) where - Q: QueryDispatcherUnerased<'tcx, C>, - Q::UnerasedValue: Encodable>, + C: QueryCache>, + V: Erasable + Encodable>, { let _timer = tcx.prof.generic_activity_with_arg("encode_query_results_for", query.name); @@ -346,7 +346,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q, C: QueryCache>( // Encode the type check tables with the `SerializedDepNodeIndex` // as tag. - encoder.encode_tagged(dep_node, &Q::restore_val(*value)); + encoder.encode_tagged(dep_node, &erase::restore_val::(*value)); } }); } @@ -473,7 +473,6 @@ macro_rules! define_queries { pub(crate) mod query_impl { $(pub(crate) mod $name { use super::super::*; - use std::marker::PhantomData; use ::rustc_middle::query::erase::{self, Erased}; pub(crate) mod get_query_incr { @@ -607,29 +606,16 @@ macro_rules! define_queries { } } - #[derive(Copy, Clone, Default)] - pub(crate) struct QueryType<'tcx> { - data: PhantomData<&'tcx ()> - } + /// Marker type that implements [`GetQueryVTable`] for this query. + pub(crate) enum VTableGetter {} - impl<'tcx> QueryDispatcherUnerased<'tcx, queries::$name::Storage<'tcx>> - for QueryType<'tcx> - { - type UnerasedValue = queries::$name::Value<'tcx>; + impl<'tcx> GetQueryVTable<'tcx> for VTableGetter { + type Cache = rustc_middle::queries::$name::Storage<'tcx>; #[inline(always)] - fn query_vtable(tcx: TyCtxt<'tcx>) - -> &'tcx QueryVTable<'tcx, queries::$name::Storage<'tcx>> - { + fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache> { &tcx.query_system.query_vtables.$name } - - #[inline(always)] - fn restore_val(value: as QueryCache>::Value) - -> Self::UnerasedValue - { - erase::restore_val::>(value) - } } /// Internal per-query plumbing for collecting the set of active jobs for this query. @@ -683,12 +669,9 @@ macro_rules! define_queries { encoder: &mut CacheEncoder<'_, 'tcx>, query_result_index: &mut EncodedDepNodeIndex ) { - $crate::plumbing::encode_query_results::< - query_impl::$name::QueryType<'tcx>, - _ - > ( - &tcx.query_system.query_vtables.$name, + $crate::plumbing::encode_query_results_inner( tcx, + &tcx.query_system.query_vtables.$name, encoder, query_result_index, ) @@ -773,8 +756,8 @@ macro_rules! define_queries { $( /// `DepKindVTable` constructor for this query. pub(crate) fn $name<'tcx>() -> DepKindVTable<'tcx> { - use $crate::query_impl::$name::QueryType; - make_dep_kind_vtable_for_query::, _>( + use $crate::query_impl::$name::VTableGetter; + make_dep_kind_vtable_for_query::( is_anon!([$($modifiers)*]), is_eval_always!([$($modifiers)*]), )