pchickey opened PR #10610 from bytecodealliance:pch/typecheck_componentfunc to bytecodealliance:main:
<!--
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
-->
pchickey updated PR #10610.
pchickey updated PR #10610.
pchickey updated PR #10610.
pchickey updated PR #10610.
pchickey updated PR #10610.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Technically this isn't possible, type-checking at the component level. Components import abstract resources which don't match any types defined in Rust, which is what would be passed in as the type parameters here. The type-check can only be done once you have an
InstancePreorLinkerwhere the actual resource types are all assigned and we can match up the host-provided resources with our expectations.That being said I do like the property that
FooIndicesis all you need to "quickly load the thing" and as such represents a type-checked version of the component. Given that one options is to switch this to usingInstancePre<T>instead of&Componentas a construction argument. In doing so though we're not really prepared to have that working. The problem is that we'd have to prevent crossingFooIndicesvalues by accident. Right now export indices are intrinsically tied to aComponentwhich has a unique ID, but not aLinkerwhich does not have a unique ID. That means you could technically create aFooIndiceswith one linker and then extract exports from a component created with another linker, and if we skip the type-checks withunsafe(which I assume this PR is building towards) that could be memory-unsafe.That might be solvable though by putting a unique ID in linkers and plumbing that to
InstancePreandInstancewhich is checked.
pchickey submitted PR review.
pchickey created PR review comment:
The type-check can only be done once you have an InstancePre or Linker where the actual resource types are all assigned and we can match up the host-provided resources with our expectations.
Agreed, thats exactly where I got to - something representing that resource assignment (__internals::InstanceType) needs to be passed into ComponentFunc::typecheck as an argument. I got pretty tangled up with InstanceType because it borrows arcs of Store's type tables instead of cloning the arcs, so I am going to either change the structure or make a variant of it that owns the arcs.
pchickey edited PR review comment.
pchickey edited PR review comment.
pchickey updated PR #10610.
pchickey updated PR #10610.
Last updated: Dec 06 2025 at 07:03 UTC