From 765fa81a6e8d063db60be20e710e51d8ca995fbd Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 30 Jan 2019 17:51:59 +0100 Subject: [PATCH] Swap the names of `LocalValue` and `LocalState` --- src/librustc/mir/interpret/value.rs | 2 +- src/librustc_mir/interpret/eval_context.rs | 46 +++++++++++----------- src/librustc_mir/interpret/mod.rs | 2 +- src/librustc_mir/interpret/snapshot.rs | 16 ++++---- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 4ac84bcfd1903..1328a1aeeab96 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -14,7 +14,7 @@ pub struct RawConst<'tcx> { } /// Represents a constant value in Rust. Scalar and ScalarPair are optimizations which -/// matches the LocalValue optimizations for easy conversions between Value and ConstValue. +/// matches the LocalState optimizations for easy conversions between Value and ConstValue. #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)] pub enum ConstValue<'tcx> { /// Used only for types with layout::abi::Scalar ABI and ZSTs diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 4e66d21214b29..1b976d822ebff 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -76,7 +76,7 @@ pub struct Frame<'mir, 'tcx: 'mir, Tag=(), Extra=()> { /// The locals are stored as `Option`s. /// `None` represents a local that is currently dead, while a live local /// can either directly contain `Scalar` or refer to some part of an `Allocation`. - pub locals: IndexVec>, + pub locals: IndexVec>, //////////////////////////////////////////////////////////////////////////////// // Current position within the function @@ -107,15 +107,15 @@ pub enum StackPopCleanup { /// State of a local variable including a memoized layout #[derive(Clone, PartialEq, Eq)] -pub struct LocalValue<'tcx, Tag=(), Id=AllocId> { - pub state: LocalState, +pub struct LocalState<'tcx, Tag=(), Id=AllocId> { + pub state: LocalValue, /// Don't modify if `Some`, this is only used to prevent computing the layout twice pub layout: Cell>>, } /// State of a local variable #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub enum LocalState { +pub enum LocalValue { Dead, // Mostly for convenience, we re-use the `Operand` type here. // This is an optimization over just always having a pointer here; @@ -124,18 +124,18 @@ pub enum LocalState { Live(Operand), } -impl<'tcx, Tag> LocalValue<'tcx, Tag> { +impl<'tcx, Tag> LocalState<'tcx, Tag> { pub fn access(&self) -> EvalResult<'tcx, &Operand> { match self.state { - LocalState::Dead => err!(DeadLocal), - LocalState::Live(ref val) => Ok(val), + LocalValue::Dead => err!(DeadLocal), + LocalValue::Live(ref val) => Ok(val), } } pub fn access_mut(&mut self) -> EvalResult<'tcx, &mut Operand> { match self.state { - LocalState::Dead => err!(DeadLocal), - LocalState::Live(ref mut val) => Ok(val), + LocalValue::Dead => err!(DeadLocal), + LocalValue::Live(ref mut val) => Ok(val), } } } @@ -474,10 +474,10 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc // don't allocate at all for trivial constants if mir.local_decls.len() > 1 { // We put some marker immediate into the locals that we later want to initialize. - // This can be anything except for LocalState::Dead -- because *that* is the + // This can be anything except for LocalValue::Dead -- because *that* is the // value we use for things that we know are initially dead. - let dummy = LocalValue { - state: LocalState::Live(Operand::Immediate(Immediate::Scalar( + let dummy = LocalState { + state: LocalValue::Live(Operand::Immediate(Immediate::Scalar( ScalarMaybeUndef::Undef, ))), layout: Cell::new(None), @@ -485,7 +485,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc let mut locals = IndexVec::from_elem(dummy, &mir.local_decls); // Return place is handled specially by the `eval_place` functions, and the // entry in `locals` should never be used. Make it dead, to be sure. - locals[mir::RETURN_PLACE].state = LocalState::Dead; + locals[mir::RETURN_PLACE].state = LocalValue::Dead; // Now mark those locals as dead that we do not want to initialize match self.tcx.describe_def(instance.def_id()) { // statics and constants don't have `Storage*` statements, no need to look for them @@ -498,7 +498,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc match stmt.kind { StorageLive(local) | StorageDead(local) => { - locals[local].state = LocalState::Dead; + locals[local].state = LocalValue::Dead; } _ => {} } @@ -509,14 +509,14 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc // Finally, properly initialize all those that still have the dummy value for (idx, local) in locals.iter_enumerated_mut() { match local.state { - LocalState::Live(_) => { + LocalValue::Live(_) => { // This needs to be properly initialized. let ty = self.monomorphize(mir.local_decls[idx].ty)?; let layout = self.layout_of(ty)?; - local.state = LocalState::Live(self.uninit_operand(layout)?); + local.state = LocalValue::Live(self.uninit_operand(layout)?); local.layout = Cell::new(Some(layout)); } - LocalState::Dead => { + LocalValue::Dead => { // Nothing to do } } @@ -603,31 +603,31 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc pub fn storage_live( &mut self, local: mir::Local - ) -> EvalResult<'tcx, LocalState> { + ) -> EvalResult<'tcx, LocalValue> { assert!(local != mir::RETURN_PLACE, "Cannot make return place live"); trace!("{:?} is now live", local); let layout = self.layout_of_local(self.frame(), local, None)?; - let init = LocalState::Live(self.uninit_operand(layout)?); + let init = LocalValue::Live(self.uninit_operand(layout)?); // StorageLive *always* kills the value that's currently stored Ok(mem::replace(&mut self.frame_mut().locals[local].state, init)) } /// Returns the old value of the local. /// Remember to deallocate that! - pub fn storage_dead(&mut self, local: mir::Local) -> LocalState { + pub fn storage_dead(&mut self, local: mir::Local) -> LocalValue { assert!(local != mir::RETURN_PLACE, "Cannot make return place dead"); trace!("{:?} is now dead", local); - mem::replace(&mut self.frame_mut().locals[local].state, LocalState::Dead) + mem::replace(&mut self.frame_mut().locals[local].state, LocalValue::Dead) } pub(super) fn deallocate_local( &mut self, - local: LocalState, + local: LocalValue, ) -> EvalResult<'tcx> { // FIXME: should we tell the user that there was a local which was never written to? - if let LocalState::Live(Operand::Indirect(MemPlace { ptr, .. })) = local { + if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local { trace!("deallocating local"); let ptr = ptr.to_ptr()?; self.memory.dump_alloc(ptr.alloc_id); diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index 6ee7d3309f464..d2ab3fcb7a30a 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -18,7 +18,7 @@ mod visitor; pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here pub use self::eval_context::{ - EvalContext, Frame, StackPopCleanup, LocalValue, LocalState, + EvalContext, Frame, StackPopCleanup, LocalState, LocalValue, }; pub use self::place::{Place, PlaceTy, MemPlace, MPlaceTy}; diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index c9fe673c847d1..c4b56f571db9c 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -23,8 +23,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use syntax::ast::Mutability; use syntax::source_map::Span; -use super::eval_context::{LocalValue, StackPopCleanup}; -use super::{Frame, Memory, Operand, MemPlace, Place, Immediate, ScalarMaybeUndef, LocalState}; +use super::eval_context::{LocalState, StackPopCleanup}; +use super::{Frame, Memory, Operand, MemPlace, Place, Immediate, ScalarMaybeUndef, LocalValue}; use const_eval::CompileTimeInterpreter; #[derive(Default)] @@ -250,11 +250,11 @@ impl_snapshot_for!(enum Operand { Indirect(m), }); -impl_stable_hash_for!(enum ::interpret::LocalState { +impl_stable_hash_for!(enum ::interpret::LocalValue { Dead, Live(x), }); -impl_snapshot_for!(enum LocalState { +impl_snapshot_for!(enum LocalValue { Live(v), Dead, }); @@ -309,7 +309,7 @@ struct FrameSnapshot<'a, 'tcx: 'a> { span: &'a Span, return_to_block: &'a StackPopCleanup, return_place: Option>>, - locals: IndexVec>>, + locals: IndexVec>>, block: &'a mir::BasicBlock, stmt: usize, } @@ -356,17 +356,17 @@ impl<'a, 'mir, 'tcx, Ctx> Snapshot<'a, Ctx> for &'a Frame<'mir, 'tcx> } } -impl<'a, 'tcx, Ctx> Snapshot<'a, Ctx> for &'a LocalValue<'tcx> +impl<'a, 'tcx, Ctx> Snapshot<'a, Ctx> for &'a LocalState<'tcx> where Ctx: SnapshotContext<'a>, { - type Item = LocalState<(), AllocIdSnapshot<'a>>; + type Item = LocalValue<(), AllocIdSnapshot<'a>>; fn snapshot(&self, ctx: &'a Ctx) -> Self::Item { self.state.snapshot(ctx) } } -impl_stable_hash_for!(struct LocalValue<'tcx> { +impl_stable_hash_for!(struct LocalState<'tcx> { state, layout -> _, });