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 24 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 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 Outdated 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!

src/wasm/wasm-binary.cpp Outdated Show resolved Hide resolved
src/wasm/wasm-ir-builder.cpp Outdated Show resolved Hide resolved
This commit is a partial solution to removing the type immediate
members from `cont.new,cont.bind,resume,resume_throw,switch`. However,
when I fully remove the type immediates then I observe a crash in
`child-ir.h` on
`visitContBind,visitResume,visitResumeThrow,visitStackSwitch`. It seems that `curr->cont->type` is sometimes not a continuation type...
@dhil
Copy link
Member Author

dhil commented Nov 28, 2024

@tlively I am experiencing some difficulties with getting rid of the type immediate members (contType). Whenever I swap contType for curr->cont->type.getHeapType() in child-typer.h I observe crashes in the ConstraintCollector. Supposedly, curr->cont->type is not always a continuation type... so something is wrong. I need another set of eyes to have a look. When you got time, do you mind taking a look at the code?

@tlively
Copy link
Member

tlively commented Dec 2, 2024

Check out the pattern used by other instructions that take type immediates in child-typer.h, for example visitStructGet and visitStructSet. They take an optional additional argument for the type, and if that argument is present, it is used instead of looking up the type from the instruction operand. IRBuilder always passes these type arguments through to ChildTyper.

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