@@ -151,7 +151,7 @@ pub struct CtxtInterners<'tcx> {
151
151
clauses : InternedSet < ' tcx , List < Clause < ' tcx > > > ,
152
152
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
153
153
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
154
- const_ : InternedSet < ' tcx , ConstData < ' tcx > > ,
154
+ const_ : InternedSet < ' tcx , WithCachedTypeInfo < ConstData < ' tcx > > > ,
155
155
const_allocation : InternedSet < ' tcx , Allocation > ,
156
156
bound_variable_kinds : InternedSet < ' tcx , List < ty:: BoundVariableKind > > ,
157
157
layout : InternedSet < ' tcx , LayoutS < FieldIdx , VariantIdx > > ,
@@ -212,6 +212,32 @@ impl<'tcx> CtxtInterners<'tcx> {
212
212
) )
213
213
}
214
214
215
+ /// Interns a const. (Use `mk_*` functions instead, where possible.)
216
+ #[ allow( rustc:: usage_of_ty_tykind) ]
217
+ #[ inline( never) ]
218
+ fn intern_const (
219
+ & self ,
220
+ data : ty:: ConstData < ' tcx > ,
221
+ sess : & Session ,
222
+ untracked : & Untracked ,
223
+ ) -> Const < ' tcx > {
224
+ Const ( Interned :: new_unchecked (
225
+ self . const_
226
+ . intern ( data, |data : ConstData < ' _ > | {
227
+ let flags = super :: flags:: FlagComputation :: for_const ( & data. kind , data. ty ) ;
228
+ let stable_hash = self . stable_hash ( & flags, sess, untracked, & data) ;
229
+
230
+ InternedInSet ( self . arena . alloc ( WithCachedTypeInfo {
231
+ internee : data,
232
+ stable_hash,
233
+ flags : flags. flags ,
234
+ outer_exclusive_binder : flags. outer_exclusive_binder ,
235
+ } ) )
236
+ } )
237
+ . 0 ,
238
+ ) )
239
+ }
240
+
215
241
fn stable_hash < ' a , T : HashStable < StableHashingContext < ' a > > > (
216
242
& self ,
217
243
flags : & ty:: flags:: FlagComputation ,
@@ -418,11 +444,17 @@ impl<'tcx> CommonLifetimes<'tcx> {
418
444
}
419
445
420
446
impl < ' tcx > CommonConsts < ' tcx > {
421
- fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
447
+ fn new (
448
+ interners : & CtxtInterners < ' tcx > ,
449
+ types : & CommonTypes < ' tcx > ,
450
+ sess : & Session ,
451
+ untracked : & Untracked ,
452
+ ) -> CommonConsts < ' tcx > {
422
453
let mk_const = |c| {
423
- Const ( Interned :: new_unchecked (
424
- interners. const_ . intern ( c, |c| InternedInSet ( interners. arena . alloc ( c) ) ) . 0 ,
425
- ) )
454
+ interners. intern_const (
455
+ c, sess, // This is only used to create a stable hashing context.
456
+ untracked,
457
+ )
426
458
} ;
427
459
428
460
CommonConsts {
@@ -714,7 +746,7 @@ impl<'tcx> TyCtxt<'tcx> {
714
746
let interners = CtxtInterners :: new ( arena) ;
715
747
let common_types = CommonTypes :: new ( & interners, s, & untracked) ;
716
748
let common_lifetimes = CommonLifetimes :: new ( & interners) ;
717
- let common_consts = CommonConsts :: new ( & interners, & common_types) ;
749
+ let common_consts = CommonConsts :: new ( & interners, & common_types, s , & untracked ) ;
718
750
719
751
GlobalCtxt {
720
752
sess : s,
@@ -1533,7 +1565,6 @@ macro_rules! direct_interners {
1533
1565
// crate only, and have a corresponding `mk_` function.
1534
1566
direct_interners ! {
1535
1567
region: pub ( crate ) intern_region( RegionKind <' tcx>) : Region -> Region <' tcx>,
1536
- const_: intern_const( ConstData <' tcx>) : Const -> Const <' tcx>,
1537
1568
const_allocation: pub mk_const_alloc( Allocation ) : ConstAllocation -> ConstAllocation <' tcx>,
1538
1569
layout: pub mk_layout( LayoutS <FieldIdx , VariantIdx >) : Layout -> Layout <' tcx>,
1539
1570
adt_def: pub mk_adt_def_from_data( AdtDefData ) : AdtDef -> AdtDef <' tcx>,
@@ -1710,7 +1741,12 @@ impl<'tcx> TyCtxt<'tcx> {
1710
1741
1711
1742
#[ inline]
1712
1743
pub fn mk_ct_from_kind ( self , kind : ty:: ConstKind < ' tcx > , ty : Ty < ' tcx > ) -> Const < ' tcx > {
1713
- self . intern_const ( ty:: ConstData { kind, ty } )
1744
+ self . interners . intern_const (
1745
+ ty:: ConstData { kind, ty } ,
1746
+ self . sess ,
1747
+ // This is only used to create a stable hashing context.
1748
+ & self . untracked ,
1749
+ )
1714
1750
}
1715
1751
1716
1752
// Avoid this in favour of more specific `Ty::new_*` methods, where possible.
0 commit comments