Skip to content

Updated waitqueue support#8672

Open
stevenfontanella wants to merge 9 commits into
mainfrom
waitqueue
Open

Updated waitqueue support#8672
stevenfontanella wants to merge 9 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
CostType visitStructNotify(StructNotify* curr) {
return AtomicCost + nullCheckCost(curr->ref) + visit(curr->ref) +
visit(curr->count);
CostType visitWaitqueueNew(WaitqueueNew* curr) { return 1; }

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.

Other allocation instructions like visitStructNew or visitArrayNew has AllocationCost in them. Does this not need it?

Comment thread src/ir/effects.h
}
// AtomicNotify doesn't strictly write the struct, but it does
// modify the waiters list associated with the waitqueue field, which we
// AtomicNotify doesn't strictly write anything, but it does

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.

Suggested change
// AtomicNotify doesn't strictly write anything, but it does
// WaitqueueNotify doesn't strictly write anything, but it does

Comment thread src/parser/contexts.h
Comment on lines +267 to +272
HeapTypeT makeWaitqueueType(Shareability share) {
return HeapType(HeapType::waitqueue).getBasic(share);
}
HeapTypeT makeNowaitqueueType(Shareability share) {
return HeapType(HeapType::nowaitqueue).getBasic(share);
}

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.

Suggested change
HeapTypeT makeWaitqueueType(Shareability share) {
return HeapType(HeapType::waitqueue).getBasic(share);
}
HeapTypeT makeNowaitqueueType(Shareability share) {
return HeapType(HeapType::nowaitqueue).getBasic(share);
}
HeapTypeT makeWaitqueueType(Shareability share) {
return HeapTypes::waitqueue.getBasic(share);
}
HeapTypeT makeNowaitqueueType(Shareability share) {
return HeapTypes::nowaitqueue.getBasic(share);
}

Comment on lines +703 to +715
void visitStructWait(StructWait* curr) {
auto type = curr->ref->type.getHeapType();
if (type.isBottom()) {
// This will be emitted as unreachable. Do not require anything of the
// input, except that the ref remain bottom.
clearStack();
push(Type(HeapType::none, Nullable));
return;
}

auto generalized = generalizeStructType(type, curr->index, Type::i32);
push(Type(generalized, 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.

It looks this PR contains the basic infra for waitqueue and doesn't include optimization-pass-specific updates, except for this one. Was this intended to be in a separate PR? Also I think pass-specific updates are better if they have accompanying tests.

}

void visitStructNotify(StructNotify* curr) { WASM_UNREACHABLE("TODO"); }
void visitWaitqueueNew(WaitqueueNew* curr) {}

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.

Other visit***New functions have

    // We cannot yet generalize allocations. Push a requirement for the
    // reference type needed to initialize the array, if any.
    pop();

Doesn't this need that too?

Comment on lines +6648 to +6649
return pick(HeapType(HeapType::waitqueue),
HeapType(HeapType::nowaitqueue))

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.

Suggested change
return pick(HeapType(HeapType::waitqueue),
HeapType(HeapType::nowaitqueue))
assert(wasm.features.hasSharedEverything());
return pick(HeapTypes::waitqueue, HeapTypes::nowaitqueue)

We technically need assert(wasm.features.hasReferenceTypes()); to but it looks that's the case for every case here and some of them have it and the others don't. Can we just put assert(wasm.features.hasReferenceTypes()); in the beginning of the function and remove others?


shouldBeSubType(
curr->waitqueue->type,
Type(HeapType(HeapType::waitqueue).getBasic(Shared), 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.

Suggested change
Type(HeapType(HeapType::waitqueue).getBasic(Shared), Nullable),
Type(HeapTypes::waitqueue.getBasic(Shared), Nullable),


shouldBeSubType(
curr->waitqueue->type,
Type(HeapType(HeapType::waitqueue).getBasic(Shared), 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.

Suggested change
Type(HeapType(HeapType::waitqueue).getBasic(Shared), Nullable),
Type(HeapType::waitqueue.getBasic(Shared), Nullable),

Comment thread src/wasm/wasm.cpp

void StructNotify::finalize() { type = Type::i32; }
void WaitqueueNew::finalize() {
type = Type(HeapType(HeapType::waitqueue).getBasic(Shared), NonNullable);

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.

Suggested change
type = Type(HeapType(HeapType::waitqueue).getBasic(Shared), NonNullable);
type = Type(HeapTypes::waitqueue.getBasic(Shared), NonNullable);

Comment thread src/wasm/wasm-binary.cpp
Comment on lines +1936 to +1938
case HeapType::waitqueue:
case HeapType::nowaitqueue:
break; // No shorthand, encode as ref 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.

Why don't they have shorthands?

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