Skip to content

Commit fbea6dd

Browse files
committed
Rename trait Key as trait QueryKey`
Because `Key` is extremely generic and hard to search for. Also rename `LocalKey` and `AsLocalKey` similarly, for consistency.
1 parent 6ba5b1a commit fbea6dd

7 files changed

Lines changed: 66 additions & 66 deletions

File tree

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use std::fmt;
5151
use std::hash::Hash;
5252

5353
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
54-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
54+
use rustc_data_structures::stable_hasher::{StableHasher, StableOrd, ToStableHashKey};
5555
use rustc_hir::def_id::DefId;
5656
use rustc_hir::definitions::DefPathHash;
5757
use rustc_macros::{Decodable, Encodable, HashStable};

compiler/rustc_middle/src/query/keys.rs

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ use crate::{mir, traits};
2020
#[derive(Copy, Clone, Debug)]
2121
pub struct LocalCrate;
2222

23-
/// The `Key` trait controls what types can legally be used as the key
24-
/// for a query.
25-
pub trait Key: Sized {
23+
/// Controls what types can legally be used as the key for a query.
24+
pub trait QueryKey: Sized {
2625
/// The type of in-memory cache to use for queries with this key type.
2726
///
2827
/// In practice the cache type must implement [`QueryCache`], though that
@@ -47,70 +46,70 @@ pub trait Key: Sized {
4746
}
4847
}
4948

50-
pub trait AsLocalKey: Key {
51-
type LocalKey;
49+
pub trait AsLocalQueryKey: QueryKey {
50+
type LocalQueryKey;
5251

5352
/// Given an instance of this key, what crate is it referring to?
5453
/// This is used to find the provider.
55-
fn as_local_key(&self) -> Option<Self::LocalKey>;
54+
fn as_local_key(&self) -> Option<Self::LocalQueryKey>;
5655
}
5756

58-
impl Key for () {
57+
impl QueryKey for () {
5958
type Cache<V> = SingleCache<V>;
6059

6160
fn default_span(&self, _: TyCtxt<'_>) -> Span {
6261
DUMMY_SP
6362
}
6463
}
6564

66-
impl<'tcx> Key for ty::InstanceKind<'tcx> {
65+
impl<'tcx> QueryKey for ty::InstanceKind<'tcx> {
6766
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
6867
tcx.def_span(self.def_id())
6968
}
7069
}
7170

72-
impl<'tcx> Key for ty::Instance<'tcx> {
71+
impl<'tcx> QueryKey for ty::Instance<'tcx> {
7372
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
7473
tcx.def_span(self.def_id())
7574
}
7675
}
7776

78-
impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
77+
impl<'tcx> QueryKey for mir::interpret::GlobalId<'tcx> {
7978
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
8079
self.instance.default_span(tcx)
8180
}
8281
}
8382

84-
impl<'tcx> Key for (Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>) {
83+
impl<'tcx> QueryKey for (Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>) {
8584
fn default_span(&self, _: TyCtxt<'_>) -> Span {
8685
DUMMY_SP
8786
}
8887
}
8988

90-
impl<'tcx> Key for ty::LitToConstInput<'tcx> {
89+
impl<'tcx> QueryKey for ty::LitToConstInput<'tcx> {
9190
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
9291
DUMMY_SP
9392
}
9493
}
9594

96-
impl Key for CrateNum {
95+
impl QueryKey for CrateNum {
9796
type Cache<V> = VecCache<Self, V, DepNodeIndex>;
9897

9998
fn default_span(&self, _: TyCtxt<'_>) -> Span {
10099
DUMMY_SP
101100
}
102101
}
103102

104-
impl AsLocalKey for CrateNum {
105-
type LocalKey = LocalCrate;
103+
impl AsLocalQueryKey for CrateNum {
104+
type LocalQueryKey = LocalCrate;
106105

107106
#[inline(always)]
108-
fn as_local_key(&self) -> Option<Self::LocalKey> {
107+
fn as_local_key(&self) -> Option<Self::LocalQueryKey> {
109108
(*self == LOCAL_CRATE).then_some(LocalCrate)
110109
}
111110
}
112111

113-
impl Key for OwnerId {
112+
impl QueryKey for OwnerId {
114113
type Cache<V> = VecCache<Self, V, DepNodeIndex>;
115114

116115
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
@@ -122,7 +121,7 @@ impl Key for OwnerId {
122121
}
123122
}
124123

125-
impl Key for LocalDefId {
124+
impl QueryKey for LocalDefId {
126125
type Cache<V> = VecCache<Self, V, DepNodeIndex>;
127126

128127
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
@@ -134,7 +133,7 @@ impl Key for LocalDefId {
134133
}
135134
}
136135

137-
impl Key for DefId {
136+
impl QueryKey for DefId {
138137
type Cache<V> = DefIdCache<V>;
139138

140139
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
@@ -147,16 +146,16 @@ impl Key for DefId {
147146
}
148147
}
149148

150-
impl AsLocalKey for DefId {
151-
type LocalKey = LocalDefId;
149+
impl AsLocalQueryKey for DefId {
150+
type LocalQueryKey = LocalDefId;
152151

153152
#[inline(always)]
154-
fn as_local_key(&self) -> Option<Self::LocalKey> {
153+
fn as_local_key(&self) -> Option<Self::LocalQueryKey> {
155154
self.as_local()
156155
}
157156
}
158157

159-
impl Key for LocalModDefId {
158+
impl QueryKey for LocalModDefId {
160159
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
161160
tcx.def_span(*self)
162161
}
@@ -167,19 +166,19 @@ impl Key for LocalModDefId {
167166
}
168167
}
169168

170-
impl Key for SimplifiedType {
169+
impl QueryKey for SimplifiedType {
171170
fn default_span(&self, _: TyCtxt<'_>) -> Span {
172171
DUMMY_SP
173172
}
174173
}
175174

176-
impl Key for (DefId, DefId) {
175+
impl QueryKey for (DefId, DefId) {
177176
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
178177
self.1.default_span(tcx)
179178
}
180179
}
181180

182-
impl Key for (DefId, Ident) {
181+
impl QueryKey for (DefId, Ident) {
183182
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
184183
tcx.def_span(self.0)
185184
}
@@ -190,73 +189,73 @@ impl Key for (DefId, Ident) {
190189
}
191190
}
192191

193-
impl Key for (LocalDefId, LocalDefId, Ident) {
192+
impl QueryKey for (LocalDefId, LocalDefId, Ident) {
194193
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
195194
self.1.default_span(tcx)
196195
}
197196
}
198197

199-
impl Key for (CrateNum, DefId) {
198+
impl QueryKey for (CrateNum, DefId) {
200199
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
201200
self.1.default_span(tcx)
202201
}
203202
}
204203

205-
impl AsLocalKey for (CrateNum, DefId) {
206-
type LocalKey = DefId;
204+
impl AsLocalQueryKey for (CrateNum, DefId) {
205+
type LocalQueryKey = DefId;
207206

208207
#[inline(always)]
209-
fn as_local_key(&self) -> Option<Self::LocalKey> {
208+
fn as_local_key(&self) -> Option<Self::LocalQueryKey> {
210209
(self.0 == LOCAL_CRATE).then(|| self.1)
211210
}
212211
}
213212

214-
impl Key for (CrateNum, SimplifiedType) {
213+
impl QueryKey for (CrateNum, SimplifiedType) {
215214
fn default_span(&self, _: TyCtxt<'_>) -> Span {
216215
DUMMY_SP
217216
}
218217
}
219218

220-
impl AsLocalKey for (CrateNum, SimplifiedType) {
221-
type LocalKey = SimplifiedType;
219+
impl AsLocalQueryKey for (CrateNum, SimplifiedType) {
220+
type LocalQueryKey = SimplifiedType;
222221

223222
#[inline(always)]
224-
fn as_local_key(&self) -> Option<Self::LocalKey> {
223+
fn as_local_key(&self) -> Option<Self::LocalQueryKey> {
225224
(self.0 == LOCAL_CRATE).then(|| self.1)
226225
}
227226
}
228227

229-
impl Key for (DefId, ty::SizedTraitKind) {
228+
impl QueryKey for (DefId, ty::SizedTraitKind) {
230229
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
231230
self.0.default_span(tcx)
232231
}
233232
}
234233

235-
impl<'tcx> Key for GenericArgsRef<'tcx> {
234+
impl<'tcx> QueryKey for GenericArgsRef<'tcx> {
236235
fn default_span(&self, _: TyCtxt<'_>) -> Span {
237236
DUMMY_SP
238237
}
239238
}
240239

241-
impl<'tcx> Key for (DefId, GenericArgsRef<'tcx>) {
240+
impl<'tcx> QueryKey for (DefId, GenericArgsRef<'tcx>) {
242241
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
243242
self.0.default_span(tcx)
244243
}
245244
}
246245

247-
impl<'tcx> Key for ty::TraitRef<'tcx> {
246+
impl<'tcx> QueryKey for ty::TraitRef<'tcx> {
248247
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
249248
tcx.def_span(self.def_id)
250249
}
251250
}
252251

253-
impl<'tcx> Key for GenericArg<'tcx> {
252+
impl<'tcx> QueryKey for GenericArg<'tcx> {
254253
fn default_span(&self, _: TyCtxt<'_>) -> Span {
255254
DUMMY_SP
256255
}
257256
}
258257

259-
impl<'tcx> Key for Ty<'tcx> {
258+
impl<'tcx> QueryKey for Ty<'tcx> {
260259
fn default_span(&self, _: TyCtxt<'_>) -> Span {
261260
DUMMY_SP
262261
}
@@ -270,19 +269,19 @@ impl<'tcx> Key for Ty<'tcx> {
270269
}
271270
}
272271

273-
impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) {
272+
impl<'tcx> QueryKey for (Ty<'tcx>, Ty<'tcx>) {
274273
fn default_span(&self, _: TyCtxt<'_>) -> Span {
275274
DUMMY_SP
276275
}
277276
}
278277

279-
impl<'tcx> Key for ty::Clauses<'tcx> {
278+
impl<'tcx> QueryKey for ty::Clauses<'tcx> {
280279
fn default_span(&self, _: TyCtxt<'_>) -> Span {
281280
DUMMY_SP
282281
}
283282
}
284283

285-
impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> {
284+
impl<'tcx, T: QueryKey> QueryKey for ty::PseudoCanonicalInput<'tcx, T> {
286285
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
287286
self.value.default_span(tcx)
288287
}
@@ -292,75 +291,75 @@ impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> {
292291
}
293292
}
294293

295-
impl Key for Symbol {
294+
impl QueryKey for Symbol {
296295
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
297296
DUMMY_SP
298297
}
299298
}
300299

301-
impl Key for Option<Symbol> {
300+
impl QueryKey for Option<Symbol> {
302301
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
303302
DUMMY_SP
304303
}
305304
}
306305

307-
impl<'tcx> Key for &'tcx OsStr {
306+
impl<'tcx> QueryKey for &'tcx OsStr {
308307
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
309308
DUMMY_SP
310309
}
311310
}
312311

313312
/// Canonical query goals correspond to abstract trait operations that
314313
/// are not tied to any crate in particular.
315-
impl<'tcx, T: Clone> Key for CanonicalQueryInput<'tcx, T> {
314+
impl<'tcx, T: Clone> QueryKey for CanonicalQueryInput<'tcx, T> {
316315
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
317316
DUMMY_SP
318317
}
319318
}
320319

321-
impl<'tcx, T: Clone> Key for (CanonicalQueryInput<'tcx, T>, bool) {
320+
impl<'tcx, T: Clone> QueryKey for (CanonicalQueryInput<'tcx, T>, bool) {
322321
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
323322
DUMMY_SP
324323
}
325324
}
326325

327-
impl<'tcx> Key for (Ty<'tcx>, rustc_abi::VariantIdx) {
326+
impl<'tcx> QueryKey for (Ty<'tcx>, rustc_abi::VariantIdx) {
328327
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
329328
DUMMY_SP
330329
}
331330
}
332331

333-
impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
332+
impl<'tcx> QueryKey for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
334333
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
335334
DUMMY_SP
336335
}
337336
}
338337

339-
impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
338+
impl<'tcx> QueryKey for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
340339
fn default_span(&self, _: TyCtxt<'_>) -> Span {
341340
DUMMY_SP
342341
}
343342
}
344343

345-
impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
344+
impl<'tcx> QueryKey for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
346345
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
347346
self.0.default_span(tcx)
348347
}
349348
}
350349

351-
impl<'tcx> Key for ty::Value<'tcx> {
350+
impl<'tcx> QueryKey for ty::Value<'tcx> {
352351
fn default_span(&self, _: TyCtxt<'_>) -> Span {
353352
DUMMY_SP
354353
}
355354
}
356355

357-
impl<'tcx> Key for (LocalExpnId, &'tcx TokenStream) {
356+
impl<'tcx> QueryKey for (LocalExpnId, &'tcx TokenStream) {
358357
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
359358
self.0.expn_data().call_site
360359
}
361360
}
362361

363-
impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) {
362+
impl<'tcx> QueryKey for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) {
364363
// Just forward to `Ty<'tcx>`
365364

366365
fn default_span(&self, _: TyCtxt<'_>) -> Span {
@@ -375,7 +374,7 @@ impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>
375374
}
376375
}
377376

378-
impl<'tcx> Key for (ty::Instance<'tcx>, CollectionMode) {
377+
impl<'tcx> QueryKey for (ty::Instance<'tcx>, CollectionMode) {
379378
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
380379
self.0.default_span(tcx)
381380
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use self::caches::{
44
DefIdCache, DefaultCache, QueryCache, QueryCacheKey, SingleCache, VecCache,
55
};
66
pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryLatch, QueryWaiter};
7-
pub use self::keys::{AsLocalKey, Key, LocalCrate};
7+
pub use self::keys::{AsLocalQueryKey, LocalCrate, QueryKey};
88
pub use self::plumbing::{
99
ActiveKeyStatus, CycleError, CycleErrorHandling, EnsureMode, IntoQueryParam, QueryMode,
1010
QueryState, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk,

0 commit comments

Comments
 (0)