From: Felix S. Klock II Date: Fri, 26 Oct 2018 09:28:40 +0000 (+0200) Subject: Add intern table for `List>`. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=47e2d825e1615813d9b5b3b97e20cfe169f5097f;p=rust.git Add intern table for `List>`. Also added alias `ProjectionKind<'tcx>` for `ProjectionElem<'tcx, (), ()>`. --- diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 142dc40e5b1..952783a91b2 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1944,6 +1944,10 @@ pub enum ProjectionElem<'tcx, V, T> { /// and the index is a local. pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>; +/// Alias for projections as they appear in `UserTypeProjection`, where we +/// need neither the `V` parameter for `Index` nor the `T` for `Field`. +pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>; + newtype_index! { pub struct Field { DEBUG_FORMAT = "field[{}]" @@ -2531,6 +2535,10 @@ pub struct UserTypeProjection<'tcx> { pub projs: Vec>, } +impl<'tcx> Copy for ProjectionKind<'tcx> { } + +CloneTypeFoldableAndLiftImpls! { ProjectionKind<'tcx>, } + impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { use mir::ProjectionElem::*; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1686e3e0e0c..1e3b372c029 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -31,7 +31,7 @@ use middle::lang_items; use middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use middle::stability; -use mir::{self, Mir, interpret}; +use mir::{self, Mir, interpret, ProjectionKind}; use mir::interpret::Allocation; use ty::subst::{CanonicalUserSubsts, Kind, Substs, Subst}; use ty::ReprOptions; @@ -132,6 +132,7 @@ pub struct CtxtInterners<'tcx> { clauses: InternedSet<'tcx, List>>, goal: InternedSet<'tcx, GoalKind<'tcx>>, goal_list: InternedSet<'tcx, List>>, + projs: InternedSet<'tcx, List>>, } impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> { @@ -149,6 +150,7 @@ fn new(arena: &'tcx SyncDroplessArena) -> CtxtInterners<'tcx> { clauses: Default::default(), goal: Default::default(), goal_list: Default::default(), + projs: Default::default(), } } @@ -2294,6 +2296,13 @@ fn borrow<'a>(&'a self) -> &'a [Kind<'lcx>] { } } +impl<'tcx: 'lcx, 'lcx> Borrow<[ProjectionKind<'lcx>]> + for Interned<'tcx, List>> { + fn borrow<'a>(&'a self) -> &'a [ProjectionKind<'lcx>] { + &self.0[..] + } +} + impl<'tcx> Borrow for Interned<'tcx, RegionKind> { fn borrow<'a>(&'a self) -> &'a RegionKind { &self.0 @@ -2441,7 +2450,8 @@ macro_rules! slice_interners { type_list: _intern_type_list(Ty), substs: _intern_substs(Kind), clauses: _intern_clauses(Clause), - goal_list: _intern_goals(Goal) + goal_list: _intern_goals(Goal), + projs: _intern_projs(ProjectionKind) ); // This isn't a perfect fit: CanonicalVarInfo slices are always @@ -2743,6 +2753,14 @@ pub fn intern_substs(self, ts: &[Kind<'tcx>]) -> &'tcx List> { } } + pub fn intern_projs(self, ps: &[ProjectionKind<'tcx>]) -> &'tcx List> { + if ps.len() == 0 { + List::empty() + } else { + self._intern_projs(ps) + } + } + pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'gcx> { if ts.len() == 0 { List::empty()