Updated waitqueue support#8672
Conversation
a621ae7 to
5944f1c
Compare
fbb212f to
7984294
Compare
7984294 to
ec73bbe
Compare
aheejin
left a comment
There was a problem hiding this comment.
Sorry for the late reply!
Haven't read everything yet, but some nits and questions:
| CostType visitStructNotify(StructNotify* curr) { | ||
| return AtomicCost + nullCheckCost(curr->ref) + visit(curr->ref) + | ||
| visit(curr->count); | ||
| CostType visitWaitqueueNew(WaitqueueNew* curr) { return 1; } |
There was a problem hiding this comment.
Other allocation instructions like visitStructNew or visitArrayNew has AllocationCost in them. Does this not need it?
| } | ||
| // 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 |
There was a problem hiding this comment.
| // AtomicNotify doesn't strictly write anything, but it does | |
| // WaitqueueNotify doesn't strictly write anything, but it does |
| HeapTypeT makeWaitqueueType(Shareability share) { | ||
| return HeapType(HeapType::waitqueue).getBasic(share); | ||
| } | ||
| HeapTypeT makeNowaitqueueType(Shareability share) { | ||
| return HeapType(HeapType::nowaitqueue).getBasic(share); | ||
| } |
There was a problem hiding this comment.
| 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); | |
| } |
| 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)); | ||
| } |
There was a problem hiding this comment.
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) {} |
There was a problem hiding this comment.
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?
| return pick(HeapType(HeapType::waitqueue), | ||
| HeapType(HeapType::nowaitqueue)) |
There was a problem hiding this comment.
| 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), |
There was a problem hiding this comment.
| Type(HeapType(HeapType::waitqueue).getBasic(Shared), Nullable), | |
| Type(HeapTypes::waitqueue.getBasic(Shared), Nullable), |
|
|
||
| shouldBeSubType( | ||
| curr->waitqueue->type, | ||
| Type(HeapType(HeapType::waitqueue).getBasic(Shared), Nullable), |
There was a problem hiding this comment.
| Type(HeapType(HeapType::waitqueue).getBasic(Shared), Nullable), | |
| Type(HeapType::waitqueue.getBasic(Shared), Nullable), |
|
|
||
| void StructNotify::finalize() { type = Type::i32; } | ||
| void WaitqueueNew::finalize() { | ||
| type = Type(HeapType(HeapType::waitqueue).getBasic(Shared), NonNullable); |
There was a problem hiding this comment.
| type = Type(HeapType(HeapType::waitqueue).getBasic(Shared), NonNullable); | |
| type = Type(HeapTypes::waitqueue.getBasic(Shared), NonNullable); |
| case HeapType::waitqueue: | ||
| case HeapType::nowaitqueue: | ||
| break; // No shorthand, encode as ref null |
There was a problem hiding this comment.
Why don't they have shorthands?
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:
eqref