Explorer: fix class destructor not called with heap.Delete (#2546)

This change ensures that DestroyAction is executed for the value being deallocated when calling heap.Delete.

Relates to #2521
This commit is contained in:
Adrien Leravat
2023-01-24 11:34:47 -05:00
committed by GitHub
parent 82f7d06855
commit b4e3a3e6cc
3 changed files with 92 additions and 2 deletions
+12 -2
View File
@@ -1454,8 +1454,18 @@ auto Interpreter::StepExp() -> ErrorOr<Success> {
}
case IntrinsicExpression::Intrinsic::Dealloc: {
CARBON_CHECK(args.size() == 1);
heap_.Deallocate(cast<PointerValue>(args[0])->address());
return todo_.FinishAction(TupleValue::Empty());
CARBON_CHECK(act.pos() > 0);
const auto* ptr = cast<PointerValue>(args[0]);
if (act.pos() == 1) {
CARBON_ASSIGN_OR_RETURN(
const auto* pointee,
this->heap_.Read(ptr->address(), exp.source_loc()));
return todo_.Spawn(std::make_unique<DestroyAction>(
arena_->New<LValue>(ptr->address()), pointee));
} else {
heap_.Deallocate(ptr->address());
return todo_.FinishAction(TupleValue::Empty());
}
}
case IntrinsicExpression::Intrinsic::Rand: {
CARBON_CHECK(args.size() == 2);