Skip to content

Commit 47e2d82

Browse files
committed
Add intern table for List<ProjectionElem<'tcx, (), ()>>.
Also added alias `ProjectionKind<'tcx>` for `ProjectionElem<'tcx, (), ()>`.
1 parent 92cbe47 commit 47e2d82

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/librustc/mir/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,10 @@ pub type PlaceProjection<'tcx> = Projection<'tcx, Place<'tcx>, Local, Ty<'tcx>>;
19441944
/// and the index is a local.
19451945
pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
19461946

1947+
/// Alias for projections as they appear in `UserTypeProjection`, where we
1948+
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
1949+
pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>;
1950+
19471951
newtype_index! {
19481952
pub struct Field {
19491953
DEBUG_FORMAT = "field[{}]"
@@ -2531,6 +2535,10 @@ pub struct UserTypeProjection<'tcx> {
25312535
pub projs: Vec<ProjectionElem<'tcx, (), ()>>,
25322536
}
25332537

2538+
impl<'tcx> Copy for ProjectionKind<'tcx> { }
2539+
2540+
CloneTypeFoldableAndLiftImpls! { ProjectionKind<'tcx>, }
2541+
25342542
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> {
25352543
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
25362544
use mir::ProjectionElem::*;

src/librustc/ty/context.rs

+20-2
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, ProjectionKind};
3535
use mir::interpret::Allocation;
3636
use ty::subst::{CanonicalUserSubsts, Kind, Substs, Subst};
3737
use ty::ReprOptions;
@@ -132,6 +132,7 @@ pub struct CtxtInterners<'tcx> {
132132
clauses: InternedSet<'tcx, List<Clause<'tcx>>>,
133133
goal: InternedSet<'tcx, GoalKind<'tcx>>,
134134
goal_list: InternedSet<'tcx, List<Goal<'tcx>>>,
135+
projs: InternedSet<'tcx, List<ProjectionKind<'tcx>>>,
135136
}
136137

137138
impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
@@ -149,6 +150,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
149150
clauses: Default::default(),
150151
goal: Default::default(),
151152
goal_list: Default::default(),
153+
projs: Default::default(),
152154
}
153155
}
154156

@@ -2294,6 +2296,13 @@ impl<'tcx: 'lcx, 'lcx> Borrow<[Kind<'lcx>]> for Interned<'tcx, Substs<'tcx>> {
22942296
}
22952297
}
22962298

2299+
impl<'tcx: 'lcx, 'lcx> Borrow<[ProjectionKind<'lcx>]>
2300+
for Interned<'tcx, List<ProjectionKind<'tcx>>> {
2301+
fn borrow<'a>(&'a self) -> &'a [ProjectionKind<'lcx>] {
2302+
&self.0[..]
2303+
}
2304+
}
2305+
22972306
impl<'tcx> Borrow<RegionKind> for Interned<'tcx, RegionKind> {
22982307
fn borrow<'a>(&'a self) -> &'a RegionKind {
22992308
&self.0
@@ -2441,7 +2450,8 @@ slice_interners!(
24412450
type_list: _intern_type_list(Ty),
24422451
substs: _intern_substs(Kind),
24432452
clauses: _intern_clauses(Clause),
2444-
goal_list: _intern_goals(Goal)
2453+
goal_list: _intern_goals(Goal),
2454+
projs: _intern_projs(ProjectionKind)
24452455
);
24462456

24472457
// This isn't a perfect fit: CanonicalVarInfo slices are always
@@ -2743,6 +2753,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27432753
}
27442754
}
27452755

2756+
pub fn intern_projs(self, ps: &[ProjectionKind<'tcx>]) -> &'tcx List<ProjectionKind<'tcx>> {
2757+
if ps.len() == 0 {
2758+
List::empty()
2759+
} else {
2760+
self._intern_projs(ps)
2761+
}
2762+
}
2763+
27462764
pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'gcx> {
27472765
if ts.len() == 0 {
27482766
List::empty()

0 commit comments

Comments
 (0)