Title: [273962] trunk
Revision
273962
Author
commit-qu...@webkit.org
Date
2021-03-05 04:16:49 -0800 (Fri, 05 Mar 2021)

Log Message

[WASM-Function-References] Update ref.func to produce (ref $t)
https://bugs.webkit.org/show_bug.cgi?id=222779

Patch by Dmitry Bezhetskov <dbezhets...@igalia.com> on 2021-03-05
Reviewed by Yusuke Suzuki.

Make ref.func to produce non nullable reference type which
incorporates signature index. Since in JSC signature index represents
type of the function from Type section we use it instead of type_idx
for representing type of function references.

JSTests:

* wasm/wasm.json:

Source/_javascript_Core:

* runtime/OptionsList.h:
* wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::addTableGrow):
(JSC::Wasm::AirIRGenerator::addTableFill):
(JSC::Wasm::AirIRGenerator::unify):
* wasm/WasmFormat.h:
(JSC::Wasm::isValueType):
(JSC::Wasm::isSubtype):
(JSC::Wasm::isRefType):
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::checkBranchTarget):
(JSC::Wasm::FunctionParser<Context>::unify):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* wasm/WasmLLIntGenerator.cpp:
(JSC::Wasm::LLIntGenerator::callInformationForCaller):
(JSC::Wasm::LLIntGenerator::callInformationForCallee):
(JSC::Wasm::LLIntGenerator::addArguments):
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseGlobal):
* wasm/generateWasmOpsHeader.py:
* wasm/js/WasmToJS.cpp:
(JSC::Wasm::wasmToJS):
* wasm/js/WebAssemblyFunction.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* wasm/wasm.json:

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (273961 => 273962)


--- trunk/JSTests/ChangeLog	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/JSTests/ChangeLog	2021-03-05 12:16:49 UTC (rev 273962)
@@ -1,3 +1,17 @@
+2021-03-05  Dmitry Bezhetskov  <dbezhets...@igalia.com>
+
+        [WASM-Function-References] Update ref.func to produce (ref $t)
+        https://bugs.webkit.org/show_bug.cgi?id=222779
+
+        Reviewed by Yusuke Suzuki.
+
+        Make ref.func to produce non nullable reference type which
+        incorporates signature index. Since in JSC signature index represents
+        type of the function from Type section we use it instead of type_idx
+        for representing type of function references.
+
+        * wasm/wasm.json:
+
 2021-03-04  Saam Barati  <sbar...@apple.com>
 
         Don't trust parsing information to tell us if we've emitted op_call_eval

Modified: trunk/JSTests/wasm/wasm.json (273961 => 273962)


--- trunk/JSTests/wasm/wasm.json	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/JSTests/wasm/wasm.json	2021-03-05 12:16:49 UTC (rev 273962)
@@ -7,18 +7,19 @@
         { "name": "version",      "type": "uint32", "value":          1, "description": "Version number" }
     ],
     "type" : {
-        "i32":       { "type": "varint7", "value":  -1, "b3type": "B3::Int32" },
-        "i64":       { "type": "varint7", "value":  -2, "b3type": "B3::Int64" },
-        "f32":       { "type": "varint7", "value":  -3, "b3type": "B3::Float" },
-        "f64":       { "type": "varint7", "value":  -4, "b3type": "B3::Double" },
-        "funcref":   { "type": "varint7", "value": -16, "b3type": "B3::Int64" },
-        "externref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" },
-        "func":      { "type": "varint7", "value": -32, "b3type": "B3::Void" },
-        "void":      { "type": "varint7", "value": -64, "b3type": "B3::Void" }
+        "i32":       { "type": "varint7", "value":   -1, "b3type": "B3::Int32" },
+        "i64":       { "type": "varint7", "value":   -2, "b3type": "B3::Int64" },
+        "f32":       { "type": "varint7", "value":   -3, "b3type": "B3::Float" },
+        "f64":       { "type": "varint7", "value":   -4, "b3type": "B3::Double" },
+        "funcref":   { "type": "varint7", "value":  -16, "b3type": "B3::Int64" },
+        "externref": { "type": "varint7", "value":  -17, "b3type": "B3::Int64" },
+        "func":      { "type": "varint7", "value":  -32, "b3type": "B3::Void" },
+        "void":      { "type": "varint7", "value":  -64, "b3type": "B3::Void" },
+        "type_idx":  { "type": "varint7", "value": -128, "b3type": "B3::Int64" }
     },
     "value_type": ["i32", "i64", "f32", "f64", "externref", "funcref"],
     "block_type": ["i32", "i64", "f32", "f64", "void", "externref", "funcref"],
-    "ref_type": ["funcref","externref"],
+    "ref_type": ["funcref", "externref", "type_idx"],
     "external_kind": {
         "Function": { "type": "uint8", "value": 0 },
         "Table":    { "type": "uint8", "value": 1 },

Modified: trunk/Source/_javascript_Core/ChangeLog (273961 => 273962)


--- trunk/Source/_javascript_Core/ChangeLog	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-03-05 12:16:49 UTC (rev 273962)
@@ -1,3 +1,42 @@
+2021-03-05  Dmitry Bezhetskov  <dbezhets...@igalia.com>
+
+        [WASM-Function-References] Update ref.func to produce (ref $t)
+        https://bugs.webkit.org/show_bug.cgi?id=222779
+
+        Reviewed by Yusuke Suzuki.
+
+        Make ref.func to produce non nullable reference type which
+        incorporates signature index. Since in JSC signature index represents
+        type of the function from Type section we use it instead of type_idx
+        for representing type of function references.
+
+
+        * runtime/OptionsList.h:
+        * wasm/WasmAirIRGenerator.cpp:
+        (JSC::Wasm::AirIRGenerator::addTableGrow):
+        (JSC::Wasm::AirIRGenerator::addTableFill):
+        (JSC::Wasm::AirIRGenerator::unify):
+        * wasm/WasmFormat.h:
+        (JSC::Wasm::isValueType):
+        (JSC::Wasm::isSubtype):
+        (JSC::Wasm::isRefType):
+        * wasm/WasmFunctionParser.h:
+        (JSC::Wasm::FunctionParser<Context>::checkBranchTarget):
+        (JSC::Wasm::FunctionParser<Context>::unify):
+        (JSC::Wasm::FunctionParser<Context>::parseExpression):
+        * wasm/WasmLLIntGenerator.cpp:
+        (JSC::Wasm::LLIntGenerator::callInformationForCaller):
+        (JSC::Wasm::LLIntGenerator::callInformationForCallee):
+        (JSC::Wasm::LLIntGenerator::addArguments):
+        * wasm/WasmSectionParser.cpp:
+        (JSC::Wasm::SectionParser::parseGlobal):
+        * wasm/generateWasmOpsHeader.py:
+        * wasm/js/WasmToJS.cpp:
+        (JSC::Wasm::wasmToJS):
+        * wasm/js/WebAssemblyFunction.cpp:
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+        * wasm/wasm.json:
+
 2021-03-04  Alex Christensen  <achristen...@webkit.org>
 
         [Cocoa] REGRESSION(r272752): fix some internal builds that use WTFString::WTFString(NSString *)

Modified: trunk/Source/_javascript_Core/runtime/OptionsList.h (273961 => 273962)


--- trunk/Source/_javascript_Core/runtime/OptionsList.h	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/runtime/OptionsList.h	2021-03-05 12:16:49 UTC (rev 273962)
@@ -520,6 +520,7 @@
     v(Bool, usePrivateMethods, true, Normal, "If true, the parser will understand private methods inside classes.") \
     v(Bool, useWebAssemblyStreaming, true, Normal, "Allow to run WebAssembly's Streaming API") \
     v(Bool, useWebAssemblyReferences, true, Normal, "Allow types from the wasm references spec.") \
+    v(Bool, useWebAssemblyTypedFunctionReferences, false, Normal, "Allow function types from the wasm typed function references spec.") \
     v(Bool, useWebAssemblyMultiValues, true, Normal, "Allow types from the wasm mulit-values spec.") \
     v(Bool, useWebAssemblyThreading, true, Normal, "Allow instructions from the wasm threading spec.") \
     v(Bool, useWeakRefs, true, Normal, "Expose the WeakRef constructor.") \

Modified: trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp	2021-03-05 12:16:49 UTC (rev 273962)
@@ -1176,7 +1176,7 @@
 auto AirIRGenerator::addTableGrow(unsigned tableIndex, ExpressionType fill, ExpressionType delta, ExpressionType& result) -> PartialResult
 {
     ASSERT(fill.tmp());
-    ASSERT(fill.type() == m_info.tables[tableIndex].wasmType());
+    ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()));
     ASSERT(delta.tmp());
     ASSERT(delta.type().isI32());
     result = tmpForType(Types::I32);
