Files
wasmtime/crates
Alex Crichton 20f510671d Enable passing host functions to components (#4219)
* Enable passing host functions to components

This commit implements the ability to pass a host function into a
component. The `wasmtime::component::Linker` type now has a `func_wrap`
method allowing it to take a host function which is exposed internally
to the component and available for lowering.

This is currently mostly a "let's get at least the bare minimum working"
implementation. That involves plumbing around lots of various bits of
the canonical ABI and getting all the previous PRs to line up in this
one to get a test where we call a function where the host takes a
string. This PR also additionally starts reading and using the
`may_{enter,leave}` flags since this is the first time they're actually
relevant.

Overall while this is the bare bones of working this is not a final spot
we should end up at. One of the major downsides is that host functions
are represented as:

    F: Fn(StoreContextMut<'_, T>, Arg1, Arg2, ...) -> Result<Return>

while this naively seems reasonable this critically doesn't allow
`Return` to actually close over any of its arguments. This means that if
you want to return a string to wasm then it has to be `String` or
`Rc<str>` or some other owned type. In the case of `String` this means
that to return a string to wasm you first have to copy it from the host
to a temporary `String` allocation, then to wasm. This extra copy for
all strings/lists is expected to be prohibitive. Unfortuantely I don't
think Rust is able to solve this, at least on stable, today.

Nevertheless I wanted to at least post this to get some feedback on it
since it's the final step in implementing host imports to see how others
feel about it.

* Fix a typo in an assertion

* Fix some typos

* Review comments
2022-06-07 09:39:02 -05:00
..
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00
2022-06-06 09:12:47 -05:00