mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Stop allocating Actions on the Arena (#934)
This enables us to manage local variables in Carbon using C++ RAII. Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
cabba3e93e
commit
a4aff26821
@@ -244,13 +244,7 @@ void Value::Print(llvm::raw_ostream& out) const {
|
||||
out << cast<VariableType>(*this).name();
|
||||
break;
|
||||
case Value::Kind::ContinuationValue: {
|
||||
out << "{";
|
||||
llvm::ListSeparator sep(" :: ");
|
||||
for (Nonnull<const Action*> action :
|
||||
cast<ContinuationValue>(*this).stack()) {
|
||||
out << sep << *action;
|
||||
}
|
||||
out << "}";
|
||||
out << cast<ContinuationValue>(*this).stack();
|
||||
break;
|
||||
}
|
||||
case Value::Kind::StringType:
|
||||
@@ -264,6 +258,43 @@ void Value::Print(llvm::raw_ostream& out) const {
|
||||
}
|
||||
}
|
||||
|
||||
ContinuationValue::StackFragment::~StackFragment() {
|
||||
CHECK(reversed_todo_.empty())
|
||||
<< "All StackFragments must be empty before the Carbon program ends.";
|
||||
}
|
||||
|
||||
void ContinuationValue::StackFragment::StoreReversed(
|
||||
std::vector<std::unique_ptr<Action>> reversed_todo) {
|
||||
CHECK(reversed_todo_.empty());
|
||||
reversed_todo_ = std::move(reversed_todo);
|
||||
}
|
||||
|
||||
void ContinuationValue::StackFragment::RestoreTo(
|
||||
Stack<std::unique_ptr<Action>>& todo) {
|
||||
while (!reversed_todo_.empty()) {
|
||||
todo.Push(std::move(reversed_todo_.back()));
|
||||
reversed_todo_.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void ContinuationValue::StackFragment::Clear() {
|
||||
// We destroy the underlying Actions explicitly to ensure they're
|
||||
// destroyed in the correct order.
|
||||
for (auto& action : reversed_todo_) {
|
||||
action.reset();
|
||||
}
|
||||
reversed_todo_.clear();
|
||||
}
|
||||
|
||||
void ContinuationValue::StackFragment::Print(llvm::raw_ostream& out) const {
|
||||
out << "{";
|
||||
llvm::ListSeparator sep(" :: ");
|
||||
for (const std::unique_ptr<Action>& action : reversed_todo_) {
|
||||
out << sep << *action;
|
||||
}
|
||||
out << "}";
|
||||
}
|
||||
|
||||
auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool {
|
||||
if (t1->kind() != t2->kind()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user