@@ -1189,7 +1189,7 @@
 auto AirIRGenerator::addTableFill(unsigned tableIndex, ExpressionType offset, ExpressionType fill, ExpressionType count) -> PartialResult
 {
     ASSERT(fill.tmp());
-    ASSERT(fill.type() == m_info.tables[tableIndex].wasmType());
+    ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()));
     ASSERT(offset.tmp());
     ASSERT(offset.type().isI32());
     ASSERT(count.tmp());
@@ -3419,7 +3419,7 @@
 
 void AirIRGenerator::unify(const ExpressionType dst, const ExpressionType source)
 {
-    ASSERT(source.type() == dst.type());
+    ASSERT(isSubtype(source.type(), dst.type()));
     append(moveOpForValueType(dst.type()), source, dst);
 }
 

Modified: trunk/Source/_javascript_Core/wasm/WasmFormat.h (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmFormat.h	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmFormat.h	2021-03-05 12:16:49 UTC (rev 273962)
@@ -70,6 +70,8 @@
     case TypeKind::Externref:
     case TypeKind::Funcref:
         return Options::useWebAssemblyReferences();
+    case TypeKind::TypeIdx:
+        return Options::useWebAssemblyTypedFunctionReferences();
     default:
         break;
     }
@@ -76,11 +78,19 @@
     return false;
 }
 
+inline bool isSubtype(Type sub, Type parent)
+{
+    if (sub.isTypeIdx() && parent.isFuncref())
+        return true;
+
+    return sub == parent;
+}
+
 inline bool isRefType(Type type)
 {
-    return type.isFuncref() || type.isExternref();
+    return type.isFuncref() || type.isExternref() || type.isTypeIdx();
 }
-    
+
 enum class ExternalKind : uint8_t {
     // FIXME auto-generate this. https://bugs.webkit.org/show_bug.cgi?id=165231
     Function = 0,

Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2021-03-05 12:16:49 UTC (rev 273962)
@@ -699,7 +699,7 @@
 
     unsigned offset = m_expressionStack.size() - target.branchTargetArity();
     for (unsigned i = 0; i < target.branchTargetArity(); ++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().kind, " but branch target expects a value of ", target.branchTargetType(i).kind, " at index ", i);
+        WASM_VALIDATOR_FAIL_IF(!isSubtype(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().kind, " but branch target expects a value of ", target.branchTargetType(i).kind, " at index ", i);
 
     return { };
 }
@@ -709,7 +709,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(m_expressionStack[i].type() != controlData.signature()->returnType(i), "control flow returns with unexpected type. ", m_expressionStack[i].type().kind, " is not a ", controlData.signature()->returnType(i).kind);
+        WASM_VALIDATOR_FAIL_IF(!isSubtype(m_expressionStack[i].type(), controlData.signature()->returnType(i)), "control flow returns with unexpected type. ", m_expressionStack[i].type().kind, " is not a ", controlData.signature()->returnType(i).kind);
 
     return { };
 }
@@ -836,7 +836,7 @@
         WASM_TRY_POP_EXPRESSION_STACK_INTO(index, "table.set");
         WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != index.type().kind, "table.set index to type ", index.type().kind, " expected ", TypeKind::I32);
         Type type = m_info.tables[tableIndex].wasmType();
-        WASM_VALIDATOR_FAIL_IF(value.type() != type, "table.set value to type ", value.type().kind, " expected ", type.kind);
+        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), type), "table.set value to type ", value.type().kind, " expected ", type.kind);
         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 { };
@@ -899,7 +899,8 @@
             WASM_TRY_POP_EXPRESSION_STACK_INTO(delta, "table.grow");
             WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.grow");
 
