Skip to content

Commit bd62ca8

Browse files
waitqueue.wait
1 parent 74a471c commit bd62ca8

30 files changed

+219
-4
lines changed

scripts/gen-s-parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@
608608
("resume_throw", "makeResumeThrow()"),
609609
("resume_throw_ref", "makeResumeThrowRef()"),
610610
("switch", "makeStackSwitch()"),
611+
("waitqueue.wait", "makeWaitQueueWait()"),
611612
# GC
612613
("ref.i31", "makeRefI31(Unshared)"),
613614
("ref.i31_shared", "makeRefI31(Shared)"),

src/gen-s-parser.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5784,6 +5784,12 @@ switch (buf[0]) {
57845784
default: goto parse_error;
57855785
}
57865786
}
5787+
case 'w':
5788+
if (op == "waitqueue.wait"sv) {
5789+
CHECK_ERR(makeWaitQueueWait(ctx, pos, annotations));
5790+
return Ok{};
5791+
}
5792+
goto parse_error;
57875793
default: goto parse_error;
57885794
}
57895795
parse_error:

src/interpreter/interpreter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ struct ExpressionInterpreter : OverriddenVisitor<ExpressionInterpreter, Flow> {
283283
Flow visitResume(Resume* curr) { WASM_UNREACHABLE("TODO"); }
284284
Flow visitResumeThrow(ResumeThrow* curr) { WASM_UNREACHABLE("TODO"); }
285285
Flow visitStackSwitch(StackSwitch* curr) { WASM_UNREACHABLE("TODO"); }
286+
Flow visitWaitQueueWait(WaitQueueWait* curr) { WASM_UNREACHABLE("TODO"); }
286287
};
287288

288289
} // anonymous namespace

src/ir/ReFinalize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ void ReFinalize::visitResumeThrow(ResumeThrow* curr) {
202202
}
203203
}
204204
void ReFinalize::visitStackSwitch(StackSwitch* curr) { curr->finalize(); }
205+
void ReFinalize::visitWaitQueueWait(WaitQueueWait* curr) { curr->finalize(); }
205206

206207
void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE("unimp"); }
207208
void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE("unimp"); }

src/ir/child-typer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,15 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
13571357
}
13581358
note(&curr->cont, Type(*ct, Nullable));
13591359
}
1360+
1361+
void visitWaitQueueWait(WaitQueueWait* curr) {
1362+
note(&curr->waitqueue,
1363+
Type(HeapType(Struct(std::vector{
1364+
Field(Field::PackedType::WaitQueue, Mutability::Immutable)})),
1365+
NonNullable));
1366+
note(&curr->value, Type(Type::BasicType::i32));
1367+
note(&curr->timeout, Type(Type::BasicType::i64));
1368+
}
13601369
};
13611370

13621371
} // namespace wasm

src/ir/cost.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
118118
return AtomicCost + visit(curr->ptr) + visit(curr->expected) +
119119
visit(curr->timeout);
120120
}
121+
CostType visitWaitQueueWait(WaitQueueWait* curr) {
122+
return AtomicCost + visit(curr->waitqueue) + visit(curr->value) +
123+
visit(curr->timeout);
124+
}
121125
CostType visitAtomicNotify(AtomicNotify* curr) {
122126
return AtomicCost + visit(curr->ptr) + visit(curr->notifyCount);
123127
}

src/ir/effects.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,19 @@ class EffectAnalyzer {
11591159
parent.throws_ = true;
11601160
}
11611161
}
1162+
1163+
void visitWaitQueueWait(WaitQueueWait* curr) {
1164+
parent.isAtomic = true;
1165+
parent.mayNotReturn = true;
1166+
1167+
// field 0 must exist and be a packed waitqueue if this is valid Wasm.
1168+
if (curr->waitqueue->type.getHeapType()
1169+
.getStruct()
1170+
.fields.at(0)
1171+
.mutable_ == Mutable) {
1172+
parent.readsMutableStruct = true;
1173+
}
1174+
}
11621175
};
11631176

11641177
public:

src/ir/module-utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ struct CodeScanner : PostWalker<CodeScanner> {
446446
info.note(curr->cont->type);
447447
info.note(curr->type);
448448
}
449+
void visitWaitQueueWait(WaitQueueWait* curr) {
450+
info.note(curr->waitqueue->type);
451+
}
449452
void visitBlock(Block* curr) {
450453
info.noteControlFlow(Signature(Type::none, curr->type));
451454
}

src/ir/possible-contents.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,9 @@ struct InfoCollector
14011401
// TODO: optimize when possible
14021402
addRoot(curr);
14031403
}
1404+
void visitWaitQueueWait(WaitQueueWait* curr) {
1405+
// todo
1406+
}
14041407

14051408
void visitFunction(Function* func) {
14061409
// Functions with a result can flow a value out from their body.

src/ir/subtype-exprs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
598598
.type.getSignature();
599599
self()->noteSubtype(currResult, retSig.results);
600600
}
601+
// todo?
602+
void visitWaitQueueWait(WaitQueueWait* curr) {}
601603
};
602604

603605
} // namespace wasm

0 commit comments

Comments
 (0)