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

[Parser] Use unreachables to fulfill tuple requirements #6488

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

tlively
Copy link
Member

@tlively tlively commented Apr 11, 2024

When we need to pop a tuple and the top value on the stack is unreachable, just
pop the unreachable rather than producing a tuple.make. This always produces
valid IR since an unreachable is always valid where a tuple would otherwise be
expected. It also avoids bloating the parsed IR, since we would previously parse
a tuple.make where all the children were unreachable in this case.

@tlively tlively requested a review from kripken April 11, 2024 01:01
@tlively
Copy link
Member Author

tlively commented Apr 11, 2024

@@ -175,7 +175,7 @@ Result<Expression*> IRBuilder::pop(size_t size) {
CHECK_ERR(packageHoistedValue(*hoisted, size));

auto* ret = scope.exprStack.back();
if (ret->type.size() == size) {
if (ret->type.size() == size || ret->type == Type::unreachable) {
Copy link
Member

Choose a reason for hiding this comment

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

From your description I thought this was for tuples, but ret->type.size() == size can be the case for non-tuples too, can't it? (when size == 1)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but since we report the size of Type::unreachable as 1, this code path was already taken for singular unreachable popped values.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks. Maybe worth a comment?

Base automatically changed from tuple-extract-valid-arity to main April 11, 2024 16:22
When we need to pop a tuple and the top value on the stack is unreachable, just
pop the unreachable rather than producing a tuple.make. This always produces
valid IR since an unreachable is always valid where a tuple would otherwise be
expected. It also avoids bloating the parsed IR, since we would previously parse
a `tuple.make` where all the children were unreachable in this case.
@tlively tlively force-pushed the parser-pop-unreachable-tuple branch from f64f57d to 59c021e Compare April 11, 2024 18:34
@tlively tlively enabled auto-merge (squash) April 11, 2024 18:38
@tlively tlively merged commit da8b071 into main Apr 11, 2024
26 checks passed
@tlively tlively deleted the parser-pop-unreachable-tuple branch April 11, 2024 19:10
@gkdn gkdn mentioned this pull request Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants