@@ -151,7 +151,7 @@ pub struct CtxtInterners<'tcx> {
151151 clauses : InternedSet < ' tcx , List < Clause < ' tcx > > > ,
152152 projs : InternedSet < ' tcx , List < ProjectionKind > > ,
153153 place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
154- const_ : InternedSet < ' tcx , ConstData < ' tcx > > ,
154+ const_ : InternedSet < ' tcx , WithCachedTypeInfo < ConstData < ' tcx > > > ,
155155 const_allocation : InternedSet < ' tcx , Allocation > ,
156156 bound_variable_kinds : InternedSet < ' tcx , List < ty:: BoundVariableKind > > ,
157157 layout : InternedSet < ' tcx , LayoutS < FieldIdx , VariantIdx > > ,
@@ -212,6 +212,32 @@ impl<'tcx> CtxtInterners<'tcx> {
212212 ) )
213213 }
214214
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+
215241 fn stable_hash < ' a , T : HashStable < StableHashingContext < ' a > > > (
216242 & self ,
217243 flags : & ty:: flags:: FlagComputation ,
@@ -418,11 +444,17 @@ impl<'tcx> CommonLifetimes<'tcx> {
418444}
419445
420446impl < ' 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 > {
422453 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+ )
426458 } ;
427459
428460 CommonConsts {
@@ -714,7 +746,7 @@ impl<'tcx> TyCtxt<'tcx> {
714746 let interners = CtxtInterners :: new ( arena) ;
715747 let common_types = CommonTypes :: new ( & interners, s, & untracked) ;
716748 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 ) ;
718750
719751 GlobalCtxt {
720752 sess : s,
@@ -1533,7 +1565,6 @@ macro_rules! direct_interners {
15331565// crate only, and have a corresponding `mk_` function.
15341566direct_interners ! {
15351567 region: pub ( crate ) intern_region( RegionKind <' tcx>) : Region -> Region <' tcx>,
1536- const_: intern_const( ConstData <' tcx>) : Const -> Const <' tcx>,
15371568 const_allocation: pub mk_const_alloc( Allocation ) : ConstAllocation -> ConstAllocation <' tcx>,
15381569 layout: pub mk_layout( LayoutS <FieldIdx , VariantIdx >) : Layout -> Layout <' tcx>,
15391570 adt_def: pub mk_adt_def_from_data( AdtDefData ) : AdtDef -> AdtDef <' tcx>,
@@ -1710,7 +1741,12 @@ impl<'tcx> TyCtxt<'tcx> {
17101741
17111742 #[ inline]
17121743 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+ )
17141750 }
17151751
17161752 // Avoid this in favour of more specific `Ty::new_*` methods, where possible.
0 commit comments