@@ -174,6 +174,8 @@ impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
174174type InternedSet < ' tcx , T > = ShardedHashMap < InternedInSet < ' tcx , T > , ( ) > ;
175175
176176pub struct CtxtInterners < ' tcx > {
177+ sess : & ' tcx Session ,
178+ untracked : & ' tcx Untracked ,
177179 /// The arena that types, regions, etc. are allocated from.
178180 arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
179181
@@ -207,11 +209,17 @@ pub struct CtxtInterners<'tcx> {
207209}
208210
209211impl < ' tcx > CtxtInterners < ' tcx > {
210- fn new ( arena : & ' tcx WorkerLocal < Arena < ' tcx > > ) -> CtxtInterners < ' tcx > {
212+ fn new (
213+ sess : & ' tcx Session ,
214+ untracked : & ' tcx Untracked ,
215+ arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
216+ ) -> CtxtInterners < ' tcx > {
211217 // Default interner size - this value has been chosen empirically, and may need to be
212218 // adjusted as the compiler evolves.
213219 const N : usize = 2048 ;
214220 CtxtInterners {
221+ sess,
222+ untracked,
215223 arena,
216224 // The factors have been chosen by @FractalFir based on observed interner sizes, and
217225 // local perf runs. To get the interner sizes, insert `eprintln` printing the size of
@@ -248,12 +256,12 @@ impl<'tcx> CtxtInterners<'tcx> {
248256 /// Interns a type. (Use `mk_*` functions instead, where possible.)
249257 #[ allow( rustc:: usage_of_ty_tykind) ]
250258 #[ inline( never) ]
251- fn intern_ty ( & self , kind : TyKind < ' tcx > , sess : & Session , untracked : & Untracked ) -> Ty < ' tcx > {
259+ fn intern_ty ( & self , kind : TyKind < ' tcx > ) -> Ty < ' tcx > {
252260 Ty ( Interned :: new_unchecked (
253261 self . type_
254262 . intern ( kind, |kind| {
255263 let flags = ty:: FlagComputation :: < TyCtxt < ' tcx > > :: for_kind ( & kind) ;
256- let stable_hash = self . stable_hash ( & flags, sess , untracked , & kind) ;
264+ let stable_hash = self . stable_hash ( & flags, & kind) ;
257265
258266 InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
259267 internee : kind,
@@ -269,17 +277,12 @@ impl<'tcx> CtxtInterners<'tcx> {
269277 /// Interns a const. (Use `mk_*` functions instead, where possible.)
270278 #[ allow( rustc:: usage_of_ty_tykind) ]
271279 #[ inline( never) ]
272- fn intern_const (
273- & self ,
274- kind : ty:: ConstKind < ' tcx > ,
275- sess : & Session ,
276- untracked : & Untracked ,
277- ) -> Const < ' tcx > {
280+ fn intern_const ( & self , kind : ty:: ConstKind < ' tcx > ) -> Const < ' tcx > {
278281 Const ( Interned :: new_unchecked (
279282 self . const_
280283 . intern ( kind, |kind : ty:: ConstKind < ' _ > | {
281284 let flags = ty:: FlagComputation :: < TyCtxt < ' tcx > > :: for_const_kind ( & kind) ;
282- let stable_hash = self . stable_hash ( & flags, sess , untracked , & kind) ;
285+ let stable_hash = self . stable_hash ( & flags, & kind) ;
283286
284287 InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
285288 internee : kind,
@@ -292,40 +295,33 @@ impl<'tcx> CtxtInterners<'tcx> {
292295 ) )
293296 }
294297
295- fn stable_hash < ' a , T : HashStable < StableHashingContext < ' a > > > (
298+ fn stable_hash < T : HashStable < StableHashingContext < ' tcx > > > (
296299 & self ,
297300 flags : & ty:: FlagComputation < TyCtxt < ' tcx > > ,
298- sess : & ' a Session ,
299- untracked : & ' a Untracked ,
300301 val : & T ,
301302 ) -> Fingerprint {
302303 // It's impossible to hash inference variables (and will ICE), so we don't need to try to
303304 // cache them. Without incremental, we rarely stable-hash types, so let's not do it
304305 // proactively.
305- if flags. flags . intersects ( TypeFlags :: HAS_INFER ) || sess. opts . incremental . is_none ( ) {
306+ if flags. flags . intersects ( TypeFlags :: HAS_INFER ) || self . sess . opts . incremental . is_none ( ) {
306307 Fingerprint :: ZERO
307308 } else {
308309 let mut hasher = StableHasher :: new ( ) ;
309- let mut hcx = StableHashingContext :: new ( sess, untracked) ;
310+ let mut hcx = StableHashingContext :: new ( self . sess , self . untracked ) ;
310311 val. hash_stable ( & mut hcx, & mut hasher) ;
311312 hasher. finish ( )
312313 }
313314 }
314315
315316 /// Interns a predicate. (Use `mk_predicate` instead, where possible.)
316317 #[ inline( never) ]
317- fn intern_predicate (
318- & self ,
319- kind : Binder < ' tcx , PredicateKind < ' tcx > > ,
320- sess : & Session ,
321- untracked : & Untracked ,
322- ) -> Predicate < ' tcx > {
318+ fn intern_predicate ( & self , kind : Binder < ' tcx , PredicateKind < ' tcx > > ) -> Predicate < ' tcx > {
323319 Predicate ( Interned :: new_unchecked (
324320 self . predicate
325321 . intern ( kind, |kind| {
326322 let flags = ty:: FlagComputation :: < TyCtxt < ' tcx > > :: for_predicate ( kind) ;
327323
328- let stable_hash = self . stable_hash ( & flags, sess , untracked , & kind) ;
324+ let stable_hash = self . stable_hash ( & flags, & kind) ;
329325
330326 InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
331327 internee : kind,
@@ -466,12 +462,8 @@ pub struct CommonConsts<'tcx> {
466462}
467463
468464impl < ' tcx > CommonTypes < ' tcx > {
469- fn new (
470- interners : & CtxtInterners < ' tcx > ,
471- sess : & Session ,
472- untracked : & Untracked ,
473- ) -> CommonTypes < ' tcx > {
474- let mk = |ty| interners. intern_ty ( ty, sess, untracked) ;
465+ fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonTypes < ' tcx > {
466+ let mk = |ty| interners. intern_ty ( ty) ;
475467
476468 let ty_vars =
477469 ( 0 ..NUM_PREINTERNED_TY_VARS ) . map ( |n| mk ( Infer ( ty:: TyVar ( TyVid :: from ( n) ) ) ) ) . collect ( ) ;
@@ -587,18 +579,8 @@ impl<'tcx> CommonLifetimes<'tcx> {
587579}
588580
589581impl < ' tcx > CommonConsts < ' tcx > {
590- fn new (
591- interners : & CtxtInterners < ' tcx > ,
592- types : & CommonTypes < ' tcx > ,
593- sess : & Session ,
594- untracked : & Untracked ,
595- ) -> CommonConsts < ' tcx > {
596- let mk_const = |c| {
597- interners. intern_const (
598- c, sess, // This is only used to create a stable hashing context.
599- untracked,
600- )
601- } ;
582+ fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
583+ let mk_const = |c| interners. intern_const ( c) ;
602584
603585 let mk_valtree = |v| {
604586 ty:: ValTree ( Interned :: new_unchecked (
@@ -858,7 +840,7 @@ pub struct GlobalCtxt<'tcx> {
858840 /// be called from rustc_middle.
859841 pub ( crate ) hooks : crate :: hooks:: Providers ,
860842
861- untracked : Untracked ,
843+ untracked : & ' tcx Untracked ,
862844
863845 pub query_system : QuerySystem < ' tcx > ,
864846 pub ( crate ) dep_kind_vtables : & ' tcx [ DepKindVTable < ' tcx > ] ,
@@ -1078,7 +1060,7 @@ impl<'tcx> TyCtxt<'tcx> {
10781060 stable_crate_id : StableCrateId ,
10791061 arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
10801062 hir_arena : & ' tcx WorkerLocal < hir:: Arena < ' tcx > > ,
1081- untracked : Untracked ,
1063+ untracked : & ' tcx Untracked ,
10821064 dep_graph : DepGraph ,
10831065 dep_kind_vtables : & ' tcx [ DepKindVTable < ' tcx > ] ,
10841066 query_system : QuerySystem < ' tcx > ,
@@ -1090,10 +1072,10 @@ impl<'tcx> TyCtxt<'tcx> {
10901072 let data_layout = sess. target . parse_data_layout ( ) . unwrap_or_else ( |err| {
10911073 sess. dcx ( ) . emit_fatal ( err) ;
10921074 } ) ;
1093- let interners = CtxtInterners :: new ( arena) ;
1094- let common_types = CommonTypes :: new ( & interners, sess , & untracked ) ;
1075+ let interners = CtxtInterners :: new ( sess , untracked , arena) ;
1076+ let common_types = CommonTypes :: new ( & interners) ;
10951077 let common_lifetimes = CommonLifetimes :: new ( & interners) ;
1096- let common_consts = CommonConsts :: new ( & interners, & common_types, sess , & untracked ) ;
1078+ let common_consts = CommonConsts :: new ( & interners, & common_types) ;
10971079
10981080 let gcx = gcx_cell. get_or_init ( || GlobalCtxt {
10991081 sess,
@@ -2224,12 +2206,7 @@ impl<'tcx> TyCtxt<'tcx> {
22242206
22252207 #[ inline]
22262208 pub fn mk_predicate ( self , binder : Binder < ' tcx , PredicateKind < ' tcx > > ) -> Predicate < ' tcx > {
2227- self . interners . intern_predicate (
2228- binder,
2229- self . sess ,
2230- // This is only used to create a stable hashing context.
2231- & self . untracked ,
2232- )
2209+ self . interners . intern_predicate ( binder)
22332210 }
22342211
22352212 #[ inline]
@@ -2350,24 +2327,14 @@ impl<'tcx> TyCtxt<'tcx> {
23502327
23512328 #[ inline]
23522329 pub fn mk_ct_from_kind ( self , kind : ty:: ConstKind < ' tcx > ) -> Const < ' tcx > {
2353- self . interners . intern_const (
2354- kind,
2355- self . sess ,
2356- // This is only used to create a stable hashing context.
2357- & self . untracked ,
2358- )
2330+ self . interners . intern_const ( kind)
23592331 }
23602332
23612333 // Avoid this in favour of more specific `Ty::new_*` methods, where possible.
23622334 #[ allow( rustc:: usage_of_ty_tykind) ]
23632335 #[ inline]
23642336 pub fn mk_ty_from_kind ( self , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
2365- self . interners . intern_ty (
2366- st,
2367- self . sess ,
2368- // This is only used to create a stable hashing context.
2369- & self . untracked ,
2370- )
2337+ self . interners . intern_ty ( st)
23712338 }
23722339
23732340 pub fn mk_param_from_def ( self , param : & ty:: GenericParamDef ) -> GenericArg < ' tcx > {
0 commit comments