-
Notifications
You must be signed in to change notification settings - Fork 851
Fix and improve unreachable parsing #8617
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5260,6 +5260,54 @@ | |
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $stacky-unreachable-fallback (type $0) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (block ;; (replaces unreachable StructSet we can't emit) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (block | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $stacky-unreachable-fallback | ||
| ;; i32 cannot be the struct.set's ref child, so we cannot pop past the | ||
| ;; unreachable. The unreachable and the following nop are popped together. | ||
| i32.const 0 | ||
| unreachable | ||
| nop | ||
| struct.set $pair 0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not stop parsing entirely at the unreachable? We can skip unreachable code since we don't try to precisely roundtrip anyhow. In fact I believe we used to do that in the past?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't skip parsing instructions after unreachables if we want to be able to write tests containing expressions with unreachable children (which we definitely do). We might have skipped parsing such instructions in the binary parser in the past, but now both text and binary parsers use IRBuilder.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right - makes sense. |
||
| ) | ||
|
|
||
| ;; CHECK: (func $stacky-unreachable-ok (type $0) | ||
| ;; CHECK-NEXT: (struct.set $pair $first | ||
| ;; CHECK-NEXT: (struct.new_default $pair) | ||
| ;; CHECK-NEXT: (block | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $stacky-unreachable-ok | ||
| ;; Now we can pop past the unreachable. The unreachable and nop are still | ||
| ;; popped together. | ||
| struct.new_default $pair | ||
| unreachable | ||
| nop | ||
| struct.set $pair 0 | ||
| ) | ||
|
|
||
| ;; CHECK: (func $paren-in-string (type $0) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (string.const ")") | ||
| ;; CHECK-NEXT: ) | ||
| (func $paren-in-string | ||
| ;; We should not be tripped up by an extra close parenthesis inside a string. | ||
| (drop | ||
|
|
||
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.
Wouldn't this fail validation?
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.
Ah, this is from an outdated version of #8616. Will update this branch.
But to answer the question, yes, this would fail validation, but this code is used from the Printer, so needs to work correctly for invalid IR as well.