fitzgen opened PR #14746 from fitzgen:define-unknown-imports-for-components to bytecodealliance:main:
Core Wasm modules could already do this, but components couldn't. The wrinkle is that we don't currently have a way to implement default values for future, stream, and error-context types. For now, those become traps instead of default values, but I could foresee e.g. creating a host API for making streams of a dynamic
Ttype and creating a/dev/null-style stream for the default stream.<!--
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 review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
fitzgen requested alexcrichton for a review on PR #14746.
fitzgen requested wasmtime-core-reviewers for a review on PR #14746.
:speech_balloon: alexcrichton created PR review comment:
This function might make more sense to take
impl AsContextMutwhich means that this could be implemented? Otherwise this'll always be impossible to implement
:memo: alexcrichton submitted PR review:
In theory adding future/stream support shouldn't be too too hard -- a default stream is always empty and a default future immediately produces its default value. If you'd prefer to defer though that seems fine.
Otherwise though this'll want some more special handling w.r.t. resources. In addition to the types lining up I mention below you'll also want non-trapping stubs to delete any resources found in the arguments. For example borrows given to the host need to be dropped lest that causes a trap of "borrows remain when returning" when the host returns.
:speech_balloon: alexcrichton created PR review comment:
I don't think that this will work -- this needs to create a resource of the correct type to pass the type-check of resources flowing back into the guest. I'm not entirely sure if we have the public API for that, but
DefaultResult::Resourcewill likely need a payload with the type of the resource being created.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
I would prefer to push this to a follow up, because I don't think we even have an API for a host to create a
StreamAnytype thing?
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Right yeah good point. We can convert
StreamReader<T>intoStreamAny, but that means we have to statically knowTwhich isn't possible here. That being said though takingAsContextMutwould make this implementable for resources I believe, at least host-defined ones
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
(but deferring is still fine of course)
fitzgen updated PR #14746.
fitzgen commented on PR #14746:
Added a store context parameter and cleaned things up a bit. Still no streams/futures, will look into that in a follow up.
:memo: alexcrichton submitted PR review:
To confirm: can you test whether this method works with polyfilling APIs that have a borrow resource as an argument? For example a method on a resource -- I'd expect that this implementation will not work because it's not destroying the arguments meaning that the borrows are always leftover at the end of the call and would always trap-on-return
:speech_balloon: alexcrichton created PR review comment:
This'll want to validate
tyI think to ensure that it only works with host-defined types. It's semantically not really possible to synthesize a guest resource indefault_value, so that'll have to just unconditionally return an error saying "sorry, can't do that".
github-actions[bot] added the label wasmtime:api on PR #14746.
github-actions[bot] added the label wasmtime:c-api on PR #14746.
fitzgen updated PR #14746.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Done
fitzgen updated PR #14746.
fitzgen commented on PR #14746:
To confirm: can you test whether this method works with polyfilling APIs that have a borrow resource as an argument? For example a method on a resource -- I'd expect that this implementation will not work because it's not destroying the arguments meaning that the borrows are always leftover at the end of the call and would always trap-on-return
Good catch, this did indeed fail, and I've pushed a commit that drops handles now, and added tests for this scenario.
:thumbs_up: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
This is I think overkill for here - we've got validation checks in place to bound the depth of a type hierarchy reasonable meaning that the host shouldn't blow its stack handling anything naturally. That plus
Drop for Valis already recursive anyway and has no special handling.
:speech_balloon: alexcrichton created PR review comment:
This should still drop futures/streams because otherwise it's basically akin to a memory leak in the store
:speech_balloon: alexcrichton created PR review comment:
I'm realizing on re-reading this (sorry didn't notice this earlier) -- but like above I think the on-heap stack is probably overkill here given the validation we already have about type depth.
:speech_balloon: alexcrichton created PR review comment:
Along the line of previous comments, I think it's fine to drop this test since we have a ton of "near the limit" we don't test anywhere else and we rely on the validation check to avoid the need to test
:speech_balloon: alexcrichton created PR review comment:
In general as LLMs are relatively good at writing tests I'm a bit wary of adding hundreds of lines per test per change as we'll quickly get to the point that the test suite basically can't be compiled in any reasonable amount of time (it's already quite large). To that extent could tests perhaps be combined and/or shuffled around here? For example tests that
cli_tests.rsrun are generally quicker to both compile and run insfoar as compiling running a fewCommands is not too taxing for rustc. Most of the tests here I think are probably implementable with CLI flags an--runand asserting over the output I think too.Mostly though mind looking into trying to reduce the testing overhead here?
fitzgen updated PR #14746.
fitzgen has enabled auto merge for PR #14746.
fitzgen updated PR #14746.
fitzgen added PR #14746 Add component support for unknown imports returning default values to the merge queue.
:check: fitzgen merged PR #14746.
fitzgen removed PR #14746 Add component support for unknown imports returning default values from the merge queue.
Last updated: Oct 31 2026 at 23:03 UTC