[webkit-changes] [WebKit/WebKit] c3c975: [wasm] Implement Extended Const Expressions

Asumu Takikawa noreply at github.com
Mon Aug 28 19:28:00 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c3c9754a47b03abd7bbada3d865d8842fbb618a2
      https://github.com/WebKit/WebKit/commit/c3c9754a47b03abd7bbada3d865d8842fbb618a2
  Author: Asumu Takikawa <asumu at igalia.com>
  Date:   2023-08-28 (Mon, 28 Aug 2023)

  Changed paths:
    M JSTests/wasm.yaml
    A JSTests/wasm/extended-const-spec-tests/data.wast.js
    A JSTests/wasm/extended-const-spec-tests/elem.wast.js
    A JSTests/wasm/extended-const-spec-tests/global.wast.js
    A JSTests/wasm/extended-const/extended-const.js
    A JSTests/wasm/extended-const/flag-turned-off.js
    M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
    M Source/JavaScriptCore/Sources.txt
    M Source/JavaScriptCore/runtime/OptionsList.h
    A Source/JavaScriptCore/wasm/WasmConstExprGenerator.cpp
    A Source/JavaScriptCore/wasm/WasmConstExprGenerator.h
    M Source/JavaScriptCore/wasm/WasmFormat.h
    M Source/JavaScriptCore/wasm/WasmFunctionParser.h
    M Source/JavaScriptCore/wasm/WasmModuleInformation.h
    M Source/JavaScriptCore/wasm/WasmParser.h
    M Source/JavaScriptCore/wasm/WasmSectionParser.cpp
    M Source/JavaScriptCore/wasm/WasmSectionParser.h
    M Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
    M Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h
    M Tools/Scripts/run-jsc-stress-tests

  Log Message:
  -----------
  [wasm] Implement Extended Const Expressions
https://bugs.webkit.org/show_bug.cgi?id=252483

Reviewed by Justin Michaud and Yusuke Suzuki.

Enables the extended const expressions proposal, which allows i32.add, i32.sub,
i64.add, and i64.sub instructions in global, element, and data initialization
expressions. Since these instructions take arguments, the init expressions have
a tree structure and require a more complex evaluator with a stack.

The existing code paths for simple, one-instruction init expressions are kept
intact as fast paths. The general parsing case is only used if an `End`
instruction does not follow the first opcode and the proposal flag is on.

For extended expressions, a FunctionParser instance is used alongside a new
generator class for init expressions. The generator class will error on any
non-constant opcodes. The generator, when used in evaluation mode by module
initialization code paths, can also evaluate the constant expression.

At wasm module validation time, the extended expressions are only parsed and
validated. The binary opcodes for the expressions are then stored in
ModuleInformation, so that the module initialization step can evaluate them to
a wasm value.

This patch does not, however, generalize the parsing of element segment item
vectors. This can be done but requires some additional restructuring of element
segment representation.

Tests imported from the proposal spec repo are from commit
7612271a72f00e2b385a98a7f79a031f94fb77e6 of
https://github.com/WebAssembly/extended-const

