Skip to content

Updated waitqueue support#8672

Open
stevenfontanella wants to merge 11 commits into
mainfrom
waitqueue
Open

Updated waitqueue support#8672
stevenfontanella wants to merge 11 commits into
mainfrom
waitqueue

Conversation

@stevenfontanella

@stevenfontanella stevenfontanella commented May 5, 2026

Copy link
Copy Markdown
Member

Part of #8315. Implements the updated design from https://github.com/WebAssembly/shared-everything-threads/blob/main/proposals/shared-everything-threads/Overview.md#managed-waiter-queues / WebAssembly/shared-everything-threads#110. Also see the discussion in WebAssembly/shared-everything-threads#102. This PR implements struct.wait for i32 fields only at the moment (like in V8).

Binary constants are not spec'ed yet and taken from https://chromium-review.googlesource.com/c/v8/v8/+/7790723.

Remaining after this PR:

  • struct.wait for any field that is eqref
  • Fuzzer support (generating instructions that are guaranteed not to block).

@stevenfontanella stevenfontanella force-pushed the waitqueue branch 10 times, most recently from a621ae7 to 5944f1c Compare May 12, 2026 20:12
@stevenfontanella stevenfontanella force-pushed the waitqueue branch 2 times, most recently from fbb212f to 7984294 Compare May 12, 2026 22:20
@stevenfontanella stevenfontanella marked this pull request as ready for review July 8, 2026 19:31
@stevenfontanella stevenfontanella requested a review from a team as a code owner July 8, 2026 19:31
@stevenfontanella stevenfontanella requested review from aheejin and removed request for a team July 8, 2026 19:31

@aheejin aheejin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late reply!
Haven't read everything yet, but some nits and questions:

Comment thread src/ir/cost.h Outdated
Comment thread src/ir/effects.h Outdated
Comment thread src/parser/contexts.h
Comment thread src/passes/TypeGeneralizing.cpp Outdated
Comment thread src/passes/TypeGeneralizing.cpp Outdated
Comment thread src/tools/fuzzing/fuzzing.cpp Outdated
Comment thread src/wasm/wasm-validator.cpp Outdated
Comment thread src/wasm/wasm-validator.cpp Outdated
Comment thread src/wasm/wasm.cpp Outdated
Comment thread src/wasm/wasm-binary.cpp Outdated
Comment thread src/wasm/literal.cpp
Comment thread src/wasm/wasm-type.cpp
Comment thread src/wasm/wasm-type.cpp Outdated
Comment thread src/wasm/wasm-type.cpp
Comment thread src/wasm/wasm-type.cpp Outdated
Comment thread src/binaryen-c.cpp
Comment thread src/binaryen-c.cpp
Comment thread src/wasm-delegations-fields.def Outdated
Comment thread src/wasm-interpreter.h Outdated
Comment thread src/wasm-interpreter.h
Comment thread src/ir/child-typer.h
}

note(&curr->ref, Type(*ht, Nullable));
note(&curr->waitqueue, Type(HeapType::waitqueue, Nullable));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The waitqueue heap type should be shared here.

Comment thread src/ir/child-typer.h

note(&curr->ref, Type(*ht, Nullable));
void visitWaitqueueNotify(WaitqueueNotify* curr) {
note(&curr->waitqueue, Type(HeapType::waitqueue, Nullable));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here.

Comment thread src/ir/module-utils.cpp
Comment on lines +457 to +460
void visitWaitqueueNew(WaitqueueNew* curr) { info.note(curr->type); }
void visitWaitqueueNotify(WaitqueueNotify* curr) {
info.note(curr->waitqueue->type);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to have visitors for waitqueue.new and waitqueue.notify. They don't have type immediates in the binary or text formats and they don't use any defined types that we have to make sure to keep around.

Comment thread src/ir/properties.cpp
void visitArrayNewElem(ArrayNewElem* curr) { generative = true; }
void visitArrayNewFixed(ArrayNewFixed* curr) { generative = true; }
void visitContNew(ContNew* curr) { generative = true; }
void visitWaitqueueNew(WaitqueueNew* curr) { generative = true; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

notify should probably also be considered generative, since calling it more than once can produce different results each time. Although it looks like the linear memory notify is not considered generative... Maybe just a TODO for now, then.

auto null =
builder.makeRefNull(HeapType(HeapType::waitqueue).getBasic(share));
if (!type.isNullable()) {
return builder.makeRefAs(RefAsNonNull, null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should add an assertion that we're in a function context here. If we're not, for example because we are creating a global initializer, then we would generate invalid IR here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't realize this but from looking at the other code, it looks like it's expected that we may generate invalid IR here and the caller will fix it up later: 1 2. Basically after generating ref.as_non_null (ref.null waitqueue), the calling code in setupGlobals would just change this into an MVP type. Added a comment here and updated the comment in the second code link for now.

And looking more, it seems like this may hit a bug for table initializers, because we use makeConst in them, which flows to this code (and other code in this function that can generate ref.as_non_null), and never gets fixed up like globals do. Will fix this separately.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Filed #8911 about this.

Comment thread src/wasm/wasm-ir-builder.cpp
Comment thread src/wasm/wasm-ir-builder.cpp
Comment thread src/wasm/wasm-type.cpp
Comment thread src/literal.h
Comment thread src/wasm-type.h
constexpr HeapType array = HeapType::array;
constexpr HeapType exn = HeapType::exn;
constexpr HeapType string = HeapType::string;
constexpr HeapType waitqueue = HeapType::waitqueue;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe as a special case we should have constexpr HeapType sharedWaitqueue as well because the unshared version is so useless. OTOH, maybe consistency is more important.

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