Changeset 273962 in webkit
- Timestamp:
- Mar 5, 2021 4:16:49 AM (17 months ago)
- Location:
- trunk
- Files:
-
- 16 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/wasm/wasm.json (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/runtime/OptionsList.h (modified) (1 diff)
-
Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/wasm/WasmFormat.h (modified) (2 diffs)
-
Source/JavaScriptCore/wasm/WasmFunctionParser.h (modified) (11 diffs)
-
Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp (modified) (5 diffs)
-
Source/JavaScriptCore/wasm/WasmModule.h (modified) (2 diffs)
-
Source/JavaScriptCore/wasm/WasmSectionParser.cpp (modified) (1 diff)
-
Source/JavaScriptCore/wasm/WasmSignature.h (modified) (1 diff)
-
Source/JavaScriptCore/wasm/generateWasmOpsHeader.py (modified) (1 diff)
-
Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h (modified) (2 diffs)
-
Source/JavaScriptCore/wasm/js/WasmToJS.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp (modified) (1 diff)
-
Source/JavaScriptCore/wasm/wasm.json (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r273931 r273962 1 2021-03-05 Dmitry Bezhetskov <dbezhetskov@igalia.com> 2 3 [WASM-Function-References] Update ref.func to produce (ref $t) 4 https://bugs.webkit.org/show_bug.cgi?id=222779 5 6 Reviewed by Yusuke Suzuki. 7 8 Make ref.func to produce non nullable reference type which 9 incorporates signature index. Since in JSC signature index represents 10 type of the function from Type section we use it instead of type_idx 11 for representing type of function references. 12 13 * wasm/wasm.json: 14 1 15 2021-03-04 Saam Barati <sbarati@apple.com> 2 16 -
trunk/JSTests/wasm/wasm.json
r272933 r273962 8 8 ], 9 9 "type" : { 10 "i32": { "type": "varint7", "value": -1, "b3type": "B3::Int32" }, 11 "i64": { "type": "varint7", "value": -2, "b3type": "B3::Int64" }, 12 "f32": { "type": "varint7", "value": -3, "b3type": "B3::Float" }, 13 "f64": { "type": "varint7", "value": -4, "b3type": "B3::Double" }, 14 "funcref": { "type": "varint7", "value": -16, "b3type": "B3::Int64" }, 15 "externref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" }, 16 "func": { "type": "varint7", "value": -32, "b3type": "B3::Void" }, 17 "void": { "type": "varint7", "value": -64, "b3type": "B3::Void" } 10 "i32": { "type": "varint7", "value": -1, "b3type": "B3::Int32" }, 11 "i64": { "type": "varint7", "value": -2, "b3type": "B3::Int64" }, 12 "f32": { "type": "varint7", "value": -3, "b3type": "B3::Float" }, 13 "f64": { "type": "varint7", "value": -4, "b3type": "B3::Double" }, 14 "funcref": { "type": "varint7", "value": -16, "b3type": "B3::Int64" }, 15 "externref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" }, 16 "func": { "type": "varint7", "value": -32, "b3type": "B3::Void" }, 17 "void": { "type": "varint7", "value": -64, "b3type": "B3::Void" }, 18 "type_idx": { "type": "varint7", "value": -128, "b3type": "B3::Int64" } 18 19 }, 19 20 "value_type": ["i32", "i64", "f32", "f64", "externref", "funcref"], 20 21 "block_type": ["i32", "i64", "f32", "f64", "void", "externref", "funcref"], 21 "ref_type": ["funcref", "externref"],22 "ref_type": ["funcref", "externref", "type_idx"], 22 23 "external_kind": { 23 24 "Function": { "type": "uint8", "value": 0 }, -
trunk/Source/JavaScriptCore/ChangeLog
r273940 r273962 1 2021-03-05 Dmitry Bezhetskov <dbezhetskov@igalia.com> 2 3 [WASM-Function-References] Update ref.func to produce (ref $t) 4 https://bugs.webkit.org/show_bug.cgi?id=222779 5 6 Reviewed by Yusuke Suzuki. 7 8 Make ref.func to produce non nullable reference type which 9 incorporates signature index. Since in JSC signature index represents 10 type of the function from Type section we use it instead of type_idx 11 for representing type of function references. 12 13 14 * runtime/OptionsList.h: 15 * wasm/WasmAirIRGenerator.cpp: 16 (JSC::Wasm::AirIRGenerator::addTableGrow): 17 (JSC::Wasm::AirIRGenerator::addTableFill): 18 (JSC::Wasm::AirIRGenerator::unify): 19 * wasm/WasmFormat.h: 20 (JSC::Wasm::isValueType): 21 (JSC::Wasm::isSubtype): 22 (JSC::Wasm::isRefType): 23 * wasm/WasmFunctionParser.h: 24 (JSC::Wasm::FunctionParser<Context>::checkBranchTarget): 25 (JSC::Wasm::FunctionParser<Context>::unify): 26 (JSC::Wasm::FunctionParser<Context>::parseExpression): 27 * wasm/WasmLLIntGenerator.cpp: 28 (JSC::Wasm::LLIntGenerator::callInformationForCaller): 29 (JSC::Wasm::LLIntGenerator::callInformationForCallee): 30 (JSC::Wasm::LLIntGenerator::addArguments): 31 * wasm/WasmSectionParser.cpp: 32 (JSC::Wasm::SectionParser::parseGlobal): 33 * wasm/generateWasmOpsHeader.py: 34 * wasm/js/WasmToJS.cpp: 35 (JSC::Wasm::wasmToJS): 36 * wasm/js/WebAssemblyFunction.cpp: 37 (JSC::JSC_DEFINE_HOST_FUNCTION): 38 * wasm/wasm.json: 39 1 40 2021-03-04 Alex Christensen <achristensen@webkit.org> 2 41 -
trunk/Source/JavaScriptCore/runtime/OptionsList.h
r273225 r273962 521 521 v(Bool, useWebAssemblyStreaming, true, Normal, "Allow to run WebAssembly's Streaming API") \ 522 522 v(Bool, useWebAssemblyReferences, true, Normal, "Allow types from the wasm references spec.") \ 523 v(Bool, useWebAssemblyTypedFunctionReferences, false, Normal, "Allow function types from the wasm typed function references spec.") \ 523 524 v(Bool, useWebAssemblyMultiValues, true, Normal, "Allow types from the wasm mulit-values spec.") \ 524 525 v(Bool, useWebAssemblyThreading, true, Normal, "Allow instructions from the wasm threading spec.") \ -
trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp
r273813 r273962 1177 1177 { 1178 1178 ASSERT(fill.tmp()); 1179 ASSERT( fill.type() == m_info.tables[tableIndex].wasmType());1179 ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType())); 1180 1180 ASSERT(delta.tmp()); 1181 1181 ASSERT(delta.type().isI32()); … … 1190 1190 { 1191 1191 ASSERT(fill.tmp()); 1192 ASSERT( fill.type() == m_info.tables[tableIndex].wasmType());1192 ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType())); 1193 1193 ASSERT(offset.tmp()); 1194 1194 ASSERT(offset.type().isI32()); … … 3420 3420 void AirIRGenerator::unify(const ExpressionType dst, const ExpressionType source) 3421 3421 { 3422 ASSERT( source.type() == dst.type());3422 ASSERT(isSubtype(source.type(), dst.type())); 3423 3423 append(moveOpForValueType(dst.type()), source, dst); 3424 3424 } -
trunk/Source/JavaScriptCore/wasm/WasmFormat.h
r273813 r273962 71 71 case TypeKind::Funcref: 72 72 return Options::useWebAssemblyReferences(); 73 case TypeKind::TypeIdx: 74 return Options::useWebAssemblyTypedFunctionReferences(); 73 75 default: 74 76 break; … … 77 79 } 78 80 81 inline bool isSubtype(Type sub, Type parent) 82 { 83 if (sub.isTypeIdx() && parent.isFuncref()) 84 return true; 85 86 return sub == parent; 87 } 88 79 89 inline bool isRefType(Type type) 80 90 { 81 return type.isFuncref() || type.isExternref() ;82 } 83 91 return type.isFuncref() || type.isExternref() || type.isTypeIdx(); 92 } 93 84 94 enum class ExternalKind : uint8_t { 85 95 // FIXME auto-generate this. https://bugs.webkit.org/show_bug.cgi?id=165231 -
trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h
r273813 r273962 700 700 unsigned offset = m_expressionStack.size() - target.branchTargetArity(); 701 701 for (unsigned i = 0; i < target.branchTargetArity(); ++i) 702 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);702 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); 703 703 704 704 return { }; … … 710 710 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"); 711 711 for (unsigned i = 0; i < controlData.signature()->returnCount(); ++i) 712 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);712 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); 713 713 714 714 return { }; … … 837 837 WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != index.type().kind, "table.set index to type ", index.type().kind, " expected ", TypeKind::I32); 838 838 Type type = m_info.tables[tableIndex].wasmType(); 839 WASM_VALIDATOR_FAIL_IF( value.type() != type, "table.set value to type ", value.type().kind, " expected ", type.kind);839 WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), type), "table.set value to type ", value.type().kind, " expected ", type.kind); 840 840 RELEASE_ASSERT(m_info.tables[tableIndex].type() == TableElementType::Externref || m_info.tables[tableIndex].type() == TableElementType::Funcref); 841 841 WASM_TRY_ADD_TO_CONTEXT(addTableSet(tableIndex, index, value)); … … 900 900 WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.grow"); 901 901 902 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); 902 Type tableType = m_info.tables[tableIndex].wasmType(); 903 WASM_VALIDATOR_FAIL_IF(!isSubtype(fill.type(), tableType), "table.grow expects fill value of type ", tableType.kind, " got ", fill.type().kind); 903 904 WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != delta.type().kind, "table.grow expects an i32 delta value, got ", delta.type().kind); 904 905 … … 919 920 WASM_TRY_POP_EXPRESSION_STACK_INTO(offset, "table.fill"); 920 921 921 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); 922 Type tableType = m_info.tables[tableIndex].wasmType(); 923 WASM_VALIDATOR_FAIL_IF(!isSubtype(fill.type(), tableType), "table.fill expects fill value of type ", tableType.kind, " got ", fill.type().kind); 922 924 WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != offset.type().kind, "table.fill expects an i32 offset value, got ", offset.type().kind); 923 925 WASM_VALIDATOR_FAIL_IF(TypeKind::I32 != count.type().kind, "table.fill expects an i32 count value, got ", count.type().kind); … … 1105 1107 ExpressionType result; 1106 1108 WASM_TRY_ADD_TO_CONTEXT(addRefFunc(index, result)); 1109 1110 if (Options::useWebAssemblyTypedFunctionReferences()) { 1111 SignatureIndex signatureIndex = m_info.signatureIndexFromFunctionIndexSpace(index); 1112 m_expressionStack.constructAndAppend(Type {TypeKind::TypeIdx, signatureIndex}, result); 1113 return { }; 1114 } 1115 1107 1116 m_expressionStack.constructAndAppend(Types::Funcref, result); 1108 1117 return { }; … … 1126 1135 WASM_TRY_POP_EXPRESSION_STACK_INTO(value, "set_local"); 1127 1136 WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to set unknown local ", index, " last one is ", m_locals.size()); 1128 WASM_VALIDATOR_FAIL_IF( value.type() != m_locals[index], "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);1137 WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type().kind, " expected ", m_locals[index].kind); 1129 1138 WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value)); 1130 1139 return { }; … … 1138 1147 TypedExpression value = m_expressionStack.last(); 1139 1148 WASM_VALIDATOR_FAIL_IF(index >= m_locals.size(), "attempt to tee unknown local ", index, " last one is ", m_locals.size()); 1140 WASM_VALIDATOR_FAIL_IF( value.type() != m_locals[index], "set_local to type ", value.type().kind, " expected ", m_locals[index].kind);1149 WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), m_locals[index]), "set_local to type ", value.type().kind, " expected ", m_locals[index].kind); 1141 1150 WASM_TRY_ADD_TO_CONTEXT(setLocal(index, value)); 1142 1151 return { }; … … 1166 1175 Type globalType = m_info.globals[index].type; 1167 1176 ASSERT(isValueType(globalType)); 1168 WASM_VALIDATOR_FAIL_IF( globalType != value.type(), "set_global ", index, " with type ", globalType.kind, " with a variable of type ", value.type().kind);1177 WASM_VALIDATOR_FAIL_IF(!isSubtype(value.type(), globalType), "set_global ", index, " with type ", globalType.kind, " with a variable of type ", value.type().kind); 1169 1178 1170 1179 WASM_TRY_ADD_TO_CONTEXT(setGlobal(index, value)); … … 1185 1194 for (size_t i = firstArgumentIndex; i < m_expressionStack.size(); ++i) { 1186 1195 TypedExpression arg = m_expressionStack.at(i); 1187 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);1196 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); 1188 1197 args.uncheckedAppend(arg); 1189 1198 m_context.didPopValueFromStack(); … … 1226 1235 TypedExpression arg = m_expressionStack.at(i); 1227 1236 if (i < m_expressionStack.size() - 1) 1228 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);1237 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); 1229 1238 args.uncheckedAppend(arg); 1230 1239 m_context.didPopValueFromStack(); -
trunk/Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp
r273813 r273962 540 540 case TypeKind::Externref: 541 541 case TypeKind::Funcref: 542 case TypeKind::TypeIdx: 542 543 if (gprIndex < gprCount) 543 544 ++gprIndex; … … 595 596 case TypeKind::Externref: 596 597 case TypeKind::Funcref: 598 case TypeKind::TypeIdx: 597 599 if (gprIndex > gprLimit) 598 600 arguments[i] = virtualRegisterForLocal(--gprIndex); … … 622 624 case TypeKind::Externref: 623 625 case TypeKind::Funcref: 626 case TypeKind::TypeIdx: 624 627 if (gprIndex > gprLimit) 625 628 temporaryResults[i] = virtualRegisterForLocal(--gprIndex); … … 677 680 case TypeKind::Externref: 678 681 case TypeKind::Funcref: 682 case TypeKind::TypeIdx: 679 683 if (gprIndex < maxGPRIndex) 680 684 m_results.append(virtualRegisterForLocal(numberOfLLIntCalleeSaveRegisters + gprIndex++)); … … 731 735 case TypeKind::Externref: 732 736 case TypeKind::Funcref: 737 case TypeKind::TypeIdx: 733 738 addArgument(i, gprIndex, maxGPRIndex); 734 739 break; -
trunk/Source/JavaScriptCore/wasm/WasmModule.h
r273662 r273962 31 31 #include "WasmEmbedder.h" 32 32 #include "WasmMemory.h" 33 #include "WasmOps.h" 33 34 #include <wtf/Expected.h> 34 35 #include <wtf/Lock.h> … … 41 42 struct Context; 42 43 struct ModuleInformation; 43 44 using SignatureIndex = uintptr_t;45 44 46 45 class Module : public ThreadSafeRefCounted<Module> { -
trunk/Source/JavaScriptCore/wasm/WasmSectionParser.cpp
r273813 r273962 305 305 else 306 306 global.initializationType = GlobalInformation::FromExpression; 307 WASM_PARSER_FAIL_IF( typeForInitOpcode != global.type, "Global init_expr opcode of type ", typeForInitOpcode.kind, " doesn't match global's type ", global.type.kind);307 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); 308 308 309 309 if (initOpcode == RefFunc) -
trunk/Source/JavaScriptCore/wasm/WasmSignature.h
r273813 r273962 45 45 46 46 using SignatureArgCount = uint32_t; 47 using SignatureIndex = uintptr_t;48 47 49 48 class Signature : public ThreadSafeRefCounted<Signature> { -
trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py
r273813 r273962 213 213 #undef CREATE_ENUM_VALUE 214 214 215 using SignatureIndex = uintptr_t; 216 215 217 struct Type { 216 218 TypeKind kind; 217 unsignedindex;219 SignatureIndex index; 218 220 219 221 bool operator==(const Type& other) const -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
r273662 r273962 31 31 #include "JSObject.h" 32 32 #include "WasmMemoryMode.h" 33 #include "WasmOps.h" 33 34 #include <wtf/Bag.h> 34 35 #include <wtf/Expected.h> … … 43 44 struct ModuleInformation; 44 45 class Plan; 45 using SignatureIndex = uintptr_t;46 46 } 47 47 -
trunk/Source/JavaScriptCore/wasm/js/WasmToJS.cpp
r273813 r273962 106 106 case TypeKind::Func: 107 107 RELEASE_ASSERT_NOT_REACHED(); // Handled above. 108 case TypeKind::TypeIdx: 108 109 case TypeKind::Externref: 109 110 case TypeKind::Funcref: … … 178 179 case TypeKind::Func: 179 180 RELEASE_ASSERT_NOT_REACHED(); // Handled above. 181 case TypeKind::TypeIdx: 180 182 case TypeKind::Externref: 181 183 case TypeKind::Funcref: … … 320 322 case TypeKind::Funcref: 321 323 case TypeKind::Externref: 324 case TypeKind::TypeIdx: 322 325 jit.move(GPRInfo::returnValueGPR, wasmCallInfo.results[0].gpr()); 323 326 break; -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
r273813 r273962 84 84 arg = JSValue::decode(arg.toInt32(globalObject)); 85 85 break; 86 case Wasm::TypeKind::TypeIdx: 86 87 case Wasm::TypeKind::Funcref: { 87 88 if (!isWebAssemblyHostFunction(vm, arg) && !arg.isNull()) -
trunk/Source/JavaScriptCore/wasm/wasm.json
r272933 r273962 8 8 ], 9 9 "type" : { 10 "i32": { "type": "varint7", "value": -1, "b3type": "B3::Int32" }, 11 "i64": { "type": "varint7", "value": -2, "b3type": "B3::Int64" }, 12 "f32": { "type": "varint7", "value": -3, "b3type": "B3::Float" }, 13 "f64": { "type": "varint7", "value": -4, "b3type": "B3::Double" }, 14 "funcref": { "type": "varint7", "value": -16, "b3type": "B3::Int64" }, 15 "externref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" }, 16 "func": { "type": "varint7", "value": -32, "b3type": "B3::Void" }, 17 "void": { "type": "varint7", "value": -64, "b3type": "B3::Void" } 10 "i32": { "type": "varint7", "value": -1, "b3type": "B3::Int32" }, 11 "i64": { "type": "varint7", "value": -2, "b3type": "B3::Int64" }, 12 "f32": { "type": "varint7", "value": -3, "b3type": "B3::Float" }, 13 "f64": { "type": "varint7", "value": -4, "b3type": "B3::Double" }, 14 "funcref": { "type": "varint7", "value": -16, "b3type": "B3::Int64" }, 15 "externref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" }, 16 "func": { "type": "varint7", "value": -32, "b3type": "B3::Void" }, 17 "void": { "type": "varint7", "value": -64, "b3type": "B3::Void" }, 18 "type_idx": { "type": "varint7", "value": -128, "b3type": "B3::Int64" } 18 19 }, 19 20 "value_type": ["i32", "i64", "f32", "f64", "externref", "funcref"], 20 21 "block_type": ["i32", "i64", "f32", "f64", "void", "externref", "funcref"], 21 "ref_type": ["funcref", "externref"],22 "ref_type": ["funcref", "externref", "type_idx"], 22 23 "external_kind": { 23 24 "Function": { "type": "uint8", "value": 0 },
Note: See TracChangeset
for help on using the changeset viewer.