Closed Bug 1842798 Opened 2 years ago Closed 2 years ago

Stop using MozPromise in the module loader

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
118 Branch
Tracking Status
firefox118 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

(Blocks 2 open bugs)

Details

Attachments

(4 files, 2 obsolete files)

There are a few bugs open at the moment concerning memory leaks that look like they might be caused by the module loader. Bug 1811635 is one example, in which mccr8 says:

I'm not sure exactly how the promise ownership chains work, but I'm guessing the basic issue is that mFetchingModules is not being cleared as expected, and the MozPromise can't be cycle collected because it is some fancy threadsafe thing.

MozPromise is indeed not cycle collected. I think the idea is that promises are transient and so this doesn't matter but it is plausible that this is involved somehow.

I originally used MozPromise in the module loader because I thought it would simplify the code and offload a tricky part of the implementation. However this wasn't entirely successful as it's not clear exactly what resolving/rejecting a promise is going to do and it still ended up pretty hard to understand.

Overall I don't think its use adds much to the module loader and therefore I'd like to remove it.

This replaces the promise with a list of module requests that are waiting for a
resource to be fetched. When the fetch completes the waiting requests are
resumed appropriately. Like MozPromise, this happens via runnables dispatched
to the module loader's event target.

This replaces the use of a promise to waits for all imports of a module to load
with a counter of reminaing imports in the parent and a pointer to the parent
that is waiting in the child.

Depends on D183272

This was previously used by MozPromise but is no longer required.

Depends on D183273

This is no longer necessary since the module loader is now always synchronous.

Depends on D183586

This fixes two failures that are currently marked as expected to fail.

Depends on D183588

Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b2e6bdd781ac Part 1: Remove use of MozPromise to wait for module fetch r=smaug https://hg.mozilla.org/integration/autoland/rev/1b89736a463f Part 2: Remove use of MozPromise to wait for module imports to load r=smaug https://hg.mozilla.org/integration/autoland/rev/946e4dfe5452 Part 3: Remove unused event target from ModuleLoaderBase r=smaug https://hg.mozilla.org/integration/autoland/rev/23d10eb8f853 Part 4: Removed unused sync event target r=smaug https://hg.mozilla.org/integration/autoland/rev/5dad4aeacd53 Part 5: Update test expectations r=smaug https://hg.mozilla.org/integration/autoland/rev/38669a2ddad9 apply code formatting via Lando

Backed out for causing failures on js/src/tests/test262/language/*

[task 2023-07-17T17:43:16.717Z] 17:43:16     INFO - REFTEST TEST-START | js/src/tests/test262/language/expressions/dynamic-import/eval-export-dflt-cls-anon.js;module;async
[task 2023-07-17T17:43:16.719Z] 17:43:16     INFO - REFTEST TEST-LOAD | file:///builds/worker/workspace/build/tests/jsreftest/tests/js/src/tests/jsreftest.html?test=test262/language/expressions/dynamic-import/eval-export-dflt-cls-anon.js;module;async | 7964 / 11170 (71%)
[task 2023-07-17T17:43:16.772Z] 17:43:16     INFO - TEST-INFO |  FAILED!  InternalError: module record has unexpected status: Evaluating
[task 2023-07-17T17:43:16.883Z] 17:43:16     INFO - REFTEST TEST-UNEXPECTED-FAIL | js/src/tests/test262/language/expressions/dynamic-import/eval-export-dflt-cls-anon.js;module;async | No test results reported. (SCRIPT)
[task 2023-07-17T17:43:16.884Z] 17:43:16     INFO - 
[task 2023-07-17T17:43:16.885Z] 17:43:16     INFO - REFTEST TEST-END | js/src/tests/test262/language/expressions/dynamic-import/eval-export-dflt-cls-anon.js;module;async
Flags: needinfo?(jcoppeard)

Turns out my try pushes didn't run all JS reftests.

Flags: needinfo?(jcoppeard)

According to spec this should happen asynchronously. If it doesn't it's
possible for the importing module to still be in the evaluating state when
trying to instantiate and evaluate the dynamically imported module which breaks
the module loader invariants.

Depends on D183273

Attachment #9343909 - Attachment is obsolete: true
Attachment #9343911 - Attachment is obsolete: true
Attachment #9343912 - Attachment description: Bug 1842798 - Part 5: Update test expectations r?smaug → Bug 1842798 - Part 4: Update test expectations r?smaug
Attachment #9344428 - Attachment description: Bug 1842798 - Part 3: Complete dynamic imports asynchronously r?smaug → Bug 1842798 - Part 3: Complete dynamic imports asynchronusly with a microtask r?smaug
Attachment #9344428 - Attachment description: Bug 1842798 - Part 3: Complete dynamic imports asynchronusly with a microtask r?smaug → Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?smaug
Attachment #9344428 - Attachment description: Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?smaug → Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?baku
Blocks: 1843838
See Also: 1843838
Attachment #9344428 - Attachment description: Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?baku → Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?smaug
Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/98a1aa86513d Part 1: Remove use of MozPromise to wait for module fetch r=smaug https://hg.mozilla.org/integration/autoland/rev/0864a23409e6 Part 2: Remove use of MozPromise to wait for module imports to load r=smaug https://hg.mozilla.org/integration/autoland/rev/05bcaff61b68 Part 3: Complete dynamic imports asynchronously with a microtask r=smaug https://hg.mozilla.org/integration/autoland/rev/b153ebf104ef Part 4: Update test expectations r=smaug
Blocks: 1846720
Attachment #9344428 - Attachment description: Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?smaug → Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r?baku
Flags: needinfo?(jcoppeard)
Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3528d70acb5f Part 1: Remove use of MozPromise to wait for module fetch r=smaug https://hg.mozilla.org/integration/autoland/rev/507da9d36f91 Part 2: Remove use of MozPromise to wait for module imports to load r=smaug https://hg.mozilla.org/integration/autoland/rev/2a6b3ff79a01 Part 3: Complete dynamic imports asynchronously with a microtask r=smaug https://hg.mozilla.org/integration/autoland/rev/879154594bb1 Part 4: Update test expectations r=smaug
Flags: needinfo?(jcoppeard)
Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1642f8c1f603 Part 1: Remove use of MozPromise to wait for module fetch r=smaug https://hg.mozilla.org/integration/autoland/rev/7b867fa107f5 Part 2: Remove use of MozPromise to wait for module imports to load r=smaug https://hg.mozilla.org/integration/autoland/rev/6aaab5ae37f2 Part 3: Complete dynamic imports asynchronously with a microtask r=smaug https://hg.mozilla.org/integration/autoland/rev/ce70368fe145 Part 4: Update test expectations r=smaug
Regressions: 1847090
Regressions: 1847702
See Also: → 1849089
Regressions: 1860802
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: