Skip to content

Commit

Permalink
Bug 1832378 - wasm: Refactor feature flags and let GC build in beta/r…
Browse files Browse the repository at this point in the history
…elease but remain disabled by-default. r=yury

This commit cleans up some of our feature logic.
 - A WasmFeatures.h internal header is added for all this code
 - The stage of a feature is turned into an enum, not a separate
   macro. This is generally easier to read.

As an improvement the concept of 'force enable flag' extension point
was added. This is used to enable the GC proposal even if the function
references proposal is not enabled.

This commit also lets wasm-gc/fr start building in beta/release. They
will remain off by default though (behind a pref).

Differential Revision: https://phabricator.services.mozilla.com/D177681
  • Loading branch information
eqrion committed Jul 12, 2023
1 parent dab12ef commit d796bdc
Show file tree
Hide file tree
Showing 27 changed files with 614 additions and 534 deletions.
24 changes: 9 additions & 15 deletions js/moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -666,20 +666,14 @@ option(
# ===========================


@depends(milestone.is_nightly)
def default_wasm_function_references(is_nightly):
if is_nightly:
return True


option(
"--enable-wasm-function-references",
default=default_wasm_function_references,
"--disable-wasm-function-references",
default=True,
help="{Enable|Disable} WebAssembly function-references",
)


@depends("--enable-wasm-function-references", "--wasm-no-experimental")
@depends("--disable-wasm-function-references", "--wasm-no-experimental")
def wasm_function_references(value, no_experimental):
if no_experimental:
return
Expand All @@ -695,19 +689,19 @@ set_define("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
# ===========================


@depends(milestone.is_nightly, "--enable-wasm-function-references")
def default_wasm_gc(is_nightly, function_references):
if is_nightly and function_references:
@depends("--disable-wasm-function-references")
def default_wasm_gc(function_references):
if function_references:
return True


option(
"--enable-wasm-gc", default=default_wasm_gc, help="{Enable|Disable} WebAssembly GC"
"--disable-wasm-gc", default=default_wasm_gc, help="{Enable|Disable} WebAssembly GC"
)


@depends(
"--enable-wasm-gc", "--enable-wasm-function-references", "--wasm-no-experimental"
"--disable-wasm-gc", "--disable-wasm-function-references", "--wasm-no-experimental"
)
def wasm_gc(value, function_references, no_experimental):
if no_experimental or not value:
Expand All @@ -716,7 +710,7 @@ def wasm_gc(value, function_references, no_experimental):
if function_references:
return True

die("--enable-wasm-gc only possible with --enable-wasm-function-references")
die("--disable-wasm-gc only possible with --disable-wasm-function-references")


set_config("ENABLE_WASM_GC", wasm_gc)
Expand Down
12 changes: 5 additions & 7 deletions js/public/ContextOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ class JS_PUBLIC_API ContextOptions {
wasmVerbose_(false),
wasmBaseline_(true),
wasmIon_(true),
#define WASM_DEFAULT_FEATURE(NAME, ...) wasm##NAME##_(true),
#define WASM_EXPERIMENTAL_FEATURE(NAME, ...) wasm##NAME##_(false),
JS_FOR_WASM_FEATURES(WASM_DEFAULT_FEATURE, WASM_DEFAULT_FEATURE, WASM_EXPERIMENTAL_FEATURE)
#undef WASM_DEFAULT_FEATURE
#undef WASM_EXPERIMENTAL_FEATURE
#define WASM_FEATURE(NAME, LOWER_NAME, STAGE, ...) wasm##NAME##_(STAGE == WasmFeatureStage::Default),
JS_FOR_WASM_FEATURES(WASM_FEATURE)
#undef WASM_FEATURE
testWasmAwaitTier2_(false),
throwOnAsmJSValidationFailure_(false),
disableIon_(false),
Expand Down Expand Up @@ -106,7 +104,7 @@ class JS_PUBLIC_API ContextOptions {
wasm##NAME##_ = flag; \
return *this; \
}
JS_FOR_WASM_FEATURES(WASM_FEATURE, WASM_FEATURE, WASM_FEATURE)
JS_FOR_WASM_FEATURES(WASM_FEATURE)
#undef WASM_FEATURE

bool throwOnAsmJSValidationFailure() const {
Expand Down Expand Up @@ -214,7 +212,7 @@ class JS_PUBLIC_API ContextOptions {
bool wasmBaseline_ : 1;
bool wasmIon_ : 1;
#define WASM_FEATURE(NAME, ...) bool wasm##NAME##_ : 1;
JS_FOR_WASM_FEATURES(WASM_FEATURE, WASM_FEATURE, WASM_FEATURE)
JS_FOR_WASM_FEATURES(WASM_FEATURE)
#undef WASM_FEATURE
bool testWasmAwaitTier2_ : 1;
bool throwOnAsmJSValidationFailure_ : 1;
Expand Down
189 changes: 107 additions & 82 deletions js/public/WasmFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
// 5. [fuzzing] Add the feature to gluesmith/src/lib.rs, if wasm-smith has
// support for it.

#ifdef ENABLE_WASM_SIMD
# define WASM_SIMD_ENABLED 1
#else
# define WASM_SIMD_ENABLED 0
#endif
#ifdef ENABLE_WASM_RELAXED_SIMD
# define WASM_RELAXED_SIMD_ENABLED 1
#else
Expand Down Expand Up @@ -101,84 +96,114 @@
# define WASM_MULTI_MEMORY_ENABLED 0
#endif

enum class WasmFeatureStage {
Experimental = 0,
Tentative,
Default,
};

// clang-format off
#define JS_FOR_WASM_FEATURES(DEFAULT, TENTATIVE, EXPERIMENTAL) \
TENTATIVE(/* capitalized name */ ExtendedConst, \
/* lower case name */ extendedConst, \
/* compile predicate */ WASM_EXTENDED_CONST_ENABLED, \
/* compiler predicate */ true, \
/* flag predicate */ true, \
/* shell flag */ "extended-const", \
/* preference name */ "extended_const") \
TENTATIVE( \
/* capitalized name */ Exceptions, \
/* lower case name */ exceptions, \
/* compile predicate */ true, \
/* compiler predicate */ BaselineAvailable(cx) || IonAvailable(cx), \
/* flag predicate */ true, \
/* shell flag */ "exceptions", \
/* preference name */ "exceptions") \
EXPERIMENTAL(/* capitalized name */ FunctionReferences, \
/* lower case name */ functionReferences, \
/* compile predicate */ WASM_FUNCTION_REFERENCES_ENABLED, \
/* compiler predicate */ BaselineAvailable(cx) || \
IonAvailable(cx), \
/* flag predicate */ true, \
/* shell flag */ "function-references", \
/* preference name */ "function_references") \
EXPERIMENTAL(/* capitalized name */ Gc, \
/* lower case name */ gc, \
/* compile predicate */ WASM_GC_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ WasmFunctionReferencesFlag(cx), \
/* shell flag */ "gc", \
/* preference name */ "gc") \
TENTATIVE(/* capitalized name */ RelaxedSimd, \
/* lower case name */ v128Relaxed, \
/* compile predicate */ WASM_RELAXED_SIMD_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ js::jit::JitSupportsWasmSimd(), \
/* shell flag */ "relaxed-simd", \
/* preference name */ "relaxed_simd") \
TENTATIVE( \
/* capitalized name */ Memory64, \
/* lower case name */ memory64, \
/* compile predicate */ WASM_MEMORY64_ENABLED, \
/* compiler predicate */ BaselineAvailable(cx) || IonAvailable(cx), \
/* flag predicate */ true, \
/* shell flag */ "memory64", \
/* preference name */ "memory64") \
EXPERIMENTAL( \
/* capitalized name */ MemoryControl, \
/* lower case name */ memoryControl, \
/* compile predicate */ WASM_MEMORY_CONTROL_ENABLED, \
/* compiler predicate */ BaselineAvailable(cx) || IonAvailable(cx), \
/* flag predicate */ true, \
/* shell flag */ "memory-control", \
/* preference name */ "memory_control") \
EXPERIMENTAL( \
/* capitalized name */ MultiMemory, \
/* lower case name */ multiMemory, \
/* compile predicate */ WASM_MULTI_MEMORY_ENABLED, \
/* compiler predicate */ BaselineAvailable(cx) || IonAvailable(cx), \
/* flag predicate */ true, \
/* shell flag */ "multi-memory", \
/* preference name */ "multi_memory") \
EXPERIMENTAL(/* capitalized name */ MozIntGemm, \
/* lower case name */ mozIntGemm, \
/* compile predicate */ WASM_MOZ_INTGEMM_ENABLED, \
/* compiler predicate */ BaselineAvailable(cx) || \
IonAvailable(cx), \
/* flag predicate */ IsSimdPrivilegedContext(cx), \
/* shell flag */ "moz-intgemm", \
/* preference name */ "moz_intgemm") \
EXPERIMENTAL(/* capitalized name */ TestSerialization, \
/* lower case name */ testSerialization, \
/* compile predicate */ 1, \
/* compiler predicate */ IonAvailable(cx), \
/* flag predicate */ true, \
/* shell flag */ "test-serialization", \
/* preference name */ "test-serialization")
#define JS_FOR_WASM_FEATURES(FEATURE) \
FEATURE( \
/* capitalized name */ ExtendedConst, \
/* lower case name */ extendedConst, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_EXTENDED_CONST_ENABLED, \
/* compiler predicate */ true, \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "extended-const", \
/* preference name */ "extended_const") \
FEATURE( \
/* capitalized name */ Exceptions, \
/* lower case name */ exceptions, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ true, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "exceptions", \
/* preference name */ "exceptions") \
FEATURE( \
/* capitalized name */ FunctionReferences, \
/* lower case name */ functionReferences, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_FUNCTION_REFERENCES_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ WasmGcFlag(cx), \
/* shell flag */ "function-references", \
/* preference name */ "function_references") \
FEATURE( \
/* capitalized name */ Gc, \
/* lower case name */ gc, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_GC_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "gc", \
/* preference name */ "gc") \
FEATURE( \
/* capitalized name */ RelaxedSimd, \
/* lower case name */ v128Relaxed, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_RELAXED_SIMD_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ js::jit::JitSupportsWasmSimd(), \
/* flag force enable */ false, \
/* shell flag */ "relaxed-simd", \
/* preference name */ "relaxed_simd") \
FEATURE( \
/* capitalized name */ Memory64, \
/* lower case name */ memory64, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_MEMORY64_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "memory64", \
/* preference name */ "memory64") \
FEATURE( \
/* capitalized name */ MemoryControl, \
/* lower case name */ memoryControl, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_MEMORY_CONTROL_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "memory-control", \
/* preference name */ "memory_control") \
FEATURE( \
/* capitalized name */ MultiMemory, \
/* lower case name */ multiMemory, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_MULTI_MEMORY_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "multi-memory", \
/* preference name */ "multi_memory") \
FEATURE( \
/* capitalized name */ MozIntGemm, \
/* lower case name */ mozIntGemm, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_MOZ_INTGEMM_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ IsSimdPrivilegedContext(cx), \
/* flag force enable */ false, \
/* shell flag */ "moz-intgemm", \
/* preference name */ "moz_intgemm") \
FEATURE( \
/* capitalized name */ TestSerialization, \
/* lower case name */ testSerialization, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ 1, \
/* compiler predicate */ IonAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* shell flag */ "test-serialization", \
/* preference name */ "test-serialization")

// clang-format on

Expand Down
5 changes: 3 additions & 2 deletions js/src/builtin/TestingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
#include "vm/StringType.h"
#include "wasm/AsmJS.h"
#include "wasm/WasmBaselineCompile.h"
#include "wasm/WasmFeatures.h"
#include "wasm/WasmGcObject.h"
#include "wasm/WasmInstance.h"
#include "wasm/WasmIntrinsic.h"
Expand Down Expand Up @@ -910,7 +911,7 @@ static bool WasmThreadsEnabled(JSContext* cx, unsigned argc, Value* vp) {
args.rval().setBoolean(wasm::NAME##Available(cx)); \
return true; \
}
JS_FOR_WASM_FEATURES(WASM_FEATURE, WASM_FEATURE, WASM_FEATURE);
JS_FOR_WASM_FEATURES(WASM_FEATURE);
#undef WASM_FEATURE

static bool WasmSimdEnabled(JSContext* cx, unsigned argc, Value* vp) {
Expand Down Expand Up @@ -9125,7 +9126,7 @@ gc::ZealModeHelpText),
JS_FN_HELP("wasm" #NAME "Enabled", Wasm##NAME##Enabled, 0, 0, \
"wasm" #NAME "Enabled()", \
" Returns a boolean indicating whether the WebAssembly " #NAME " proposal is enabled."),
JS_FOR_WASM_FEATURES(WASM_FEATURE, WASM_FEATURE, WASM_FEATURE)
JS_FOR_WASM_FEATURES(WASM_FEATURE)
#undef WASM_FEATURE

JS_FN_HELP("wasmThreadsEnabled", WasmThreadsEnabled, 0, 0,
Expand Down
1 change: 1 addition & 0 deletions js/src/fuzz-tests/testWasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "vm/TypedArrayObject.h"

#include "wasm/WasmCompile.h"
#include "wasm/WasmFeatures.h"
#include "wasm/WasmIonCompile.h"
#include "wasm/WasmJS.h"
#include "wasm/WasmTable.h"
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/directives.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
|jit-test| test-also=--wasm-compiler=optimizing; test-also=--wasm-function-references --wasm-gc; test-also=--wasm-compiler=baseline --wasm-function-references --wasm-gc; include:wasm.js
|jit-test| test-also=--wasm-compiler=optimizing; --wasm-gc; test-also=--wasm-compiler=baseline --wasm-gc; include:wasm.js
2 changes: 1 addition & 1 deletion js/src/jit/Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "js/experimental/JitInfo.h" // JSJitInfo
#include "util/Memory.h"
#include "wasm/WasmCodegenTypes.h"
#include "wasm/WasmFeatures.h" // for wasm::ReportSimdAnalysis
#include "wasm/WasmInstanceData.h"
#include "wasm/WasmJS.h" // for wasm::ReportSimdAnalysis

#include "jit/shared/Lowering-shared-inl.h"
#include "vm/BytecodeUtil-inl.h"
Expand Down
1 change: 1 addition & 0 deletions js/src/jit/MIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "vm/PlainObject.h" // js::PlainObject
#include "vm/Uint8Clamped.h"
#include "wasm/WasmCode.h"
#include "wasm/WasmFeatures.h" // for wasm::ReportSimdAnalysis

#include "vm/JSAtom-inl.h"
#include "wasm/WasmInstance-inl.h"
Expand Down
1 change: 1 addition & 0 deletions js/src/jit/ShuffleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "jit/ShuffleAnalysis.h"
#include "jit/MIR.h"
#include "wasm/WasmFeatures.h"

using namespace js;
using namespace jit;
Expand Down
2 changes: 2 additions & 0 deletions js/src/jit/arm64/Lowering-arm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "jit/arm64/Assembler-arm64.h"
#include "jit/Lowering.h"
#include "jit/MIR.h"
#include "wasm/WasmFeatures.h" // for wasm::ReportSimdAnalysis

#include "jit/shared/Lowering-shared-inl.h"

using namespace js;
Expand Down
1 change: 1 addition & 0 deletions js/src/jit/x86-shared/Lowering-x86-shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "jit/Lowering.h"
#include "jit/MIR.h"
#include "wasm/WasmFeatures.h" // for wasm::ReportSimdAnalysis

#include "jit/shared/Lowering-shared-inl.h"

Expand Down
Loading

0 comments on commit d796bdc

Please sign in to comment.