Stream: git-wasmtime

Topic: wasmtime / PR #4198 Redesign interface type value represe...


view this post on Zulip Wasmtime GitHub notifications bot (May 31 2022 at 15:39):

alexcrichton opened PR #4198 from no-component-value to main:

Prior to this PR a major feature of calling component exports (#4039)
was the usage of the Value<T> type. This type represents a value
stored in wasm linear memory (the type T stored there). This
implementation had a number of drawbacks though:

None of these drawbacks were deal-breakers per-se. When I started
to implement imported functions, though, the Value<T> type no longer
worked. The major difference between imports and exports is that when
receiving values from wasm an export returns at most one wasm primitive
where an import can yield (through arguments) up to 16 wasm primitives.
This means that if an export returned a string it would always be
Value<String> but if an import took a string as an argument there was
actually no way to represent this with Value<String> since the value
wasn't actually stored in memory but rather the pointer/length pair is
received as arguments. Overall this meant that Value<T> couldn't be
used for arguments-to-imports, which means that altogether something new
would be required.

This PR completely removes the Value<T> and Cursor<T> type in favor
of a different implementation. The inspiration from this comes from the
fact that all primitives can be both lifted and lowered into wasm while
it's just some times which can only go one direction. For example
String can be lowered into wasm but can't be lifted from wasm. Instead
some sort of "view" into wasm needs to be created during lifting.

One of the realizations from #4039 was that we could leverage
run-time-type-checking to reject static constructions that don't make
sense. For example if an embedder asserts that a wasm function returns a
Rust String we can reject that at typechecking time because it's
impossible for a wasm module to ever do that.

The new system of imports/exports in this PR now looks like:

Overall this felt like a much clearer system to work with and should be
much easier to integrate with imported functions as well. The new
WasmStr and WasmList<T> types can be used in import arguments and
lifted from the immediate arguments provided rather than forcing them to
always be stored in memory.

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Jun 01 2022 at 17:55):

alexcrichton requested fitzgen for a review on PR #4198.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 01 2022 at 18:07):

alexcrichton updated PR #4198 from no-component-value to main.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 01 2022 at 20:17):

fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 01 2022 at 20:38):

alexcrichton merged PR #4198.


Last updated: Oct 23 2024 at 20:03 UTC