alexcrichton opened PR #6667 from alexcrichton:lift-lower-types to bytecodealliance:main:
This commit is a large refactor to the component runtime of Wasmtime to shepherd along type information when lifting and lowering values. Previously lifting and lowering would assume type information given context such as "surely lowering a
u32must lower into the typeInterfaceType::U32" or "lowering aValworks as it knows its own type". This is still true, and this commit isn't changing these features. The rationale for this commit instead stems from the upcoming implementation of resources in Wasmtime.Resources are trickier than all existing types in Wasmtime because what exactly is the type of a resource depends on who you're asking. For example the host might have one type called
http::Headersbut a component could import it as two distinct types:(component (import "headers1" (type $h1 (sub resource))) (import "headers2" (type $h2 (sub resource))) ;; ... )in the above component the
$h1and$h2types will each get their own table at runtime for managing their state. This means that if the host instantiates the component withhttp::Headerssupplied as both types then the same type on the outside maps to two different types inside. This means that the lowering of a host-defined type into the component is now dependent on the "name" that the component has for the type, basically if the function used$h1or$h2. This overall means that the type that the component assigned for a function is significant as part of lifting and lowering. Hence the rationale for this commit, threading around this type information.The major change in this commit is updates to the
LiftandLowertraits. Previously they took a mishmash of parameters and now they needed to take more parameters, so I've updated them with:
Liftoperations take a&LiftContext<'_>and anInterfaceTypeas contextual information. The context stores the store, the options, and type information. TheInterfaceTypeis the type that's being lifted, which would indicate which resource table to load from for example.
Loweroperations now take a&mut LowerContext<'_, T>and anInterfaceType. TheLowerContextis similar to its lift cousin where it stores the store, options, and type information.The different context passed in to
liftandload, for example, is no longer distinguished and both simply take a&LiftContext<'_>which simplifies things a bit.This refactoring was pretty far reaching and touches quite a bit of the component model implementation. This is because basically everything deals with type information as types can be recursively nested in one another. I've taken the liberty to make code continue to be ergonomic/understandable where appropriate so some "shapes" of code are now different to continue to accommodate readability and maintainability.
Finally it's worth noting that this should not have any actual function impact on components running today (or tomorrow). User-facing APIs haven't changed at all here and it's just the guts that are refactored. One unfortunate aspect, though, is that this is going to be a small perf hit on lifting/lowering due to the fact that type information essentially needs to be "iterated" over during the lifting/lowering process. This iteration involves index lookups in
&ComponentTypesalong with assertions that when you lowerVec<T>that the type isInterfaceType::List(i). These assertions should always succeed, and in theory could become some sort ofunreachable_uncheckedin the future, but for now it's all left as safe checks/panics for us to optimize at a later date if necessary.<!--
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 wasmtime-core-reviewers for a review on PR #6667.
alexcrichton requested fitzgen for a review on PR #6667.
alexcrichton updated PR #6667.
alexcrichton updated PR #6667.
fitzgen submitted PR review:
I like it!
fitzgen merged PR #6667.
Last updated: Dec 13 2025 at 19:03 UTC