From 3065273601f2fe7865ffaebbdf750c41f545399c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 7 Dec 2016 09:19:14 +0100 Subject: [PATCH] simplify the interpreter locals, since they always must be backed by an allocation --- src/interpreter/mod.rs | 15 +++++++++++---- src/interpreter/terminator/mod.rs | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index f5da33d4b378..a8ccfae3dc7b 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -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, + pub interpreter_temporaries: Vec, //////////////////////////////////////////////////////////////////////////////// // 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, + temporaries: Vec, ) -> 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(()) } diff --git a/src/interpreter/terminator/mod.rs b/src/interpreter/terminator/mod.rs index 8c7d06af4190..837c70111252 100644 --- a/src/interpreter/terminator/mod.rs +++ b/src/interpreter/terminator/mod.rs @@ -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)> { + ) -> EvalResult<'tcx, (DefId, &'tcx Substs<'tcx>, Vec)> { 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 }, };