Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 82435444ce3d2521ee101acb6eaf91bb785e2a3c
      
https://github.com/WebKit/WebKit/commit/82435444ce3d2521ee101acb6eaf91bb785e2a3c
  Author: Alexey Shvayka <ashva...@apple.com>
  Date:   2024-10-02 (Wed, 02 Oct 2024)

  Changed paths:
    M JSTests/stress/iterator-from.js
    A JSTests/stress/iterator-prototype-map.js
    M JSTests/test262/expectations.yaml
    M Source/JavaScriptCore/CMakeLists.txt
    M Source/JavaScriptCore/DerivedSources-input.xcfilelist
    M Source/JavaScriptCore/DerivedSources-output.xcfilelist
    M Source/JavaScriptCore/DerivedSources.make
    M Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
    M Source/JavaScriptCore/Sources.txt
    M Source/JavaScriptCore/builtins/JSIteratorConstructor.js
    A Source/JavaScriptCore/builtins/JSIteratorHelperPrototype.js
    M Source/JavaScriptCore/builtins/JSIteratorPrototype.js
    M Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp
    M Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
    M Source/JavaScriptCore/bytecode/BytecodeList.rb
    M Source/JavaScriptCore/bytecode/BytecodeUseDef.cpp
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
    M Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp
    M Source/JavaScriptCore/dfg/DFGOperations.cpp
    M Source/JavaScriptCore/dfg/DFGOperations.h
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp
    M Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
    M Source/JavaScriptCore/ftl/FTLOperations.cpp
    M Source/JavaScriptCore/heap/Heap.h
    M Source/JavaScriptCore/heap/HeapSubspaceTypes.h
    M Source/JavaScriptCore/jit/JIT.cpp
    M Source/JavaScriptCore/llint/LowLevelInterpreter.asm
    M Source/JavaScriptCore/runtime/CommonSlowPaths.cpp
    M Source/JavaScriptCore/runtime/CommonSlowPaths.h
    M Source/JavaScriptCore/runtime/JSGlobalObject.cpp
    M Source/JavaScriptCore/runtime/JSGlobalObject.h
    A Source/JavaScriptCore/runtime/JSIteratorHelper.cpp
    A Source/JavaScriptCore/runtime/JSIteratorHelper.h
    A Source/JavaScriptCore/runtime/JSIteratorHelperPrototype.cpp
    A Source/JavaScriptCore/runtime/JSIteratorHelperPrototype.h
    A Source/JavaScriptCore/runtime/JSIteratorHelperPrototypeInlines.h
    M Source/JavaScriptCore/runtime/JSIteratorPrototype.cpp
    M Source/JavaScriptCore/runtime/JSType.cpp
    M Source/JavaScriptCore/runtime/JSType.h

  Log Message:
  -----------
  [JSC] Complete the implementation of Iterator helpers proposal
https://bugs.webkit.org/show_bug.cgi?id=248650
<rdar://problem/103171739>

Reviewed by Yusuke Suzuki.

This patch completes the implementation of Iterator helpers proposal [1] by 
adding map(), filter(),
take(), drop(), and flatMap() methods to Iterator.prototype, all still behind a 
feature flag.
Except for merging two loops in drop() [2], this change precisely follows the 
spec steps.

While it is possible to squeeze out a bit more performance by hand-rolling 
generators, we utilize
them because optimization of generators is one of long-term goals for 
JetStream3.

Except for flatMap(), which has complex (yet easily implementable via nested 
for/of loops) semantics
of closing inner and then outer iterator [3], this patch avoids iterator 
wrappers as much as possible.
Iterator wrappers are necessary to make an early "next" method lookup and/or 
prevent second @@iterator
method lookup; they are hard to get right and they will get costly once 
generators will get faster.

Instead of for/of loops with wrappers, this change introduces 
@ifAbruptCloseIterator(), which provides
complex iterator closing semantics [4] of a for/of loop as a bytecode 
intrinsic. The syntax is quirky,
but it is the best we can do without introducing another intrinsic node.