* JSTests/wasm.yaml:
* JSTests/wasm/extended-const-spec-tests/data.wast.js: Added.
* JSTests/wasm/extended-const-spec-tests/elem.wast.js: Added.
* JSTests/wasm/extended-const-spec-tests/global.wast.js: Added.
* JSTests/wasm/extended-const/extended-const.js: Added.
(module):
(async testConstExprFastPaths):
(async testExtendedConstGlobal):
(async testExtendedConstElement):
(async testExtendedConstData):
(async testInvalidConstExprs):
* JSTests/wasm/extended-const/flag-turned-off.js: Added.
(module):
(async testConstExprErrorPaths):
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/runtime/OptionsList.h:
* Source/JavaScriptCore/wasm/WasmConstExprGenerator.cpp: Added.
(JSC::Wasm::ConstExprGenerator::ControlData::isIf):
(JSC::Wasm::ConstExprGenerator::ControlData::isTry):
(JSC::Wasm::ConstExprGenerator::ControlData::isAnyCatch):
(JSC::Wasm::ConstExprGenerator::ControlData::isCatch):
(JSC::Wasm::ConstExprGenerator::ControlData::isTopLevel):
(JSC::Wasm::ConstExprGenerator::ControlData::isLoop):
(JSC::Wasm::ConstExprGenerator::ControlData::isBlock):
(JSC::Wasm::ConstExprGenerator::ControlData::ControlData):
(JSC::Wasm::ConstExprGenerator::ControlData::signature const):
(JSC::Wasm::ConstExprGenerator::ControlData::branchTargetArity const):
(JSC::Wasm::ConstExprGenerator::ControlData::branchTargetType const):
(JSC::Wasm::ConstExprGenerator::emptyExpression):
(JSC::Wasm::ConstExprGenerator::fail const):
(JSC::Wasm::ConstExprGenerator::ConstExprGenerator):
(JSC::Wasm::ConstExprGenerator::result const):
(JSC::Wasm::ConstExprGenerator::setParser):
(JSC::Wasm::ConstExprGenerator::addArguments):
(JSC::Wasm::ConstExprGenerator::addConstant):
(JSC::Wasm::ConstExprGenerator::addLocal):
(JSC::Wasm::ConstExprGenerator::getGlobal):
(JSC::Wasm::ConstExprGenerator::addI32Add):
(JSC::Wasm::ConstExprGenerator::addI64Add):
(JSC::Wasm::ConstExprGenerator::addI32Sub):
(JSC::Wasm::ConstExprGenerator::addI64Sub):
(JSC::Wasm::ConstExprGenerator::addI32Mul):
(JSC::Wasm::ConstExprGenerator::addI64Mul):
(JSC::Wasm::ConstExprGenerator::addRefFunc):
(JSC::Wasm::ConstExprGenerator::addTopLevel):
(JSC::Wasm::ConstExprGenerator::endBlock):
(JSC::Wasm::ConstExprGenerator::endTopLevel):
(JSC::Wasm::ConstExprGenerator::notifyFunctionUsesSIMD):
(JSC::Wasm::ConstExprGenerator::dump):
(JSC::Wasm::ConstExprGenerator::willParseOpcode):
(JSC::Wasm::ConstExprGenerator::didParseOpcode):
(JSC::Wasm::ConstExprGenerator::didFinishParsingLocals):
(JSC::Wasm::ConstExprGenerator::didPopValueFromStack):
(JSC::Wasm::parseExtendedConstExpr):
(JSC::Wasm::evaluateExtendedConstExpr):
* Source/JavaScriptCore/wasm/WasmConstExprGenerator.h: Added.
* Source/JavaScriptCore/wasm/WasmFormat.h:
(JSC::Wasm::I32InitExpr::extendedExpression):
(JSC::Wasm::I32InitExpr::isExtendedExpression const):
(JSC::Wasm::I32InitExpr::constantExpressionIndex const):
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseConstantExpression):
* Source/JavaScriptCore/wasm/WasmModuleInformation.h:
* Source/JavaScriptCore/wasm/WasmParser.h:
(JSC::Wasm::makeI32InitExpr):
* Source/JavaScriptCore/wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseGlobal):
(JSC::Wasm::SectionParser::parseInitExpr):
(JSC::Wasm::SectionParser::parseI32InitExpr):
* Source/JavaScriptCore/wasm/WasmSectionParser.h:
* Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::initializeExports):
(JSC::WebAssemblyModuleRecord::evaluateConstantExpression):
(JSC::WebAssemblyModuleRecord::evaluate):
* Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h:
* Tools/Scripts/run-jsc-stress-tests:

Canonical link: https://commits.webkit.org/267382@main




More information about the webkit-changes mailing list