mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-18 20:50:29 +00: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:
1 parent
cabba3e93e
commit
a4aff26821
9 files changed
+354
-255
No files matched your search
@@ -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