diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-09-17 07:46:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-17 07:46:40 +0200 |
commit | e1d74ef2acdd88f06b9e58f91f30bb56b9a26fe8 (patch) | |
tree | 3b52301afd147617cf14e32fd487378394bc709b /src | |
parent | a96e8310e1a58c0a43b2d0e2ff4f9db24dd9a18a (diff) | |
download | binaryen-e1d74ef2acdd88f06b9e58f91f30bb56b9a26fe8.tar.gz binaryen-e1d74ef2acdd88f06b9e58f91f30bb56b9a26fe8.tar.bz2 binaryen-e1d74ef2acdd88f06b9e58f91f30bb56b9a26fe8.zip |
Add GC feature flag (#3135)
Adds the `--enable-gc` feature flag, so far enabling the `anyref` type incl. subtyping, and removes the temporary `--enable-anyref` feature flag that it replaces.
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 4 | ||||
-rw-r--r-- | src/binaryen-c.h | 2 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 2 | ||||
-rw-r--r-- | src/passes/InstrumentLocals.cpp | 2 | ||||
-rw-r--r-- | src/tools/fuzzing.h | 27 | ||||
-rw-r--r-- | src/tools/tool-options.h | 2 | ||||
-rw-r--r-- | src/wasm-binary.h | 2 | ||||
-rw-r--r-- | src/wasm-features.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 8 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 2 |
12 files changed, 34 insertions, 33 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 3582c99ca..3084ae2ae 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -327,8 +327,8 @@ BinaryenFeatures BinaryenFeatureReferenceTypes(void) { BinaryenFeatures BinaryenFeatureMultivalue(void) { return static_cast<BinaryenFeatures>(FeatureSet::Multivalue); } -BinaryenFeatures BinaryenFeatureAnyref(void) { - return static_cast<BinaryenFeatures>(FeatureSet::Anyref); +BinaryenFeatures BinaryenFeatureGC(void) { + return static_cast<BinaryenFeatures>(FeatureSet::GC); } BinaryenFeatures BinaryenFeatureAll(void) { return static_cast<BinaryenFeatures>(FeatureSet::All); diff --git a/src/binaryen-c.h b/src/binaryen-c.h index fdef58410..c462bfc0f 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -197,7 +197,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureExceptionHandling(void); BINARYEN_API BinaryenFeatures BinaryenFeatureTailCall(void); BINARYEN_API BinaryenFeatures BinaryenFeatureReferenceTypes(void); BINARYEN_API BinaryenFeatures BinaryenFeatureMultivalue(void); -BINARYEN_API BinaryenFeatures BinaryenFeatureAnyref(void); +BINARYEN_API BinaryenFeatures BinaryenFeatureGC(void); BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void); // Modules diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index d7c1878fd..7f5467312 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -121,7 +121,7 @@ function initializeConstants() { 'TailCall', 'ReferenceTypes', 'Multivalue', - 'Anyref', + 'GC', 'All' ].forEach(name => { Module['Features'][name] = Module['_BinaryenFeature' + name](); diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp index b1ce5f05e..f9c26d788 100644 --- a/src/passes/InstrumentLocals.cpp +++ b/src/passes/InstrumentLocals.cpp @@ -198,7 +198,7 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { addImport( curr, set_exnref, {Type::i32, Type::i32, Type::exnref}, Type::exnref); } - if (curr->features.hasAnyref()) { + if (curr->features.hasGC()) { addImport( curr, get_anyref, {Type::i32, Type::i32, Type::anyref}, Type::anyref); addImport( diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 9768b63c4..e6cc4e444 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -848,8 +848,7 @@ private: } Expression* _makeConcrete(Type type) { - bool canMakeControlFlow = - !type.isTuple() || wasm.features.has(FeatureSet::Multivalue); + bool canMakeControlFlow = !type.isTuple() || wasm.features.hasMultivalue(); using Self = TranslateToFuzzReader; FeatureOptions<Expression* (Self::*)(Type)> options; using WeightedOption = decltype(options)::WeightedOption; @@ -2609,16 +2608,7 @@ private: Expression* makeRefIsNull(Type type) { assert(type == Type::i32); assert(wasm.features.hasReferenceTypes()); - SmallVector<Type, 2> options; - options.push_back(Type::externref); - options.push_back(Type::funcref); - if (wasm.features.hasExceptionHandling()) { - options.push_back(Type::exnref); - } - if (wasm.features.hasAnyref()) { - options.push_back(Type::anyref); - } - return builder.makeRefIsNull(make(pick(options))); + return builder.makeRefIsNull(make(getReferenceType())); } Expression* makeMemoryInit() { @@ -2684,11 +2674,22 @@ private: .add(FeatureSet::ReferenceTypes, Type::funcref, Type::externref) .add(FeatureSet::ReferenceTypes | FeatureSet::ExceptionHandling, Type::exnref) - .add(FeatureSet::ReferenceTypes | FeatureSet::Anyref, Type::anyref)); + .add(FeatureSet::ReferenceTypes | FeatureSet::GC, Type::anyref)); } Type getSingleConcreteType() { return pick(getSingleConcreteTypes()); } + std::vector<Type> getReferenceTypes() { + return items( + FeatureOptions<Type>() + .add(FeatureSet::ReferenceTypes, Type::funcref, Type::externref) + .add(FeatureSet::ReferenceTypes | FeatureSet::ExceptionHandling, + Type::exnref) + .add(FeatureSet::ReferenceTypes | FeatureSet::GC, Type::anyref)); + } + + Type getReferenceType() { return pick(getReferenceTypes()); } + Type getTupleType() { std::vector<Type> elements; size_t numElements = 2 + upTo(MAX_TUPLE_SIZE - 1); diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h index 082e95549..2e7158b34 100644 --- a/src/tools/tool-options.h +++ b/src/tools/tool-options.h @@ -87,7 +87,7 @@ struct ToolOptions : public Options { .addFeature(FeatureSet::TailCall, "tail call operations") .addFeature(FeatureSet::ReferenceTypes, "reference types") .addFeature(FeatureSet::Multivalue, "multivalue functions") - .addFeature(FeatureSet::Anyref, "anyref type (without GC)") + .addFeature(FeatureSet::GC, "garbage collection") .add("--no-validation", "-n", "Disables validation, assumes inputs are correct", diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b979be853..77f53fcd2 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -383,7 +383,7 @@ extern const char* ExceptionHandlingFeature; extern const char* TailCallFeature; extern const char* ReferenceTypesFeature; extern const char* MultivalueFeature; -extern const char* AnyrefFeature; +extern const char* GCFeature; enum Subsection { NameModule = 0, diff --git a/src/wasm-features.h b/src/wasm-features.h index 5d05b6284..56436bd6a 100644 --- a/src/wasm-features.h +++ b/src/wasm-features.h @@ -36,7 +36,7 @@ struct FeatureSet { TailCall = 1 << 7, ReferenceTypes = 1 << 8, Multivalue = 1 << 9, - Anyref = 1 << 10, + GC = 1 << 10, All = (1 << 11) - 1 }; @@ -62,8 +62,8 @@ struct FeatureSet { return "reference-types"; case Multivalue: return "multivalue"; - case Anyref: - return "anyref"; + case GC: + return "gc"; default: WASM_UNREACHABLE("unexpected feature"); } @@ -87,7 +87,7 @@ struct FeatureSet { bool hasTailCall() const { return (features & TailCall) != 0; } bool hasReferenceTypes() const { return (features & ReferenceTypes) != 0; } bool hasMultivalue() const { return (features & Multivalue) != 0; } - bool hasAnyref() const { return (features & Anyref) != 0; } + bool hasGC() const { return (features & GC) != 0; } bool hasAll() const { return (features & All) != 0; } void makeMVP() { features = MVP; } @@ -104,7 +104,7 @@ struct FeatureSet { void setTailCall(bool v = true) { set(TailCall, v); } void setReferenceTypes(bool v = true) { set(ReferenceTypes, v); } void setMultivalue(bool v = true) { set(Multivalue, v); } - void setAnyref(bool v = true) { set(Anyref, v); } + void setGC(bool v = true) { set(GC, v); } void setAll(bool v = true) { features = v ? All : MVP; } void enable(const FeatureSet& other) { features |= other.features; } diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 5942a979f..2910bb383 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -750,8 +750,8 @@ void WasmBinaryWriter::writeFeaturesSection() { return BinaryConsts::UserSections::ReferenceTypesFeature; case FeatureSet::Multivalue: return BinaryConsts::UserSections::MultivalueFeature; - case FeatureSet::Anyref: - return BinaryConsts::UserSections::AnyrefFeature; + case FeatureSet::GC: + return BinaryConsts::UserSections::GCFeature; default: WASM_UNREACHABLE("unexpected feature flag"); } @@ -2307,8 +2307,8 @@ void WasmBinaryBuilder::readFeatures(size_t payloadLen) { wasm.features.setReferenceTypes(); } else if (name == BinaryConsts::UserSections::MultivalueFeature) { wasm.features.setMultivalue(); - } else if (name == BinaryConsts::UserSections::AnyrefFeature) { - wasm.features.setAnyref(); + } else if (name == BinaryConsts::UserSections::GCFeature) { + wasm.features.setGC(); } } } diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 0c49e8dcc..d88b7b027 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -454,7 +454,7 @@ FeatureSet Type::getFeatures() const { case Type::exnref: return FeatureSet::ReferenceTypes | FeatureSet::ExceptionHandling; case Type::anyref: - return FeatureSet::ReferenceTypes | FeatureSet::Anyref; + return FeatureSet::ReferenceTypes | FeatureSet::GC; default: return FeatureSet::MVP; } diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 80c54abed..15fb66926 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2478,10 +2478,10 @@ static void validateModule(Module& module, ValidationInfo& info) { } static void validateFeatures(Module& module, ValidationInfo& info) { - if (module.features.hasAnyref()) { + if (module.features.hasGC()) { info.shouldBeTrue(module.features.hasReferenceTypes(), module.features, - "--enable-anyref requires --enable-reference-types"); + "--enable-gc requires --enable-reference-types"); } if (module.features.hasExceptionHandling()) { // implies exnref info.shouldBeTrue( diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 5931b56aa..9d43a33b1 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -45,7 +45,7 @@ const char* SIMD128Feature = "simd128"; const char* TailCallFeature = "tail-call"; const char* ReferenceTypesFeature = "reference-types"; const char* MultivalueFeature = "multivalue"; -const char* AnyrefFeature = "anyref"; +const char* GCFeature = "gc"; } // namespace UserSections } // namespace BinaryConsts |