mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 11:01:05 +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
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user