diff options
author | Thomas Lively <tlively@google.com> | 2024-06-14 12:07:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-14 19:07:44 +0000 |
commit | 0fa99fb09b881985cf94e74b8c0b339bdef61be6 (patch) | |
tree | 81d1a340dc17a55e6b611962807dd34599757651 /src/wasm | |
parent | 000fa2a8ac8dd66b8ca53b0451702966d59da4d0 (diff) | |
download | binaryen-0fa99fb09b881985cf94e74b8c0b339bdef61be6.tar.gz binaryen-0fa99fb09b881985cf94e74b8c0b339bdef61be6.tar.bz2 binaryen-0fa99fb09b881985cf94e74b8c0b339bdef61be6.zip |
[threads] Add a "shared-everything" feature (#6658)
Add the feature and flags to enable and disable it. Require the new feature to
be enabled for shared heap types to validate. To make the test work, update the
validator to actually check features for global types.
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 11 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 13 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 19 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 1 |
4 files changed, 39 insertions, 5 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 32dcc883a..7b88bdd76 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1319,9 +1319,14 @@ void WasmBinaryWriter::writeFeaturesSection() { return BinaryConsts::CustomSections::MultiMemoryFeature; case FeatureSet::TypedContinuations: return BinaryConsts::CustomSections::TypedContinuationsFeature; - default: - WASM_UNREACHABLE("unexpected feature flag"); + case FeatureSet::SharedEverything: + return BinaryConsts::CustomSections::SharedEverythingFeature; + case FeatureSet::None: + case FeatureSet::Default: + case FeatureSet::All: + break; } + WASM_UNREACHABLE("unexpected feature flag"); }; std::vector<const char*> features; @@ -3825,6 +3830,8 @@ void WasmBinaryReader::readFeatures(size_t payloadLen) { } else if (name == BinaryConsts::CustomSections::TypedContinuationsFeature) { feature = FeatureSet::TypedContinuations; + } else if (name == BinaryConsts::CustomSections::SharedEverythingFeature) { + feature = FeatureSet::SharedEverything; } else { // Silently ignore unknown features (this may be and old binaryen running // on a new wasm). diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 83bf47107..532ebb913 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -932,10 +932,17 @@ FeatureSet Type::getFeatures() const { } } - if (heapType->isStruct() || heapType->isArray() || - heapType->getRecGroup().size() > 1 || + if (heapType->getRecGroup().size() > 1 || heapType->getDeclaredSuperType() || heapType->isOpen()) { feats |= FeatureSet::ReferenceTypes | FeatureSet::GC; + } + + if (heapType->isShared()) { + feats |= FeatureSet::SharedEverything; + } + + if (heapType->isStruct() || heapType->isArray()) { + feats |= FeatureSet::ReferenceTypes | FeatureSet::GC; } else if (heapType->isSignature()) { // This is a function reference, which requires reference types and // possibly also multivalue (if it has multiple returns). Note that @@ -969,7 +976,7 @@ FeatureSet Type::getFeatures() const { collector.noteChild(&heapType); return collector.feats; } - TODO_SINGLE_COMPOUND(t); + switch (t.getBasic()) { case Type::v128: return FeatureSet::SIMD; diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 689872a19..f8bd08e1d 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -3701,6 +3701,25 @@ static void validateGlobals(Module& module, ValidationInfo& info) { seen.insert(curr); } }); + + // Check that globals have allowed types. + 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"; + } + } } static void validateMemories(Module& module, ValidationInfo& info) { diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index cae413397..ed05e9b47 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -54,6 +54,7 @@ const char* ExtendedConstFeature = "extended-const"; const char* StringsFeature = "strings"; const char* MultiMemoryFeature = "multimemory"; const char* TypedContinuationsFeature = "typed-continuations"; +const char* SharedEverythingFeature = "shared-everything"; } // namespace CustomSections } // namespace BinaryConsts |