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

Stack switching proposal support #7041

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

dhil
Copy link
Member

@dhil dhil commented Oct 30, 2024

This patch implements text and binary encoding/decoding support for the stack switching proposal. It does so by adapting the previous typed-continunations implementation. Particular changes:

  • Support for new resume encoding.
  • Added support for resume_throw and switch.
  • Feature flag typed-continuations has been renamed to stack-switching.

A small unfortunate implementation detail is that the internal name Switch was already taken by the br_table instruction, so I opted to give the switch instruction the internal name StackSwitch.

A minor detail is that I have reordered the declarations/definitions of the stack switching instructions such that they appear in ascending order according to their opcode value (this is the same order that the stack-switching explainer document present them in).

I can look into adding validation support in a subsequent patch.

@dhil dhil force-pushed the stack-switching branch 2 times, most recently from 1be4ea5 to d531797 Compare November 1, 2024 15:43
This patch implements text and binary encoding/decoding support for
the stack switching proposal. It does so by adapting the previous
typed-continunations implementation. Particular changes:

* Support for new `resume` encoding.
* Added support for `resume_throw` and `switch`.
* Feature flag `typed-continuations` has been renamed to `stack-switching`.

A small unfortunate implementation detail is that the internal name
`Switch` was already taken by the `br_table` instruction, so I opted
to give the `switch` instruction the internal name `StackSwitch`.

A minor detail is that I have reordered the declarations/definitions
of the stack switching instructions such that they appear in ascending
order according to their opcode value (this is the same order that the
stack-switching explainer document present them in).
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Happy to meet and discuss any of these comments in real time if it would be more efficient for you.

src/wasm.h Outdated Show resolved Hide resolved
src/wasm.h Outdated Show resolved Hide resolved
src/wasm.h Outdated Show resolved Hide resolved
src/wasm.h Outdated Show resolved Hide resolved
src/wasm/wasm.cpp Outdated Show resolved Hide resolved
src/parser/parsers.h Outdated Show resolved Hide resolved
src/parser/parsers.h Outdated Show resolved Hide resolved
src/wasm/wasm-ir-builder.cpp Outdated Show resolved Hide resolved
src/wasm/wasm-ir-builder.cpp Outdated Show resolved Hide resolved
src/wasm/wasm-validator.cpp Outdated Show resolved Hide resolved
@tlively
Copy link
Member

tlively commented Nov 5, 2024

Also, if you could avoid force pushes as you update the PR, that will help me see what changes from version to version.

@dhil
Copy link
Member Author

dhil commented Nov 5, 2024

Also, if you could avoid force pushes as you update the PR, that will help me see what changes from version to version.

Yes, I only did that while rebasing and noone were reviewing :-) I will implement your feedback and push it directly on top of here.

@dhil
Copy link
Member Author

dhil commented Nov 6, 2024

@tlively I think I have addressed all of your feedback now. Please take a look when you got time. Thanks in advance!

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes! Here are a few more comments, but I think we're getting close.

src/parser/parsers.h Outdated Show resolved Hide resolved
@@ -301,7 +301,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
void visitLoop(Loop* curr);
void visitTry(Try* curr);
void visitTryTable(TryTable* curr);
void visitResume(Resume* curr);
Copy link
Member

Choose a reason for hiding this comment

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

For the expressions that now depend on the types of their children to recover the printed type annotations, we now need to handle the case where the children are unreachable or have bottom heap types. See what we do for StructNew and friends just below this. It would also be good to add tests that exercise these cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please take a look at commits 157552a and 480843d.

src/wasm/wasm-validator.cpp Show resolved Hide resolved
test/lit/basic/stack_switching_resume_throw.wast Outdated Show resolved Hide resolved
src/wasm/wasm-binary.cpp Show resolved Hide resolved
src/passes/Print.cpp Outdated Show resolved Hide resolved
src/wasm/wasm.cpp Outdated Show resolved Hide resolved
@dhil
Copy link
Member Author

dhil commented Nov 18, 2024

Do you prefer I resolve the merge conflict via rebase+force-push or just as a merge commit?

@tlively
Copy link
Member

tlively commented Nov 18, 2024

Do you prefer I resolve the merge conflict via rebase+force-push or just as a merge commit?

A merge would be good, thanks!

Comment on lines 8011 to 8013
HeapType ftPrime{Signature(tgrs, ctrs)};
HeapType ctPrime{Continuation(ftPrime)};
Type ctPrimeRef(ctPrime, Nullability::NonNullable);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be looking up the types based on the labels now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is your point that we can simply read the type of the continuation off the (corresponding branch target) label type? I think so yes, it must have been given statically in the source code. It is not entirely clear to me what the purpose of sentTypes is (I suppose it is some caching mechanism).

Comment on lines 1975 to 1977
HeapType ftPrime{Signature(tgrs, ctrs)};
HeapType ctPrime{Continuation(ftPrime)};
Type ctPrimeRef(ctPrime, Nullability::NonNullable);
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

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