1
1
//! Type context book-keeping.
2
2
3
+ #![ allow( rustc:: usage_of_ty_tykind) ]
4
+
3
5
use crate :: arena:: Arena ;
4
6
use crate :: dep_graph:: { DepGraph , DepKindStruct } ;
5
7
use crate :: hir:: place:: Place as HirPlace ;
@@ -19,15 +21,15 @@ use crate::ty::{
19
21
self , AdtDef , AdtDefData , AdtKind , Binder , BindingMode , BoundVar , CanonicalPolyFnSig ,
20
22
ClosureSizeProfileData , Const , ConstS , DefIdTree , FloatTy , FloatVar , FloatVid ,
21
23
GenericParamDefKind , InferTy , IntTy , IntVar , IntVid , List , ParamConst , ParamTy ,
22
- PolyExistentialPredicate , PolyFnSig , Predicate , PredicateKind , PredicateS , ProjectionTy ,
23
- Region , RegionKind , ReprOptions , TraitObjectVisitor , Ty , TyKind , TyS , TyVar , TyVid , TypeAndMut ,
24
- UintTy , Visibility ,
24
+ PolyExistentialPredicate , PolyFnSig , Predicate , PredicateKind , ProjectionTy , Region ,
25
+ RegionKind , ReprOptions , TraitObjectVisitor , Ty , TyKind , TyVar , TyVid , TypeAndMut , UintTy ,
26
+ Visibility ,
25
27
} ;
26
28
use crate :: ty:: { GenericArg , GenericArgKind , InternalSubsts , SubstsRef , UserSubsts } ;
27
29
use rustc_ast as ast;
28
30
use rustc_data_structures:: fingerprint:: Fingerprint ;
29
31
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
30
- use rustc_data_structures:: intern:: { Interned , WithStableHash } ;
32
+ use rustc_data_structures:: intern:: Interned ;
31
33
use rustc_data_structures:: memmap:: Mmap ;
32
34
use rustc_data_structures:: profiling:: SelfProfilerRef ;
33
35
use rustc_data_structures:: sharded:: { IntoPointer , ShardedHashMap } ;
@@ -68,6 +70,7 @@ use rustc_span::{Span, DUMMY_SP};
68
70
use rustc_target:: abi:: { Layout , LayoutS , TargetDataLayout , VariantIdx } ;
69
71
use rustc_target:: spec:: abi;
70
72
use rustc_type_ir:: sty:: TyKind :: * ;
73
+ use rustc_type_ir:: WithCachedTypeInfo ;
71
74
use rustc_type_ir:: { DynKind , InternAs , InternIteratorElement , Interner , TypeFlags } ;
72
75
73
76
use std:: any:: Any ;
@@ -137,13 +140,13 @@ pub struct CtxtInterners<'tcx> {
137
140
138
141
// Specifically use a speedy hash algorithm for these hash sets, since
139
142
// they're accessed quite often.
140
- type_ : InternedSet < ' tcx , WithStableHash < TyS < ' tcx > > > ,
143
+ type_ : InternedSet < ' tcx , WithCachedTypeInfo < TyKind < ' tcx > > > ,
141
144
const_lists : InternedSet < ' tcx , List < ty:: Const < ' tcx > > > ,
142
145
substs : InternedSet < ' tcx , InternalSubsts < ' tcx > > ,
143
146
canonical_var_infos : InternedSet < ' tcx , List < CanonicalVarInfo < ' tcx > > > ,
144
147
region : InternedSet < ' tcx , RegionKind < ' tcx > > ,
145
148
poly_existential_predicates : InternedSet < ' tcx , List < PolyExistentialPredicate < ' tcx > > > ,
146
- predicate : InternedSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > ,
149
+ predicate : InternedSet < ' tcx , WithCachedTypeInfo < ty :: Binder < ' tcx , PredicateKind < ' tcx > > > > ,
147
150
predicates : InternedSet < ' tcx , List < Predicate < ' tcx > > > ,
148
151
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
149
152
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
@@ -194,15 +197,12 @@ impl<'tcx> CtxtInterners<'tcx> {
194
197
let stable_hash =
195
198
self . stable_hash ( & flags, sess, definitions, cstore, source_span, & kind) ;
196
199
197
- let ty_struct = TyS {
198
- kind,
200
+ InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
201
+ internee : kind,
202
+ stable_hash,
199
203
flags : flags. flags ,
200
204
outer_exclusive_binder : flags. outer_exclusive_binder ,
201
- } ;
202
-
203
- InternedInSet (
204
- self . arena . alloc ( WithStableHash { internee : ty_struct, stable_hash } ) ,
205
- )
205
+ } ) )
206
206
} )
207
207
. 0 ,
208
208
) )
@@ -246,16 +246,12 @@ impl<'tcx> CtxtInterners<'tcx> {
246
246
let stable_hash =
247
247
self . stable_hash ( & flags, sess, definitions, cstore, source_span, & kind) ;
248
248
249
- let predicate_struct = PredicateS {
250
- kind,
249
+ InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
250
+ internee : kind,
251
+ stable_hash,
251
252
flags : flags. flags ,
252
253
outer_exclusive_binder : flags. outer_exclusive_binder ,
253
- } ;
254
-
255
- InternedInSet (
256
- self . arena
257
- . alloc ( WithStableHash { internee : predicate_struct, stable_hash } ) ,
258
- )
254
+ } ) )
259
255
} )
260
256
. 0 ,
261
257
) )
@@ -2104,7 +2100,7 @@ macro_rules! sty_debug_print {
2104
2100
let shards = tcx. interners. type_. lock_shards( ) ;
2105
2101
let types = shards. iter( ) . flat_map( |shard| shard. keys( ) ) ;
2106
2102
for & InternedInSet ( t) in types {
2107
- let variant = match t. kind {
2103
+ let variant = match t. internee {
2108
2104
ty:: Bool | ty:: Char | ty:: Int ( ..) | ty:: Uint ( ..) |
2109
2105
ty:: Float ( ..) | ty:: Str | ty:: Never => continue ,
2110
2106
ty:: Error ( _) => /* unimportant */ continue ,
@@ -2214,51 +2210,26 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for InternedInSet<'tcx, T> {
2214
2210
}
2215
2211
2216
2212
#[ allow( rustc:: usage_of_ty_tykind) ]
2217
- impl < ' tcx > Borrow < TyKind < ' tcx > > for InternedInSet < ' tcx , WithStableHash < TyS < ' tcx > > > {
2218
- fn borrow < ' a > ( & ' a self ) -> & ' a TyKind < ' tcx > {
2219
- & self . 0 . kind
2220
- }
2221
- }
2222
-
2223
- impl < ' tcx > PartialEq for InternedInSet < ' tcx , WithStableHash < TyS < ' tcx > > > {
2224
- fn eq ( & self , other : & InternedInSet < ' tcx , WithStableHash < TyS < ' tcx > > > ) -> bool {
2225
- // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
2226
- // `x == y`.
2227
- self . 0 . kind == other. 0 . kind
2228
- }
2229
- }
2230
-
2231
- impl < ' tcx > Eq for InternedInSet < ' tcx , WithStableHash < TyS < ' tcx > > > { }
2232
-
2233
- impl < ' tcx > Hash for InternedInSet < ' tcx , WithStableHash < TyS < ' tcx > > > {
2234
- fn hash < H : Hasher > ( & self , s : & mut H ) {
2235
- // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
2236
- self . 0 . kind . hash ( s)
2237
- }
2238
- }
2239
-
2240
- impl < ' tcx > Borrow < Binder < ' tcx , PredicateKind < ' tcx > > >
2241
- for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > >
2242
- {
2243
- fn borrow < ' a > ( & ' a self ) -> & ' a Binder < ' tcx , PredicateKind < ' tcx > > {
2244
- & self . 0 . kind
2213
+ impl < ' tcx , T > Borrow < T > for InternedInSet < ' tcx , WithCachedTypeInfo < T > > {
2214
+ fn borrow < ' a > ( & ' a self ) -> & ' a T {
2215
+ & self . 0 . internee
2245
2216
}
2246
2217
}
2247
2218
2248
- impl < ' tcx > PartialEq for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > {
2249
- fn eq ( & self , other : & InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > ) -> bool {
2219
+ impl < ' tcx , T : PartialEq > PartialEq for InternedInSet < ' tcx , WithCachedTypeInfo < T > > {
2220
+ fn eq ( & self , other : & InternedInSet < ' tcx , WithCachedTypeInfo < T > > ) -> bool {
2250
2221
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
2251
2222
// `x == y`.
2252
- self . 0 . kind == other. 0 . kind
2223
+ self . 0 . internee == other. 0 . internee
2253
2224
}
2254
2225
}
2255
2226
2256
- impl < ' tcx > Eq for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > { }
2227
+ impl < ' tcx , T : Eq > Eq for InternedInSet < ' tcx , WithCachedTypeInfo < T > > { }
2257
2228
2258
- impl < ' tcx > Hash for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > {
2229
+ impl < ' tcx , T : Hash > Hash for InternedInSet < ' tcx , WithCachedTypeInfo < T > > {
2259
2230
fn hash < H : Hasher > ( & self , s : & mut H ) {
2260
2231
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
2261
- self . 0 . kind . hash ( s)
2232
+ self . 0 . internee . hash ( s)
2262
2233
}
2263
2234
}
2264
2235
0 commit comments