mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:24:42 +01:00
Destroy locals at the end of blocks, not only on return (#7448)
Destroy local variables and temporaries at each `}`, and when branching with `break` and `continue`. In `for` statements, destroy loop variables along with anything created within the loop at the end of each loop iteration, and destroy the cursor and range object when the loop terminates. Assisted-by: Gemini via Antigravity --------- Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
co-authored by
Geoff Romer
parent
8bae79f44a
commit
6e62a7d4a2
@@ -86,6 +86,24 @@ class ArrayStack {
|
||||
llvm::append_range(values_, values);
|
||||
}
|
||||
|
||||
// Truncates the top array on the stack to the given size.
|
||||
auto TruncateTopArray(size_t size) -> void {
|
||||
CARBON_CHECK(!array_offsets_.empty());
|
||||
values_.truncate(array_offsets_.back() + size);
|
||||
}
|
||||
|
||||
// Merges the top array into the the array two before it, leaving the top
|
||||
// array empty.
|
||||
auto MergeTopArrayIntoGrandparent() -> void {
|
||||
CARBON_CHECK(array_offsets_.size() >= 3);
|
||||
auto new_mid =
|
||||
std::rotate(values_.begin() + array_offsets_[array_offsets_.size() - 2],
|
||||
values_.begin() + array_offsets_[array_offsets_.size() - 1],
|
||||
values_.end());
|
||||
array_offsets_[array_offsets_.size() - 2] = new_mid - values_.begin();
|
||||
array_offsets_[array_offsets_.size() - 1] = values_.size();
|
||||
}
|
||||
|
||||
// Returns the current number of values in all arrays.
|
||||
auto all_values_size() const -> size_t { return values_.size(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user