alexcrichton opened PR #6638 from alexcrichton:use-wasmparser-types
to bytecodealliance:main
:
Before this commit Wasmtime would build up its own representation of type information independently of wasmparser, effectively duplicating things such as type scopes and managing indices. This to some degree is required because Wasmtime's type information is serialized into compiled images and wasmparser's information isn't easily serialized. With the advent of resources in components, however, the task of doing this correctly has become much more difficult.
When component translation was first written it was more difficult to acquire type information from
wasmparser::Validator
. Nowadays there's helpful type information exposed every step of the way which makes it much easier to get at the types of items while we're translating rather than only at the very end (or not at all). This is one of the motivations for this commit where now it's possible to avoid duplicating the workwasmparser
is doing whereas before it wasn't as easy.Additionally with resources in the component model they perform namely a number of involved type substitutions during instantiation of arbitrary components which isn't implemented in Wasmtime today. Some of this will be required for Wasmtime to correctly implement resources so instead of doing all that again I've decided to replace Wasmtime's management of types with wasmparser's management of types.
The main difference in this commit is that Wasmtime no longer tracks type information during translation and that conversion into Wasmtime's type hierarchy now has a different entry point. Previously conversion would happen based on raw types read from the wasm file (think index-based things) whereas now translation happens on
wasmparser
's parsed and validated hierarchy of types (think ID-based things rather than index-based things). This makes translation slightly more involved but overall it's largely performing the same work.One gotcha with this PR is that core wasm modules using GC types and typed function references could theoretically have worked previously but they no longer work. It turns out that
wasmparser
is not correctly surfacing type information in components for core modules that use GC types, namely becausewasmparser
's validated type hierarchy uses the same core wasm types as what's read raw from the type section. This in turn means that the index-based format can't be resolved. This is a bug inwasmparser
which will need resolving but is a big chunk of work to take on, so for now the component model will panic on these sorts of modules (which are disabled by default anyway).Overall the end-goal of this commit is to ease the implementation of resources a bit by heavily relying on
wasmparser
's understanding of resources, chiefly the functionality of performing type substitutions on subcomponent instantiations.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested itsrainy for a review on PR #6638.
alexcrichton requested wasmtime-core-reviewers for a review on PR #6638.
alexcrichton updated PR #6638.
alexcrichton updated PR #6638.
pchickey requested pchickey for a review on PR #6638.
pchickey submitted PR review.
alexcrichton merged PR #6638.
Last updated: Dec 23 2024 at 12:05 UTC