Skip to content

Conversation

@alexcrichton
Copy link
Member

This commit starts to fill out the support for async in wit-dylib. In doing so this has filled out a number of pieces of functionality elsewhere and implemented more thorough testing. As a result of this some issues were discovered which are also fixed in this PR. Notable changes are:

  • Naming of the task-return intrinsic is now in a helper in wit-parser to avoid needing to duplicate that elsewhere.
  • A new roundtrip test was added to wit-dylib which generates arbitrary WITs and arbitrary values for the WIT and ensures that the values are communicated successfully.
  • Composition code shared between the all and roundtrip tests was moved to the artifacts crate as a shared dependency of the two.
  • In-memory data structures for wit_func_t are updated to reflect async support.
  • Deferred deallocation of bytes is pushed as a responsibility to the embedder. Storing values on the stack was getting too tricky and felt like a too-clever-by-half implementation. To simplify the generated code the responsibility is now on the wit_dylib_* implementor to deallocate bytes in a deferred fashion.
  • The wit-bindgen crate is a dependency of wit-dylib-ffi, the guest bindings of wit_dylib.h, for async support.
  • The wasm-tools wit-dylib subcommand now has configuration, in the same manner as wit-bindgen for which functions should be async and which should be sync.
  • The with_temp_stack helper was removed as that was also getting too tricky to manage and instead functions just always allocate some temporary space.
  • Existing bindings were updated for async functions when that ABI is selected, and new bindings were added for various intrinsics related to the lifecycle of async imports/exports.

Perhaps the biggest feature in this commit is the addition of the roundtrip test which is hoped to provide a much more thorough implementation of testing this crate. Notably it generates an arbitrary WIT structure and additionally generates arbitrary values of this structure. This has weeded out a number of bugs in the bindings generator and necessitated various refactorings here. This is intended to be a crucial part of making this a solid dependency to build on.

This commit starts to fill out the support for async in `wit-dylib`. In
doing so this has filled out a number of pieces of functionality
elsewhere and implemented more thorough testing. As a result of this
some issues were discovered which are also fixed in this PR. Notable
changes are:

* Naming of the `task-return` intrinsic is now in a helper in
  `wit-parser` to avoid needing to duplicate that elsewhere.
* A new `roundtrip` test was added to `wit-dylib` which generates
  arbitrary WITs and arbitrary values for the WIT and ensures that the
  values are communicated successfully.
* Composition code shared between the `all` and `roundtrip` tests was
  moved to the `artifacts` crate as a shared dependency of the two.
* In-memory data structures for `wit_func_t` are updated to reflect
  async support.
* Deferred deallocation of bytes is pushed as a responsibility to the
  embedder. Storing values on the stack was getting too tricky and felt
  like a too-clever-by-half implementation. To simplify the generated
  code the responsibility is now on the `wit_dylib_*` implementor to
  deallocate bytes in a deferred fashion.
* The `wit-bindgen` crate is a dependency of `wit-dylib-ffi`, the guest
  bindings of `wit_dylib.h`, for async support.
* The `wasm-tools wit-dylib` subcommand now has configuration, in the
  same manner as `wit-bindgen` for which functions should be async and
  which should be sync.
* The `with_temp_stack` helper was removed as that was also getting too
  tricky to manage and instead functions just always allocate some
  temporary space.
* Existing bindings were updated for async functions when that ABI is
  selected, and new bindings were added for various intrinsics related
  to the lifecycle of async imports/exports.

Perhaps the biggest feature in this commit is the addition of the
`roundtrip` test which is hoped to provide a much more thorough
implementation of testing this crate. Notably it generates an arbitrary
WIT structure *and additionally* generates arbitrary values of this
structure. This has weeded out a number of bugs in the bindings
generator and necessitated various refactorings here. This is intended
to be a crucial part of making this a solid dependency to build on.
@alexcrichton alexcrichton changed the title Initial skeleton of async support wit-dylib: Initial skeleton of async support Sep 21, 2025
@alexcrichton
Copy link
Member Author

Draft for now until bytecodealliance/wit-bindgen#1390 is merged

@alexcrichton alexcrichton requested a review from dicej September 24, 2025 15:23
@alexcrichton alexcrichton marked this pull request as ready for review September 24, 2025 15:23
@alexcrichton alexcrichton requested a review from a team as a code owner September 24, 2025 15:23
Copy link
Collaborator

@dicej dicej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, I've only skimmed this, but looks reasonable to me.

alexcrichton and others added 2 commits September 29, 2025 17:29
Co-authored-by: Joel Dice <joel.dice@fermyon.com>
Co-authored-by: Joel Dice <joel.dice@fermyon.com>
@alexcrichton alexcrichton added this pull request to the merge queue Sep 29, 2025
Merged via the queue into bytecodealliance:main with commit e898c94 Sep 29, 2025
34 checks passed
@alexcrichton alexcrichton deleted the wit-dylib-async branch September 29, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants