Closed Bug 1770509 Opened 3 years ago Closed 3 years ago

Use an IC when closing for-of iterators

Categories

(Core :: JavaScript Engine: JIT, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: iain, Assigned: iain)

References

(Blocks 1 open bug)

Details

Attachments

(15 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

We generate a lot of bytecode for for-of loops. A lot of that bytecode is dedicated to closing iterators on the way out. Many/most for-of loops are iterating over arrays or other collections that don't even have a return method. We can reduce bytecode size by folding the iterator closure code up in an IC.

This initial implementation doesn't handle throw completions. Support for those is added in a later patch.

Depends on D147344

tryAttachNoReturnMethod covers built-in collections (arrays, maps, and sets), and any custom iterator that doesn't have a return method.

Depends on D147345

Depends on D147346

We had LoadDynamicSlot, but not LoadFixedSlot.

Depends on D147347

Entering a stub frame is the same whether we're doing a callVM or a callJit. This aligns better with baseline and simplifies the getter/setter code.

At some point we could consider rewriting the Ion code to use AutoStubFrame.

Depends on D147348

This supports custom iterators with return methods. It is also necessary to support generators (which call the self-hosted GeneratorReturn function), although those won't work until a subsequent patch adds support for rectifier frames.

Depends on D147350

Depends on D147351

When closing a for-of iterator, we overwrite the iterator on the stack with undefined. Comments / commit messages say it's so the iterator doesn't get closed again in the catch block. But there's a for-of-iterclose trynote covering this code, so we never end up in the catch block, and this code is dead.

Depends on D147352

The spec handles IteratorClose specially when the completion kind is 'throw' so that the original exception isn't overwritten by an exception that happens while closing the iterator. See https://tc39.es/ecma262/#sec-iteratorclose.

Depends on D147353

We guard on the specific function/script, so nargs is constant for a particular IC stub. Generating a rectifier frame is overkill.

The main use case for this is generators: GeneratorReturn takes one argument.

Depends on D147354

Depends on D147355

In the next patch, we want to change the bailout kind in BaselineStackBuilder. This patch sets the initial bailout kind earlier, so that we don't clobber the update.

Depends on D147356

If we throw an exception while building the stack frame in BailoutIonToBaseline, we will skip try/catch blocks in that frame. Throwing in FinishBailoutToBaseline ensures that we unwind correctly.

Depends on D148332

Pushed by iireland@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0f94133f476e Add JSOp::CloseIter r=jandem https://hg.mozilla.org/integration/autoland/rev/6c908030c328 Add baseline IC for CloseIter r=jandem https://hg.mozilla.org/integration/autoland/rev/bbfedd0e08ce Add CacheIR generator for CloseIter r=jandem https://hg.mozilla.org/integration/autoland/rev/9d37be10da8f Add Warp support r=jandem https://hg.mozilla.org/integration/autoland/rev/874a4adcb3bf Add LoadFixedSlot to CacheIR r=jandem https://hg.mozilla.org/integration/autoland/rev/d20dcc34e87c Rename prepareVMCall to enterStubFrame r=jandem https://hg.mozilla.org/integration/autoland/rev/4235a298993a Support GuardFunctionScript in IonCacheIRCompiler r=jandem https://hg.mozilla.org/integration/autoland/rev/1d912ad801b0 Add CloseIterScriptedResult r=jandem https://hg.mozilla.org/integration/autoland/rev/7d425224ec84 Transpile CloseIterScriptedResult r=jandem https://hg.mozilla.org/integration/autoland/rev/cc2d84593658 Don't overwrite stack slot with undefined r=arai https://hg.mozilla.org/integration/autoland/rev/7ad24b936f3b Support CompletionKind::Throw r=jandem https://hg.mozilla.org/integration/autoland/rev/347c2d2b6751 Support return methods with nargs > 0 r=jandem https://hg.mozilla.org/integration/autoland/rev/d26c5eb9eb33 Add tests r=jandem https://hg.mozilla.org/integration/autoland/rev/0c4b84f3d824 Update bailoutKind earlier r=jandem https://hg.mozilla.org/integration/autoland/rev/0b909b1ebdf8 Add ResumeMode::ResumeAfterCheckIsObject r=jandem
Regressions: 1773496
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: