@@ -31,7 +31,7 @@ use middle::cstore::EncodedMetadata;
31
31
use middle:: lang_items;
32
32
use middle:: resolve_lifetime:: { self , ObjectLifetimeDefault } ;
33
33
use middle:: stability;
34
- use mir:: { self , Mir , interpret} ;
34
+ use mir:: { self , Mir , interpret, PlaceElem } ;
35
35
use mir:: interpret:: Allocation ;
36
36
use ty:: subst:: { Kind , Substs , Subst } ;
37
37
use ty:: ReprOptions ;
@@ -140,6 +140,7 @@ pub struct CtxtInterners<'tcx> {
140
140
canonical_var_infos : InternedSet < ' tcx , Slice < CanonicalVarInfo > > ,
141
141
region : InternedSet < ' tcx , RegionKind > ,
142
142
existential_predicates : InternedSet < ' tcx , Slice < ExistentialPredicate < ' tcx > > > ,
143
+ place_elems : InternedSet < ' tcx , Slice < PlaceElem < ' tcx > > > ,
143
144
predicates : InternedSet < ' tcx , Slice < Predicate < ' tcx > > > ,
144
145
const_ : InternedSet < ' tcx , Const < ' tcx > > ,
145
146
clauses : InternedSet < ' tcx , Slice < Clause < ' tcx > > > ,
@@ -156,6 +157,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
156
157
region : Default :: default ( ) ,
157
158
existential_predicates : Default :: default ( ) ,
158
159
canonical_var_infos : Default :: default ( ) ,
160
+ place_elems : Default :: default ( ) ,
159
161
predicates : Default :: default ( ) ,
160
162
const_ : Default :: default ( ) ,
161
163
clauses : Default :: default ( ) ,
@@ -1720,6 +1722,27 @@ impl<'a, 'tcx> Lift<'tcx> for &'a Slice<Predicate<'a>> {
1720
1722
}
1721
1723
}
1722
1724
1725
+ impl < ' a , ' tcx > Lift < ' tcx > for & ' a Slice < PlaceElem < ' a > > {
1726
+ type Lifted = & ' tcx Slice < PlaceElem < ' tcx > > ;
1727
+ fn lift_to_tcx < ' b , ' gcx > ( & self , tcx : TyCtxt < ' b , ' gcx , ' tcx > )
1728
+ -> Option < & ' tcx Slice < PlaceElem < ' tcx > > > {
1729
+ if self . is_empty ( ) {
1730
+ return Some ( Slice :: empty ( ) ) ;
1731
+ }
1732
+ if tcx. interners . arena . in_arena ( * self as * const _ ) {
1733
+ return Some ( unsafe {
1734
+ mem:: transmute ( * self )
1735
+ } ) ;
1736
+ }
1737
+
1738
+ if !tcx. is_global ( ) {
1739
+ self . lift_to_tcx ( tcx. global_tcx ( ) )
1740
+ } else {
1741
+ None
1742
+ }
1743
+ }
1744
+ }
1745
+
1723
1746
impl < ' a , ' tcx > Lift < ' tcx > for & ' a Slice < CanonicalVarInfo > {
1724
1747
type Lifted = & ' tcx Slice < CanonicalVarInfo > ;
1725
1748
fn lift_to_tcx < ' b , ' gcx > ( & self , tcx : TyCtxt < ' b , ' gcx , ' tcx > ) -> Option < Self :: Lifted > {
@@ -2160,6 +2183,13 @@ impl<'tcx: 'lcx, 'lcx> Borrow<[ExistentialPredicate<'lcx>]>
2160
2183
}
2161
2184
}
2162
2185
2186
+ impl < ' tcx : ' lcx , ' lcx > Borrow < [ PlaceElem < ' lcx > ] >
2187
+ for Interned < ' tcx , Slice < PlaceElem < ' tcx > > > {
2188
+ fn borrow < ' a > ( & ' a self ) -> & ' a [ PlaceElem < ' lcx > ] {
2189
+ & self . 0 [ ..]
2190
+ }
2191
+ }
2192
+
2163
2193
impl < ' tcx : ' lcx , ' lcx > Borrow < [ Predicate < ' lcx > ] >
2164
2194
for Interned < ' tcx , Slice < Predicate < ' tcx > > > {
2165
2195
fn borrow < ' a > ( & ' a self ) -> & ' a [ Predicate < ' lcx > ] {
@@ -2284,6 +2314,7 @@ macro_rules! slice_interners {
2284
2314
slice_interners ! (
2285
2315
existential_predicates: _intern_existential_predicates( ExistentialPredicate ) ,
2286
2316
predicates: _intern_predicates( Predicate ) ,
2317
+ place_elems: _intern_place_elems( PlaceElem ) ,
2287
2318
type_list: _intern_type_list( Ty ) ,
2288
2319
substs: _intern_substs( Kind ) ,
2289
2320
clauses: _intern_clauses( Clause ) ,
@@ -2573,6 +2604,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2573
2604
}
2574
2605
}
2575
2606
2607
+ pub fn intern_place_elems ( self , place_elems : & [ PlaceElem < ' tcx > ] )
2608
+ -> & ' tcx Slice < PlaceElem < ' tcx > > {
2609
+ if place_elems. is_empty ( ) {
2610
+ Slice :: empty ( )
2611
+ } else {
2612
+ self . _intern_place_elems ( place_elems)
2613
+ }
2614
+ }
2615
+
2576
2616
pub fn intern_type_list ( self , ts : & [ Ty < ' tcx > ] ) -> & ' tcx Slice < Ty < ' tcx > > {
2577
2617
if ts. len ( ) == 0 {
2578
2618
Slice :: empty ( )
@@ -2635,6 +2675,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2635
2675
iter. intern_with ( |xs| self . intern_existential_predicates ( xs) )
2636
2676
}
2637
2677
2678
+ pub fn mk_place_elems < I : InternAs < [ PlaceElem < ' tcx > ] , & ' tcx Slice < PlaceElem < ' tcx > > > > (
2679
+ self ,
2680
+ iter : I ,
2681
+ ) -> I :: Output {
2682
+ iter. intern_with ( |xs| self . intern_place_elems ( xs) )
2683
+ }
2684
+
2638
2685
pub fn mk_predicates < I : InternAs < [ Predicate < ' tcx > ] ,
2639
2686
& ' tcx Slice < Predicate < ' tcx > > > > ( self , iter : I )
2640
2687
-> I :: Output {
0 commit comments