Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threads: add thread.spawn_indirect #2042

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

abrown
Copy link
Collaborator

@abrown abrown commented Feb 7, 2025

This propagates the upstream spec changes to the component model in #447 here. See commit messages for more details.

As discussed in [bytecodealliance#89], this adds support for a new intrinsic,
`thread.spawn_indirect`. This new operation would allow spawning a
shared function stored in a table via a table index.

This leaves some future work undone:
- `thread.spawn` could/should be renamed to `thread.spawn_ref`
- `thread.spawn_indirect` could/should take the encoding byte from
  `thread.hw_concurrency`--swap `0x07` for `0x06`
- importantly, `thread.spawn_indirect` should gain a field indicating
  which type to expect in the indirect table; due to current limitations
  in `wasm-tools`, the locations to check once this is possible are
  marked with `TODO: spawn indirect types`.

[bytecodealliance#89]: WebAssembly/shared-everything-threads#89
This encoding change is necessary due to recent additions to the
component model; see [bytecodealliance#447].

[bytecodealliance#447]: WebAssembly/component-model#447
[bytecodealliance#447] tries to make the built-in naming a bit more consistent; this
change propagates that here.

[bytecodealliance#447]: WebAssembly/component-model#447
@abrown abrown force-pushed the set-spawn-indirect branch from cfc0969 to 7d7f530 Compare February 7, 2025 19:16
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.

Looks good, thanks! Mind adding a test as well for using a table of the wrong type? (e.g. a non-shared funcref or a shared-externref)

Comment on lines +288 to +290
0x24 => CanonicalFunction::ThreadSpawnIndirect {
table_index: reader.read()?,
},
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense logically to put here but for easily scanning this list mind moving it down to the bottom so it's more clear where the "holes" are in decoding?

Comment on lines +391 to +394
// Eventually this should resolve the specific type associated
// with this canonical function, e.g.,
// `self.resolve_type_use(&mut info.ty)?;` (TODO: spawn indirect
// types).
Copy link
Member

Choose a reason for hiding this comment

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

Adding a comment to flag this. This looks though like it's a TODO at the spec-level, right? (as opposed to just exclusively the implementation here)

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