From fbea6ddcd29377d53de23f537fbda71af0ba45d5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 18 Feb 2026 14:35:24 +1100 Subject: [PATCH] Rename `trait Key` as `trait `QueryKey` Because `Key` is extremely generic and hard to search for. Also rename `LocalKey` and `AsLocalKey` similarly, for consistency. --- .../rustc_middle/src/dep_graph/dep_node.rs | 2 +- compiler/rustc_middle/src/query/keys.rs | 113 +++++++++--------- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/query/plumbing.rs | 4 +- compiler/rustc_mir_transform/src/errors.rs | 2 +- compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/plumbing.rs | 7 +- 7 files changed, 66 insertions(+), 66 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index ee7723e78201..63b78955ba87 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -51,7 +51,7 @@ use std::hash::Hash; use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; +use rustc_data_structures::stable_hasher::{StableHasher, StableOrd, ToStableHashKey}; use rustc_hir::def_id::DefId; use rustc_hir::definitions::DefPathHash; use rustc_macros::{Decodable, Encodable, HashStable}; diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 6652e6e78e76..d41f2ac66ba2 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -20,9 +20,8 @@ #[derive(Copy, Clone, Debug)] pub struct LocalCrate; -/// The `Key` trait controls what types can legally be used as the key -/// for a query. -pub trait Key: Sized { +/// Controls what types can legally be used as the key for a query. +pub trait QueryKey: Sized { /// The type of in-memory cache to use for queries with this key type. /// /// In practice the cache type must implement [`QueryCache`], though that @@ -47,15 +46,15 @@ fn def_id_for_ty_in_cycle(&self) -> Option { } } -pub trait AsLocalKey: Key { - type LocalKey; +pub trait AsLocalQueryKey: QueryKey { + type LocalQueryKey; /// Given an instance of this key, what crate is it referring to? /// This is used to find the provider. - fn as_local_key(&self) -> Option; + fn as_local_key(&self) -> Option; } -impl Key for () { +impl QueryKey for () { type Cache = SingleCache; fn default_span(&self, _: TyCtxt<'_>) -> Span { @@ -63,37 +62,37 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span { } } -impl<'tcx> Key for ty::InstanceKind<'tcx> { +impl<'tcx> QueryKey for ty::InstanceKind<'tcx> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.def_id()) } } -impl<'tcx> Key for ty::Instance<'tcx> { +impl<'tcx> QueryKey for ty::Instance<'tcx> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.def_id()) } } -impl<'tcx> Key for mir::interpret::GlobalId<'tcx> { +impl<'tcx> QueryKey for mir::interpret::GlobalId<'tcx> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.instance.default_span(tcx) } } -impl<'tcx> Key for (Ty<'tcx>, Option>) { +impl<'tcx> QueryKey for (Ty<'tcx>, Option>) { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for ty::LitToConstInput<'tcx> { +impl<'tcx> QueryKey for ty::LitToConstInput<'tcx> { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl Key for CrateNum { +impl QueryKey for CrateNum { type Cache = VecCache; fn default_span(&self, _: TyCtxt<'_>) -> Span { @@ -101,16 +100,16 @@ fn default_span(&self, _: TyCtxt<'_>) -> Span { } } -impl AsLocalKey for CrateNum { - type LocalKey = LocalCrate; +impl AsLocalQueryKey for CrateNum { + type LocalQueryKey = LocalCrate; #[inline(always)] - fn as_local_key(&self) -> Option { + fn as_local_key(&self) -> Option { (*self == LOCAL_CRATE).then_some(LocalCrate) } } -impl Key for OwnerId { +impl QueryKey for OwnerId { type Cache = VecCache; fn default_span(&self, tcx: TyCtxt<'_>) -> Span { @@ -122,7 +121,7 @@ fn key_as_def_id(&self) -> Option { } } -impl Key for LocalDefId { +impl QueryKey for LocalDefId { type Cache = VecCache; fn default_span(&self, tcx: TyCtxt<'_>) -> Span { @@ -134,7 +133,7 @@ fn key_as_def_id(&self) -> Option { } } -impl Key for DefId { +impl QueryKey for DefId { type Cache = DefIdCache; fn default_span(&self, tcx: TyCtxt<'_>) -> Span { @@ -147,16 +146,16 @@ fn key_as_def_id(&self) -> Option { } } -impl AsLocalKey for DefId { - type LocalKey = LocalDefId; +impl AsLocalQueryKey for DefId { + type LocalQueryKey = LocalDefId; #[inline(always)] - fn as_local_key(&self) -> Option { + fn as_local_key(&self) -> Option { self.as_local() } } -impl Key for LocalModDefId { +impl QueryKey for LocalModDefId { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(*self) } @@ -167,19 +166,19 @@ fn key_as_def_id(&self) -> Option { } } -impl Key for SimplifiedType { +impl QueryKey for SimplifiedType { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl Key for (DefId, DefId) { +impl QueryKey for (DefId, DefId) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) } } -impl Key for (DefId, Ident) { +impl QueryKey for (DefId, Ident) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.0) } @@ -190,73 +189,73 @@ fn key_as_def_id(&self) -> Option { } } -impl Key for (LocalDefId, LocalDefId, Ident) { +impl QueryKey for (LocalDefId, LocalDefId, Ident) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) } } -impl Key for (CrateNum, DefId) { +impl QueryKey for (CrateNum, DefId) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.1.default_span(tcx) } } -impl AsLocalKey for (CrateNum, DefId) { - type LocalKey = DefId; +impl AsLocalQueryKey for (CrateNum, DefId) { + type LocalQueryKey = DefId; #[inline(always)] - fn as_local_key(&self) -> Option { + fn as_local_key(&self) -> Option { (self.0 == LOCAL_CRATE).then(|| self.1) } } -impl Key for (CrateNum, SimplifiedType) { +impl QueryKey for (CrateNum, SimplifiedType) { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl AsLocalKey for (CrateNum, SimplifiedType) { - type LocalKey = SimplifiedType; +impl AsLocalQueryKey for (CrateNum, SimplifiedType) { + type LocalQueryKey = SimplifiedType; #[inline(always)] - fn as_local_key(&self) -> Option { + fn as_local_key(&self) -> Option { (self.0 == LOCAL_CRATE).then(|| self.1) } } -impl Key for (DefId, ty::SizedTraitKind) { +impl QueryKey for (DefId, ty::SizedTraitKind) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) } } -impl<'tcx> Key for GenericArgsRef<'tcx> { +impl<'tcx> QueryKey for GenericArgsRef<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for (DefId, GenericArgsRef<'tcx>) { +impl<'tcx> QueryKey for (DefId, GenericArgsRef<'tcx>) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) } } -impl<'tcx> Key for ty::TraitRef<'tcx> { +impl<'tcx> QueryKey for ty::TraitRef<'tcx> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.def_id) } } -impl<'tcx> Key for GenericArg<'tcx> { +impl<'tcx> QueryKey for GenericArg<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for Ty<'tcx> { +impl<'tcx> QueryKey for Ty<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } @@ -270,19 +269,19 @@ fn def_id_for_ty_in_cycle(&self) -> Option { } } -impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) { +impl<'tcx> QueryKey for (Ty<'tcx>, Ty<'tcx>) { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for ty::Clauses<'tcx> { +impl<'tcx> QueryKey for ty::Clauses<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> { +impl<'tcx, T: QueryKey> QueryKey for ty::PseudoCanonicalInput<'tcx, T> { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.value.default_span(tcx) } @@ -292,19 +291,19 @@ fn def_id_for_ty_in_cycle(&self) -> Option { } } -impl Key for Symbol { +impl QueryKey for Symbol { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl Key for Option { +impl QueryKey for Option { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for &'tcx OsStr { +impl<'tcx> QueryKey for &'tcx OsStr { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } @@ -312,55 +311,55 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { /// Canonical query goals correspond to abstract trait operations that /// are not tied to any crate in particular. -impl<'tcx, T: Clone> Key for CanonicalQueryInput<'tcx, T> { +impl<'tcx, T: Clone> QueryKey for CanonicalQueryInput<'tcx, T> { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx, T: Clone> Key for (CanonicalQueryInput<'tcx, T>, bool) { +impl<'tcx, T: Clone> QueryKey for (CanonicalQueryInput<'tcx, T>, bool) { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for (Ty<'tcx>, rustc_abi::VariantIdx) { +impl<'tcx> QueryKey for (Ty<'tcx>, rustc_abi::VariantIdx) { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) { +impl<'tcx> QueryKey for (ty::Predicate<'tcx>, traits::WellFormedLoc) { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List>) { +impl<'tcx> QueryKey for (ty::PolyFnSig<'tcx>, &'tcx ty::List>) { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List>) { +impl<'tcx> QueryKey for (ty::Instance<'tcx>, &'tcx ty::List>) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) } } -impl<'tcx> Key for ty::Value<'tcx> { +impl<'tcx> QueryKey for ty::Value<'tcx> { fn default_span(&self, _: TyCtxt<'_>) -> Span { DUMMY_SP } } -impl<'tcx> Key for (LocalExpnId, &'tcx TokenStream) { +impl<'tcx> QueryKey for (LocalExpnId, &'tcx TokenStream) { fn default_span(&self, _tcx: TyCtxt<'_>) -> Span { self.0.expn_data().call_site } } -impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) { +impl<'tcx> QueryKey for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) { // Just forward to `Ty<'tcx>` fn default_span(&self, _: TyCtxt<'_>) -> Span { @@ -375,7 +374,7 @@ fn def_id_for_ty_in_cycle(&self) -> Option { } } -impl<'tcx> Key for (ty::Instance<'tcx>, CollectionMode) { +impl<'tcx> QueryKey for (ty::Instance<'tcx>, CollectionMode) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { self.0.default_span(tcx) } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index bb457ab03fb5..5aa447da11da 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -4,7 +4,7 @@ DefIdCache, DefaultCache, QueryCache, QueryCacheKey, SingleCache, VecCache, }; pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter}; -pub use self::keys::{AsLocalKey, Key, LocalCrate}; +pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey}; pub use self::plumbing::{ ActiveKeyStatus, CycleError, CycleErrorHandling, EnsureMode, IntoQueryParam, QueryMode, QueryState, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk, diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index c2d524d200de..f9e3b1de5bcb 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -383,7 +383,7 @@ pub mod $name { pub type LocalKey<'tcx> = if_separate_provide_extern!( [$($modifiers)*] - ( as $crate::query::AsLocalKey>::LocalKey) + ( as $crate::query::AsLocalQueryKey>::LocalQueryKey) (Key<'tcx>) ); @@ -428,7 +428,7 @@ pub fn provided_to_erased<'tcx>( } pub type Storage<'tcx> = - as $crate::query::Key>::Cache>>; + as $crate::query::QueryKey>::Cache>>; // Ensure that keys grow no larger than 88 bytes by accident. // Increase this limit if necessary, but do try to keep the size low if possible diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs index 34720fc2f295..820becd7031a 100644 --- a/compiler/rustc_mir_transform/src/errors.rs +++ b/compiler/rustc_mir_transform/src/errors.rs @@ -4,7 +4,7 @@ }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::mir::AssertKind; -use rustc_middle::query::Key; +use rustc_middle::query::QueryKey; use rustc_middle::ty::TyCtxt; use rustc_session::lint::{self, Lint}; use rustc_span::def_id::DefId; diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index afb41f69b5eb..1b93ffe945b3 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -13,7 +13,7 @@ use rustc_middle::queries::{self, ExternProviders, Providers}; use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache}; use rustc_middle::query::plumbing::{QuerySystem, QueryVTable}; -use rustc_middle::query::{AsLocalKey, QueryCache, QueryMode}; +use rustc_middle::query::{AsLocalQueryKey, QueryCache, QueryMode}; use rustc_middle::ty::TyCtxt; use rustc_span::Span; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 275fe5b63d8b..e4183bc254dc 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -19,7 +19,8 @@ }; use rustc_middle::query::plumbing::QueryVTable; use rustc_middle::query::{ - Key, QueryCache, QueryJobId, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, erase, + QueryCache, QueryJobId, QueryKey, QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, + erase, }; use rustc_middle::ty::codec::TyEncoder; use rustc_middle::ty::print::with_reduced_queries; @@ -274,7 +275,7 @@ fn mk_query_stack_frame_extra<'tcx, Cache>( ) -> QueryStackFrameExtra where Cache: QueryCache, - Cache::Key: Key, + Cache::Key: QueryKey, { let def_id = key.key_as_def_id(); @@ -313,7 +314,7 @@ pub(crate) fn create_deferred_query_stack_frame<'tcx, C>( ) -> QueryStackFrame> where C: QueryCache, - C::Key: Key + DynSend + DynSync, + C::Key: QueryKey + DynSend + DynSync, QueryVTable<'tcx, C>: DynSync, { let kind = vtable.dep_kind;