11//! Type context book-keeping.
22
3+ #![ allow( rustc:: usage_of_ty_tykind) ]
4+
35use crate :: arena:: Arena ;
46use crate :: dep_graph:: { DepGraph , DepKindStruct } ;
57use crate :: hir:: place:: Place as HirPlace ;
@@ -19,15 +21,15 @@ use crate::ty::{
1921 self , AdtDef , AdtDefData , AdtKind , Binder , BindingMode , BoundVar , CanonicalPolyFnSig ,
2022 ClosureSizeProfileData , Const , ConstS , DefIdTree , FloatTy , FloatVar , FloatVid ,
2123 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 ,
2527} ;
2628use crate :: ty:: { GenericArg , GenericArgKind , InternalSubsts , SubstsRef , UserSubsts } ;
2729use rustc_ast as ast;
2830use rustc_data_structures:: fingerprint:: Fingerprint ;
2931use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
30- use rustc_data_structures:: intern:: { Interned , WithStableHash } ;
32+ use rustc_data_structures:: intern:: Interned ;
3133use rustc_data_structures:: memmap:: Mmap ;
3234use rustc_data_structures:: profiling:: SelfProfilerRef ;
3335use rustc_data_structures:: sharded:: { IntoPointer , ShardedHashMap } ;
@@ -68,6 +70,7 @@ use rustc_span::{Span, DUMMY_SP};
6870use rustc_target:: abi:: { Layout , LayoutS , TargetDataLayout , VariantIdx } ;
6971use rustc_target:: spec:: abi;
7072use rustc_type_ir:: sty:: TyKind :: * ;
73+ use rustc_type_ir:: WithCachedTypeInfo ;
7174use rustc_type_ir:: { DynKind , InternAs , InternIteratorElement , Interner , TypeFlags } ;
7275
7376use std:: any:: Any ;
@@ -137,13 +140,13 @@ pub struct CtxtInterners<'tcx> {
137140
138141 // Specifically use a speedy hash algorithm for these hash sets, since
139142 // they're accessed quite often.
140- type_ : InternedSet < ' tcx , WithStableHash < TyS < ' tcx > > > ,
143+ type_ : InternedSet < ' tcx , WithCachedTypeInfo < TyKind < ' tcx > > > ,
141144 const_lists : InternedSet < ' tcx , List < ty:: Const < ' tcx > > > ,
142145 substs : InternedSet < ' tcx , InternalSubsts < ' tcx > > ,
143146 canonical_var_infos : InternedSet < ' tcx , List < CanonicalVarInfo < ' tcx > > > ,
144147 region : InternedSet < ' tcx , RegionKind < ' tcx > > ,
145148 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 > > > > ,
147150 predicates : InternedSet < ' tcx , List < Predicate < ' tcx > > > ,
148151 projs : InternedSet < ' tcx , List < ProjectionKind > > ,
149152 place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
@@ -194,15 +197,12 @@ impl<'tcx> CtxtInterners<'tcx> {
194197 let stable_hash =
195198 self . stable_hash ( & flags, sess, definitions, cstore, source_span, & kind) ;
196199
197- let ty_struct = TyS {
198- kind,
200+ InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
201+ internee : kind,
202+ stable_hash,
199203 flags : flags. flags ,
200204 outer_exclusive_binder : flags. outer_exclusive_binder ,
201- } ;
202-
203- InternedInSet (
204- self . arena . alloc ( WithStableHash { internee : ty_struct, stable_hash } ) ,
205- )
205+ } ) )
206206 } )
207207 . 0 ,
208208 ) )
@@ -246,16 +246,12 @@ impl<'tcx> CtxtInterners<'tcx> {
246246 let stable_hash =
247247 self . stable_hash ( & flags, sess, definitions, cstore, source_span, & kind) ;
248248
249- let predicate_struct = PredicateS {
250- kind,
249+ InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
250+ internee : kind,
251+ stable_hash,
251252 flags : flags. flags ,
252253 outer_exclusive_binder : flags. outer_exclusive_binder ,
253- } ;
254-
255- InternedInSet (
256- self . arena
257- . alloc ( WithStableHash { internee : predicate_struct, stable_hash } ) ,
258- )
254+ } ) )
259255 } )
260256 . 0 ,
261257 ) )
@@ -2104,7 +2100,7 @@ macro_rules! sty_debug_print {
21042100 let shards = tcx. interners. type_. lock_shards( ) ;
21052101 let types = shards. iter( ) . flat_map( |shard| shard. keys( ) ) ;
21062102 for & InternedInSet ( t) in types {
2107- let variant = match t. kind {
2103+ let variant = match t. internee {
21082104 ty:: Bool | ty:: Char | ty:: Int ( ..) | ty:: Uint ( ..) |
21092105 ty:: Float ( ..) | ty:: Str | ty:: Never => continue ,
21102106 ty:: Error ( _) => /* unimportant */ continue ,
@@ -2214,51 +2210,26 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for InternedInSet<'tcx, T> {
22142210}
22152211
22162212#[ 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
22452216 }
22462217}
22472218
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 {
22502221 // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
22512222 // `x == y`.
2252- self . 0 . kind == other. 0 . kind
2223+ self . 0 . internee == other. 0 . internee
22532224 }
22542225}
22552226
2256- impl < ' tcx > Eq for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > { }
2227+ impl < ' tcx , T : Eq > Eq for InternedInSet < ' tcx , WithCachedTypeInfo < T > > { }
22572228
2258- impl < ' tcx > Hash for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > {
2229+ impl < ' tcx , T : Hash > Hash for InternedInSet < ' tcx , WithCachedTypeInfo < T > > {
22592230 fn hash < H : Hasher > ( & self , s : & mut H ) {
22602231 // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
2261- self . 0 . kind . hash ( s)
2232+ self . 0 . internee . hash ( s)
22622233 }
22632234}
22642235
0 commit comments