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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ def is_git_repo():
'shared-struct.wast',
'shared-array.wast',
'shared-i31.wast',
'shared-null.wast',
'shared-absheaptype.wast',
'type-ssa-shared.wast',
]

Expand Down
6 changes: 4 additions & 2 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,10 @@ class Builder {
if (type.isFunction()) {
return makeRefFunc(value.getFunc(), type.getHeapType());
}
if (type.isRef() && type.getHeapType() == HeapType::i31) {
return makeRefI31(makeConst(value.geti31()));
if (type.isRef() && type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31) {
return makeRefI31(makeConst(value.geti31()),
type.getHeapType().getShared());
}
if (type.isString()) {
// The string is already WTF-16, but we need to convert from `Literals` to
Expand Down
40 changes: 25 additions & 15 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ struct ValidationInfo {
}
};

std::string getMissingFeaturesList(Module& wasm, FeatureSet feats) {
std::stringstream ss;
bool first = true;
ss << '[';
(feats - wasm.features).iterFeatures([&](FeatureSet feat) {
if (first) {
first = false;
} else {
ss << " ";
}
ss << "--enable-" << feat.toString();
});
ss << ']';
return ss.str();
}

struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
bool isFunctionParallel() override { return true; }

Expand Down Expand Up @@ -2188,9 +2204,12 @@ void FunctionValidator::visitRefNull(RefNull* curr) {
// If we are not in a function, this is a global location like a table. We
// allow RefNull there as we represent tables that way regardless of what
// features are enabled.
shouldBeTrue(!getFunction() || getModule()->features.hasReferenceTypes(),
curr,
"ref.null requires reference-types [--enable-reference-types]");
auto feats = curr->type.getFeatures();
if (!shouldBeTrue(!getFunction() || feats <= getModule()->features,
curr,
"ref.null requires additional features")) {
getStream() << getMissingFeaturesList(*getModule(), feats) << '\n';
}
if (!shouldBeTrue(
curr->type.isNullable(), curr, "ref.null types must be nullable")) {
return;
Expand Down Expand Up @@ -3711,18 +3730,9 @@ static void validateGlobals(Module& module, ValidationInfo& info) {
for (auto& g : module.globals) {
auto globalFeats = g->type.getFeatures();
if (!info.shouldBeTrue(globalFeats <= module.features, g->name, "")) {
auto& stream = info.getStream(nullptr);
stream << "global type requires additional features [";
bool first = true;
(globalFeats - module.features).iterFeatures([&](FeatureSet feat) {
if (first) {
first = false;
} else {
stream << " ";
}
stream << "--enable-" << feat.toString();
});
stream << "]\n";
info.getStream(nullptr)
<< "global type requires additional features "
<< getMissingFeaturesList(module, globalFeats) << '\n';
}
}
}
Expand Down
30 changes: 11 additions & 19 deletions test/lit/basic/shared-types.wast
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
(type $func (shared (func)))
;; CHECK: (type $array (shared (array i8)))
(type $array (shared (array i8)))
;; CHECK: (type $cont (shared (cont $func)))
(type $cont (shared (cont $func)))
)

;; CHECK: (func $use-types (type $0)
Expand All @@ -32,7 +30,6 @@
;; CHECK-NEXT: (local $3 (ref $bot))
;; CHECK-NEXT: (local $4 (ref $func))
;; CHECK-NEXT: (local $5 (ref $array))
;; CHECK-NEXT: (local $6 (ref $cont))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $use-types
Expand All @@ -42,31 +39,27 @@
(local (ref $bot))
(local (ref $func))
(local (ref $array))
(local (ref $cont))
)

;; CHECK: (func $use-basic-types (type $0)
;; CHECK-NEXT: (local $0 (ref (shared extern)))
;; CHECK-NEXT: (local $1 (ref (shared func)))
;; CHECK-NEXT: (local $2 (ref (shared cont)))
;; CHECK-NEXT: (local $3 (ref (shared any)))
;; CHECK-NEXT: (local $4 (ref (shared eq)))
;; CHECK-NEXT: (local $5 (ref (shared i31)))
;; CHECK-NEXT: (local $6 (ref (shared struct)))
;; CHECK-NEXT: (local $7 (ref (shared array)))
;; CHECK-NEXT: (local $8 (ref (shared exn)))
;; CHECK-NEXT: (local $9 (ref (shared string)))
;; CHECK-NEXT: (local $10 (ref (shared none)))
;; CHECK-NEXT: (local $11 (ref (shared noextern)))
;; CHECK-NEXT: (local $12 (ref (shared nofunc)))
;; CHECK-NEXT: (local $13 (ref (shared nocont)))
;; CHECK-NEXT: (local $14 (ref (shared noexn)))
;; CHECK-NEXT: (local $2 (ref (shared any)))
;; CHECK-NEXT: (local $3 (ref (shared eq)))
;; CHECK-NEXT: (local $4 (ref (shared i31)))
;; CHECK-NEXT: (local $5 (ref (shared struct)))
;; CHECK-NEXT: (local $6 (ref (shared array)))
;; CHECK-NEXT: (local $7 (ref (shared exn)))
;; CHECK-NEXT: (local $8 (ref (shared string)))
;; CHECK-NEXT: (local $9 (ref (shared none)))
;; CHECK-NEXT: (local $10 (ref (shared noextern)))
;; CHECK-NEXT: (local $11 (ref (shared nofunc)))
;; CHECK-NEXT: (local $12 (ref (shared noexn)))
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $use-basic-types
(local (ref (shared extern)))
(local (ref (shared func)))
(local (ref (shared cont)))
(local (ref (shared any)))
(local (ref (shared eq)))
(local (ref (shared i31)))
Expand All @@ -77,7 +70,6 @@
(local (ref (shared none)))
(local (ref (shared noextern)))
(local (ref (shared nofunc)))
(local (ref (shared nocont)))
(local (ref (shared noexn)))
)
)
38 changes: 38 additions & 0 deletions test/lit/ctor-eval/shared-i31.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: wasm-ctor-eval %s --ctors=test --kept-exports=test,other --quiet -all -S -o - | filecheck %s

;; We should be able to update `global` with a proper shared i31 reference.

(module
;; CHECK: (type $0 (func (result (ref null (shared any)))))

;; CHECK: (global $global (mut (ref null (shared i31))) (ref.i31_shared
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: ))
(global $global (mut (ref null (shared i31))) (ref.null (shared none)))

(func $test (export "test") (result (ref null (shared any)))
(global.set $global
(ref.i31_shared
(i32.const 42)
)
)
(global.get $global)
)

;; CHECK: (export "test" (func $test_2))

;; CHECK: (export "other" (func $other))

;; CHECK: (func $other (type $0) (result (ref null (shared any)))
;; CHECK-NEXT: (global.get $global)
;; CHECK-NEXT: )
(func $other (export "other") (result (ref null (shared any)))
(global.get $global)
)
)
;; CHECK: (func $test_2 (type $0) (result (ref null (shared any)))
;; CHECK-NEXT: (ref.i31_shared
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
2 changes: 1 addition & 1 deletion test/lit/validation/shared-absheaptype.wast
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; Test that shared structs require shared-everything threads
;; Test that shared basic heap types require shared-everything threads

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-SHARED
;; RUN: wasm-opt %s --enable-reference-types --enable-gc --enable-shared-everything -o - -S | filecheck %s --check-prefix SHARED
Expand Down
12 changes: 12 additions & 0 deletions test/lit/validation/shared-null.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; Test that shared nulls require shared-everything threads

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-SHARED
;; RUN: wasm-opt %s --enable-reference-types --enable-gc --enable-shared-everything -o - -S | filecheck %s --check-prefix SHARED

;; NO-SHARED: ref.null requires additional features
;; NO-SHARED: [--enable-reference-types --enable-shared-everything]
;; SHARED: (ref.null (shared none))

(module
(func (drop (ref.null (shared none))))
)