[1]: https://github.com/tc39/proposal-iterator-helpers
[2]: https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.drop 
(steps 8.b-c)
[3]: https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.flatmap 
(step 5.b.viii.4.b)
[4]: https://tc39.es/ecma262/#sec-ifabruptcloseiterator

* JSTests/stress/iterator-from.js: Adjust error message expectation.
* JSTests/stress/iterator-prototype-map.js: Added.
* JSTests/test262/expectations.yaml: Mark 326 tests as passing.
* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/DerivedSources-input.xcfilelist:
* Source/JavaScriptCore/DerivedSources-output.xcfilelist:
* Source/JavaScriptCore/DerivedSources.make:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/builtins/JSIteratorConstructor.js:
(linkTimeConstant.getIteratorFlattenable):
(from):
* Source/JavaScriptCore/builtins/JSIteratorHelperPrototype.js: Added.
* Source/JavaScriptCore/builtins/JSIteratorPrototype.js:
(map):
(filter):
(take):
(drop):
(flatMap):
* Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp:
(JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
* Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h:
* Source/JavaScriptCore/bytecode/BytecodeList.rb:
* Source/JavaScriptCore/bytecode/BytecodeUseDef.cpp:
(JSC::computeUsesForBytecodeIndexImpl):
(JSC::computeDefsForBytecodeIndexImpl):
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitNewIteratorHelper):
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::emitIsIteratorHelper):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::iteratorHelperInternalFieldIndex):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_getIteratorHelperInternalField):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_newIteratorHelper):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_iteratorGenericClose):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_iteratorGenericNext):
(JSC::BytecodeIntrinsicNode::emit_intrinsic_ifAbruptCloseIterator):
* Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::parseBlock):
* Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp:
* Source/JavaScriptCore/dfg/DFGOperations.cpp:
(JSC::DFG::JSC_DEFINE_JIT_OPERATION):
* Source/JavaScriptCore/dfg/DFGOperations.h:
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:
* Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileNewInternalFieldObject):
(JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):
* Source/JavaScriptCore/ftl/FTLOperations.cpp:
(JSC::FTL::JSC_DEFINE_NOEXCEPT_JIT_OPERATION):
* Source/JavaScriptCore/heap/Heap.h:
* Source/JavaScriptCore/heap/HeapSubspaceTypes.h:
* Source/JavaScriptCore/jit/JIT.cpp:
(JSC::JIT::privateCompileMainPass):
* Source/JavaScriptCore/llint/LowLevelInterpreter.asm:
* Source/JavaScriptCore/runtime/CommonSlowPaths.cpp:
(JSC::JSC_DEFINE_COMMON_SLOW_PATH):
* Source/JavaScriptCore/runtime/CommonSlowPaths.h:
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildrenImpl):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::iteratorHelperPrototype const):
(JSC::JSGlobalObject::iteratorHelperStructure const):
* Source/JavaScriptCore/runtime/JSIteratorHelper.cpp: Added.
(JSC::JSIteratorHelper::createWithInitialValues):
(JSC::JSIteratorHelper::create):
(JSC::JSIteratorHelper::createStructure):
(JSC::JSIteratorHelper::JSIteratorHelper):
(JSC::JSIteratorHelper::visitChildrenImpl):
* Source/JavaScriptCore/runtime/JSIteratorHelper.h: Added.
* Source/JavaScriptCore/runtime/JSIteratorHelperPrototype.cpp: Added.
(JSC::JSIteratorHelperPrototype::finishCreation):
* Source/JavaScriptCore/runtime/JSIteratorHelperPrototype.h: Added.
* Source/JavaScriptCore/runtime/JSIteratorHelperPrototypeInlines.h: Added.
(JSC::JSIteratorHelperPrototype::createStructure):
* Source/JavaScriptCore/runtime/JSIteratorPrototype.cpp:
(JSC::JSIteratorPrototype::finishCreation):
* Source/JavaScriptCore/runtime/JSType.cpp:
(WTF::printInternal):
* Source/JavaScriptCore/runtime/JSType.h:

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to