@@ -94,6 +94,8 @@ pub struct CtxtInterners<'tcx> {
9494 projs : InternedSet < ' tcx , List < ProjectionKind > > ,
9595 place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
9696 const_ : InternedSet < ' tcx , Const < ' tcx > > ,
97+ /// Const allocations.
98+ allocation : InternedSet < ' tcx , Allocation > ,
9799}
98100
99101impl < ' tcx > CtxtInterners < ' tcx > {
@@ -111,6 +113,7 @@ impl<'tcx> CtxtInterners<'tcx> {
111113 projs : Default :: default ( ) ,
112114 place_elems : Default :: default ( ) ,
113115 const_ : Default :: default ( ) ,
116+ allocation : Default :: default ( ) ,
114117 }
115118 }
116119
@@ -1013,9 +1016,6 @@ pub struct GlobalCtxt<'tcx> {
10131016 /// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes
10141017 const_stability_interner : ShardedHashMap < & ' tcx attr:: ConstStability , ( ) > ,
10151018
1016- /// Stores the value of constants (and deduplicates the actual memory)
1017- allocation_interner : ShardedHashMap < & ' tcx Allocation , ( ) > ,
1018-
10191019 /// Stores memory for globals (statics/consts).
10201020 pub ( crate ) alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
10211021
@@ -1058,7 +1058,10 @@ impl<'tcx> TyCtxt<'tcx> {
10581058 }
10591059
10601060 pub fn intern_const_alloc ( self , alloc : Allocation ) -> & ' tcx Allocation {
1061- self . allocation_interner . intern ( alloc, |alloc| self . arena . alloc ( alloc) )
1061+ self . interners
1062+ . allocation
1063+ . intern ( alloc, |alloc| Interned ( self . interners . arena . alloc ( alloc) ) )
1064+ . 0
10621065 }
10631066
10641067 /// Allocates a read-only byte or string literal for `mir::interpret`.
@@ -1174,7 +1177,6 @@ impl<'tcx> TyCtxt<'tcx> {
11741177 layout_interner : Default :: default ( ) ,
11751178 stability_interner : Default :: default ( ) ,
11761179 const_stability_interner : Default :: default ( ) ,
1177- allocation_interner : Default :: default ( ) ,
11781180 alloc_map : Lock :: new ( interpret:: AllocMap :: new ( ) ) ,
11791181 output_filenames : Arc :: new ( output_filenames. clone ( ) ) ,
11801182 }
@@ -1610,6 +1612,7 @@ macro_rules! nop_list_lift {
16101612nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
16111613nop_lift ! { region; Region <' a> => Region <' tcx>}
16121614nop_lift ! { const_; & ' a Const <' a> => & ' tcx Const <' tcx>}
1615+ nop_lift ! { allocation; & ' a Allocation => & ' tcx Allocation }
16131616nop_lift ! { predicate; & ' a PredicateInner <' a> => & ' tcx PredicateInner <' tcx>}
16141617
16151618nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
@@ -1900,7 +1903,7 @@ impl<'tcx> TyCtxt<'tcx> {
19001903 "Const Stability interner: #{}" ,
19011904 self . 0 . const_stability_interner. len( )
19021905 ) ?;
1903- writeln ! ( fmt, "Allocation interner: #{}" , self . 0 . allocation_interner . len( ) ) ?;
1906+ writeln ! ( fmt, "Allocation interner: #{}" , self . 0 . interners . allocation . len( ) ) ?;
19041907 writeln ! ( fmt, "Layout interner: #{}" , self . 0 . layout_interner. len( ) ) ?;
19051908
19061909 Ok ( ( ) )
@@ -2001,6 +2004,26 @@ impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
20012004 }
20022005}
20032006
2007+ impl < ' tcx > Borrow < Allocation > for Interned < ' tcx , Allocation > {
2008+ fn borrow < ' a > ( & ' a self ) -> & ' a Allocation {
2009+ & self . 0
2010+ }
2011+ }
2012+
2013+ impl < ' tcx > PartialEq for Interned < ' tcx , Allocation > {
2014+ fn eq ( & self , other : & Self ) -> bool {
2015+ self . 0 == other. 0
2016+ }
2017+ }
2018+
2019+ impl < ' tcx > Eq for Interned < ' tcx , Allocation > { }
2020+
2021+ impl < ' tcx > Hash for Interned < ' tcx , Allocation > {
2022+ fn hash < H : Hasher > ( & self , s : & mut H ) {
2023+ self . 0 . hash ( s)
2024+ }
2025+ }
2026+
20042027macro_rules! direct_interners {
20052028 ( $( $name: ident: $method: ident( $ty: ty) , ) +) => {
20062029 $( impl <' tcx> PartialEq for Interned <' tcx, $ty> {
0 commit comments