Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,8 @@ Expression* TranslateToFuzzReader::_makeConcrete(Type type) {
&Self::makeStringEq,
&Self::makeStringMeasure,
&Self::makeStringGet);
options.add(FeatureSet::ReferenceTypes | FeatureSet::SharedEverything,
options.add(FeatureSet::ReferenceTypes | FeatureSet::GC |
FeatureSet::SharedEverything,
&Self::makeWaitqueueNotify);
if (!structWaitFields.empty()) {
options.add(FeatureSet::ReferenceTypes | FeatureSet::GC |
Expand Down
12 changes: 7 additions & 5 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,11 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
value.type.getHeapType().isMaybeShared(HeapType::i31));
}

// GC data (structs and arrays) must be handled with the special global-
// creating logic later down. But MVP types as well as i31s (even
// externalized i31s) can be handled by the general makeConstantExpression
// logic (which knows how to handle externalization, for i31s; and it also
// can handle string constants).
// GC data (structs, arrays, and waitqueues) must be handled with the
// special global- creating logic later down. But MVP types as well as i31s
// (even externalized i31s) can be handled by the general
// makeConstantExpression logic (which knows how to handle externalization,
// for i31s; and it also can handle string constants).
if (!value.isData() || value.isString()) {
return builder.makeConstantExpression(original);
}
Expand Down Expand Up @@ -956,6 +956,8 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
} else if (heapType.isArray()) {
// TODO: for repeated identical values, can use ArrayNew
init = builder.makeArrayNewFixed(heapType, args);
} else if (heapType == HeapTypes::sharedWaitqueue) {
init = builder.makeWaitqueueNew();
} else {
WASM_UNREACHABLE("bad gc type");
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,8 @@ inline bool HeapType::isFunction() const {

inline bool HeapType::isData() const {
auto kind = getKind();
return isMaybeShared(string) || kind == HeapTypeKind::Struct ||
kind == HeapTypeKind::Array;
return isMaybeShared(string) || isMaybeShared(waitqueue) ||
kind == HeapTypeKind::Struct || kind == HeapTypeKind::Array;
Comment on lines +1197 to +1198

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.

This change is surprising to me, since waitqueues don't seem like transparent holders of other data the way structs and arrays are. And it seems like this change is the cause of several of the other changes. What's the motivation here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this in the PR description, the idea is that isData is now true which hits a different code path in ctor-eval: link.

Alternatively we could just add an extra check for waitqueue here in addition to isData, but my thinking is that waitqueues really are GC data, and other passes that look at isData are more likely to want to treat them that way (which this case is evidence of).

From a quick look, it looks like this is the only pass that's affected in terms of real logic at the moment:
https://github.com/search?q=repo%3AWebAssembly%2Fbinaryen+%2F%5CbisData%28%29%5Cb%2F&type=code

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.

That code path is using !value.isData() || value.isString() to mean "requires special global-creating logic." I think it would make more sense to update that code path to explicitly include waitqueues than it would to include waitqueues in isData.

FWIW, isData is essentially a historical accident. At one point during the development of the GC proposal, there was a data type that was a supertype of structs and arrays. The type was removed, but we kept isData() because it was shorter than writing isStruct() || isArray() everywhere. It's possible that it globally make the codebase clearer if we removed it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that waitqueue is 'similar' to struct and array that way; they are all stateful GC objects. Sounds good though, I don't have a strong opinion. waitqueue is definitely different in some ways.

FWIW it looks like we still use gcData as the identity of the global that we synthesize link. This looks like a problem with the current PR because we always use nullptr so there's no identity here link. Let me take a look and fix it.

}

inline bool HeapType::isSignature() const {
Expand Down
12 changes: 6 additions & 6 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Literal::Literal(Type type) : type(type) {

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

Expand Down Expand Up @@ -113,7 +116,6 @@ Literal::Literal(std::shared_ptr<GCData> gcData, HeapType type)
assert((isData() && gcData) ||
(type.isMaybeShared(HeapType::ext) && gcData) ||
(type.isMaybeShared(HeapType::string) && gcData) ||
(type.isMaybeShared(HeapType::waitqueue) && gcData) ||
(type.isMaybeShared(HeapType::any) && gcData) ||
(type.isBottom() && !gcData));
}
Expand Down Expand Up @@ -189,7 +191,6 @@ Literal::Literal(const Literal& other) : type(other.type) {
return;
case HeapType::ext:
case HeapType::any:
case HeapType::waitqueue:
// Externalized or internalized reference/payload.
new (&gcData) std::shared_ptr<GCData>(other.gcData);
return;
Expand All @@ -205,6 +206,7 @@ Literal::Literal(const Literal& other) : type(other.type) {
case HeapType::cont:
case HeapType::struct_:
case HeapType::array:
case HeapType::waitqueue:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
WASM_UNREACHABLE("TODO: string literals");
Expand Down Expand Up @@ -371,10 +373,8 @@ std::shared_ptr<FuncData> Literal::getFuncData() const {
}

std::shared_ptr<GCData> Literal::getGCData() const {
assert(
isNull() || isData() ||
(type.isRef() && (type.getHeapType().isMaybeShared(HeapType::ext) ||
type.getHeapType().isMaybeShared(HeapType::waitqueue))));
assert(isNull() || isData() ||
(type.isRef() && (type.getHeapType().isMaybeShared(HeapType::ext))));
return gcData;
}

Expand Down
3 changes: 2 additions & 1 deletion src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,8 @@ FeatureSet HeapType::getFeatures() const {
return;
case HeapType::waitqueue:
case HeapType::nowaitqueue:
feats |= FeatureSet::ReferenceTypes | FeatureSet::SharedEverything;
feats |= FeatureSet::ReferenceTypes | FeatureSet::GC |
FeatureSet::SharedEverything;
return;
case HeapType::noext:
case HeapType::nofunc:
Expand Down
33 changes: 21 additions & 12 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3696,10 +3696,13 @@ void FunctionValidator::visitStructCmpxchg(StructCmpxchg* curr) {
}

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

shouldBeSubType(curr->waitqueue->type,
Type(HeapTypes::sharedWaitqueue, Nullable),
Expand Down Expand Up @@ -3747,17 +3750,23 @@ void FunctionValidator::visitStructWait(StructWait* curr) {
}

void FunctionValidator::visitWaitqueueNew(WaitqueueNew* curr) {
shouldBeTrue(
!getModule() || getModule()->features.hasSharedEverything(),
curr,
"waitqueue.new requires shared-everything [--enable-shared-everything]");
FeatureSet expected =
FeatureSet::GC | FeatureSet::SharedEverything | FeatureSet::ReferenceTypes;
if (!shouldBeTrue(expected.isSubsetOf(getModule()->features),
curr,
"waitqueue.new requires additional features")) {
getStream() << getMissingFeaturesList(*getModule(), expected) << '\n';
}
}

void FunctionValidator::visitWaitqueueNotify(WaitqueueNotify* curr) {
shouldBeTrue(
!getModule() || getModule()->features.hasSharedEverything(),
curr,
"waitqueue.notify requires shared-everything [--enable-shared-everything]");
FeatureSet expected =
FeatureSet::GC | FeatureSet::SharedEverything | FeatureSet::ReferenceTypes;
if (!shouldBeTrue(expected.isSubsetOf(getModule()->features),
curr,
"waitqueue.notify requires additional features")) {
getStream() << getMissingFeaturesList(*getModule(), expected) << '\n';
}

shouldBeSubType(
curr->waitqueue->type,
Expand Down
13 changes: 10 additions & 3 deletions test/lit/validation/waitqueue.wast
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
;; RUN: not wasm-opt --enable-reference-types --enable-gc %s 2>&1 | filecheck %s
;; RUN: not wasm-opt %s 2>&1 | filecheck %s

;; Tests feature-related validations.
;; Other validations are in the spec test spec/waitqueue.wast.
(module
(type $struct (struct (field i32)))
;; CHECK: waitqueue.new requires shared-everything [--enable-shared-everything]
;; CHECK: waitqueue.new requires additional features
;; CHECK: [--enable-reference-types --enable-gc --enable-shared-everything]
(func $new
(drop (waitqueue.new))
)
;; CHECK: struct.wait requires shared-everything [--enable-shared-everything]
;; CHECK: waitqueue.notify requires additional features
;; CHECK: [--enable-reference-types --enable-gc --enable-shared-everything]
(func $notify (param $wq (ref null (shared waitqueue)))
(drop (waitqueue.notify (local.get $wq) (i32.const 1)))
)
;; CHECK: struct.wait requires additional features
;; CHECK: [--enable-reference-types --enable-gc --enable-shared-everything]
(func $wait-no-feature (param $ref (ref $struct)) (param $wq (ref null (shared waitqueue)))
(drop (struct.wait $struct 0 (local.get $ref) (local.get $wq) (i32.const 0) (i64.const 0)))
)
Expand Down
Loading