Skip to content

Conversation

TartanLlama
Copy link
Contributor

@TartanLlama TartanLlama commented Sep 4, 2025

Implements WebAssembly/component-model#557

  • Renames async variants of waitable-set.wait, waitable-set.poll, and yield to cancellable
  • Renames yield to thread.yield
  • Adds [cancellable] legacy name mangling prefix
  • Adds support to wasmparser, wasm-encoder, and wit-component for the new builtins:
    • thread.index
    • thread.new_indirect
    • thread.switch-to
    • thread.suspend
    • thread.resume-later
    • thread.yield-to
  • Replaces the cm_async_stackful and cm_async_builtins features with cm_threading
  • Makes context.get and context.set callable with a cell ref of 1 in addition to 0
  • Updates all tests for breaking changes
  • Adds tests for new functionality

The thread.new_indirect builtin required adding support for tracking exports of funcref tables so that an alias can be made for the table that stores the thread start function, which is then referenced by (canon thread.new_indirect ..)

Marking as a draft for now while I play around with wasmtime support.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

This is looking great! Thanks again for working on this!

Comment on lines +1 to +2
;; RUN: wast % --assert default --snapshot tests/snapshots \
;; -f=cm-async,-cm-threading
Copy link
Member

Choose a reason for hiding this comment

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

I think it'll be worth splitting this test in two: one for -cm-threading which asserts that all the various constructs are indeed an error if they're present. Then a separate test as well for cm-threading which asserts that the constructs are all valid. The valid test would also test things like: the table must be of the right type, each intrinsic produces a core wasm function of an expected signature, validation of intrinsic arguments like the function type to spawn, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, thanks!

It's ok to leave that as-is in this PR, but if you're up for it the file structure here was already a bit messy and needs cleanup. We had a number of tests originally added for component-model-async and then retroactively we carved out part of the specification under new feature flags. At that time we didn't actually split any tests so the tests are still all lumped together. For new features though it's typically best to have all the tests in a new file as opposed to intermingling with old tests.

Although as I type this out I realize that this hinges on the merging-or-not of the old features into the threading feature. I'm assuming in my head that we won't want to do that, but if we did move forward with that what I'm describing is probably already matching the current organization.

Basically it's fine to disregard this for now, I can always try to come back to it later.

Comment on lines 1775 to 1956
fn yield_(&self) -> Option<&str> {
Some("[yield]")
fn thread_yield(&self) -> Option<&str> {
Some("[thread-yield]")
}
Copy link
Member

Choose a reason for hiding this comment

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

One thing I mentioned earlier today was we need to be careful about this change because we can get ourselves into a theoretical state where we can't update either wit-bindgen or wasmtime. Thinking about this specific change though I think we should be ok if we update wit-bindgen first. In updating wit-bindgen's usage of wasm-tools we'll update the name emitted in core wasm, but the binary encoding in the component will stay the same so it'll still work in Wasmtime today. After wit-bindgen is updated we can update Wasmtime's version of wasm-tools which will also require updating wit-bindgen at the same time since wasmtime's tests use wit-bindgen and the yield intrinsic.

Basically I wanted to write down "I don't think we need to handle the old name" which is nice, yay! Just requires updating wit-bindgen once this is published, then updating wasmtime.

@alexcrichton
Copy link
Member

For the CI failure to resolve that you might need to blow away tests/snapshots and then recreate it with BLESS=1 to delete the now-stale files

@alexcrichton
Copy link
Member

@TartanLlama WDYT about merging this? I was thinking I'd try to tackle WebAssembly/component-model#560 today and I don't want to cause unnecessary merge conflicts for this

@TartanLlama TartanLlama marked this pull request as ready for review September 9, 2025 15:56
@TartanLlama TartanLlama requested a review from a team as a code owner September 9, 2025 15:56
@TartanLlama TartanLlama requested review from pchickey and removed request for a team September 9, 2025 15:56
@TartanLlama
Copy link
Contributor Author

TartanLlama commented Sep 9, 2025

@TartanLlama WDYT about merging this?

Fine by me!

@alexcrichton alexcrichton added this pull request to the merge queue Sep 9, 2025
Merged via the queue into bytecodealliance:main with commit fd0a4f8 Sep 9, 2025
34 checks passed
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