-            WASM_VALIDATOR_FAIL_IF(fill.type() != m_info.tables[tableIndex].wasmType(), "table.grow expects fill value of type ", m_info.tables[tableIndex].wasmType().kind, " got ", fill.type().kind);
+            Type tableType = m_info.tables[tableIndex].wasmType();
+            WASM_VALIDATOR_FAIL_IF(!isSubtype(fill.type(), tableType), "table.grow expects fill value of type ", tableType.kind, " got ", fill.type().kind);
             WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != delta.type().kind, "table.grow expects an i32 delta value, got ", delta.type().kind);
 
             ExpressionType result;
@@ -918,7 +919,8 @@
             WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.fill");
             WASM_TRY_POP_EXPRESSION_STACK_INTO(offset, "table.fill");
 
-            WASM_VALIDATOR_FAIL_IF(fill.type() != m_info.tables[tableIndex].wasmType(), "table.fill expects fill value of type ", m_info.tables[tableIndex].wasmType().kind, " got ", fill.type().kind);
+            Type tableType = m_info.tables[tableIndex].wasmType();
+            WASM_VALIDATOR_FAIL_IF(!isSubtype(fill.type(), tableType), "table.fill expects fill value of type ", tableType.kind, " got ", fill.type().kind);
             WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != offset.type().kind, "table.fill expects an i32 offset value, got ", offset.type().kind);
             WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != count.type().kind, "table.fill expects an i32 count value, got ", count.type().kind);
 
@@ -1104,6 +1106,13 @@
 
         ExpressionType result;
         WASM_TRY_ADD_TO_CONTEXT(addRefFunc(index, result));
+
+        if (Options::useWebAssemblyTypedFunctionReferences()) {
+            SignatureIndex signatureIndex = m_info.signatureIndexFromFunctionIndexSpace(index);
+            m_expressionStack.constructAndAppend(Type {TypeKind::TypeIdx, signatureIndex}, result);
+            return { };
+        }
+
         m_expressionStack.constructAndAppend(Types::Funcref, result);
         return { };
     }
@@ -1125,7 +1134,7 @@
         TypedExpression value;
         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(value.type() != m_locals[index], "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);
+        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);
         WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value));
         return { };
     }
@@ -1137,7 +1146,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(value.type() != m_locals[index], "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);
+        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);
         WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value));
         return { };
     }
@@ -1165,7 +1174,7 @@
 
         Type globalType = m_info.globals[index].type;
         ASSERT(isValueType(globalType));
-        WASM_VALIDATOR_FAIL_IF(globalType != value.type(), "set_global ", index, " with type ", globalType.kind, " with a variable of type ", value.type().kind);
+        WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), globalType), "set_global ", index, " with type ", globalType.kind, " with a variable of type ", value.type().kind);
 
         WASM_TRY_ADD_TO_CONTEXT(setGlobal(index, value));
         return { };
@@ -1184,7 +1193,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(arg.type() != calleeSignature.argument(i - firstArgumentIndex), "argument type mismatch in call, got ", arg.type().kind, ", expected ", calleeSignature.argument(i - firstArgumentIndex).kind);
+            WASM_VALIDATOR_FAIL_IF(!isSubtype(arg.type(), calleeSignature.argument(i - firstArgumentIndex)), "argument type mismatch in call, got ", arg.type().kind, ", expected ", calleeSignature.argument(i - firstArgumentIndex).kind);
             args.uncheckedAppend(arg);
             m_context.didPopValueFromStack();
         }
@@ -1225,7 +1234,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(arg.type() != calleeSignature.argument(i - firstArgumentIndex), "argument type mismatch in call_indirect, got ", arg.type().kind, ", expected ", calleeSignature.argument(i - firstArgumentIndex).kind);
+                WASM_VALIDATOR_FAIL_IF(!isSubtype(arg.type(), calleeSignature.argument(i - firstArgumentIndex)), "argument type mismatch in call_indirect, got ", arg.type().kind, ", expected ", calleeSignature.argument(i - firstArgumentIndex).kind);
             args.uncheckedAppend(arg);
             m_context.didPopValueFromStack();
         }

Modified: trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmLLIntGenerator.cpp	2021-03-05 12:16:49 UTC (rev 273962)
@@ -539,6 +539,7 @@
         case TypeKind::I64:
         case TypeKind::Externref:
         case TypeKind::Funcref:
+        case TypeKind::TypeIdx:
             if (gprIndex < gprCount)
                 ++gprIndex;
             else if (stackIndex++ >= stackCount)
