@@ -24,6 +24,7 @@ use crate::ty::{
2424 RegionKind , ReprOptions , TraitObjectVisitor , Ty , TyKind , TyS , TyVar , TyVid , TypeAndMut , UintTy ,
2525} ;
2626use rustc_ast as ast;
27+ use rustc_data_structures:: fingerprint:: Fingerprint ;
2728use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
2829use rustc_data_structures:: intern:: Interned ;
2930use rustc_data_structures:: memmap:: Mmap ;
@@ -58,6 +59,7 @@ use rustc_span::{Span, DUMMY_SP};
5859use rustc_target:: abi:: { Layout , TargetDataLayout , VariantIdx } ;
5960use rustc_target:: spec:: abi;
6061
62+ use rustc_type_ir:: TypeFlags ;
6163use smallvec:: SmallVec ;
6264use std:: any:: Any ;
6365use std:: borrow:: Borrow ;
@@ -140,16 +142,40 @@ impl<'tcx> CtxtInterners<'tcx> {
140142 /// Interns a type.
141143 #[ allow( rustc:: usage_of_ty_tykind) ]
142144 #[ inline( never) ]
143- fn intern_ty ( & self , kind : TyKind < ' tcx > ) -> Ty < ' tcx > {
145+ fn intern_ty (
146+ & self ,
147+ kind : TyKind < ' tcx > ,
148+ sess : & Session ,
149+ resolutions : & ty:: ResolverOutputs ,
150+ ) -> Ty < ' tcx > {
144151 Ty ( Interned :: new_unchecked (
145152 self . type_
146153 . intern ( kind, |kind| {
147154 let flags = super :: flags:: FlagComputation :: for_kind ( & kind) ;
148155
156+ let stable_hash = if flags. flags . intersects ( TypeFlags :: HAS_RE_INFER ) {
157+ Fingerprint :: ZERO
158+ } else {
159+ let mut hasher = StableHasher :: new ( ) ;
160+ let mut hcx = StableHashingContext :: new (
161+ sess,
162+ & resolutions. definitions ,
163+ & * resolutions. cstore ,
164+ ) ;
165+
166+ hcx. while_hashing_spans ( false , |hcx| {
167+ hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
168+ kind. hash_stable ( hcx, & mut hasher) ;
169+ } ) ;
170+ } ) ;
171+ hasher. finish ( )
172+ } ;
173+
149174 let ty_struct = TyS {
150175 kind,
151176 flags : flags. flags ,
152177 outer_exclusive_binder : flags. outer_exclusive_binder ,
178+ stable_hash,
153179 } ;
154180
155181 InternedInSet ( self . arena . alloc ( ty_struct) )
@@ -887,8 +913,12 @@ pub enum UserType<'tcx> {
887913}
888914
889915impl < ' tcx > CommonTypes < ' tcx > {
890- fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonTypes < ' tcx > {
891- let mk = |ty| interners. intern_ty ( ty) ;
916+ fn new (
917+ interners : & CtxtInterners < ' tcx > ,
918+ sess : & Session ,
919+ resolutions : & ty:: ResolverOutputs ,
920+ ) -> CommonTypes < ' tcx > {
921+ let mk = |ty| interners. intern_ty ( ty, sess, resolutions) ;
892922
893923 CommonTypes {
894924 unit : mk ( Tuple ( List :: empty ( ) ) ) ,
@@ -1162,7 +1192,7 @@ impl<'tcx> TyCtxt<'tcx> {
11621192 s. fatal ( & err) ;
11631193 } ) ;
11641194 let interners = CtxtInterners :: new ( arena) ;
1165- let common_types = CommonTypes :: new ( & interners) ;
1195+ let common_types = CommonTypes :: new ( & interners, s , & resolutions ) ;
11661196 let common_lifetimes = CommonLifetimes :: new ( & interners) ;
11671197 let common_consts = CommonConsts :: new ( & interners, & common_types) ;
11681198
@@ -2276,7 +2306,7 @@ impl<'tcx> TyCtxt<'tcx> {
22762306 #[ allow( rustc:: usage_of_ty_tykind) ]
22772307 #[ inline]
22782308 pub fn mk_ty ( self , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
2279- self . interners . intern_ty ( st)
2309+ self . interners . intern_ty ( st, self . sess , & self . gcx . untracked_resolutions )
22802310 }
22812311
22822312 #[ inline]
0 commit comments