From 2f39ed5e4a73fdf7ed3678f8038572806b7cf75e Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Fri, 1 Mar 2019 09:33:31 +0100 Subject: [PATCH] Bug 1531670 - Replace ENABLE_WASM_GENERALIZED_TABLES. r=bbouvier Replace all uses of ENABLE_WASM_GENERALIZED_TABLES with ENABLE_WASM_REFTYPES, plus some knock-on effects. Replace all uses of wasmGeneralizedTables with wasmReftypesEnabled. Drive-by fix: replace 'anyfunc' in a couple of error strings with the canonical 'funcref'. Drive-by fix: remove isSimdAvailable, it is not used and we have no SIMD. Differential Revision: https://phabricator.services.mozilla.com/D21653 --HG-- extra : rebase_source : 043732afa1661133eaff54554e56f76fe3e32504 --- js/moz.configure | 16 ---------- js/src/builtin/TestingFunctions.cpp | 29 ------------------- .../wasm/gc/tables-generalized-disabled.js | 2 +- .../wasm/gc/tables-generalized-struct.js | 2 +- .../tests/wasm/gc/tables-generalized.js | 2 +- .../jit-test/tests/wasm/gc/tables-multiple.js | 2 +- .../jit-test/tests/wasm/gc/tables-stress.js | 2 +- js/src/wasm/WasmAST.h | 6 ++-- js/src/wasm/WasmBaselineCompile.cpp | 4 +-- js/src/wasm/WasmConstants.h | 4 +-- js/src/wasm/WasmIonCompile.cpp | 8 ++--- js/src/wasm/WasmJS.cpp | 4 +-- js/src/wasm/WasmOpIter.cpp | 21 ++++---------- js/src/wasm/WasmTextToBinary.cpp | 20 ++++++------- js/src/wasm/WasmValidate.cpp | 12 ++++---- 15 files changed, 39 insertions(+), 95 deletions(-) diff --git a/js/moz.configure b/js/moz.configure index 68ef50972e76..cebfbbeb8914 100644 --- a/js/moz.configure +++ b/js/moz.configure @@ -558,22 +558,6 @@ set_config('ENABLE_WASM_REFTYPES', depends_if('--enable-wasm-reftypes')(lambda x set_define('ENABLE_WASM_REFTYPES', depends_if('--enable-wasm-reftypes')(lambda x: True)) -# Support for WebAssembly generalized tables (anyref tables, multiple tables). -# ============================================================================ - -@depends(milestone.is_nightly, '--enable-wasm-reftypes') -def default_wasm_generalized_tables(is_nightly, reftypes): - if reftypes and is_nightly: - return True - -js_option('--enable-wasm-generalized-tables', - default=default_wasm_generalized_tables, - help='{Enable|Disable} WebAssembly generalized reference tables') - -set_config('ENABLE_WASM_GENERALIZED_TABLES', depends_if('--enable-wasm-generalized-tables')(lambda x: True)) -set_define('ENABLE_WASM_GENERALIZED_TABLES', depends_if('--enable-wasm-generalized-tables')(lambda x: True)) - - # Support for WebAssembly GC. # =========================== diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 208985bcfa84..13c4cae52b37 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -704,19 +704,6 @@ static bool WasmDebugSupport(JSContext* cx, unsigned argc, Value* vp) { return true; } -static bool WasmGeneralizedTables(JSContext* cx, unsigned argc, Value* vp) { - CallArgs args = CallArgsFromVp(argc, vp); -#ifdef ENABLE_WASM_GENERALIZED_TABLES - // Generalized tables depend on anyref, though not currently on (ref T) - // types nor on structures or other GC-proposal features. - bool isSupported = wasm::HasReftypesSupport(cx); -#else - bool isSupported = false; -#endif - args.rval().setBoolean(isSupported); - return true; -} - static bool WasmCompileMode(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); @@ -4011,12 +3998,6 @@ static bool ShellCloneAndExecuteScript(JSContext* cx, unsigned argc, return true; } -static bool IsSimdAvailable(JSContext* cx, unsigned argc, Value* vp) { - CallArgs args = CallArgsFromVp(argc, vp); - args.rval().set(BooleanValue(cx->jitSupportsSimd())); - return true; -} - static bool ByteSize(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); mozilla::MallocSizeOf mallocSizeOf = cx->runtime()->debuggerMallocSizeOf; @@ -5928,10 +5909,6 @@ gc::ZealModeHelpText), " Returns whether asm.js compilation is currently available or whether it is disabled\n" " (e.g., by the debugger)."), - JS_FN_HELP("isSimdAvailable", IsSimdAvailable, 0, 0, -"isSimdAvailable", -" Returns true if SIMD extensions are supported on this platform."), - JS_FN_HELP("getJitCompilerOptions", GetJitCompilerOptions, 0, 0, "getJitCompilerOptions()", " Return an object describing some of the JIT compiler options.\n"), @@ -6010,12 +5987,6 @@ gc::ZealModeHelpText), "wasmDebugSupport(bool)", " Returns a boolean indicating whether the WebAssembly compilers support debugging."), - JS_FN_HELP("wasmGeneralizedTables", WasmGeneralizedTables, 1, 0, -"wasmGeneralizedTables(bool)", -" Returns a boolean indicating whether generalized tables are available.\n" -" This feature set includes 'anyref' as a table type, and new instructions\n" -" including table.get, table.set, table.grow, and table.size."), - JS_FN_HELP("isLazyFunction", IsLazyFunction, 1, 0, "isLazyFunction(fun)", " True if fun is a lazy JSFunction."), diff --git a/js/src/jit-test/tests/wasm/gc/tables-generalized-disabled.js b/js/src/jit-test/tests/wasm/gc/tables-generalized-disabled.js index 078b749c45aa..b3dbd5e6312e 100644 --- a/js/src/jit-test/tests/wasm/gc/tables-generalized-disabled.js +++ b/js/src/jit-test/tests/wasm/gc/tables-generalized-disabled.js @@ -1,4 +1,4 @@ -// |jit-test| skip-if: wasmGeneralizedTables() +// |jit-test| skip-if: wasmReftypesEnabled() assertErrorMessage(() => new WebAssembly.Table({element:"anyref", initial:10}), TypeError, diff --git a/js/src/jit-test/tests/wasm/gc/tables-generalized-struct.js b/js/src/jit-test/tests/wasm/gc/tables-generalized-struct.js index fcbade4cf2b1..9c2e7697d842 100644 --- a/js/src/jit-test/tests/wasm/gc/tables-generalized-struct.js +++ b/js/src/jit-test/tests/wasm/gc/tables-generalized-struct.js @@ -1,4 +1,4 @@ -// |jit-test| skip-if: !wasmGeneralizedTables() || !wasmGcEnabled() || wasmCompileMode() != 'baseline' +// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline' // table.set in bounds with i32 x anyref - works, no value generated // table.set with (ref T) - works diff --git a/js/src/jit-test/tests/wasm/gc/tables-generalized.js b/js/src/jit-test/tests/wasm/gc/tables-generalized.js index 914c2dd117cf..f417f2ea9f22 100644 --- a/js/src/jit-test/tests/wasm/gc/tables-generalized.js +++ b/js/src/jit-test/tests/wasm/gc/tables-generalized.js @@ -1,4 +1,4 @@ -// |jit-test| skip-if: !wasmGeneralizedTables() +// |jit-test| skip-if: !wasmReftypesEnabled() /////////////////////////////////////////////////////////////////////////// // diff --git a/js/src/jit-test/tests/wasm/gc/tables-multiple.js b/js/src/jit-test/tests/wasm/gc/tables-multiple.js index 811cb7f71a35..f3b95ad16f9c 100644 --- a/js/src/jit-test/tests/wasm/gc/tables-multiple.js +++ b/js/src/jit-test/tests/wasm/gc/tables-multiple.js @@ -1,4 +1,4 @@ -// |jit-test| skip-if: !wasmGeneralizedTables() +// |jit-test| skip-if: !wasmReftypesEnabled() // Note that negative tests not having to do with table indices have been taken // care of by tables-generalized.js. diff --git a/js/src/jit-test/tests/wasm/gc/tables-stress.js b/js/src/jit-test/tests/wasm/gc/tables-stress.js index 733f56f0d88d..b823bac3d954 100644 --- a/js/src/jit-test/tests/wasm/gc/tables-stress.js +++ b/js/src/jit-test/tests/wasm/gc/tables-stress.js @@ -1,4 +1,4 @@ -// |jit-test| skip-if: !wasmGeneralizedTables() +// |jit-test| skip-if: !wasmReftypesEnabled() for ( let prefix of ['', '(table $prefix 0 32 funcref)']) { let mod = new WebAssembly.Module(wasmTextToBinary( diff --git a/js/src/wasm/WasmAST.h b/js/src/wasm/WasmAST.h index 7fbdeb0804fd..c3668ae909d5 100644 --- a/js/src/wasm/WasmAST.h +++ b/js/src/wasm/WasmAST.h @@ -429,7 +429,7 @@ enum class AstExprKind { StructSet, StructNarrow, #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES TableGet, TableGrow, TableSet, @@ -918,7 +918,7 @@ class AstMemOrTableInit : public AstExpr { }; #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES class AstTableGet : public AstExpr { AstRef targetTable_; AstExpr* index_; @@ -980,7 +980,7 @@ class AstTableSize : public AstExpr { AstRef& targetTable() { return targetTable_; } }; -#endif // ENABLE_WASM_GENERALIZED_TABLES +#endif // ENABLE_WASM_REFTYPES #ifdef ENABLE_WASM_GC class AstStructNew : public AstExpr { diff --git a/js/src/wasm/WasmBaselineCompile.cpp b/js/src/wasm/WasmBaselineCompile.cpp index 69868ee35a26..ccaa242c93b9 100644 --- a/js/src/wasm/WasmBaselineCompile.cpp +++ b/js/src/wasm/WasmBaselineCompile.cpp @@ -10942,7 +10942,7 @@ bool BaseCompiler::emitBody() { CHECK_NEXT(emitGetGlobal()); case uint16_t(Op::SetGlobal): CHECK_NEXT(emitSetGlobal()); -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case uint16_t(Op::TableGet): CHECK_NEXT(emitTableGet()); case uint16_t(Op::TableSet): @@ -11544,7 +11544,7 @@ bool BaseCompiler::emitBody() { case uint16_t(MiscOp::TableInit): CHECK_NEXT(emitMemOrTableInit(/*isMem=*/false)); #endif // ENABLE_WASM_BULKMEM_OPS -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case uint16_t(MiscOp::TableGrow): CHECK_NEXT(emitTableGrow()); case uint16_t(MiscOp::TableSize): diff --git a/js/src/wasm/WasmConstants.h b/js/src/wasm/WasmConstants.h index b61cd44659a0..5d4cf76a85f1 100644 --- a/js/src/wasm/WasmConstants.h +++ b/js/src/wasm/WasmConstants.h @@ -170,7 +170,7 @@ enum class Op { TeeLocal = 0x22, GetGlobal = 0x23, SetGlobal = 0x24, - TableGet = 0x25, // Generalized table ops, + TableGet = 0x25, // Reftypes, TableSet = 0x26, // per proposal as of February 2019 // Memory-related operators @@ -382,7 +382,7 @@ enum class MiscOp { ElemDrop = 0x0d, TableCopy = 0x0e, - // Generalized table operations, per proposal as of February 2019. + // Reftypes, per proposal as of February 2019. TableGrow = 0x0f, TableSize = 0x10, // TableFill = 0x11, // reserved diff --git a/js/src/wasm/WasmIonCompile.cpp b/js/src/wasm/WasmIonCompile.cpp index 0ad32b3aba43..93e4b750c9b5 100644 --- a/js/src/wasm/WasmIonCompile.cpp +++ b/js/src/wasm/WasmIonCompile.cpp @@ -3113,7 +3113,7 @@ static bool EmitMemOrTableInit(FunctionCompiler& f, bool isMem) { } #endif // ENABLE_WASM_BULKMEM_OPS -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES // Note, table.{get,grow,set} on table(anyfunc) are currently rejected by the // verifier. @@ -3311,7 +3311,7 @@ static bool EmitTableSize(FunctionCompiler& f) { f.iter().setResult(ret); return true; } -#endif // ENABLE_WASM_GENERALIZED_TABLES +#endif // ENABLE_WASM_REFTYPES #ifdef ENABLE_WASM_REFTYPES static bool EmitRefNull(FunctionCompiler& f) { @@ -3425,7 +3425,7 @@ static bool EmitBodyExprs(FunctionCompiler& f) { CHECK(EmitGetGlobal(f)); case uint16_t(Op::SetGlobal): CHECK(EmitSetGlobal(f)); -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case uint16_t(Op::TableGet): CHECK(EmitTableGet(f)); case uint16_t(Op::TableSet): @@ -3849,7 +3849,7 @@ static bool EmitBodyExprs(FunctionCompiler& f) { case uint16_t(MiscOp::TableInit): CHECK(EmitMemOrTableInit(f, /*isMem=*/false)); #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case uint16_t(MiscOp::TableGrow): CHECK(EmitTableGrow(f)); case uint16_t(MiscOp::TableSize): diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index 345898c9c8ba..8690a9a9ade3 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -2103,7 +2103,7 @@ bool WasmTableObject::construct(JSContext* cx, unsigned argc, Value* vp) { StringEqualsAscii(elementLinearStr, "funcref")) { tableKind = TableKind::AnyFunction; -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES } else if (StringEqualsAscii(elementLinearStr, "anyref")) { if (!HasReftypesSupport(cx)) { JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, @@ -2113,7 +2113,7 @@ bool WasmTableObject::construct(JSContext* cx, unsigned argc, Value* vp) { tableKind = TableKind::AnyRef; #endif } else { -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_ELEMENT_GENERALIZED); #else diff --git a/js/src/wasm/WasmOpIter.cpp b/js/src/wasm/WasmOpIter.cpp index 59f18979242c..f48490e4bcb5 100644 --- a/js/src/wasm/WasmOpIter.cpp +++ b/js/src/wasm/WasmOpIter.cpp @@ -22,12 +22,6 @@ using namespace js; using namespace js::jit; using namespace js::wasm; -#ifdef ENABLE_WASM_GENERALIZED_TABLES -# ifndef ENABLE_WASM_REFTYPES -# error "Generalized tables require the reftypes feature" -# endif -#endif - #ifdef ENABLE_WASM_GC # ifndef ENABLE_WASM_REFTYPES # error "GC types require the reftypes feature" @@ -51,11 +45,6 @@ using namespace js::wasm; # else # define WASM_BULK_OP(code) break # endif -# ifdef ENABLE_WASM_GENERALIZED_TABLES -# define WASM_TABLE_OP(code) return code -# else -# define WASM_TABLE_OP(code) break -# endif OpKind wasm::Classify(OpBytes op) { switch (Op(op.b0)) { @@ -253,9 +242,9 @@ OpKind wasm::Classify(OpBytes op) { case Op::SetGlobal: return OpKind::SetGlobal; case Op::TableGet: - WASM_TABLE_OP(OpKind::TableGet); + WASM_REF_OP(OpKind::TableGet); case Op::TableSet: - WASM_TABLE_OP(OpKind::TableSet); + WASM_REF_OP(OpKind::TableSet); case Op::Call: return OpKind::Call; case Op::CallIndirect: @@ -308,9 +297,9 @@ OpKind wasm::Classify(OpBytes op) { case MiscOp::TableInit: WASM_BULK_OP(OpKind::MemOrTableInit); case MiscOp::TableGrow: - WASM_TABLE_OP(OpKind::TableGrow); + WASM_REF_OP(OpKind::TableGrow); case MiscOp::TableSize: - WASM_TABLE_OP(OpKind::TableSize); + WASM_REF_OP(OpKind::TableSize); case MiscOp::StructNew: WASM_GC_OP(OpKind::StructNew); case MiscOp::StructGet: @@ -455,6 +444,6 @@ OpKind wasm::Classify(OpBytes op) { # undef WASM_GC_OP # undef WASM_BULK_OP -# undef WASM_TABLE_OP +# undef WASM_REF_OP #endif diff --git a/js/src/wasm/WasmTextToBinary.cpp b/js/src/wasm/WasmTextToBinary.cpp index e3af8641ff76..80c8633c3138 100644 --- a/js/src/wasm/WasmTextToBinary.cpp +++ b/js/src/wasm/WasmTextToBinary.cpp @@ -145,7 +145,7 @@ class WasmToken { ElemDrop, TableInit, #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES TableGet, TableGrow, TableSet, @@ -345,7 +345,7 @@ class WasmToken { case TableCopy: case TableInit: #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case TableGet: case TableGrow: case TableSet: @@ -2256,7 +2256,7 @@ WasmToken WasmTokenStream::next() { return WasmToken(WasmToken::TableInit, begin, cur_); } #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES if (consume(u"get")) { return WasmToken(WasmToken::TableGet, begin, cur_); } @@ -3782,7 +3782,7 @@ static AstMemOrTableInit* ParseMemOrTableInit(WasmParseContext& c, } #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES static AstTableGet* ParseTableGet(WasmParseContext& c, bool inParens) { // (table.get table index) // (table.get index) @@ -4037,7 +4037,7 @@ static AstExpr* ParseExprBody(WasmParseContext& c, WasmToken token, case WasmToken::TableInit: return ParseMemOrTableInit(c, inParens, /*isMem=*/false); #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case WasmToken::TableGet: return ParseTableGet(c, inParens); case WasmToken::TableGrow: @@ -4656,7 +4656,7 @@ static bool ParseElemType(WasmParseContext& c, TableKind* tableKind) { *tableKind = TableKind::AnyFunction; return true; } -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES if (c.ts.getIf(WasmToken::ValueType, &token) && token.valueType() == ValType::AnyRef) { *tableKind = TableKind::AnyRef; @@ -5650,7 +5650,7 @@ static bool ResolveMemOrTableInit(Resolver& r, AstMemOrTableInit& s) { } #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES static bool ResolveTableGet(Resolver& r, AstTableGet& s) { return ResolveExpr(r, s.index()) && r.resolveTable(s.targetTable()); } @@ -5802,7 +5802,7 @@ static bool ResolveExpr(Resolver& r, AstExpr& expr) { case AstExprKind::MemOrTableInit: return ResolveMemOrTableInit(r, expr.as()); #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case AstExprKind::TableGet: return ResolveTableGet(r, expr.as()); case AstExprKind::TableGrow: @@ -6424,7 +6424,7 @@ static bool EncodeMemOrTableInit(Encoder& e, AstMemOrTableInit& s) { } #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES static bool EncodeTableGet(Encoder& e, AstTableGet& s) { return EncodeExpr(e, s.index()) && e.writeOp(Op::TableGet) && e.writeVarU32(s.targetTable().index()); @@ -6604,7 +6604,7 @@ static bool EncodeExpr(Encoder& e, AstExpr& expr) { case AstExprKind::MemOrTableInit: return EncodeMemOrTableInit(e, expr.as()); #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case AstExprKind::TableGet: return EncodeTableGet(e, expr.as()); case AstExprKind::TableGrow: diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index 678f286c71ec..b00073fa50ec 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -534,7 +534,7 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, uint32_t unused; CHECK(iter.readSetGlobal(&unused, ¬hing)); } -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case uint16_t(Op::TableGet): { uint32_t unusedTableIndex; CHECK(iter.readTableGet(&unusedTableIndex, ¬hing)); @@ -869,7 +869,7 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env, ¬hing)); } #endif -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES case uint16_t(MiscOp::TableGrow): { uint32_t unusedTableIndex; CHECK(iter.readTableGrow(&unusedTableIndex, ¬hing, ¬hing)); @@ -1562,7 +1562,7 @@ static bool DecodeTableTypeAndLimits(Decoder& d, bool gcTypesEnabled, TableKind tableKind; if (elementType == uint8_t(TypeCode::AnyFunc)) { tableKind = TableKind::AnyFunction; -#ifdef ENABLE_WASM_GENERALIZED_TABLES +#ifdef ENABLE_WASM_REFTYPES } else if (elementType == uint8_t(TypeCode::AnyRef)) { if (!gcTypesEnabled) { return d.fail("reference types not enabled"); @@ -1570,10 +1570,10 @@ static bool DecodeTableTypeAndLimits(Decoder& d, bool gcTypesEnabled, tableKind = TableKind::AnyRef; #endif } else { -#ifdef ENABLE_WASM_GENERALIZED_TABLES - return d.fail("expected 'anyfunc' or 'anyref' element type"); +#ifdef ENABLE_WASM_REFTYPES + return d.fail("expected 'funcref' or 'anyref' element type"); #else - return d.fail("expected 'anyfunc' element type"); + return d.fail("expected 'funcref' element type"); #endif }