@@ -118,8 +118,8 @@ pub struct CtxtInterners<'tcx> {
118118 /// The arena that types, regions, etc. are allocated from.
119119 arena : & ' tcx WorkerLocal < Arena < ' tcx > > ,
120120
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.
123123 type_ : InternedSet < ' tcx , TyS < ' tcx > > ,
124124 type_list : InternedSet < ' tcx , List < Ty < ' tcx > > > ,
125125 substs : InternedSet < ' tcx , InternalSubsts < ' tcx > > ,
@@ -132,9 +132,9 @@ pub struct CtxtInterners<'tcx> {
132132 projs : InternedSet < ' tcx , List < ProjectionKind > > ,
133133 place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
134134 const_ : InternedSet < ' tcx , Const < ' tcx > > ,
135- /// Const allocations.
136- allocation : InternedSet < ' tcx , Allocation > ,
135+ const_allocation : InternedSet < ' tcx , Allocation > ,
137136 bound_variable_kinds : InternedSet < ' tcx , List < ty:: BoundVariableKind > > ,
137+ layout : InternedSet < ' tcx , Layout > ,
138138}
139139
140140impl < ' tcx > CtxtInterners < ' tcx > {
@@ -152,8 +152,9 @@ impl<'tcx> CtxtInterners<'tcx> {
152152 projs : Default :: default ( ) ,
153153 place_elems : Default :: default ( ) ,
154154 const_ : Default :: default ( ) ,
155- allocation : Default :: default ( ) ,
155+ const_allocation : Default :: default ( ) ,
156156 bound_variable_kinds : Default :: default ( ) ,
157+ layout : Default :: default ( ) ,
157158 }
158159 }
159160
@@ -1062,10 +1063,9 @@ pub struct GlobalCtxt<'tcx> {
10621063 /// Stores memory for globals (statics/consts).
10631064 pub ( crate ) alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
10641065
1065- layout_interner : ShardedHashMap < & ' tcx Layout , ( ) > ,
1066-
10671066 output_filenames : Arc < OutputFilenames > ,
10681067
1068+ // FIXME(eddyb) this doesn't belong here and should be using a query.
10691069 pub ( super ) vtables_cache :
10701070 Lock < FxHashMap < ( Ty < ' tcx > , Option < ty:: PolyExistentialTraitRef < ' tcx > > ) , AllocId > > ,
10711071}
@@ -1107,13 +1107,6 @@ impl<'tcx> TyCtxt<'tcx> {
11071107 self . arena . alloc ( ty:: AdtDef :: new ( self , did, kind, variants, repr) )
11081108 }
11091109
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-
11171110 /// Allocates a read-only byte or string literal for `mir::interpret`.
11181111 pub fn allocate_bytes ( self , bytes : & [ u8 ] ) -> interpret:: AllocId {
11191112 // Create an allocation that just contains these bytes.
@@ -1122,20 +1115,19 @@ impl<'tcx> TyCtxt<'tcx> {
11221115 self . create_memory_alloc ( alloc)
11231116 }
11241117
1118+ // FIXME(eddyb) move to `direct_interners!`.
11251119 pub fn intern_stability ( self , stab : attr:: Stability ) -> & ' tcx attr:: Stability {
11261120 self . stability_interner . intern ( stab, |stab| self . arena . alloc ( stab) )
11271121 }
11281122
1123+ // FIXME(eddyb) move to `direct_interners!`.
11291124 pub fn intern_const_stability ( self , stab : attr:: ConstStability ) -> & ' tcx attr:: ConstStability {
11301125 self . const_stability_interner . intern ( stab, |stab| self . arena . alloc ( stab) )
11311126 }
11321127
1133- pub fn intern_layout ( self , layout : Layout ) -> & ' tcx Layout {
1134- self . layout_interner . intern ( layout, |layout| self . arena . alloc ( layout) )
1135- }
1136-
11371128 /// Returns a range of the start/end indices specified with the
11381129 /// `rustc_layout_scalar_valid_range` attribute.
1130+ // FIXME(eddyb) this is an awkward spot for this method, maybe move it?
11391131 pub fn layout_scalar_valid_range ( self , def_id : DefId ) -> ( Bound < u128 > , Bound < u128 > ) {
11401132 let attrs = self . get_attrs ( def_id) ;
11411133 let get = |name| {
@@ -1210,7 +1202,6 @@ impl<'tcx> TyCtxt<'tcx> {
12101202 evaluation_cache : Default :: default ( ) ,
12111203 crate_name : Symbol :: intern ( crate_name) ,
12121204 data_layout,
1213- layout_interner : Default :: default ( ) ,
12141205 stability_interner : Default :: default ( ) ,
12151206 const_stability_interner : Default :: default ( ) ,
12161207 alloc_map : Lock :: new ( interpret:: AllocMap :: new ( ) ) ,
@@ -1670,7 +1661,7 @@ macro_rules! nop_list_lift {
16701661nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
16711662nop_lift ! { region; Region <' a> => Region <' tcx>}
16721663nop_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 }
16741665nop_lift ! { predicate; & ' a PredicateInner <' a> => & ' tcx PredicateInner <' tcx>}
16751666
16761667nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
@@ -1962,8 +1953,12 @@ impl<'tcx> TyCtxt<'tcx> {
19621953 "Const Stability interner: #{}" ,
19631954 self . 0 . const_stability_interner. len( )
19641955 ) ?;
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( ) ) ?;
19671962
19681963 Ok ( ( ) )
19691964 }
@@ -2051,38 +2046,6 @@ impl<'tcx, T> Borrow<[T]> for Interned<'tcx, List<T>> {
20512046 }
20522047}
20532048
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-
20862049macro_rules! direct_interners {
20872050 ( $( $name: ident: $method: ident( $ty: ty) , ) +) => {
20882051 $( impl <' tcx> PartialEq for Interned <' tcx, $ty> {
@@ -2099,9 +2062,15 @@ macro_rules! direct_interners {
20992062 }
21002063 }
21012064
2065+ impl <' tcx> Borrow <$ty> for Interned <' tcx, $ty> {
2066+ fn borrow<' a>( & ' a self ) -> & ' a $ty {
2067+ & self . 0
2068+ }
2069+ }
2070+
21022071 impl <' tcx> TyCtxt <' tcx> {
21032072 pub fn $method( self , v: $ty) -> & ' tcx $ty {
2104- self . interners. $name. intern_ref ( & v, || {
2073+ self . interners. $name. intern ( v, |v | {
21052074 Interned ( self . interners. arena. alloc( v) )
21062075 } ) . 0
21072076 }
@@ -2112,6 +2081,8 @@ macro_rules! direct_interners {
21122081direct_interners ! {
21132082 region: mk_region( RegionKind ) ,
21142083 const_: mk_const( Const <' tcx>) ,
2084+ const_allocation: intern_const_alloc( Allocation ) ,
2085+ layout: intern_layout( Layout ) ,
21152086}
21162087
21172088macro_rules! slice_interners {
0 commit comments