Skip to content

Commit f3388dc

Browse files
Fix
Require GC for waitqueues Fix destructor issue
1 parent 4d8ac54 commit f3388dc

7 files changed

Lines changed: 45 additions & 25 deletions

File tree

‎src/tools/fuzzing/fuzzing.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,8 @@ Expression* TranslateToFuzzReader::_makeConcrete(Type type) {
28942894
&Self::makeStringEq,
28952895
&Self::makeStringMeasure,
28962896
&Self::makeStringGet);
2897-
options.add(FeatureSet::ReferenceTypes | FeatureSet::SharedEverything,
2897+
options.add(FeatureSet::ReferenceTypes | FeatureSet::GC |
2898+
FeatureSet::SharedEverything,
28982899
&Self::makeWaitqueueNotify);
28992900
if (!structWaitFields.empty()) {
29002901
options.add(FeatureSet::ReferenceTypes | FeatureSet::GC |

‎src/tools/wasm-ctor-eval.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
956956
} else if (heapType.isArray()) {
957957
// TODO: for repeated identical values, can use ArrayNew
958958
init = builder.makeArrayNewFixed(heapType, args);
959+
} else if (heapType == HeapTypes::sharedWaitqueue) {
960+
init = builder.makeWaitqueueNew();
959961
} else {
960962
WASM_UNREACHABLE("bad gc type");
961963
}

‎src/wasm-type.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,8 @@ inline bool HeapType::isFunction() const {
11941194

11951195
inline bool HeapType::isData() const {
11961196
auto kind = getKind();
1197-
return isMaybeShared(string) || kind == HeapTypeKind::Struct ||
1198-
kind == HeapTypeKind::Array;
1197+
return isMaybeShared(string) || isMaybeShared(waitqueue) ||
1198+
kind == HeapTypeKind::Struct || kind == HeapTypeKind::Array;
11991199
}
12001200

12011201
inline bool HeapType::isSignature() const {

‎src/wasm/literal.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Literal::Literal(Type type) : type(type) {
7373

7474
if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::waitqueue)) {
7575
assert(type.isNonNullable());
76+
// See ~Literal and isData(). isData() is true for waitqueues so we expect
77+
// gcData to be present even if null.
78+
new (&gcData) std::shared_ptr<GCData>();
7679
return;
7780
}
7881

@@ -113,7 +116,6 @@ Literal::Literal(std::shared_ptr<GCData> gcData, HeapType type)
113116
assert((isData() && gcData) ||
114117
(type.isMaybeShared(HeapType::ext) && gcData) ||
115118
(type.isMaybeShared(HeapType::string) && gcData) ||
116-
(type.isMaybeShared(HeapType::waitqueue) && gcData) ||
117119
(type.isMaybeShared(HeapType::any) && gcData) ||
118120
(type.isBottom() && !gcData));
119121
}
@@ -189,7 +191,6 @@ Literal::Literal(const Literal& other) : type(other.type) {
189191
return;
190192
case HeapType::ext:
191193
case HeapType::any:
192-
case HeapType::waitqueue:
193194
// Externalized or internalized reference/payload.
194195
new (&gcData) std::shared_ptr<GCData>(other.gcData);
195196
return;
@@ -205,6 +206,7 @@ Literal::Literal(const Literal& other) : type(other.type) {
205206
case HeapType::cont:
206207
case HeapType::struct_:
207208
case HeapType::array:
209+
case HeapType::waitqueue:
208210
WASM_UNREACHABLE("invalid type");
209211
case HeapType::string:
210212
WASM_UNREACHABLE("TODO: string literals");
@@ -371,10 +373,8 @@ std::shared_ptr<FuncData> Literal::getFuncData() const {
371373
}
372374

373375
std::shared_ptr<GCData> Literal::getGCData() const {
374-
assert(
375-
isNull() || isData() ||
376-
(type.isRef() && (type.getHeapType().isMaybeShared(HeapType::ext) ||
377-
type.getHeapType().isMaybeShared(HeapType::waitqueue))));
376+
assert(isNull() || isData() ||
377+
(type.isRef() && (type.getHeapType().isMaybeShared(HeapType::ext))));
378378
return gcData;
379379
}
380380

‎src/wasm/wasm-type.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ FeatureSet HeapType::getFeatures() const {
12941294
return;
12951295
case HeapType::waitqueue:
12961296
case HeapType::nowaitqueue:
1297-
feats |= FeatureSet::ReferenceTypes | FeatureSet::SharedEverything;
1297+
feats |= FeatureSet::ReferenceTypes | FeatureSet::GC |
1298+
FeatureSet::SharedEverything;
12981299
return;
12991300
case HeapType::noext:
13001301
case HeapType::nofunc:

‎src/wasm/wasm-validator.cpp‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,10 +3696,13 @@ void FunctionValidator::visitStructCmpxchg(StructCmpxchg* curr) {
36963696
}
36973697

36983698
void FunctionValidator::visitStructWait(StructWait* curr) {
3699-
shouldBeTrue(
3700-
!getModule() || getModule()->features.hasSharedEverything(),
3701-
curr,
3702-
"struct.wait requires shared-everything [--enable-shared-everything]");
3699+
FeatureSet expected =
3700+
FeatureSet::GC | FeatureSet::SharedEverything | FeatureSet::ReferenceTypes;
3701+
if (!shouldBeTrue(expected.isSubsetOf(getModule()->features),
3702+
curr,
3703+
"struct.wait requires additional features")) {
3704+
getStream() << getMissingFeaturesList(*getModule(), expected) << '\n';
3705+
}
37033706

37043707
shouldBeSubType(curr->waitqueue->type,
37053708
Type(HeapTypes::sharedWaitqueue, Nullable),
@@ -3747,17 +3750,23 @@ void FunctionValidator::visitStructWait(StructWait* curr) {
37473750
}
37483751

37493752
void FunctionValidator::visitWaitqueueNew(WaitqueueNew* curr) {
3750-
shouldBeTrue(
3751-
!getModule() || getModule()->features.hasSharedEverything(),
3752-
curr,
3753-
"waitqueue.new requires shared-everything [--enable-shared-everything]");
3753+
FeatureSet expected =
3754+
FeatureSet::GC | FeatureSet::SharedEverything | FeatureSet::ReferenceTypes;
3755+
if (!shouldBeTrue(expected.isSubsetOf(getModule()->features),
3756+
curr,
3757+
"waitqueue.new requires additional features")) {
3758+
getStream() << getMissingFeaturesList(*getModule(), expected) << '\n';
3759+
}
37543760
}
37553761

37563762
void FunctionValidator::visitWaitqueueNotify(WaitqueueNotify* curr) {
3757-
shouldBeTrue(
3758-
!getModule() || getModule()->features.hasSharedEverything(),
3759-
curr,
3760-
"waitqueue.notify requires shared-everything [--enable-shared-everything]");
3763+
FeatureSet expected =
3764+
FeatureSet::GC | FeatureSet::SharedEverything | FeatureSet::ReferenceTypes;
3765+
if (!shouldBeTrue(expected.isSubsetOf(getModule()->features),
3766+
curr,
3767+
"waitqueue.notify requires additional features")) {
3768+
getStream() << getMissingFeaturesList(*getModule(), expected) << '\n';
3769+
}
37613770

37623771
shouldBeSubType(
37633772
curr->waitqueue->type,

‎test/lit/validation/waitqueue.wast‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
;; RUN: not wasm-opt --enable-reference-types --enable-gc %s 2>&1 | filecheck %s
1+
;; RUN: not wasm-opt %s 2>&1 | filecheck %s
22

33
;; Tests feature-related validations.
44
;; Other validations are in the spec test spec/waitqueue.wast.
55
(module
66
(type $struct (struct (field i32)))
7-
;; CHECK: waitqueue.new requires shared-everything [--enable-shared-everything]
7+
;; CHECK: waitqueue.new requires additional features
8+
;; CHECK: [--enable-reference-types --enable-gc --enable-shared-everything]
89
(func $new
910
(drop (waitqueue.new))
1011
)
11-
;; CHECK: struct.wait requires shared-everything [--enable-shared-everything]
12+
;; CHECK: waitqueue.notify requires additional features
13+
;; CHECK: [--enable-reference-types --enable-gc --enable-shared-everything]
14+
(func $notify (param $wq (ref null (shared waitqueue)))
15+
(drop (waitqueue.notify (local.get $wq) (i32.const 1)))
16+
)
17+
;; CHECK: struct.wait requires additional features
18+
;; CHECK: [--enable-reference-types --enable-gc --enable-shared-everything]
1219
(func $wait-no-feature (param $ref (ref $struct)) (param $wq (ref null (shared waitqueue)))
1320
(drop (struct.wait $struct 0 (local.get $ref) (local.get $wq) (i32.const 0) (i64.const 0)))
1421
)

0 commit comments

Comments
 (0)