simplify the interpreter locals, since they always must be backed by an allocation

This commit is contained in:
Oliver Schneider 2016-12-07 09:19:14 +01:00
parent bfe1efcbf8
commit 3065273601
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
2 changed files with 14 additions and 7 deletions

View file

@ -86,7 +86,7 @@ pub struct Frame<'tcx> {
/// This is pure interpreter magic and has nothing to do with how rustc does it
/// An example is calling an FnMut closure that has been converted to a FnOnce closure
/// If they are Value::ByRef, their memory will be freed when the stackframe finishes
pub interpreter_temporaries: Vec<Value>,
pub interpreter_temporaries: Vec<Pointer>,
////////////////////////////////////////////////////////////////////////////////
// Current position within the function
@ -333,7 +333,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
substs: &'tcx Substs<'tcx>,
return_lvalue: Lvalue<'tcx>,
return_to_block: StackPopCleanup,
temporaries: Vec<Value>,
temporaries: Vec<Pointer>,
) -> EvalResult<'tcx, ()> {
::log_settings::settings().indentation += 1;
@ -393,8 +393,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
StackPopCleanup::None => {},
}
// deallocate all locals that are backed by an allocation
for local in frame.locals.into_iter().filter_map(|l| l).chain(frame.interpreter_temporaries) {
if let Value::ByRef(ptr) = local {
for local in frame.locals.into_iter() {
if let Some(Value::ByRef(ptr)) = local {
trace!("deallocating local");
self.memory.dump(ptr.alloc_id);
match self.memory.deallocate(ptr) {
// Any frozen memory means that it belongs to a constant or something referenced
@ -406,6 +407,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
}
}
// deallocate all temporary allocations
for ptr in frame.interpreter_temporaries {
trace!("deallocating temporary allocation");
self.memory.dump(ptr.alloc_id);
self.memory.deallocate(ptr)?;
}
Ok(())
}

View file

@ -432,7 +432,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
def_id: DefId,
substs: &'tcx Substs<'tcx>,
args: &mut Vec<(Value, Ty<'tcx>)>,
) -> EvalResult<'tcx, (DefId, &'tcx Substs<'tcx>, Vec<Value>)> {
) -> EvalResult<'tcx, (DefId, &'tcx Substs<'tcx>, Vec<Pointer>)> {
let trait_ref = ty::TraitRef::from_method(self.tcx, trait_id, substs);
let trait_ref = self.tcx.normalize_associated_type(&ty::Binder(trait_ref));
@ -481,13 +481,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let ptr = self.alloc_ptr(args[0].1)?;
let kind = self.ty_to_primval_kind(args[0].1)?;
self.memory.write_primval(ptr, primval, kind)?;
temporaries.push(Value::ByRef(ptr));
temporaries.push(ptr);
ptr
},
Value::ByValPair(a, b) => {
let ptr = self.alloc_ptr(args[0].1)?;
self.write_pair_to_ptr(a, b, ptr, args[0].1)?;
temporaries.push(Value::ByRef(ptr));
temporaries.push(ptr);
ptr
},
};