-
Notifications
You must be signed in to change notification settings - Fork 839
Poppy IR wast parsing and validation #3105
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 |
|---|---|---|
|
|
@@ -33,7 +33,10 @@ | |
| // stack type of each instruction. Pops may not have `unreachable` type. | ||
| // | ||
| // 4. Only control flow structures and instructions that have polymorphic | ||
| // unreachable behavior in WebAssembly may have unreachable type. | ||
| // unreachable behavior in WebAssembly may have unreachable type. Blocks may | ||
| // be unreachable when they are not branch targets and when they have an | ||
| // unreachable child. Note that this means a block may be unreachable even | ||
| // if it would otherwise have a concrete type, unlike in Binaryen IR. | ||
|
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. Where do we do this? Poppy IR doesn't seem to have its own
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. Eventually we will need to add alternate logic to
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. For example, (block (result i32)
(unreachable)
)According to your explanation, this block's type will be What I meant was, as you said, given that we only use
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. In both Binaryen IR and Poppy IR, the block in your example can have either The difference between Poppy IR and Binaryen IR is in a block like this: In Binaryen IR, it would be illegal for that block to have
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. I see, thanks. Is there any particular reason for this distinction?
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. Yes, it has to do with type inference in Poppy IR, which we don't do in Binaryen IR. Consider the following function: Binaryen IR unconditionally gives |
||
| // | ||
| // For example, the following Binaryen IR Function: | ||
| // | ||
|
|
@@ -58,7 +61,10 @@ | |
| // ) | ||
| // | ||
| // Notice that the sequence of instructions in the block is now identical to the | ||
| // sequence of instructions in raw WebAssembly. | ||
| // sequence of instructions in raw WebAssembly. Also note that Poppy IR's | ||
| // validation rules are largely additional on top of the normal Binaryen IR | ||
| // validation rules, with the only exceptions being block body validation and | ||
| // block unreahchability rules. | ||
| // | ||
|
|
||
| #ifndef wasm_ir_stack_h | ||
|
|
@@ -75,6 +81,10 @@ namespace StackUtils { | |
| // Iterate through `block` and remove nops. | ||
| void removeNops(Block* block); | ||
|
|
||
| // Whether `expr` may be unreachable in Poppy IR. True for control flow | ||
| // structures and polymorphic unreachable instructions. | ||
| bool mayBeUnreachable(Expression* expr); | ||
|
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. I still think my comment about this is relevant: tlively#1 (comment) The comment here doesn't clearly say which of the two cases it is IMO. If it is "not exited normally" or such, that might be good to clarify?
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. I mean, is "unreachable" here referring to a type in the type system, or to a particular property, etc. |
||
|
|
||
| } // namespace StackUtils | ||
|
|
||
| // Stack signatures are like regular function signatures, but they are used to | ||
|
|
||
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.
Can't this use
StackSignatureand precisely compute whether it is really unreachable or not?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.
We can use
StackSignature(or just look atexpr->type) to figure out if it is unreachable, but what we want to do in this function is determine if it is allowed to be unreachable.