Simplify local accessors

This commit is contained in:
Oliver Schneider 2018-03-23 12:44:33 +01:00
parent 4ea4dd23cd
commit f9019aee5b
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 8 additions and 10 deletions

View file

@ -17,6 +17,7 @@ use rustc::mir::interpret::{
GlobalId, Value, Pointer, PrimVal, PrimValKind,
EvalError, EvalResult, EvalErrorKind, MemoryPointer,
};
use std::mem;
use super::{Place, PlaceExtra, Memory,
HasMemory, MemoryKind,
@ -1704,20 +1705,17 @@ impl<'mir, 'tcx> Frame<'mir, 'tcx> {
}
}
pub fn storage_live(&mut self, local: mir::Local) -> EvalResult<'tcx, Option<Value>> {
pub fn storage_live(&mut self, local: mir::Local) -> Option<Value> {
trace!("{:?} is now live", local);
let old = self.locals[local];
self.locals[local] = Some(Value::ByVal(PrimVal::Undef)); // StorageLive *always* kills the value that's currently stored
return Ok(old);
// StorageLive *always* kills the value that's currently stored
mem::replace(&mut self.locals[local], Some(Value::ByVal(PrimVal::Undef)))
}
/// Returns the old value of the local
pub fn storage_dead(&mut self, local: mir::Local) -> EvalResult<'tcx, Option<Value>> {
pub fn storage_dead(&mut self, local: mir::Local) -> Option<Value> {
trace!("{:?} is now dead", local);
let old = self.locals[local];
self.locals[local] = None;
return Ok(old);
self.locals[local].take()
}
}

View file

@ -69,13 +69,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
// Mark locals as alive
StorageLive(local) => {
let old_val = self.frame_mut().storage_live(local)?;
let old_val = self.frame_mut().storage_live(local);
self.deallocate_local(old_val)?;
}
// Mark locals as dead
StorageDead(local) => {
let old_val = self.frame_mut().storage_dead(local)?;
let old_val = self.frame_mut().storage_dead(local);
self.deallocate_local(old_val)?;
}