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

Add thread.spawn_indirect #447

Merged
merged 21 commits into from
Feb 28, 2025
Merged

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Feb 7, 2025

This change codifies the conclusions we arrived to in #89. It adds a new way to spawn threads, thread.spawn_indirect, which retrieves the thread start function from a table. This prompted me to rename thread.spawn to thread.spawn_ref.

abrown added a commit to abrown/wasm-tools that referenced this pull request Feb 7, 2025
This encoding change is necessary due to recent additions to the
component model; see [bytecodealliance#447].

[bytecodealliance#447]: WebAssembly/component-model#447
abrown added a commit to abrown/wasm-tools that referenced this pull request Feb 7, 2025
[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 added a commit to abrown/wasm-tools that referenced this pull request Feb 7, 2025
This encoding change is necessary due to recent additions to the
component model; see [bytecodealliance#447].

[bytecodealliance#447]: WebAssembly/component-model#447
abrown added a commit to abrown/wasm-tools that referenced this pull request Feb 7, 2025
[bytecodealliance#447] tries to make the built-in naming a bit more consistent; this
change propagates that here.

[bytecodealliance#447]: WebAssembly/component-model#447
Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Looks generally good. One initial suggestion:

This change codifies the conclusions we arrived to in [WebAssembly#89]. It adds a
new way to spawn threads, `thread.spawn_indirect`, which retrieves the
thread start function from a table. This prompted me to rename
`thread.spawn` to `thread.spawn_ref`.

[WebAssembly#89]: WebAssembly/shared-everything-threads#89
@abrown abrown marked this pull request as ready for review February 27, 2025 23:08
@abrown
Copy link
Contributor Author

abrown commented Feb 27, 2025

@lukewagner, I had to rebase due to some conflicts but the follow-on commits should have the changes we discussed.

Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Great, thanks! This looks good to me with these suggestions:

Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Last tiny nits:

abrown and others added 2 commits February 28, 2025 11:44
@lukewagner lukewagner merged commit 5c54dcd into WebAssembly:main Feb 28, 2025
1 check passed
@abrown abrown deleted the spawn-indirect branch February 28, 2025 20:27
Comment on lines +3834 to +3835
* `$tbl` must refer to a table with type `(table (ref null (shared func))
shared)`
Copy link
Member

Choose a reason for hiding this comment

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

The table type doesn't seem to follow any syntax defined in the proposal. More importantly, we have subtyping. So I think this ought to say:

* `$tbl` must refer to a shared table whose element type matches `(ref null (shared func))`

Copy link
Member

Choose a reason for hiding this comment

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

Ah, thanks, good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in #462.

abrown added a commit to abrown/component-model that referenced this pull request Mar 5, 2025
This uses the language suggested [here] to document the table type
needed for the `thread.spawn_indirect` canonical builtin.

[here]: WebAssembly#447 (comment)
lukewagner pushed a commit that referenced this pull request Mar 5, 2025
This uses the language suggested [here] to document the table type
needed for the `thread.spawn_indirect` canonical builtin.

[here]: #447 (comment)
abrown added a commit to abrown/wasm-tools that referenced this pull request Mar 17, 2025
[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 added a commit to abrown/wasm-tools that referenced this pull request Mar 17, 2025
This encoding change is necessary due to recent additions to the
component model; see [bytecodealliance#447].

[bytecodealliance#447]: WebAssembly/component-model#447
abrown added a commit to abrown/wasm-tools that referenced this pull request Mar 17, 2025
[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 added a commit to abrown/wasm-tools that referenced this pull request Mar 17, 2025
This encoding change is necessary due to recent additions to the
component model; see [bytecodealliance#447].

[bytecodealliance#447]: WebAssembly/component-model#447
github-merge-queue bot pushed a commit to bytecodealliance/wasm-tools that referenced this pull request Mar 17, 2025
* threads: add `thread.spawn_indirect`

As discussed in [#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`.

[#89]: WebAssembly/shared-everything-threads#89

* threads: rename `thread.spawn` to `thread.spawn_ref`

[#447] tries to make the built-in naming a bit more consistent; this
change propagates that here.

[#447]: WebAssembly/component-model#447

* threads: move `thread.*` canonical opcodes to `0x40+`

This encoding change is necessary due to recent additions to the
component model; see [#447].

[#447]: WebAssembly/component-model#447

* threads: add function types to `thread.spawn_indirect`

Initially I implemented `thread.spawn_indirect` without the ability to
check the type of the function to spawn out of an abundance of caution
(see the implementation issues described in [#89]). In the process of
writing out the specification, we convinced ourselves that these
problems should not apply to `thread.spawn_indirect`.

This change adds the function type index necessary for doing some extra
validation of `thread.spawn_indirect` and adds some tests related to
this. One unimplemented TODO is what to do about shared tables:
technically, the table used by a `thread.spawn_indirect` should be
shared but we have so far prevented this in the component model; this
can be resolved later, though.

[#89]: WebAssembly/shared-everything-threads#89

* review: simplify WAST parsing
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.

3 participants