diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2019-12-11 16:50:03 -0300 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-01-10 09:08:25 +0100 |
| commit | 5d9b39904436f6f20e34e85a4e06384116080f56 (patch) | |
| tree | 4b1a69935dc518c2d39919ea4e7360e2687313f1 /src/librustc/mir | |
| parent | fd5aa32c352d9aa7e652a64320f89b7f3859858b (diff) | |
| download | rust-5d9b39904436f6f20e34e85a4e06384116080f56.tar.gz rust-5d9b39904436f6f20e34e85a4e06384116080f56.zip | |
Remove PlaceBase enum and make Place base field be local: Local
Diffstat (limited to 'src/librustc/mir')
| -rw-r--r-- | src/librustc/mir/mod.rs | 64 | ||||
| -rw-r--r-- | src/librustc/mir/tcx.rs | 19 | ||||
| -rw-r--r-- | src/librustc/mir/visit.rs | 32 |
3 files changed, 32 insertions, 83 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 05bb1d96980..32d85314c7a 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1655,7 +1655,7 @@ impl Debug for Statement<'_> { /// changing or disturbing program state. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, HashStable)] pub struct Place<'tcx> { - pub base: PlaceBase, + pub local: Local, /// projection out of a place (access a field, deref a pointer, etc) pub projection: &'tcx List<PlaceElem<'tcx>>, @@ -1663,12 +1663,6 @@ pub struct Place<'tcx> { impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {} -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable)] -pub enum PlaceBase { - /// local variable - Local(Local), -} - #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(RustcEncodable, RustcDecodable, HashStable)] pub enum ProjectionElem<V, T> { @@ -1756,14 +1750,14 @@ rustc_index::newtype_index! { #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct PlaceRef<'a, 'tcx> { - pub base: &'a PlaceBase, + pub local: &'a Local, pub projection: &'a [PlaceElem<'tcx>], } impl<'tcx> Place<'tcx> { // FIXME change this to a const fn by also making List::empty a const fn. pub fn return_place() -> Place<'tcx> { - Place { base: PlaceBase::Local(RETURN_PLACE), projection: List::empty() } + Place { local: RETURN_PLACE, projection: List::empty() } } /// Returns `true` if this `Place` contains a `Deref` projection. @@ -1780,10 +1774,8 @@ impl<'tcx> Place<'tcx> { // FIXME: can we safely swap the semantics of `fn base_local` below in here instead? pub fn local_or_deref_local(&self) -> Option<Local> { match self.as_ref() { - PlaceRef { base: &PlaceBase::Local(local), projection: &[] } - | PlaceRef { base: &PlaceBase::Local(local), projection: &[ProjectionElem::Deref] } => { - Some(local) - } + PlaceRef { local, projection: &[] } + | PlaceRef { local, projection: &[ProjectionElem::Deref] } => Some(*local), _ => None, } } @@ -1795,19 +1787,13 @@ impl<'tcx> Place<'tcx> { } pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> { - PlaceRef { base: &self.base, projection: &self.projection } + PlaceRef { local: &self.local, projection: &self.projection } } } impl From<Local> for Place<'_> { fn from(local: Local) -> Self { - Place { base: local.into(), projection: List::empty() } - } -} - -impl From<Local> for PlaceBase { - fn from(local: Local) -> Self { - PlaceBase::Local(local) + Place { local: local.into(), projection: List::empty() } } } @@ -1818,10 +1804,8 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> { // FIXME: can we safely swap the semantics of `fn base_local` below in here instead? pub fn local_or_deref_local(&self) -> Option<Local> { match self { - PlaceRef { base: PlaceBase::Local(local), projection: [] } - | PlaceRef { base: PlaceBase::Local(local), projection: [ProjectionElem::Deref] } => { - Some(*local) - } + PlaceRef { local, projection: [] } + | PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(**local), _ => None, } } @@ -1830,7 +1814,7 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> { /// projections, return `Some(_X)`. pub fn as_local(&self) -> Option<Local> { match self { - PlaceRef { base: PlaceBase::Local(l), projection: [] } => Some(*l), + PlaceRef { local, projection: [] } => Some(**local), _ => None, } } @@ -1852,7 +1836,7 @@ impl Debug for Place<'_> { } } - write!(fmt, "{:?}", self.base)?; + write!(fmt, "{:?}", self.local)?; for elem in self.projection.iter() { match elem { @@ -1896,14 +1880,6 @@ impl Debug for Place<'_> { } } -impl Debug for PlaceBase { - fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { - match *self { - PlaceBase::Local(id) => write!(fmt, "{:?}", id), - } - } -} - /////////////////////////////////////////////////////////////////////////// // Scopes @@ -2964,25 +2940,11 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind { impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> { fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { - Place { base: self.base.fold_with(folder), projection: self.projection.fold_with(folder) } + Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) } } fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { - self.base.visit_with(visitor) || self.projection.visit_with(visitor) - } -} - -impl<'tcx> TypeFoldable<'tcx> for PlaceBase { - fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { - match self { - PlaceBase::Local(local) => PlaceBase::Local(local.fold_with(folder)), - } - } - - fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { - match self { - PlaceBase::Local(local) => local.visit_with(visitor), - } + self.local.visit_with(visitor) || self.projection.visit_with(visitor) } } diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 5adf6447d39..e2aac562cc4 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -114,7 +114,7 @@ impl<'tcx> PlaceTy<'tcx> { impl<'tcx> Place<'tcx> { pub fn ty_from<D>( - base: &PlaceBase, + local: &Local, projection: &[PlaceElem<'tcx>], local_decls: &D, tcx: TyCtxt<'tcx>, @@ -124,25 +124,16 @@ impl<'tcx> Place<'tcx> { { projection .iter() - .fold(base.ty(local_decls), |place_ty, elem| place_ty.projection_ty(tcx, elem)) + .fold(PlaceTy::from_ty(local_decls.local_decls()[*local].ty), |place_ty, elem| { + place_ty.projection_ty(tcx, elem) + }) } pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> where D: HasLocalDecls<'tcx>, { - Place::ty_from(&self.base, &self.projection, local_decls, tcx) - } -} - -impl<'tcx> PlaceBase { - pub fn ty<D>(&self, local_decls: &D) -> PlaceTy<'tcx> - where - D: HasLocalDecls<'tcx>, - { - match self { - PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty), - } + Place::ty_from(&self.local, &self.projection, local_decls, tcx) } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index a31931c8a99..4c5db1b07d2 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -164,10 +164,10 @@ macro_rules! make_mir_visitor { } fn visit_place_base(&mut self, - base: & $($mutability)? PlaceBase, + local: & $($mutability)? Local, context: PlaceContext, location: Location) { - self.super_place_base(base, context, location); + self.super_place_base(local, context, location); } visit_place_fns!($($mutability)?); @@ -705,14 +705,10 @@ macro_rules! make_mir_visitor { } fn super_place_base(&mut self, - place_base: & $($mutability)? PlaceBase, + local: & $($mutability)? Local, context: PlaceContext, location: Location) { - match place_base { - PlaceBase::Local(local) => { - self.visit_local(local, context, location); - } - } + self.visit_local(local, context, location); } fn super_local_decl(&mut self, @@ -845,7 +841,7 @@ macro_rules! visit_place_fns { context: PlaceContext, location: Location, ) { - self.visit_place_base(&mut place.base, context, location); + self.visit_place_base(&mut place.local, context, location); if let Some(new_projection) = self.process_projection(&place.projection) { place.projection = self.tcx().intern_place_elems(&new_projection); @@ -886,23 +882,23 @@ macro_rules! visit_place_fns { () => ( fn visit_projection( &mut self, - base: &PlaceBase, + local: &Local, projection: &[PlaceElem<'tcx>], context: PlaceContext, location: Location, ) { - self.super_projection(base, projection, context, location); + self.super_projection(local, projection, context, location); } fn visit_projection_elem( &mut self, - base: &PlaceBase, + local: &Local, proj_base: &[PlaceElem<'tcx>], elem: &PlaceElem<'tcx>, context: PlaceContext, location: Location, ) { - self.super_projection_elem(base, proj_base, elem, context, location); + self.super_projection_elem(local, proj_base, elem, context, location); } fn super_place( @@ -921,9 +917,9 @@ macro_rules! visit_place_fns { }; } - self.visit_place_base(&place.base, context, location); + self.visit_place_base(&place.local, context, location); - self.visit_projection(&place.base, + self.visit_projection(&place.local, &place.projection, context, location); @@ -931,7 +927,7 @@ macro_rules! visit_place_fns { fn super_projection( &mut self, - base: &PlaceBase, + local: &Local, projection: &[PlaceElem<'tcx>], context: PlaceContext, location: Location, @@ -939,13 +935,13 @@ macro_rules! visit_place_fns { let mut cursor = projection; while let [proj_base @ .., elem] = cursor { cursor = proj_base; - self.visit_projection_elem(base, cursor, elem, context, location); + self.visit_projection_elem(local, cursor, elem, context, location); } } fn super_projection_elem( &mut self, - _base: &PlaceBase, + _local: &Local, _proj_base: &[PlaceElem<'tcx>], elem: &PlaceElem<'tcx>, _context: PlaceContext, |
