Stop using ArrayStack for the cleanup stack. (#7505)

Because we merge cleanups across scopes in various cases, and want to
use linear indexes into the complete stack, the ArrayStack abstraction
is getting in the way more than it's helping. Switch to just a
SmallVector.

This loses the unit testing of the MergeIntoGrandparent logic. This is
covered indirectly by check tests still, but direct testing of it is a
bit tricky given that ScopeStack isn't set up for use without a Context.
This commit is contained in:
Richard Smith
2026-07-15 00:47:47 +00:00
committed by GitHub
parent 5b48274e58
commit 45d1c74df8
5 changed files with 31 additions and 162 deletions
-18
View File
@@ -86,24 +86,6 @@ 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(); }