Skip to content

Commit 34329c0

Browse files
committed
Intern Place elems
1 parent 357bc2c commit 34329c0

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/librustc/ty/context.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use middle::cstore::EncodedMetadata;
3131
use middle::lang_items;
3232
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
3333
use middle::stability;
34-
use mir::{self, Mir, interpret};
34+
use mir::{self, Mir, interpret, PlaceElem};
3535
use mir::interpret::Allocation;
3636
use ty::subst::{Kind, Substs, Subst};
3737
use ty::ReprOptions;
@@ -140,6 +140,7 @@ pub struct CtxtInterners<'tcx> {
140140
canonical_var_infos: InternedSet<'tcx, Slice<CanonicalVarInfo>>,
141141
region: InternedSet<'tcx, RegionKind>,
142142
existential_predicates: InternedSet<'tcx, Slice<ExistentialPredicate<'tcx>>>,
143+
place_elems: InternedSet<'tcx, Slice<PlaceElem<'tcx>>>,
143144
predicates: InternedSet<'tcx, Slice<Predicate<'tcx>>>,
144145
const_: InternedSet<'tcx, Const<'tcx>>,
145146
clauses: InternedSet<'tcx, Slice<Clause<'tcx>>>,
@@ -156,6 +157,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
156157
region: Default::default(),
157158
existential_predicates: Default::default(),
158159
canonical_var_infos: Default::default(),
160+
place_elems: Default::default(),
159161
predicates: Default::default(),
160162
const_: Default::default(),
161163
clauses: Default::default(),
@@ -1720,6 +1722,27 @@ impl<'a, 'tcx> Lift<'tcx> for &'a Slice<Predicate<'a>> {
17201722
}
17211723
}
17221724

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+
17231746
impl<'a, 'tcx> Lift<'tcx> for &'a Slice<CanonicalVarInfo> {
17241747
type Lifted = &'tcx Slice<CanonicalVarInfo>;
17251748
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>]>
21602183
}
21612184
}
21622185

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+
21632193
impl<'tcx: 'lcx, 'lcx> Borrow<[Predicate<'lcx>]>
21642194
for Interned<'tcx, Slice<Predicate<'tcx>>> {
21652195
fn borrow<'a>(&'a self) -> &'a [Predicate<'lcx>] {
@@ -2284,6 +2314,7 @@ macro_rules! slice_interners {
22842314
slice_interners!(
22852315
existential_predicates: _intern_existential_predicates(ExistentialPredicate),
22862316
predicates: _intern_predicates(Predicate),
2317+
place_elems: _intern_place_elems(PlaceElem),
22872318
type_list: _intern_type_list(Ty),
22882319
substs: _intern_substs(Kind),
22892320
clauses: _intern_clauses(Clause),
@@ -2573,6 +2604,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25732604
}
25742605
}
25752606

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+
25762616
pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx Slice<Ty<'tcx>> {
25772617
if ts.len() == 0 {
25782618
Slice::empty()
@@ -2635,6 +2675,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26352675
iter.intern_with(|xs| self.intern_existential_predicates(xs))
26362676
}
26372677

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+
26382685
pub fn mk_predicates<I: InternAs<[Predicate<'tcx>],
26392686
&'tcx Slice<Predicate<'tcx>>>>(self, iter: I)
26402687
-> I::Output {

0 commit comments

Comments
 (0)