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:
Geoff Romer
2021-11-10 16:35:06 -08:00
committed by GitHub
co-authored by Jon Meow
parent cabba3e93e
commit a4aff26821
9 changed files with 354 additions and 255 deletions
@@ -21,6 +21,26 @@ namespace Carbon {
using llvm::cast;
Scope::Scope(Scope&& other) noexcept
: values_(other.values_),
locals_(std::exchange(other.locals_, {})),
heap_(other.heap_) {}
auto Scope::operator=(Scope&& rhs) noexcept -> Scope& {
values_ = rhs.values_;
locals_ = std::exchange(rhs.locals_, {});
heap_ = rhs.heap_;
return *this;
}
Scope::~Scope() {
for (const auto& l : locals_) {
std::optional<AllocationId> a = values_.Get(l);
CHECK(a.has_value());
heap_->Deallocate(*a);
}
}
void Action::Print(llvm::raw_ostream& out) const {
switch (kind()) {
case Action::Kind::LValAction: