Skip to content

Disallow post-return from calling imports, allow blocking import calls even when callback is used#531

Merged
lukewagner merged 1 commit into
mainfrom
tweak-traps
Jun 20, 2025
Merged

Disallow post-return from calling imports, allow blocking import calls even when callback is used#531
lukewagner merged 1 commit into
mainfrom
tweak-traps

Conversation

@lukewagner
Copy link
Copy Markdown
Member

This PR disallows calling imports during post-return which means that sync-to-sync calls never require a fiber (noting that, if post-return can call imports, it can block after returning-to-and-unblocking the synchronous caller, thereby requiring a fiber to continue asynchronous execution in the callee), preserving the intended cost model of synchronous calls.

This implies that post-return will stick around instead of getting deprecated and removed in the future, thereby removing the reason for having the (as yet unimplemented) always-task-return canonopt. Note that, with only a bit more work, a synchronous export that wants to use task.return could always lift async (no callback) and use backpressure.set to achieve serialized execution.

The PR also relaxes a few of the traps that prevent certain blocking calls from being used in conjunction with callback. These traps were intended to avoid the need for fibers in some cases, but based on implementation experience, we think they'll be too strict and prevent various realistic scenarios where an unaware transitive dependency does a little unexpected blocking. Notes and TODOs are added to Async.md explaining this more.

@lukewagner lukewagner merged commit f1c7c30 into main Jun 20, 2025
2 checks passed
@lukewagner lukewagner deleted the tweak-traps branch June 20, 2025 16:46
@dicej
Copy link
Copy Markdown
Collaborator

dicej commented Jun 23, 2025

@lukewagner when you get a chance, would you mind adding a WAT test for this? That will help ensure implementations get it right.

@lukewagner
Copy link
Copy Markdown
Member Author

You bet; good idea: #535

dicej added a commit to dicej/wasmtime that referenced this pull request Jun 27, 2025
Per WebAssembly/component-model#531, post-return
functions are no longer allowed to call imports or intrinsics.

TODO: Update FACT to trap with a "cannot leave component instance" message
instead of the generic "wasm `unreachable` instruction executed".

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
dicej added a commit to dicej/wasmtime that referenced this pull request Jun 27, 2025
Per WebAssembly/component-model#531, post-return
functions are no longer allowed to call imports or intrinsics.

TODO: Update FACT to trap with a "cannot leave component instance" message
instead of the generic "wasm `unreachable` instruction executed".

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
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.

3 participants