Skip to content

Commit

Permalink
Simplify local accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 23, 2018
1 parent 4ea4dd2 commit f9019ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}

Expand Down

0 comments on commit f9019ae

Please sign in to comment.