-
Notifications
You must be signed in to change notification settings - Fork 454
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
Implement changes to control flow operators #163
Conversation
Btw, here is an idea for slightly simplifying the notion of default: instead of making it a target separate from the jump table, why don't we simply say that the index operand is clamped to the size of the table? That would be equivalent, since you could then just make the default the last element of the table, but it removes one minor concept. WDYT? |
See control...control.clamp for the latter suggestion. |
On Thu, Nov 5, 2015 at 10:35 AM, rossberg-chromium <[email protected]
|
@@ -157,9 +145,15 @@ expr: | |||
( memory_size ) | |||
( grow_memory <expr> ) | |||
|
|||
switch: | |||
( table <target>* ) |
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.
Part of me was hoping we could use a LISP-style array literal, #( <target>* )
or [ <target>* ]
depending on the dialect, but I'm ok if we can't because of generic S-expression parsers.
This looks good to me at an initial readthrough, with some minor comments above. We can iterate from here. I'm not partial to putting the default in the table. In my mental model, On that note, part of me would like to get rid of the default altogether and have |
@sunfishcode, removed dead code, thanks for finding! |
Once this is landed, I'll create a separate PR for the "clamping" default, so we can have the discussion there. As for a trapping switch, I'd like that even better. @titzer, do you think the scenario @sunfishcode mentions would be easy enough to optimise for something like v8-proto? |
Not sure that trapping tableswitch is a good idea. As @sunfishcode On Thu, Nov 5, 2015 at 11:25 PM, rossberg-chromium <[email protected]
|
@titzer I don't think producers would use a clamp. LLVM, for example, will do something like this:
because this avoids routing the default path through the indirect branch, which is quite nice if the default path is hot, which it sometimes is in C/C++. (This is also related to why I'm not fond of thinking about the default being inside the table.) If the JIT also lowers to this form instead of a clamp, we could end up with code effectively like this:
This way it's just a matter of recognizing that |
So anybody not okay with landing this PR? |
lgtm |
1 similar comment
lgtm |
Resolve conflicts and update unreachable.wast to use if_else
Fixed up the conflicts with unreachable, merging based on lgtms and IRC with @sunfishcode |
Implement changes to control flow operators
Thanks! |
* [test] Add spec tests for integer min/max ops Tests are pulled from WAVM/WAVM#242 * Addressed comments
Okay, here is a new implementation of the control operators (as an alternative to #153) that approximates the current description in the design doc, including the more verbose tableswitch. I managed to keep most of the complexity out of the kernel. The price to pay is that the desugaring no longer just consists of local expansions, it actually has to rewrite the case list to handle label targets. That is not ideal but probably bearable. The rest of the complexity is in the parser, where case labels get their own namespace with somewhat subtle scoping.
The abstract syntax of the jump table is more heavyweight than you envisioned, but don't say I didn't tell you so. ;)