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

runtime, builder: WebAssembly reactor mode #4082

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ydnar
Copy link
Contributor

@ydnar ydnar commented Jan 12, 2024

This is an initial attempt at enabling reactor mode for WebAssembly programs, where the host can repeatedly call into the guest Wasm program via functions exported with //go:wasmexport.

The entrypoint for a WebAssembly reactor module is _initialize instead of _start.

Assuming that the WebAssembly runtime is not reentrant (e.g. not threaded), then this works if the //go:wasmexport calls are detected and wrapped in a function that starts the Go scheduler.

When the exported function ends, all other goroutines are paused.

Goroutines started in a global init() function will run while the host has called into the guest. They are paused when the guest call returns and restarted on the next call.

TODO: figure out how to enable reactor mode:

  1. Should it be a flag to tinygo build?
  2. Should it be a build tag (e.g. -tags reactor)?
  3. Should the compiler detect the omission of main.main and automatically enable reactor mode?

TODO: figure out how and where best to wrap //go:wasmexport calls.

TODO: figure out how this works with -scheduler none

Fixes #2735.

@aykevl
Copy link
Member

aykevl commented Feb 19, 2024

TODO: figure out how to enable reactor mode:

My suggestion would be to add a new target, for example -target=wasi-reactor.

TODO: figure out how and where best to wrap //go:wasmexport calls.

I would suggest to do that in a separate PR, and make sure to fully support reactor mode first.

…tor mode

The entrypoint for a WebAssembly reactor module is _initialize instead of _start.

Assuming that the WebAssembly runtime is not reentrant (e.g. not threaded), then
this works if the //go:wasmexport calls are detected and wrapped in a function
that starts the Go scheduler.

When the exported function ends, all other goroutines are paused.

Goroutines started in a global init() function will run while the host has called into
the guest. They are paused when the guest call returns and restarted on the next call.

TODO: figure out how to enable reactor mode:
1. Should it be a flag to tinygo build?
2. Should it be a build tag (e.g. -tags reactor)?
3. Should the compiler detect the omission of main.main and automatically enable reactor mode?

TODO: figure out where best to wrap //go:wasmexport calls.

WIP
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.

None yet

2 participants