@@ -118,8 +118,8 @@ pub struct CtxtInterners<'tcx> {
118
118
/// The arena that types, regions, etc. are allocated from.
119
119
arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
120
120
121
- /// Specifically use a speedy hash algorithm for these hash sets, since
122
- /// they're accessed quite often.
121
+ // Specifically use a speedy hash algorithm for these hash sets, since
122
+ // they're accessed quite often.
123
123
type_ : InternedSet < ' tcx , TyS < ' tcx > > ,
124
124
type_list : InternedSet < ' tcx , List < Ty < ' tcx > > > ,
125
125
substs : InternedSet < ' tcx , InternalSubsts < ' tcx > > ,
@@ -132,9 +132,9 @@ pub struct CtxtInterners<'tcx> {
132
132
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
133
133
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
134
134
const_ : InternedSet < ' tcx , Const < ' tcx > > ,
135
- /// Const allocations.
136
- allocation : InternedSet < ' tcx , Allocation > ,
135
+ const_allocation : InternedSet < ' tcx , Allocation > ,
137
136
bound_variable_kinds : InternedSet < ' tcx , List < ty:: BoundVariableKind > > ,
137
+ layout : InternedSet < ' tcx , Layout > ,
138
138
}
139
139
140
140
impl < ' tcx > CtxtInterners < ' tcx > {
@@ -152,8 +152,9 @@ impl<'tcx> CtxtInterners<'tcx> {
152
152
projs : Default :: default ( ) ,
153
153
place_elems : Default :: default ( ) ,
154
154
const_ : Default :: default ( ) ,
155
- allocation : Default :: default ( ) ,
155
+ const_allocation : Default :: default ( ) ,
156
156
bound_variable_kinds : Default :: default ( ) ,
157
+ layout : Default :: default ( ) ,
157
158
}
158
159
}
159
160
@@ -1062,10 +1063,9 @@ pub struct GlobalCtxt<'tcx> {
1062
1063
/// Stores memory for globals (statics/consts).
1063
1064
pub ( crate ) alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
1064
1065
1065
- layout_interner : ShardedHashMap < & ' tcx Layout , ( ) > ,
1066
-
1067
1066
output_filenames : Arc < OutputFilenames > ,
1068
1067
1068
+ // FIXME(eddyb) this doesn't belong here and should be using a query.
1069
1069
pub ( super ) vtables_cache :
1070
1070
Lock < FxHashMap < ( Ty < ' tcx > , Option < ty:: PolyExistentialTraitRef < ' tcx > > ) , AllocId > > ,
1071
1071
}
@@ -1107,13 +1107,6 @@ impl<'tcx> TyCtxt<'tcx> {
1107
1107
self . arena . alloc ( ty:: AdtDef :: new ( self , did, kind, variants, repr) )
1108
1108
}
1109
1109
1110
- pub fn intern_const_alloc ( self , alloc : Allocation ) -> & ' tcx Allocation {
1111
- self . interners
1112
- . allocation
1113
- . intern ( alloc, |alloc| Interned ( self . interners . arena . alloc ( alloc) ) )
1114
- . 0
1115
- }
1116
-
1117
1110
/// Allocates a read-only byte or string literal for `mir::interpret`.
1118
1111
pub fn allocate_bytes ( self , bytes : & [ u8 ] ) -> interpret:: AllocId {
1119
1112
// Create an allocation that just contains these bytes.
@@ -1122,20 +1115,19 @@ impl<'tcx> TyCtxt<'tcx> {
1122
1115
self . create_memory_alloc ( alloc)
1123
1116
}
1124
1117
1118
+ // FIXME(eddyb) move to `direct_interners!`.
1125
1119
pub fn intern_stability ( self , stab : attr:: Stability ) -> & ' tcx attr:: Stability {
1126
1120
self . stability_interner . intern ( stab, |stab| self . arena . alloc ( stab) )
1127
1121
}
1128
1122
1123
+ // FIXME(eddyb) move to `direct_interners!`.
1129
1124
pub fn intern_const_stability ( self , stab : attr:: ConstStability ) -> & ' tcx attr:: ConstStability {
1130
1125
self . const_stability_interner . intern ( stab, |stab| self . arena . alloc ( stab) )
1131
1126
}
1132
1127
1133
- pub fn intern_layout ( self , layout : Layout ) -> & ' tcx Layout {
1134
- self . layout_interner . intern ( layout, |layout| self . arena . alloc ( layout) )
1135
- }
1136
-
1137
1128
/// Returns a range of the start/end indices specified with the
1138
1129
/// `rustc_layout_scalar_valid_range` attribute.
1130
+ // FIXME(eddyb) this is an awkward spot for this method, maybe move it?
1139
1131
pub fn layout_scalar_valid_range ( self , def_id : DefId ) -> ( Bound < u128 > , Bound < u128 > ) {
1140
1132
let attrs = self . get_attrs ( def_id) ;
1141
1133
let get = |name| {
@@ -1210,7 +1202,6 @@ impl<'tcx> TyCtxt<'tcx> {
1210
1202
evaluation_cache : Default :: default ( ) ,
1211
1203
crate_name : Symbol :: intern ( crate_name) ,
1212
1204
data_layout,
1213
- layout_interner : Default :: default ( ) ,
1214
1205
stability_interner : Default :: default ( ) ,
1215
1206
const_stability_interner : Default :: default ( ) ,
1216
1207
alloc_map : Lock :: new ( interpret:: AllocMap :: new ( ) ) ,
@@ -1670,7 +1661,7 @@ macro_rules! nop_list_lift {
1670
1661
nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
1671
1662
nop_lift ! { region; Region <' a> => Region <' tcx>}
1672
1663
nop_lift ! { const_; & ' a Const <' a> => & ' tcx Const <' tcx>}
1673
- nop_lift ! { allocation ; & ' a Allocation => & ' tcx Allocation }
1664
+ nop_lift ! { const_allocation ; & ' a Allocation => & ' tcx Allocation }
1674
1665
nop_lift ! { predicate; & ' a PredicateInner <' a> => & ' tcx PredicateInner <' tcx>}
1675
1666
1676
1667
nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
@@ -1962,8 +1953,12 @@ impl<'tcx> TyCtxt<'tcx> {
1962
1953
"Const Stability interner: #{}" ,
1963
1954
self . 0 . const_stability_interner. len( )
1964
1955
) ?;
1965
- writeln ! ( fmt, "Allocation interner: #{}" , self . 0 . interners. allocation. len( ) ) ?;
1966
- writeln ! ( fmt, "Layout interner: #{}" , self . 0 . layout_interner. len( ) ) ?;
1956
+ writeln ! (
1957
+ fmt,
1958
+ "Const Allocation interner: #{}" ,
1959
+ self . 0 . interners. const_allocation. len( )
1960
+ ) ?;
1961
+ writeln ! ( fmt, "Layout interner: #{}" , self . 0 . interners. layout. len( ) ) ?;
1967
1962
1968
1963
Ok ( ( ) )
1969
1964
}
@@ -2051,38 +2046,6 @@ impl<'tcx, T> Borrow<[T]> for Interned<'tcx, List<T>> {
2051
2046
}
2052
2047
}
2053
2048
2054
- impl < ' tcx > Borrow < RegionKind > for Interned < ' tcx , RegionKind > {
2055
- fn borrow ( & self ) -> & RegionKind {
2056
- & self . 0
2057
- }
2058
- }
2059
-
2060
- impl < ' tcx > Borrow < Const < ' tcx > > for Interned < ' tcx , Const < ' tcx > > {
2061
- fn borrow < ' a > ( & ' a self ) -> & ' a Const < ' tcx > {
2062
- & self . 0
2063
- }
2064
- }
2065
-
2066
- impl < ' tcx > Borrow < Allocation > for Interned < ' tcx , Allocation > {
2067
- fn borrow < ' a > ( & ' a self ) -> & ' a Allocation {
2068
- & self . 0
2069
- }
2070
- }
2071
-
2072
- impl < ' tcx > PartialEq for Interned < ' tcx , Allocation > {
2073
- fn eq ( & self , other : & Self ) -> bool {
2074
- self . 0 == other. 0
2075
- }
2076
- }
2077
-
2078
- impl < ' tcx > Eq for Interned < ' tcx , Allocation > { }
2079
-
2080
- impl < ' tcx > Hash for Interned < ' tcx , Allocation > {
2081
- fn hash < H : Hasher > ( & self , s : & mut H ) {
2082
- self . 0 . hash ( s)
2083
- }
2084
- }
2085
-
2086
2049
macro_rules! direct_interners {
2087
2050
( $( $name: ident: $method: ident( $ty: ty) , ) +) => {
2088
2051
$( impl <' tcx> PartialEq for Interned <' tcx, $ty> {
@@ -2099,9 +2062,15 @@ macro_rules! direct_interners {
2099
2062
}
2100
2063
}
2101
2064
2065
+ impl <' tcx> Borrow <$ty> for Interned <' tcx, $ty> {
2066
+ fn borrow<' a>( & ' a self ) -> & ' a $ty {
2067
+ & self . 0
2068
+ }
2069
+ }
2070
+
2102
2071
impl <' tcx> TyCtxt <' tcx> {
2103
2072
pub fn $method( self , v: $ty) -> & ' tcx $ty {
2104
- self . interners. $name. intern_ref ( & v, || {
2073
+ self . interners. $name. intern ( v, |v | {
2105
2074
Interned ( self . interners. arena. alloc( v) )
2106
2075
} ) . 0
2107
2076
}
@@ -2112,6 +2081,8 @@ macro_rules! direct_interners {
2112
2081
direct_interners ! {
2113
2082
region: mk_region( RegionKind ) ,
2114
2083
const_: mk_const( Const <' tcx>) ,
2084
+ const_allocation: intern_const_alloc( Allocation ) ,
2085
+ layout: intern_layout( Layout ) ,
2115
2086
}
2116
2087
2117
2088
macro_rules! slice_interners {
0 commit comments