@@ -594,6 +595,7 @@
         case TypeKind::I64:
         case TypeKind::Externref:
         case TypeKind::Funcref:
+        case TypeKind::TypeIdx:
             if (gprIndex > gprLimit)
                 arguments[i] = virtualRegisterForLocal(--gprIndex);
             else
@@ -621,6 +623,7 @@
         case TypeKind::I64:
         case TypeKind::Externref:
         case TypeKind::Funcref:
+        case TypeKind::TypeIdx:
             if (gprIndex > gprLimit)
                 temporaryResults[i] = virtualRegisterForLocal(--gprIndex);
             else
@@ -676,6 +679,7 @@
         case TypeKind::I64:
         case TypeKind::Externref:
         case TypeKind::Funcref:
+        case TypeKind::TypeIdx:
             if (gprIndex < maxGPRIndex)
                 m_results.append(virtualRegisterForLocal(numberOfLLIntCalleeSaveRegisters + gprIndex++));
             else
@@ -730,6 +734,7 @@
         case TypeKind::I64:
         case TypeKind::Externref:
         case TypeKind::Funcref:
+        case TypeKind::TypeIdx:
             addArgument(i, gprIndex, maxGPRIndex);
             break;
         case TypeKind::F32:

Modified: trunk/Source/_javascript_Core/wasm/WasmModule.h (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmModule.h	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmModule.h	2021-03-05 12:16:49 UTC (rev 273962)
@@ -30,6 +30,7 @@
 #include "WasmCodeBlock.h"
 #include "WasmEmbedder.h"
 #include "WasmMemory.h"
+#include "WasmOps.h"
 #include <wtf/Expected.h>
 #include <wtf/Lock.h>
 #include <wtf/SharedTask.h>
@@ -41,8 +42,6 @@
 struct Context;
 struct ModuleInformation;
 
-using SignatureIndex = uintptr_t;
-
 class Module : public ThreadSafeRefCounted<Module> {
 public:
     using ValidationResult = Expected<RefPtr<Module>, String>;

Modified: trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp	2021-03-05 12:16:49 UTC (rev 273962)
@@ -304,7 +304,7 @@
             global.initializationType = GlobalInformation::FromRefFunc;
         else
             global.initializationType = GlobalInformation::FromExpression;
-        WASM_PARSER_FAIL_IF(typeForInitOpcode != global.type, "Global init_expr opcode of type ", typeForInitOpcode.kind, " doesn't match global's type ", global.type.kind);
+        WASM_PARSER_FAIL_IF(!isSubtype(typeForInitOpcode, global.type), "Global init_expr opcode of type ", typeForInitOpcode.kind, " doesn't match global's type ", global.type.kind);
 
         if (initOpcode == RefFunc)
             m_info->addDeclaredFunction(global.initialBitsOrImportNumber);

Modified: trunk/Source/_javascript_Core/wasm/WasmSignature.h (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/WasmSignature.h	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/WasmSignature.h	2021-03-05 12:16:49 UTC (rev 273962)
@@ -44,7 +44,6 @@
 namespace Wasm {
 
 using SignatureArgCount = uint32_t;
-using SignatureIndex = uintptr_t;
 
 class Signature : public ThreadSafeRefCounted<Signature> {
     WTF_MAKE_FAST_ALLOCATED;

Modified: trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py	2021-03-05 12:16:49 UTC (rev 273962)
@@ -212,9 +212,11 @@
 };
 #undef CREATE_ENUM_VALUE
 
+using SignatureIndex = uintptr_t;
+
 struct Type {
     TypeKind kind;
-    unsigned index;
+    SignatureIndex index;
 
     bool operator==(const Type& other) const
     {

Modified: trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyModule.h (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyModule.h	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/js/JSWebAssemblyModule.h	2021-03-05 12:16:49 UTC (rev 273962)
@@ -30,6 +30,7 @@
 #include "JSDestructibleObject.h"
 #include "JSObject.h"
 #include "WasmMemoryMode.h"
+#include "WasmOps.h"
 #include <wtf/Bag.h>
 #include <wtf/Expected.h>
 #include <wtf/Forward.h>
@@ -42,7 +43,6 @@
 class Module;
 struct ModuleInformation;
 class Plan;
-using SignatureIndex = uintptr_t;
 }
 
 class SymbolTable;

Modified: trunk/Source/_javascript_Core/wasm/js/WasmToJS.cpp (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/js/WasmToJS.cpp	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/js/WasmToJS.cpp	2021-03-05 12:16:49 UTC (rev 273962)
@@ -105,6 +105,7 @@
             case TypeKind::Void:
             case TypeKind::Func:
                 RELEASE_ASSERT_NOT_REACHED(); // Handled above.
+            case TypeKind::TypeIdx:
             case TypeKind::Externref:
             case TypeKind::Funcref:
             case TypeKind::I32:
@@ -177,6 +178,7 @@
             case TypeKind::Void:
             case TypeKind::Func:
                 RELEASE_ASSERT_NOT_REACHED(); // Handled above.
+            case TypeKind::TypeIdx:
             case TypeKind::Externref:
             case TypeKind::Funcref:
             case TypeKind::I32:
@@ -319,6 +321,7 @@
         }
         case TypeKind::Funcref:
         case TypeKind::Externref:
+        case TypeKind::TypeIdx:
             jit.move(GPRInfo::returnValueGPR, wasmCallInfo.results[0].gpr());
             break;
         case TypeKind::F32: {

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.cpp (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.cpp	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.cpp	2021-03-05 12:16:49 UTC (rev 273962)
@@ -83,6 +83,7 @@
         case Wasm::TypeKind::I32:
             arg = JSValue::decode(arg.toInt32(globalObject));
             break;
+        case Wasm::TypeKind::TypeIdx:
         case Wasm::TypeKind::Funcref: {
             if (!isWebAssemblyHostFunction(vm, arg) && !arg.isNull())
                 return JSValue::encode(throwException(globalObject, scope, createJSWebAssemblyRuntimeError(globalObject, vm, "Funcref must be an exported wasm function")));

Modified: trunk/Source/_javascript_Core/wasm/wasm.json (273961 => 273962)


--- trunk/Source/_javascript_Core/wasm/wasm.json	2021-03-05 12:05:02 UTC (rev 273961)
+++ trunk/Source/_javascript_Core/wasm/wasm.json	2021-03-05 12:16:49 UTC (rev 273962)
@@ -7,18 +7,19 @@
         { "name": "version",      "type": "uint32", "value":          1, "description": "Version number" }
     ],
     "type" : {
-        "i32":       { "type": "varint7", "value":  -1, "b3type": "B3::Int32" },
-        "i64":       { "type": "varint7", "value":  -2, "b3type": "B3::Int64" },
-        "f32":       { "type": "varint7", "value":  -3, "b3type": "B3::Float" },
-        "f64":       { "type": "varint7", "value":  -4, "b3type": "B3::Double" },
-        "funcref":   { "type": "varint7", "value": -16, "b3type": "B3::Int64" },
-        "externref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" },
-        "func":      { "type": "varint7", "value": -32, "b3type": "B3::Void" },
-        "void":      { "type": "varint7", "value": -64, "b3type": "B3::Void" }
+        "i32":       { "type": "varint7", "value":   -1, "b3type": "B3::Int32" },
+        "i64":       { "type": "varint7", "value":   -2, "b3type": "B3::Int64" },
+        "f32":       { "type": "varint7", "value":   -3, "b3type": "B3::Float" },
+        "f64":       { "type": "varint7", "value":   -4, "b3type": "B3::Double" },
+        "funcref":   { "type": "varint7", "value":  -16, "b3type": "B3::Int64" },
+        "externref": { "type": "varint7", "value":  -17, "b3type": "B3::Int64" },
+        "func":      { "type": "varint7", "value":  -32, "b3type": "B3::Void" },
+        "void":      { "type": "varint7", "value":  -64, "b3type": "B3::Void" },
+        "type_idx":  { "type": "varint7", "value": -128, "b3type": "B3::Int64" }
     },
     "value_type": ["i32", "i64", "f32", "f64", "externref", "funcref"],
     "block_type": ["i32", "i64", "f32", "f64", "void", "externref", "funcref"],
-    "ref_type": ["funcref","externref"],
+    "ref_type": ["funcref", "externref", "type_idx"],
     "external_kind": {
         "Function": { "type": "uint8", "value": 0 },
         "Table":    { "type": "uint8", "value": 1 },
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to