Skip to content

Commit 97dcca4

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

7 files changed

Lines changed: 34 additions & 13 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,9 @@ 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+
// TODO: what about non-shared or null waitqueue?
961+
init = builder.makeWaitqueueNew();
959962
} else {
960963
WASM_UNREACHABLE("bad gc type");
961964
}

‎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: 5 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;
@@ -371,10 +372,8 @@ std::shared_ptr<FuncData> Literal::getFuncData() const {
371372
}
372373

373374
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))));
375+
assert(isNull() || isData() ||
376+
(type.isRef() && (type.getHeapType().isMaybeShared(HeapType::ext))));
378377
return gcData;
379378
}
380379

‎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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,9 @@ void FunctionValidator::visitStructWait(StructWait* curr) {
37003700
!getModule() || getModule()->features.hasSharedEverything(),
37013701
curr,
37023702
"struct.wait requires shared-everything [--enable-shared-everything]");
3703+
shouldBeTrue(!getModule() || getModule()->features.hasGC(),
3704+
curr,
3705+
"struct.wait requires gc [--enable-gc]");
37033706

37043707
shouldBeSubType(curr->waitqueue->type,
37053708
Type(HeapTypes::sharedWaitqueue, Nullable),
@@ -3751,13 +3754,19 @@ void FunctionValidator::visitWaitqueueNew(WaitqueueNew* curr) {
37513754
!getModule() || getModule()->features.hasSharedEverything(),
37523755
curr,
37533756
"waitqueue.new requires shared-everything [--enable-shared-everything]");
3757+
shouldBeTrue(!getModule() || getModule()->features.hasGC(),
3758+
curr,
3759+
"waitqueue.new requires gc [--enable-gc]");
37543760
}
37553761

37563762
void FunctionValidator::visitWaitqueueNotify(WaitqueueNotify* curr) {
37573763
shouldBeTrue(
37583764
!getModule() || getModule()->features.hasSharedEverything(),
37593765
curr,
37603766
"waitqueue.notify requires shared-everything [--enable-shared-everything]");
3767+
shouldBeTrue(!getModule() || getModule()->features.hasGC(),
3768+
curr,
3769+
"waitqueue.notify requires gc [--enable-gc]");
37613770

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

‎test/lit/validation/waitqueue.wast‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
;; RUN: not wasm-opt --enable-reference-types --enable-gc %s 2>&1 | filecheck %s
1+
;; RUN: not wasm-opt --enable-reference-types --enable-gc %s 2>&1 | filecheck %s --check-prefix=NO-SHARED
2+
;; RUN: not wasm-opt --enable-reference-types --enable-shared-everything %s 2>&1 | filecheck %s --check-prefix=NO-GC
23

34
;; Tests feature-related validations.
45
;; Other validations are in the spec test spec/waitqueue.wast.
56
(module
67
(type $struct (struct (field i32)))
7-
;; CHECK: waitqueue.new requires shared-everything [--enable-shared-everything]
8+
;; NO-SHARED: waitqueue.new requires shared-everything [--enable-shared-everything]
9+
;; NO-GC: waitqueue.new requires gc [--enable-gc]
810
(func $new
911
(drop (waitqueue.new))
1012
)
11-
;; CHECK: struct.wait requires shared-everything [--enable-shared-everything]
13+
;; NO-SHARED: waitqueue.notify requires shared-everything [--enable-shared-everything]
14+
;; NO-GC: waitqueue.notify requires gc [--enable-gc]
15+
(func $notify (param $wq (ref null (shared waitqueue)))
16+
(drop (waitqueue.notify (local.get $wq) (i32.const 1)))
17+
)
18+
;; NO-SHARED: struct.wait requires shared-everything [--enable-shared-everything]
19+
;; NO-GC: struct.wait requires gc [--enable-gc]
1220
(func $wait-no-feature (param $ref (ref $struct)) (param $wq (ref null (shared waitqueue)))
1321
(drop (struct.wait $struct 0 (local.get $ref) (local.get $wq) (i32.const 0) (i64.const 0)))
1422
)

0 commit comments

Comments
 (0)