Stream: git-wasmtime

Topic: wasmtime / PR #13821 component: improve async-mismatch di...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 11:24):

malformed-c opened PR #13821 from malformed-c:fix-async-import-stub-and-diagnostics to bytecodealliance:main:

Fixes #13813.

func_new/func_wrap and func_new_async/func_wrap_async all construct a DynamicHostFn/StaticHostFn with ASYNC = false — only func_new_concurrent/func_wrap_concurrent construct one with ASYNC = true. Trying to satisfy an async func-typed import with the former (an easy mistake, since func_new_async's name suggests it should work) always failed at instantiation with a bare "type mismatch with async", giving no indication of why or what to use instead.

Two changes, both discussed in #13813:

  1. A new shared typecheck_async helper (used by both StaticHostFn::typecheck and DynamicHostFn::typecheck) names the specific mismatch and points at the correct API, in both directions.
  2. Linker::define_unknown_imports_as_traps always stubbed with func_new, so it could never stub an unsatisfied async func import at all — a component with one couldn't be instantiated even if the import was never called. It now stubs with func_new_concurrent when the import is async and Config::concurrency_support is enabled, falling back to func_new (and the improved error above) otherwise.

Before / after

Manually satisfying an async import with func_new_async (the issue's primary repro — a WIT world with consume: async func(x: u32) -> string):

Before:

Error: component imports instance `test:asyncnoresource/api`, but a matching implementation was not found in the linker

Caused by:
    0: instance export `consume` has the wrong type
    1: type mismatch with async

After:

Error: component imports instance `test:asyncnoresource/api`, but a matching implementation was not found in the linker

Caused by:
    0: instance export `consume` has the wrong type
    1: type mismatch with async: this import is declared `async func` in WIT, but was satisfied with a sync-style host function (`func_new`/`func_wrap`, or `func_new_async`/`func_wrap_async`  despite the name, these implement a *sync*-WIT-typed function via blocking host code, not an `async func` import); use `func_new_concurrent`/`func_wrap_concurrent` instead

define_unknown_imports_as_traps on a component with an unsatisfied async import (nothing in the component even calls it):

Before: define_unknown_imports_as_traps itself reports success (it happily stubs with func_new regardless of async-ness), but the component can never be instantiated — the confusing error above surfaces at instantiate_async instead.

After: define_unknown_imports_as_traps stubs the import with func_new_concurrent, instantiation succeeds, and calling into the component only traps if the guest actually calls the unsatisfied import:

calling probe() (should trap - consume() is stubbed): Err(error while executing at wasm backtrace: ...

Caused by:
    unknown import: `test:asyncnoresource/api#consume` has not been defined
)

Testing

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 11:24):

malformed-c requested fitzgen for a review on PR #13821.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 11:24):

malformed-c requested wasmtime-core-reviewers for a review on PR #13821.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 11:32):

malformed-c updated PR #13821.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 11:38):

malformed-c edited PR #13821:

Fixes #13813.

func_new/func_wrap and func_new_async/func_wrap_async all build a host function with ASYNC = false — only func_new_concurrent/func_wrap_concurrent set ASYNC = true. Satisfying an async func-typed import with the former (easy to do by accident, since func_new_async's name suggests it should work) failed at instantiation with a bare type mismatch with async, with no hint why or what to use instead.

That's the first fix — a shared typecheck_async helper names the specific mismatch and points at the right API, in both directions.

The second is related: Linker::define_unknown_imports_as_traps always stubbed with func_new, so it could never even stub (let alone instantiate) a component with an unsatisfied async import, whether or not the import was ever called. It now stubs with func_new_concurrent when the import is async and Config::concurrency_support is enabled, falling back to func_new otherwise.

Before/after, using the issue's own repro (a WIT world with consume: async func(x: u32) -> string):

Manually satisfying it with func_new_async:

before: type mismatch with async
after:  type mismatch with async: this import is declared `async func` in WIT, but was satisfied with
        a sync-style host function (`func_new`/`func_wrap`, or `func_new_async`/`func_wrap_async` 
        despite the name, these implement a *sync*-WIT-typed function via blocking host code, not an
        `async func` import); use `func_new_concurrent`/`func_wrap_concurrent` instead

Stubbing it via define_unknown_imports_as_traps, where nothing in the component even calls it:

before: define_unknown_imports_as_traps reports success, but instantiate_async fails outright with
        the confusing error above
after:  instantiates fine; calling into the component only traps if the guest actually calls the
        unsatisfied import ("unknown import: ... has not been defined")

Added tests in missing_async.rs (both mismatch directions) and linker.rs (the stubbing fix) — confirmed the new linker test actually fails if just that half of the fix is reverted, so it's catching the real regression. Full component_model suite (224 tests) still green, cargo fmt/clippy clean, compiles with and without the component-model-async feature.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 13:59):

github-actions[bot] added the label wasmtime:api on PR #13821.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 14:27):

:thumbs_up: alexcrichton submitted PR review:

Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 14:27):

alexcrichton added PR #13821 component: improve async-mismatch diagnostics and stub async imports to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 14:53):

:check: alexcrichton merged PR #13821.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 06 2026 at 14:53):

alexcrichton removed PR #13821 component: improve async-mismatch diagnostics and stub async imports from the merge queue.


Last updated: Jul 29 2026 at 05:03 UTC