Stream: wasmtime

Topic: Reactors


view this post on Zulip Alexandru Ene (Jun 25 2021 at 11:46):

I was trying to do a relatively simple change (make linked get_default) to bail if _start or the default export aren't found instead of returning a method that does nothing: https://github.com/bytecodealliance/wasmtime/blob/d8d4bf81b260ea18f56475fbde96b6662a365cf8/crates/wasmtime/src/linker.rs#L1062

I was basically trying to finish up this long forgotten PR i had

Changing that last line in linker::get_default with a bail like in that PR makes some reactor tests fail. E.g. this one:

#[test]
fn minimal_reactor() -> Result<()> {
    let wasm = build_wasm("tests/wasm/minimal-reactor.wat")?;
    let stdout = run_wasmtime(&[wasm.path().to_str().unwrap(), "--disable-cache"])?;
    assert_eq!(stdout, "");
    Ok(())
}

Adding a _start function to minimal-reactor.wat gets a complaint that it can't be both a command and a reactor.

(module
    (func (export "_initialize"))
    (func (export "_start"))
)

Result:

Caused by:
    0: failed to instantiate "/var/folders/7y/bhkyc0053yb8cbd2swfz956wzsf2bs/T/.tmppNMSQK"
    1: Program cannot be both a Command and a Reactor

So it turns out that's not the right way to patch the .wat file, but it somehow expects some export in there.
This passes the test but looks suspicious (e.g. I wouldn't know how to generate this from a compiled program: e.g. rust), without manually editing the .wat file:

(module
    (func (export "_initialize"))
    (func (export ""))
)

Any advice on where I can read about reactors and how they are supposed to work?

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime
This PR changes the linker.get_default() deafult return value. It removes the return of a no-op function as this is rarely what users of the method would want. I have replaced it with an error that...

view this post on Zulip bjorn3 (Jun 25 2021 at 11:49):

(deleted)

view this post on Zulip Alexandru Ene (Jun 25 2021 at 11:50):

But if I add a _start function to the minimal reactor, the test fails as it says it can't be both a command and a reactor

view this post on Zulip bjorn3 (Jun 25 2021 at 11:51):

not sure what the fix would be.

view this post on Zulip Alexandru Ene (Jun 25 2021 at 13:43):

I'll see if other maintainers have an opinion about this.
I wanted to fix the PR above but it's unclear to me what correct is :grinning:.
Right now, get_default is slightly confusing as it returns a newly created method if no suitable function is found when asking for a function from the module (probably not the caller's intent).
At the same time, in the reactor system there are some assumptions that the linker works like that in wasmtime. (and that _start should not be present in reactors).

That said, the only slightly more serious issue I see is if someone brings their reactors to WASMTime from another VM ecosystem, they may not work, but it's really unclear what correct is here :grinning:

view this post on Zulip Alex Crichton (Jun 25 2021 at 14:11):

@Dan Gohman might know best how to fix this, but I suspect that the minimal reactor wants to keep working and it'd either be handled differently by the CLI or the get_default function would continue doing what it does for reactors or something like that

view this post on Zulip Dan Gohman (Jun 25 2021 at 16:29):

What documentation there is for reactors is here: https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md#current-unstable-abi

WebAssembly System Interface. Contribute to WebAssembly/WASI development by creating an account on GitHub.

view this post on Zulip Dan Gohman (Jun 25 2021 at 16:30):

It hasn't been well developed yet, because in trying to figure out how reactors should work, we realized that what we really needed was for module linking etc. to subsume them.

view this post on Zulip Dan Gohman (Jun 25 2021 at 16:33):

Module linking is on its way to doing that now, but not all the pieces are in place yet. So reactors are what we have for now.

view this post on Zulip Dan Gohman (Jun 25 2021 at 16:45):

If we want get_default to fail, I think what we'll need to do is make the wasmtime CLI gracefully handle get_default failing -- that minimal_reactor test case works by invoking the wasmtime CLI.

view this post on Zulip Dan Gohman (Jun 25 2021 at 16:46):

It may just be a matter of changing the get_default call in src/commands/run.rs to do handle the failure case


Last updated: Oct 23 2024 at 20:03 UTC