Skip to content

Commit 3065273

Browse files
committed
simplify the interpreter locals, since they always must be backed by an allocation
1 parent bfe1efc commit 3065273

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Diff for: src/interpreter/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct Frame<'tcx> {
8686
/// This is pure interpreter magic and has nothing to do with how rustc does it
8787
/// An example is calling an FnMut closure that has been converted to a FnOnce closure
8888
/// If they are Value::ByRef, their memory will be freed when the stackframe finishes
89-
pub interpreter_temporaries: Vec<Value>,
89+
pub interpreter_temporaries: Vec<Pointer>,
9090

9191
////////////////////////////////////////////////////////////////////////////////
9292
// Current position within the function
@@ -333,7 +333,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
333333
substs: &'tcx Substs<'tcx>,
334334
return_lvalue: Lvalue<'tcx>,
335335
return_to_block: StackPopCleanup,
336-
temporaries: Vec<Value>,
336+
temporaries: Vec<Pointer>,
337337
) -> EvalResult<'tcx, ()> {
338338
::log_settings::settings().indentation += 1;
339339

@@ -393,8 +393,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
393393
StackPopCleanup::None => {},
394394
}
395395
// deallocate all locals that are backed by an allocation
396-
for local in frame.locals.into_iter().filter_map(|l| l).chain(frame.interpreter_temporaries) {
397-
if let Value::ByRef(ptr) = local {
396+
for local in frame.locals.into_iter() {
397+
if let Some(Value::ByRef(ptr)) = local {
398+
trace!("deallocating local");
398399
self.memory.dump(ptr.alloc_id);
399400
match self.memory.deallocate(ptr) {
400401
// Any frozen memory means that it belongs to a constant or something referenced
@@ -406,6 +407,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
406407
}
407408
}
408409
}
410+
// deallocate all temporary allocations
411+
for ptr in frame.interpreter_temporaries {
412+
trace!("deallocating temporary allocation");
413+
self.memory.dump(ptr.alloc_id);
414+
self.memory.deallocate(ptr)?;
415+
}
409416
Ok(())
410417
}
411418

Diff for: src/interpreter/terminator/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
432432
def_id: DefId,
433433
substs: &'tcx Substs<'tcx>,
434434
args: &mut Vec<(Value, Ty<'tcx>)>,
435-
) -> EvalResult<'tcx, (DefId, &'tcx Substs<'tcx>, Vec<Value>)> {
435+
) -> EvalResult<'tcx, (DefId, &'tcx Substs<'tcx>, Vec<Pointer>)> {
436436
let trait_ref = ty::TraitRef::from_method(self.tcx, trait_id, substs);
437437
let trait_ref = self.tcx.normalize_associated_type(&ty::Binder(trait_ref));
438438

@@ -481,13 +481,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
481481
let ptr = self.alloc_ptr(args[0].1)?;
482482
let kind = self.ty_to_primval_kind(args[0].1)?;
483483
self.memory.write_primval(ptr, primval, kind)?;
484-
temporaries.push(Value::ByRef(ptr));
484+
temporaries.push(ptr);
485485
ptr
486486
},
487487
Value::ByValPair(a, b) => {
488488
let ptr = self.alloc_ptr(args[0].1)?;
489489
self.write_pair_to_ptr(a, b, ptr, args[0].1)?;
490-
temporaries.push(Value::ByRef(ptr));
490+
temporaries.push(ptr);
491491
ptr
492492
},
493493
};

0 commit comments

Comments
 (0)