Swap the names of LocalValue
and LocalState
This commit is contained in:
parent
a7a5cb620f
commit
765fa81a6e
4 changed files with 33 additions and 33 deletions
|
@ -14,7 +14,7 @@ pub struct RawConst<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a constant value in Rust. Scalar and ScalarPair are optimizations which
|
/// 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)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)]
|
||||||
pub enum ConstValue<'tcx> {
|
pub enum ConstValue<'tcx> {
|
||||||
/// Used only for types with layout::abi::Scalar ABI and ZSTs
|
/// Used only for types with layout::abi::Scalar ABI and ZSTs
|
||||||
|
|
|
@ -76,7 +76,7 @@ pub struct Frame<'mir, 'tcx: 'mir, Tag=(), Extra=()> {
|
||||||
/// The locals are stored as `Option<Value>`s.
|
/// The locals are stored as `Option<Value>`s.
|
||||||
/// `None` represents a local that is currently dead, while a live local
|
/// `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`.
|
/// can either directly contain `Scalar` or refer to some part of an `Allocation`.
|
||||||
pub locals: IndexVec<mir::Local, LocalValue<'tcx, Tag>>,
|
pub locals: IndexVec<mir::Local, LocalState<'tcx, Tag>>,
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Current position within the function
|
// Current position within the function
|
||||||
|
@ -107,15 +107,15 @@ pub enum StackPopCleanup {
|
||||||
|
|
||||||
/// State of a local variable including a memoized layout
|
/// State of a local variable including a memoized layout
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct LocalValue<'tcx, Tag=(), Id=AllocId> {
|
pub struct LocalState<'tcx, Tag=(), Id=AllocId> {
|
||||||
pub state: LocalState<Tag, Id>,
|
pub state: LocalValue<Tag, Id>,
|
||||||
/// Don't modify if `Some`, this is only used to prevent computing the layout twice
|
/// Don't modify if `Some`, this is only used to prevent computing the layout twice
|
||||||
pub layout: Cell<Option<TyLayout<'tcx>>>,
|
pub layout: Cell<Option<TyLayout<'tcx>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// State of a local variable
|
/// State of a local variable
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum LocalState<Tag=(), Id=AllocId> {
|
pub enum LocalValue<Tag=(), Id=AllocId> {
|
||||||
Dead,
|
Dead,
|
||||||
// Mostly for convenience, we re-use the `Operand` type here.
|
// Mostly for convenience, we re-use the `Operand` type here.
|
||||||
// This is an optimization over just always having a pointer here;
|
// This is an optimization over just always having a pointer here;
|
||||||
|
@ -124,18 +124,18 @@ pub enum LocalState<Tag=(), Id=AllocId> {
|
||||||
Live(Operand<Tag, Id>),
|
Live(Operand<Tag, Id>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, Tag> LocalValue<'tcx, Tag> {
|
impl<'tcx, Tag> LocalState<'tcx, Tag> {
|
||||||
pub fn access(&self) -> EvalResult<'tcx, &Operand<Tag>> {
|
pub fn access(&self) -> EvalResult<'tcx, &Operand<Tag>> {
|
||||||
match self.state {
|
match self.state {
|
||||||
LocalState::Dead => err!(DeadLocal),
|
LocalValue::Dead => err!(DeadLocal),
|
||||||
LocalState::Live(ref val) => Ok(val),
|
LocalValue::Live(ref val) => Ok(val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn access_mut(&mut self) -> EvalResult<'tcx, &mut Operand<Tag>> {
|
pub fn access_mut(&mut self) -> EvalResult<'tcx, &mut Operand<Tag>> {
|
||||||
match self.state {
|
match self.state {
|
||||||
LocalState::Dead => err!(DeadLocal),
|
LocalValue::Dead => err!(DeadLocal),
|
||||||
LocalState::Live(ref mut val) => Ok(val),
|
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
|
// don't allocate at all for trivial constants
|
||||||
if mir.local_decls.len() > 1 {
|
if mir.local_decls.len() > 1 {
|
||||||
// We put some marker immediate into the locals that we later want to initialize.
|
// 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.
|
// value we use for things that we know are initially dead.
|
||||||
let dummy = LocalValue {
|
let dummy = LocalState {
|
||||||
state: LocalState::Live(Operand::Immediate(Immediate::Scalar(
|
state: LocalValue::Live(Operand::Immediate(Immediate::Scalar(
|
||||||
ScalarMaybeUndef::Undef,
|
ScalarMaybeUndef::Undef,
|
||||||
))),
|
))),
|
||||||
layout: Cell::new(None),
|
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);
|
let mut locals = IndexVec::from_elem(dummy, &mir.local_decls);
|
||||||
// Return place is handled specially by the `eval_place` functions, and the
|
// 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.
|
// 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
|
// Now mark those locals as dead that we do not want to initialize
|
||||||
match self.tcx.describe_def(instance.def_id()) {
|
match self.tcx.describe_def(instance.def_id()) {
|
||||||
// statics and constants don't have `Storage*` statements, no need to look for them
|
// 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 {
|
match stmt.kind {
|
||||||
StorageLive(local) |
|
StorageLive(local) |
|
||||||
StorageDead(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
|
// Finally, properly initialize all those that still have the dummy value
|
||||||
for (idx, local) in locals.iter_enumerated_mut() {
|
for (idx, local) in locals.iter_enumerated_mut() {
|
||||||
match local.state {
|
match local.state {
|
||||||
LocalState::Live(_) => {
|
LocalValue::Live(_) => {
|
||||||
// This needs to be properly initialized.
|
// This needs to be properly initialized.
|
||||||
let ty = self.monomorphize(mir.local_decls[idx].ty)?;
|
let ty = self.monomorphize(mir.local_decls[idx].ty)?;
|
||||||
let layout = self.layout_of(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));
|
local.layout = Cell::new(Some(layout));
|
||||||
}
|
}
|
||||||
LocalState::Dead => {
|
LocalValue::Dead => {
|
||||||
// Nothing to do
|
// 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(
|
pub fn storage_live(
|
||||||
&mut self,
|
&mut self,
|
||||||
local: mir::Local
|
local: mir::Local
|
||||||
) -> EvalResult<'tcx, LocalState<M::PointerTag>> {
|
) -> EvalResult<'tcx, LocalValue<M::PointerTag>> {
|
||||||
assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
|
assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
|
||||||
trace!("{:?} is now live", local);
|
trace!("{:?} is now live", local);
|
||||||
|
|
||||||
let layout = self.layout_of_local(self.frame(), local, None)?;
|
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
|
// StorageLive *always* kills the value that's currently stored
|
||||||
Ok(mem::replace(&mut self.frame_mut().locals[local].state, init))
|
Ok(mem::replace(&mut self.frame_mut().locals[local].state, init))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the old value of the local.
|
/// Returns the old value of the local.
|
||||||
/// Remember to deallocate that!
|
/// Remember to deallocate that!
|
||||||
pub fn storage_dead(&mut self, local: mir::Local) -> LocalState<M::PointerTag> {
|
pub fn storage_dead(&mut self, local: mir::Local) -> LocalValue<M::PointerTag> {
|
||||||
assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
|
assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
|
||||||
trace!("{:?} is now dead", local);
|
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(
|
pub(super) fn deallocate_local(
|
||||||
&mut self,
|
&mut self,
|
||||||
local: LocalState<M::PointerTag>,
|
local: LocalValue<M::PointerTag>,
|
||||||
) -> EvalResult<'tcx> {
|
) -> EvalResult<'tcx> {
|
||||||
// FIXME: should we tell the user that there was a local which was never written to?
|
// 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");
|
trace!("deallocating local");
|
||||||
let ptr = ptr.to_ptr()?;
|
let ptr = ptr.to_ptr()?;
|
||||||
self.memory.dump_alloc(ptr.alloc_id);
|
self.memory.dump_alloc(ptr.alloc_id);
|
||||||
|
|
|
@ -18,7 +18,7 @@ mod visitor;
|
||||||
pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here
|
pub use rustc::mir::interpret::*; // have all the `interpret` symbols in one place: here
|
||||||
|
|
||||||
pub use self::eval_context::{
|
pub use self::eval_context::{
|
||||||
EvalContext, Frame, StackPopCleanup, LocalValue, LocalState,
|
EvalContext, Frame, StackPopCleanup, LocalState, LocalValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::place::{Place, PlaceTy, MemPlace, MPlaceTy};
|
pub use self::place::{Place, PlaceTy, MemPlace, MPlaceTy};
|
||||||
|
|
|
@ -23,8 +23,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use syntax::ast::Mutability;
|
use syntax::ast::Mutability;
|
||||||
use syntax::source_map::Span;
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
use super::eval_context::{LocalValue, StackPopCleanup};
|
use super::eval_context::{LocalState, StackPopCleanup};
|
||||||
use super::{Frame, Memory, Operand, MemPlace, Place, Immediate, ScalarMaybeUndef, LocalState};
|
use super::{Frame, Memory, Operand, MemPlace, Place, Immediate, ScalarMaybeUndef, LocalValue};
|
||||||
use const_eval::CompileTimeInterpreter;
|
use const_eval::CompileTimeInterpreter;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -250,11 +250,11 @@ impl_snapshot_for!(enum Operand {
|
||||||
Indirect(m),
|
Indirect(m),
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_stable_hash_for!(enum ::interpret::LocalState {
|
impl_stable_hash_for!(enum ::interpret::LocalValue {
|
||||||
Dead,
|
Dead,
|
||||||
Live(x),
|
Live(x),
|
||||||
});
|
});
|
||||||
impl_snapshot_for!(enum LocalState {
|
impl_snapshot_for!(enum LocalValue {
|
||||||
Live(v),
|
Live(v),
|
||||||
Dead,
|
Dead,
|
||||||
});
|
});
|
||||||
|
@ -309,7 +309,7 @@ struct FrameSnapshot<'a, 'tcx: 'a> {
|
||||||
span: &'a Span,
|
span: &'a Span,
|
||||||
return_to_block: &'a StackPopCleanup,
|
return_to_block: &'a StackPopCleanup,
|
||||||
return_place: Option<Place<(), AllocIdSnapshot<'a>>>,
|
return_place: Option<Place<(), AllocIdSnapshot<'a>>>,
|
||||||
locals: IndexVec<mir::Local, LocalState<(), AllocIdSnapshot<'a>>>,
|
locals: IndexVec<mir::Local, LocalValue<(), AllocIdSnapshot<'a>>>,
|
||||||
block: &'a mir::BasicBlock,
|
block: &'a mir::BasicBlock,
|
||||||
stmt: usize,
|
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>,
|
where Ctx: SnapshotContext<'a>,
|
||||||
{
|
{
|
||||||
type Item = LocalState<(), AllocIdSnapshot<'a>>;
|
type Item = LocalValue<(), AllocIdSnapshot<'a>>;
|
||||||
|
|
||||||
fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
|
fn snapshot(&self, ctx: &'a Ctx) -> Self::Item {
|
||||||
self.state.snapshot(ctx)
|
self.state.snapshot(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_stable_hash_for!(struct LocalValue<'tcx> {
|
impl_stable_hash_for!(struct LocalState<'tcx> {
|
||||||
state,
|
state,
|
||||||
layout -> _,
|
layout -> _,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue