-
Notifications
You must be signed in to change notification settings - Fork 695
Add a get_value operator to duplicate a value from the expression stack. #685
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
Comments
This extension might complement the text format being explored in https://github.com/sunfishcode/design/blob/text-syntax-strawman-proposal/TextFormat.md by allowing the naming of block top level expressions and their reuse. This text format introduces Personally I think it would be frustrating to write code using these annotations because there are still a lot of constraints on where they can be used and this would be a burden on the writer - a reader could assume the code is valid and I can see that help in the case of presentation. This text format proposal gives this example:
Note this example looks wrong, or I don't understand the intention of the Anyway, rewriting the example in this text format proposal to use the extension proposed here would give the following where the
I think that one of the ways that expressions help the reader is that they make it clear that the intermediate values have a single use and make the end of the definition live range clear. Unfortunately the proposal here only makes it clear that the definitions are used within the lexical scope of the block in which they are defined, and after their definition. It is sometimes possible to introduce extra blocks just to reduce the obvious live range of a definition, but this is not a comprehensive solution. If finding the live ranges of definitions is a significant burden for the runtime compiler then there might be some merit in having the producer explicitly flag the last use, so the proposal here might also add a Lets say that in a text format
Now the reader can clearly see the last use of definitions and thus their live range, and does not need to scan forward over the lexical scope to search for other uses. The runtime compiler could flag the live ranges of these definitions in a single pass. I have no idea yet how this would increase the encoded file size, but the common case is a single use with an implicit pop so perhaps there is some hope. |
Funny, I posted #693 without having seen your recent comment. Isn't the proposal here simply to introduce a new kind of local variable - a block-scoped single-assignment variable? I had the impression that such variables had been proposed earlier - or do I misremember? So what your latest comment is doing is just changing the syntax of your original proposal? |
@qwertie The definitions are already on the values stack in a post-order decoder. All the block top level expression definitions are on the values stack at the end of the block. This proposal is to allow re-use of them, the The
There may also be some utility in being able to explicitly declare the last use of these definitions. This happens implicitly when they are used as an expression argument and are popped from the top of the values stack. This could help a single pass compiler such as https://bugzilla.mozilla.org/show_bug.cgi?id=1232205 with register allocation, so it knows when a value in a register is no longer needed and can free up the register without flushing it to a memory stack. |
Could this operator, The lack of this support appears to have stalled some areas of wasm developer for a good part of this year, and blocks the MVP. There appears to have been no tool development, and the text format appears stagnant on current limitations, and critical performance and implementation complexity and thus security issues remain unanswered blocking the MVP. This is a trivial operator for implementations to add, and opens new paths for producers to explore, paths that may well lead to local variables being removed from wasm and wasm becoming SSA with a stack encoding. Even if this did not prove superior, there are immediate benefits that producers could explore such as using pick to reduce the use of local variables in patterns such as:
Not only is this shorter, it leaves less live values which should help a simple compiler and should reduce the work for an optimizing compiler. It also creates patterns in which multiple values need to be dropped out of stack order in blocks, showing clearly the efficiency of having block ends unwinding the stack. Producers could start inserting blocks to more efficiently clear the stack, leaving less live values. Handling Should an SSA encoding prove competitive in terms of encoding efficiency then it will probably be compelling, and may well open new paths to explore. |
Would there be any immediate interest in adding an operator, say
get_value
, to duplicate a value from the expression stack?With the post-order encoding there is already the issue that expression results accumulate in blocks to be discarded at the block exits. It seems consistent with the SSA decoder to allow re-use of these, so why not take advantage of them. Each of these could be viewed as binding a block local variable that could be accessed. So rather than
block
we could effective havelet
:Adding this now might allow some experimentation with the tooling, to take advantage of this.
It's not necessary to land this change, and it can be explored in local work, and local tools can rewrite the wast into this encoding, but might there happen to be any interesting in such an incremental change?
The text was updated successfully, but these errors were encountered: