@@ -94,6 +94,8 @@ pub struct CtxtInterners<'tcx> {
94
94
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
95
95
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
96
96
const_ : InternedSet < ' tcx , Const < ' tcx > > ,
97
+ /// Const allocations.
98
+ allocation : InternedSet < ' tcx , Allocation > ,
97
99
}
98
100
99
101
impl < ' tcx > CtxtInterners < ' tcx > {
@@ -111,6 +113,7 @@ impl<'tcx> CtxtInterners<'tcx> {
111
113
projs : Default :: default ( ) ,
112
114
place_elems : Default :: default ( ) ,
113
115
const_ : Default :: default ( ) ,
116
+ allocation : Default :: default ( ) ,
114
117
}
115
118
}
116
119
@@ -1013,9 +1016,6 @@ pub struct GlobalCtxt<'tcx> {
1013
1016
/// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes
1014
1017
const_stability_interner : ShardedHashMap < & ' tcx attr:: ConstStability , ( ) > ,
1015
1018
1016
- /// Stores the value of constants (and deduplicates the actual memory)
1017
- allocation_interner : ShardedHashMap < & ' tcx Allocation , ( ) > ,
1018
-
1019
1019
/// Stores memory for globals (statics/consts).
1020
1020
pub ( crate ) alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
1021
1021
@@ -1058,7 +1058,10 @@ impl<'tcx> TyCtxt<'tcx> {
1058
1058
}
1059
1059
1060
1060
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
1062
1065
}
1063
1066
1064
1067
/// Allocates a read-only byte or string literal for `mir::interpret`.
@@ -1174,7 +1177,6 @@ impl<'tcx> TyCtxt<'tcx> {
1174
1177
layout_interner : Default :: default ( ) ,
1175
1178
stability_interner : Default :: default ( ) ,
1176
1179
const_stability_interner : Default :: default ( ) ,
1177
- allocation_interner : Default :: default ( ) ,
1178
1180
alloc_map : Lock :: new ( interpret:: AllocMap :: new ( ) ) ,
1179
1181
output_filenames : Arc :: new ( output_filenames. clone ( ) ) ,
1180
1182
}
@@ -1610,6 +1612,7 @@ macro_rules! nop_list_lift {
1610
1612
nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
1611
1613
nop_lift ! { region; Region <' a> => Region <' tcx>}
1612
1614
nop_lift ! { const_; & ' a Const <' a> => & ' tcx Const <' tcx>}
1615
+ nop_lift ! { allocation; & ' a Allocation => & ' tcx Allocation }
1613
1616
nop_lift ! { predicate; & ' a PredicateInner <' a> => & ' tcx PredicateInner <' tcx>}
1614
1617
1615
1618
nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
@@ -1900,7 +1903,7 @@ impl<'tcx> TyCtxt<'tcx> {
1900
1903
"Const Stability interner: #{}" ,
1901
1904
self . 0 . const_stability_interner. len( )
1902
1905
) ?;
1903
- writeln ! ( fmt, "Allocation interner: #{}" , self . 0 . allocation_interner . len( ) ) ?;
1906
+ writeln ! ( fmt, "Allocation interner: #{}" , self . 0 . interners . allocation . len( ) ) ?;
1904
1907
writeln ! ( fmt, "Layout interner: #{}" , self . 0 . layout_interner. len( ) ) ?;
1905
1908
1906
1909
Ok ( ( ) )
@@ -2001,6 +2004,26 @@ impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
2001
2004
}
2002
2005
}
2003
2006
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
+
2004
2027
macro_rules! direct_interners {
2005
2028
( $( $name: ident: $method: ident( $ty: ty) , ) +) => {
2006
2029
$( impl <' tcx> PartialEq for Interned <' tcx, $ty> {
0 commit comments