-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
Depends on #4103 |
There was a problem hiding this 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.
common/array_stack.h
Outdated
@@ -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())); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Also added some tests for ArrayStack functions while I was in there. |
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.