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

Typed continuations: cont.new instructions #6308

Merged
merged 5 commits into from
Feb 22, 2024

Conversation

frank-emrich
Copy link
Contributor

This PR is part of a series that adds basic support for the typed continuations/wasmfx proposal.

This particular PR adds support for the cont.new instruction for creating continuations, documented here.

In short, these instructions are of the form (cont.new $ct) where $ct must be a continuation type. The instruction takes a single (nullable) function reference as its argument, which means that the folded representation of the instruction is of the form (cont.new $ct (foo ...)).

Support for the instruction is implemented in both the old and the new wat parser.

Note that this PR does not implement validation of the new instruction.

@tlively tlively self-requested a review February 22, 2024 00:32
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.

Looks great! Just a few small comments.

src/ir/cost.h Outdated
@@ -726,6 +726,10 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
return 8 + visit(curr->ref) + visit(curr->num);
}

CostType visitContNew(ContNew* curr) {
// Some arbitrary "high" value, reflecting that this may allocate a stack
return 10 + visit(curr->func);
Copy link
Member

Choose a reason for hiding this comment

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

Would you expect that this would be cheaper than resume, which we model with a base cost of 12?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, good point! If the stack allocation does happen at cont.new, this should indeed be more expensive than resume. But I could also imagine an implementation strategy where the allocation happens lazily when resume-ing a new continuation for the first time.
In general, I have little confidence in the numbers here. For now, I've increased the base cost for cont.new to 14, which is still very arbitrary, but at least greater than the value for resume. Should I add a TODO that we should probably revisit these values at some point? (e.g., once we have more experience from implementing the extension)

Copy link
Member

Choose a reason for hiding this comment

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

Ehh, probably no need for a TODO. All of the numbers in this file are similarly suspect.

Comment on lines 579 to 585
Result<> IRBuilder::visitContNew(ContNew* curr) {
auto func = pop();
CHECK_ERR(func);
curr->func = *func;

return Ok{};
}
Copy link
Member

Choose a reason for hiding this comment

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

The default visitExpression implementation will already do exactly this, so I don't think we need to implement visitConstNew here at all. If what we popped depended on the contType at all, that would be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, nice!

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.cpp Outdated Show resolved Hide resolved
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.

LGTM, thanks!

@tlively tlively merged commit e2420f0 into WebAssembly:main Feb 22, 2024
14 checks passed
@frank-emrich frank-emrich deleted the wasmfx-contnew branch February 23, 2024 14:34
ashleynh pushed a commit that referenced this pull request Feb 26, 2024
This PR is part of a series that adds basic support for the [typed
continuations/wasmfx proposal](https://github.com/wasmfx/specfx).

This particular PR adds support for the `cont.new` instruction for creating
continuations, documented [here(https://github.com/wasmfx/specfx/blob/main/proposals/continuations/Overview.md#instructions).

In short, these instructions are of the form `(cont.new $ct)` where `$ct` must
be a continuation type. The instruction takes a single (nullable) function
reference as its argument, which means that the folded representation of the
instruction is of the form `(cont.new $ct (foo ...))`. 

Support for the instruction is implemented in both the old and the new wat
parser.

Note that this PR does not implement validation of the new instruction.
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
This PR is part of a series that adds basic support for the [typed
continuations/wasmfx proposal](https://github.com/wasmfx/specfx).

This particular PR adds support for the `cont.new` instruction for creating
continuations, documented [here(https://github.com/wasmfx/specfx/blob/main/proposals/continuations/Overview.md#instructions).

In short, these instructions are of the form `(cont.new $ct)` where `$ct` must
be a continuation type. The instruction takes a single (nullable) function
reference as its argument, which means that the folded representation of the
instruction is of the form `(cont.new $ct (foo ...))`. 

Support for the instruction is implemented in both the old and the new wat
parser.

Note that this PR does not implement validation of the new instruction.
@gkdn gkdn mentioned this pull request Aug 31, 2024
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