Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor InstBlockStack to use ArrayStack. #4104

Merged
merged 2 commits into from
Jul 3, 2024

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jul 2, 2024

The use of ArrayStack here is intended to simplify the logic, and also make better use of the inst heap allocations. Prior changes #4101 and #4103 removed the less related logic from InstBlockStack, although #4103 is the actual part that blocked using ArrayStack.

BTW, note the PrintForStackDump implementation was incorrect because it didn't apply size_. This simplification fixes the issue.

@jonmeow
Copy link
Contributor Author

jonmeow commented Jul 2, 2024

Depends on #4103

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

LG with a minor nit inline.

@@ -47,6 +47,16 @@ class ArrayStack {
return llvm::ArrayRef(elements_).slice(array_offsets_.back());
}

// Returns the array at a specific index.
auto PeekArrayAt(int index) const -> llvm::ArrayRef<ValueT> {
CARBON_CHECK(index < static_cast<int>(array_offsets_.size()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llvm::ArrayRef has an equivalent assert, do we need it here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jonmeow
Copy link
Contributor Author

jonmeow commented Jul 3, 2024

Also added some tests for ArrayStack functions while I was in there.

@jonmeow jonmeow enabled auto-merge July 3, 2024 19:15
@jonmeow jonmeow added this pull request to the merge queue Jul 3, 2024
Merged via the queue into carbon-language:trunk with commit efa158d Jul 3, 2024
7 checks passed
@jonmeow jonmeow deleted the inst-block-stack branch July 3, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants