Title: [270015] trunk
Revision
270015
Author
[email protected]
Date
2020-11-18 20:11:18 -0800 (Wed, 18 Nov 2020)

Log Message

[WASM-References] Remove subtyping rule for externref and funcref
https://bugs.webkit.org/show_bug.cgi?id=218885

Patch by Dmitry Bezhetskov <[email protected]> on 2020-11-18
Reviewed by Yusuke Suzuki.

Make funcref is not a subtype of externref.
The spec: https://webassembly.github.io/reference-types/core/
The PR for removing subtype from the spec:
https://github.com/WebAssembly/reference-types/pull/87.

JSTests:

* wasm/references/func_ref.js:
(assert.eq.instance.exports.fix.fun):
(assert.eq.instance.exports.fix):
* wasm/references/validation.js:

Source/_javascript_Core:

* wasm/WasmFormat.h:
(JSC::Wasm::isSubtype):
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::link):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (270014 => 270015)


--- trunk/JSTests/ChangeLog	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/JSTests/ChangeLog	2020-11-19 04:11:18 UTC (rev 270015)
@@ -1,3 +1,20 @@
+2020-11-18  Dmitry Bezhetskov  <[email protected]>
+
+        [WASM-References] Remove subtyping rule for externref and funcref
+        https://bugs.webkit.org/show_bug.cgi?id=218885
+
+        Reviewed by Yusuke Suzuki.
+
+        Make funcref is not a subtype of externref.
+        The spec: https://webassembly.github.io/reference-types/core/
+        The PR for removing subtype from the spec:
+        https://github.com/WebAssembly/reference-types/pull/87.
+
+        * wasm/references/func_ref.js:
+        (assert.eq.instance.exports.fix.fun):
+        (assert.eq.instance.exports.fix):
+        * wasm/references/validation.js:
+
 2020-11-18  Ross Kirsling  <[email protected]>
 
         [JSC] Reinstate String#at

Modified: trunk/JSTests/wasm/js-api/web-assembly-instantiate.js (270014 => 270015)


--- trunk/JSTests/wasm/js-api/web-assembly-instantiate.js	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/JSTests/wasm/js-api/web-assembly-instantiate.js	2020-11-19 04:11:18 UTC (rev 270015)
@@ -76,7 +76,7 @@
             let {module, instance} = await WebAssembly.instantiate(bin);
         } catch(e) {
             assert.truthy(e instanceof WebAssembly.CompileError);
-            assert.eq(e.message, "WebAssembly.Module doesn't validate: control flow returns with unexpected type. F32 is not a subtype of I32, in function at index 0");
+            assert.eq(e.message, "WebAssembly.Module doesn't validate: control flow returns with unexpected type. F32 is not a I32, in function at index 0");
         }
     }
 

Modified: trunk/JSTests/wasm/references/func_ref.js (270014 => 270015)


--- trunk/JSTests/wasm/references/func_ref.js	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/JSTests/wasm/references/func_ref.js	2020-11-19 04:11:18 UTC (rev 270015)
@@ -75,20 +75,13 @@
           .Type().End()
           .Function().End()
           .Export()
-              .Function("h")
               .Function("i")
-              .Function("get_h")
+              .Function("get_i")
               .Function("fix")
               .Function("get_not_exported")
               .Function("local_read")
           .End()
           .Code()
-            .Function("h", { params: ["funcref"], ret: "externref" }, ["externref"])
-              .GetLocal(0)
-              .SetLocal(1)
-              .GetLocal(1)
-            .End()
-
             .Function("i", { params: ["funcref"], ret: "funcref" }, ["funcref"])
               .GetLocal(0)
               .SetLocal(1)
@@ -95,7 +88,7 @@
               .GetLocal(1)
             .End()
 
-            .Function("get_h", { params: [], ret: "funcref" }, ["funcref"])
+            .Function("get_i", { params: [], ret: "funcref" }, ["funcref"])
               .I32Const(0)
               .RefFunc(0)
               .SetLocal(0)
@@ -111,11 +104,11 @@
             .End()
 
             .Function("fix", { params: [], ret: "funcref" }, [])
-              .RefFunc(3)
+              .RefFunc(2)
             .End()
 
             .Function("get_not_exported", { params: [], ret: "funcref" }, [])
-              .RefFunc(5)
+              .RefFunc(4)
             .End()
 
             .Function("ret_42", { params: [], ret: "i32" }, [])
@@ -134,22 +127,16 @@
     fullGC();
 
     assert.eq(instance.exports.local_read(), 1)
-    assert.eq(instance.exports.h(null), null)
 
-    assert.throws(() => instance.exports.h(fun), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
-    assert.eq(instance.exports.h(myfun), myfun)
-    assert.throws(() => instance.exports.h(5), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
-    assert.throws(() => instance.exports.h(undefined), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
-
     assert.eq(instance.exports.i(null), null)
     assert.eq(instance.exports.i(myfun), myfun)
     assert.throws(() => instance.exports.i(fun), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
     assert.throws(() => instance.exports.i(5), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
 
-    assert.throws(() => instance.exports.get_h()(fun), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
-    assert.eq(instance.exports.get_h()(null), null)
-    assert.eq(instance.exports.get_h()(myfun), myfun)
-    assert.throws(() => instance.exports.get_h()(5), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
+    assert.throws(() => instance.exports.get_i()(fun), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
+    assert.eq(instance.exports.get_i()(null), null)
+    assert.eq(instance.exports.get_i()(myfun), myfun)
+    assert.throws(() => instance.exports.get_i()(5), Error, "Funcref must be an exported wasm function (evaluating 'func(...args)')")
 
     assert.eq(instance.exports.get_not_exported()(), 42)
 
@@ -157,6 +144,29 @@
     assert.eq(instance.exports.fix(), instance.exports.fix);
 }
 
+// Casting the Funcref to Externref is forbidden.
+
+{
+    function fun() { return 41; }
+
+    const builder = (new Builder())
+          .Type().End()
+          .Function().End()
+          .Export()
+              .Function("h")
+          .End()
+          .Code()
+            .Function("h", { params: ["funcref"], ret: "externref" }, ["externref"])
+              .GetLocal(0)
+              .SetLocal(1)
+              .GetLocal(1)
+            .End()
+          .End();
+
+    const bin = builder.WebAssembly().get();
+    assert.throws(() => new WebAssembly.Module(bin), WebAssembly.CompileError, "WebAssembly.Module doesn't validate: set_local to type Funcref expected Externref, in function at index 0 (evaluating 'new WebAssembly.Module(bin)')");
+}
+
 // Globals
 
 {
@@ -246,7 +256,7 @@
     .Function("h", { params: ["externref"], ret: "funcref" })
       .GetLocal(0)
     .End()
-  .End().WebAssembly().get()), Error, "WebAssembly.Module doesn't validate: control flow returns with unexpected type. Externref is not a subtype of Funcref, in function at index 0 (evaluating 'new WebAssembly.Module')");
+  .End().WebAssembly().get()), Error, "WebAssembly.Module doesn't validate: control flow returns with unexpected type. Externref is not a Funcref, in function at index 0 (evaluating 'new WebAssembly.Module')");
 
 assert.throws(() => new WebAssembly.Module((new Builder())
   .Type().End()

Modified: trunk/JSTests/wasm/references/validation.js (270014 => 270015)


--- trunk/JSTests/wasm/references/validation.js	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/JSTests/wasm/references/validation.js	2020-11-19 04:11:18 UTC (rev 270015)
@@ -19,7 +19,7 @@
     const bin = builder.WebAssembly();
     bin.trim();
 
-    assert.throws(() => new WebAssembly.Module(bin.get()), WebAssembly.CompileError, "WebAssembly.Module doesn't validate: ref.is_null to type I32 expected Externref, in function at index 0 (evaluating 'new WebAssembly.Module(bin.get())')");
+    assert.throws(() => new WebAssembly.Module(bin.get()), WebAssembly.CompileError, "WebAssembly.Module doesn't validate: ref.is_null to type I32 expected a reference type, in function at index 0 (evaluating 'new WebAssembly.Module(bin.get())')");
 }
 
 {
@@ -90,7 +90,7 @@
     const bin = builder.WebAssembly();
     bin.trim();
 
-    assert.throws(() => new WebAssembly.Module(bin.get()), WebAssembly.CompileError, "WebAssembly.Module doesn't validate: control flow returns with unexpected type. Externref is not a subtype of Funcref, in function at index 0 (evaluating 'new WebAssembly.Module(bin.get())')");
+    assert.throws(() => new WebAssembly.Module(bin.get()), WebAssembly.CompileError, "WebAssembly.Module doesn't validate: control flow returns with unexpected type. Externref is not a Funcref, in function at index 0 (evaluating 'new WebAssembly.Module(bin.get())')");
 }
 
 {

Modified: trunk/LayoutTests/workers/wasm-references/test.js (270014 => 270015)


--- trunk/LayoutTests/workers/wasm-references/test.js	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/LayoutTests/workers/wasm-references/test.js	2020-11-19 04:11:18 UTC (rev 270015)
@@ -1860,9 +1860,9 @@
             .Function("tbl_size", { params: [], ret: "i32" })
               .TableSize(1)
             .End()
-            .Function("tbl_grow", { params: ["i32"], ret: "i32" })
-                .RefFunc(0)
+            .Function("tbl_grow", { params: ["externref", "i32"], ret: "i32" })
                 .GetLocal(0)
+                .GetLocal(1)
                 .TableGrow(1)
             .End()
             .Function("tbl_fill", { params: ["i32", "externref", "i32"], ret: "void" })

Modified: trunk/LayoutTests/workers/wasm-references/worker.js (270014 => 270015)


--- trunk/LayoutTests/workers/wasm-references/worker.js	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/LayoutTests/workers/wasm-references/worker.js	2020-11-19 04:11:18 UTC (rev 270015)
@@ -173,10 +173,10 @@
     WebAssembly.instantiate(module).then(($1) => {
         try {
             assert.eq($1.exports.tbl_size(), 20)
-            assert.eq($1.exports.tbl_grow(5), 20)
+            assert.eq($1.exports.tbl_grow("hi", 5), 20)
             assert.eq($1.exports.tbl_size(), 25)
             assert.eq($1.exports.tbl.get(0), null)
-            assert.eq($1.exports.tbl.get(24), $1.exports.tbl_size)
+            assert.eq($1.exports.tbl.get(24), "hi")
 
             for (let i=0; i<1000; ++i) {
                 $1.exports.tbl_fill(1,"hi",3)

Modified: trunk/Source/_javascript_Core/ChangeLog (270014 => 270015)


--- trunk/Source/_javascript_Core/ChangeLog	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-11-19 04:11:18 UTC (rev 270015)
@@ -1,3 +1,22 @@
+2020-11-18  Dmitry Bezhetskov  <[email protected]>
+
+        [WASM-References] Remove subtyping rule for externref and funcref
+        https://bugs.webkit.org/show_bug.cgi?id=218885
+
+        Reviewed by Yusuke Suzuki.
+
+        Make funcref is not a subtype of externref.
+        The spec: https://webassembly.github.io/reference-types/core/
+        The PR for removing subtype from the spec:
+        https://github.com/WebAssembly/reference-types/pull/87.
+
+        * wasm/WasmFormat.h:
+        (JSC::Wasm::isSubtype):
+        * wasm/WasmFunctionParser.h:
+        (JSC::Wasm::FunctionParser<Context>::parseExpression):
+        * wasm/js/WebAssemblyModuleRecord.cpp:
+        (JSC::WebAssemblyModuleRecord::link):
+
 2020-11-18  Ross Kirsling  <[email protected]>
 
         [JSC] Reinstate String#at

Modified: trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp	2020-11-19 04:11:18 UTC (rev 270015)
@@ -1102,7 +1102,7 @@
 auto AirIRGenerator::addTableGrow(unsigned tableIndex, ExpressionType fill, ExpressionType delta, ExpressionType& result) -> PartialResult
 {
     ASSERT(fill.tmp());
-    ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()));
+    ASSERT(fill.type() == m_info.tables[tableIndex].wasmType());
     ASSERT(delta.tmp());
     ASSERT(delta.type() == Type::I32);
     result = tmpForType(Type::I32);
@@ -1115,7 +1115,7 @@
 auto AirIRGenerator::addTableFill(unsigned tableIndex, ExpressionType offset, ExpressionType fill, ExpressionType count) -> PartialResult
 {
     ASSERT(fill.tmp());
-    ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()));
+    ASSERT(fill.type() == m_info.tables[tableIndex].wasmType());
     ASSERT(offset.tmp());
     ASSERT(offset.type() == Type::I32);
     ASSERT(count.tmp());
@@ -1251,7 +1251,7 @@
             append(Add64, temp2, temp, temp);
             append(moveOpForValueType(type), value, Arg::addr(temp));
         }
-        if (isSubtype(type, Externref))
+        if (isRefType(type))
             emitWriteBarrierForJSWrapper();
         break;
     case Wasm::GlobalInformation::BindingMode::Portable:
@@ -1266,7 +1266,7 @@
         }
         append(moveOpForValueType(type), value, Arg::addr(temp));
         // We emit a write-barrier onto JSWebAssemblyGlobal, not JSWebAssemblyInstance.
-        if (isSubtype(type, Externref)) {
+        if (isRefType(type)) {
             auto cell = g64();
             auto vm = g64();
             auto cellState = g32();
@@ -2330,7 +2330,7 @@
 
 void AirIRGenerator::unify(const ExpressionType dst, const ExpressionType source)
 {
-    ASSERT(isSubtype(source.type(), dst.type()));
+    ASSERT(source.type() == dst.type());
     append(moveOpForValueType(dst.type()), source, dst);
 }
 

Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp	2020-11-19 04:11:18 UTC (rev 270015)
@@ -633,7 +633,7 @@
     for (uint32_t i = 0; i < count; ++i) {
         Variable* local = m_proc.addVariable(toB3Type(type));
         m_locals.uncheckedAppend(local);
-        auto val = isSubtype(type, Externref) ? JSValue::encode(jsNull()) : 0;
+        auto val = isRefType(type) ? JSValue::encode(jsNull()) : 0;
         m_currentBlock->appendNew<VariableValue>(m_proc, Set, Origin(), local, constant(toB3Type(type), val, Origin()));
     }
     return { };
@@ -840,7 +840,7 @@
     switch (global.bindingMode) {
     case Wasm::GlobalInformation::BindingMode::EmbeddedInInstance:
         m_currentBlock->appendNew<MemoryValue>(m_proc, Store, origin(), value, globalsArray, safeCast<int32_t>(index * sizeof(Register)));
-        if (isSubtype(global.type, Externref))
+        if (isRefType(global.type))
             emitWriteBarrierForJSWrapper();
         break;
     case Wasm::GlobalInformation::BindingMode::Portable: {
@@ -848,7 +848,7 @@
         Value* pointer = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, B3::Int64, origin(), globalsArray, safeCast<int32_t>(index * sizeof(Register)));
         m_currentBlock->appendNew<MemoryValue>(m_proc, Store, origin(), value, pointer);
         // We emit a write-barrier onto JSWebAssemblyGlobal, not JSWebAssemblyInstance.
-        if (isSubtype(global.type, Externref)) {
+        if (isRefType(global.type)) {
             Value* instance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfOwner()));
             Value* cell = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), pointer, Wasm::Global::offsetOfOwner() - Wasm::Global::offsetOfValue());
             Value* cellState = m_currentBlock->appendNew<MemoryValue>(m_proc, Load8Z, Int32, origin(), cell, safeCast<int32_t>(JSCell::cellStateOffset()));

Modified: trunk/Source/_javascript_Core/wasm/WasmFormat.h (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmFormat.h	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmFormat.h	2020-11-19 04:11:18 UTC (rev 270015)
@@ -78,13 +78,6 @@
     return false;
 }
 
-inline bool isSubtype(Type sub, Type parent)
-{
-    if (sub == parent)
-        return true;
-    return sub == Funcref && parent == Externref;
-}
-
 inline bool isRefType(Type type)
 {
     return type == Externref || type == Funcref;

Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2020-11-19 04:11:18 UTC (rev 270015)
@@ -327,7 +327,7 @@
 
     unsigned offset = m_expressionStack.size() - target.branchTargetArity();
     for (unsigned i = 0; i < target.branchTargetArity(); ++i)
-        WASM_VALIDATOR_FAIL_IF(!isSubtype(target.branchTargetType(i), m_expressionStack[offset + i].type()), "branch's stack type is not a subtype of block's type branch target type. Stack value has type", m_expressionStack[offset + i].type(), " but branch target expects a value with subtype of ", target.branchTargetType(i), " at index ", i);
+        WASM_VALIDATOR_FAIL_IF(target.branchTargetType(i) != m_expressionStack[offset + i].type(), "branch's stack type is not a block's type branch target type. Stack value has type", m_expressionStack[offset + i].type(), " but branch target expects a value of ", target.branchTargetType(i), " at index ", i);
 
     return { };
 }
@@ -337,7 +337,7 @@
 {
     WASM_VALIDATOR_FAIL_IF(controlData.signature()->returnCount() != m_expressionStack.size(), " block with type: ", controlData.signature()->toString(), " returns: ", controlData.signature()->returnCount(), " but stack has: ", m_expressionStack.size(), " values");
     for (unsigned i = 0; i < controlData.signature()->returnCount(); ++i)
-        WASM_VALIDATOR_FAIL_IF(!isSubtype(m_expressionStack[i].type(), controlData.signature()->returnType(i)), "control flow returns with unexpected type. ", m_expressionStack[i].type(), " is not a subtype of ", controlData.signature()->returnType(i));
+        WASM_VALIDATOR_FAIL_IF(m_expressionStack[i].type() != controlData.signature()->returnType(i), "control flow returns with unexpected type. ", m_expressionStack[i].type(), " is not a ", controlData.signature()->returnType(i));
 
     return { };
 }
@@ -436,7 +436,7 @@
         WASM_TRY_POP_EXPRESSION_STACK_INTO(index, "table.set");
         WASM_VALIDATOR_FAIL_IF(I32 != index.type(), "table.set index to type ", index.type(), " expected ", I32);
         Type type = m_info.tables[tableIndex].wasmType();
-        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), type), "table.set value to type ", value.type(), " expected ", type);
+        WASM_VALIDATOR_FAIL_IF(value.type() != type, "table.set value to type ", value.type(), " expected ", type);
         RELEASE_ASSERT(m_info.tables[tableIndex].type() == TableElementType::Externref || m_info.tables[tableIndex].type() == TableElementType::Funcref);
         WASM_TRY_ADD_TO_CONTEXT(addTableSet(tableIndex, index, value));
         return { };
@@ -463,7 +463,7 @@
             WASM_TRY_POP_EXPRESSION_STACK_INTO(delta, "table.grow");
             WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.grow");
 
-            WASM_VALIDATOR_FAIL_IF(!isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()), "table.grow expects fill value of type ", m_info.tables[tableIndex].wasmType(), " got ", fill.type());
+            WASM_VALIDATOR_FAIL_IF(fill.type() != m_info.tables[tableIndex].wasmType(), "table.grow expects fill value of type ", m_info.tables[tableIndex].wasmType(), " got ", fill.type());
             WASM_VALIDATOR_FAIL_IF(I32 != delta.type(), "table.grow expects an i32 delta value, got ", delta.type());
 
             ExpressionType result;
@@ -477,7 +477,7 @@
             WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.fill");
             WASM_TRY_POP_EXPRESSION_STACK_INTO(offset, "table.fill");
 
-            WASM_VALIDATOR_FAIL_IF(!isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()), "table.fill expects fill value of type ", m_info.tables[tableIndex].wasmType(), " got ", fill.type());
+            WASM_VALIDATOR_FAIL_IF(fill.type() != m_info.tables[tableIndex].wasmType(), "table.fill expects fill value of type ", m_info.tables[tableIndex].wasmType(), " got ", fill.type());
             WASM_VALIDATOR_FAIL_IF(I32 != offset.type(), "table.fill expects an i32 offset value, got ", offset.type());
             WASM_VALIDATOR_FAIL_IF(I32 != count.type(), "table.fill expects an i32 count value, got ", count.type());
 
@@ -503,7 +503,7 @@
         WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled");
         TypedExpression value;
         WASM_TRY_POP_EXPRESSION_STACK_INTO(value, "ref.is_null");
-        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), Externref), "ref.is_null to type ", value.type(), " expected ", Externref);
+        WASM_VALIDATOR_FAIL_IF(!isRefType(value.type()), "ref.is_null to type ", value.type(), " expected a reference type");
         ExpressionType result;
         WASM_TRY_ADD_TO_CONTEXT(addRefIsNull(value, result));
         m_expressionStack.constructAndAppend(I32, result);
@@ -539,7 +539,7 @@
         WASM_PARSER_FAIL_IF(!parseVarUInt32(index), "can't get index for set_local");
         WASM_TRY_POP_EXPRESSION_STACK_INTO(value, "set_local");
         WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to set unknown local ", index, " last one is ", m_locals.size());
-        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type(), " expected ", m_locals[index]);
+        WASM_VALIDATOR_FAIL_IF(value.type() != m_locals[index], "set_local to type ", value.type(), " expected ", m_locals[index]);
         WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value));
         return { };
     }
@@ -550,7 +550,7 @@
         WASM_PARSER_FAIL_IF(m_expressionStack.isEmpty(), "can't tee_local on empty _expression_ stack");
         TypedExpression value = m_expressionStack.last();
         WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to tee unknown local ", index, " last one is ", m_locals.size());
-        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type(), " expected ", m_locals[index]);
+        WASM_VALIDATOR_FAIL_IF(value.type() != m_locals[index], "set_local to type ", value.type(), " expected ", m_locals[index]);
         WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value));
         return { };
     }
@@ -598,7 +598,7 @@
         WASM_PARSER_FAIL_IF(!args.tryReserveCapacity(calleeSignature.argumentCount()), "can't allocate enough memory for call's ", calleeSignature.argumentCount(), " arguments");
         for (size_t i = firstArgumentIndex; i < m_expressionStack.size(); ++i) {
             TypedExpression arg = m_expressionStack.at(i);
-            WASM_VALIDATOR_FAIL_IF(!isSubtype(arg.type(), calleeSignature.argument(i - firstArgumentIndex)), "argument type mismatch in call, got ", arg.type(), ", expected ", calleeSignature.argument(i - firstArgumentIndex));
+            WASM_VALIDATOR_FAIL_IF(arg.type() != calleeSignature.argument(i - firstArgumentIndex), "argument type mismatch in call, got ", arg.type(), ", expected ", calleeSignature.argument(i - firstArgumentIndex));
             args.uncheckedAppend(arg);
             m_context.didPopValueFromStack();
         }
@@ -639,7 +639,7 @@
         for (size_t i = firstArgumentIndex; i < m_expressionStack.size(); ++i) {
             TypedExpression arg = m_expressionStack.at(i);
             if (i < m_expressionStack.size() - 1)
-                WASM_VALIDATOR_FAIL_IF(!isSubtype(arg.type(), calleeSignature.argument(i - firstArgumentIndex)), "argument type mismatch in call_indirect, got ", arg.type(), ", expected ", calleeSignature.argument(i - firstArgumentIndex));
+                WASM_VALIDATOR_FAIL_IF(arg.type() != calleeSignature.argument(i - firstArgumentIndex), "argument type mismatch in call_indirect, got ", arg.type(), ", expected ", calleeSignature.argument(i - firstArgumentIndex));
             args.uncheckedAppend(arg);
             m_context.didPopValueFromStack();
         }
@@ -662,7 +662,7 @@
         unsigned offset = m_expressionStack.size() - inlineSignature->argumentCount();
         for (unsigned i = 0; i < inlineSignature->argumentCount(); ++i) {
             Type type = m_expressionStack.at(offset + i).type();
-            WASM_VALIDATOR_FAIL_IF(!isSubtype(type, inlineSignature->argument(i)), "Block expects the argument at index", i, " to be a subtype of ", inlineSignature->argument(i), " but argument has type ", type);
+            WASM_VALIDATOR_FAIL_IF(type != inlineSignature->argument(i), "Block expects the argument at index", i, " to be ", inlineSignature->argument(i), " but argument has type ", type);
         }
 
         int64_t oldSize = m_expressionStack.size();
@@ -685,7 +685,7 @@
         unsigned offset = m_expressionStack.size() - inlineSignature->argumentCount();
         for (unsigned i = 0; i < inlineSignature->argumentCount(); ++i) {
             Type type = m_expressionStack.at(offset + i).type();
-            WASM_VALIDATOR_FAIL_IF(!isSubtype(type, inlineSignature->argument(i)), "Loop expects the argument at index", i, " to be a subtype of ", inlineSignature->argument(i), " but argument has type ", type);
+            WASM_VALIDATOR_FAIL_IF(type != inlineSignature->argument(i), "Loop expects the argument at index", i, " to be ", inlineSignature->argument(i), " but argument has type ", type);
         }
 
         int64_t oldSize = m_expressionStack.size();
@@ -710,7 +710,7 @@
         WASM_VALIDATOR_FAIL_IF(m_expressionStack.size() < inlineSignature->argumentCount(), "Too few arguments on stack for if block. If expects ", inlineSignature->argumentCount(), ", but only ", m_expressionStack.size(), " were present. If block has signature: ", inlineSignature->toString());
         unsigned offset = m_expressionStack.size() - inlineSignature->argumentCount();
         for (unsigned i = 0; i < inlineSignature->argumentCount(); ++i)
-            WASM_VALIDATOR_FAIL_IF(!isSubtype(m_expressionStack[offset + i].type(), inlineSignature->argument(i)), "Loop expects the argument at index", i, " to be a subtype of ", inlineSignature->argument(i), " but argument has type ", m_expressionStack[i].type());
+            WASM_VALIDATOR_FAIL_IF(m_expressionStack[offset + i].type() != inlineSignature->argument(i), "Loop expects the argument at index", i, " to be ", inlineSignature->argument(i), " but argument has type ", m_expressionStack[i].type());
 
         int64_t oldSize = m_expressionStack.size();
         Stack newStack;
@@ -784,7 +784,7 @@
             ControlType* target = targets[i];
             WASM_VALIDATOR_FAIL_IF(defaultTarget.branchTargetArity() != target->branchTargetArity(), "br_table target type size mismatch. Default has size: ", defaultTarget.branchTargetArity(), "but target: ", i, " has size: ", target->branchTargetArity());
             for (unsigned type = 0; type < defaultTarget.branchTargetArity(); ++type)
-                WASM_VALIDATOR_FAIL_IF(!isSubtype(defaultTarget.branchTargetType(type), target->branchTargetType(type)), "br_table target type mismatch at offset ", type, " expected: ", defaultTarget.branchTargetType(type), " but saw: ", target->branchTargetType(type), " when targeting block: ", target->signature()->toString());
+                WASM_VALIDATOR_FAIL_IF(defaultTarget.branchTargetType(type) != target->branchTargetType(type), "br_table target type mismatch at offset ", type, " expected: ", defaultTarget.branchTargetType(type), " but saw: ", target->branchTargetType(type), " when targeting block: ", target->signature()->toString());
         }
 
         WASM_FAIL_IF_HELPER_FAILS(checkBranchTarget(defaultTarget));

Modified: trunk/Source/_javascript_Core/wasm/WasmInstance.cpp (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmInstance.cpp	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmInstance.cpp	2020-11-19 04:11:18 UTC (rev 270015)
@@ -62,7 +62,7 @@
         if (global.bindingMode == Wasm::GlobalInformation::BindingMode::Portable) {
             // This is kept alive by JSWebAssemblyInstance -> JSWebAssemblyGlobal -> binding.
             m_globalsToBinding.set(i);
-        } else if (isSubtype(global.type, Externref)) {
+        } else if (isRefType(global.type)) {
             // This is kept alive by JSWebAssemblyInstance -> binding.
             m_globalsToMark.set(i);
         }

Modified: trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp	2020-11-19 04:11:18 UTC (rev 270015)
@@ -826,13 +826,13 @@
     Type type = global.type;
     switch (global.bindingMode) {
     case Wasm::GlobalInformation::BindingMode::EmbeddedInInstance:
-        if (isSubtype(type, Externref))
+        if (isRefType(type))
             WasmSetGlobalRef::emit(this, index, value);
         else
             WasmSetGlobal::emit(this, index, value);
         break;
     case Wasm::GlobalInformation::BindingMode::Portable:
-        if (isSubtype(type, Externref))
+        if (isRefType(type))
             WasmSetGlobalRefPortableBinding::emit(this, index, value);
         else
             WasmSetGlobalPortableBinding::emit(this, index, value);

Modified: trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp	2020-11-19 04:11:18 UTC (rev 270015)
@@ -298,7 +298,7 @@
             global.initializationType = GlobalInformation::FromRefFunc;
         else
             global.initializationType = GlobalInformation::FromExpression;
-        WASM_PARSER_FAIL_IF(!isSubtype(typeForInitOpcode, global.type), "Global init_expr opcode of type ", typeForInitOpcode, " doesn't match global's type ", global.type);
+        WASM_PARSER_FAIL_IF(typeForInitOpcode != global.type, "Global init_expr opcode of type ", typeForInitOpcode, " doesn't match global's type ", global.type);
 
         m_info->globals.uncheckedAppend(WTFMove(global));
     }

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyModuleRecord.cpp (270014 => 270015)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyModuleRecord.cpp	2020-11-19 04:02:54 UTC (rev 270014)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyModuleRecord.cpp	2020-11-19 04:11:18 UTC (rev 270015)
@@ -256,10 +256,11 @@
                         RELEASE_ASSERT_NOT_REACHED();
                     }
                 } else {
+                    const auto globalType = moduleInformation.globals[import.kindIndex].type;
                     // ii. If the global_type of i is i64 or Type(v) is not Number, throw a WebAssembly.LinkError.
-                    if (moduleInformation.globals[import.kindIndex].type == Wasm::I64)
+                    if (globalType == Wasm::I64)
                         return exception(createJSWebAssemblyLinkError(globalObject, vm, importFailMessage(import, "imported global", "cannot be an i64")));
-                    if (!isSubtype(moduleInformation.globals[import.kindIndex].type, Wasm::Externref) && !value.isNumber())
+                    if (!isRefType(globalType) && !value.isNumber())
                         return exception(createJSWebAssemblyLinkError(globalObject, vm, importFailMessage(import, "imported global", "must be a number")));
 
                     // iii. Append ToWebAssemblyValue(v) to imports.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to