archives

« Bugzilla Issues Index

#2603 — AddLoadToLinkSet should add "loading" dependencies, not just "loaded" dependencies


Guy Bedford discovered this.

The invariant is that while a LinkSet is in flight, its [[Loads]] list contains all in-flight Load Records that the LinkSet depends on.

This naturally includes both Loads that are still loading and Loads that have loaded and are waiting to be linked.

Proposed fix: in "15.2.5.2.2 AddLoadToLinkSet(linkSet, load) Abstract Operation", change step 3.c. from

> c. If load.[[Status]] is "loaded", then

to

> c. If load.[[Status]] is either "loading" or "loaded", then


Guy, can we add further assertions to make the intent/invariants clearer?

Here are some of the design invariants I have in my head.

For any given Loader,
let L = the set of Load Records in loader.[[Loads]], and
let LS = the set {linkset | linkset in load.[[LinkSets]], load in L}.

- Each Load in L is either "loading" or "loaded".

- For each linkset in LS,
linkset.[[Loads]] is a subset of loader.[[Loads]].

Together, these two imply that every Load in L and every LinkSet
in LS is still viable; if one fails, it and all its dependencies
must be removed from the loader's lists.

- For each load in L, for each linkset in LS,
load.[[LinkSets]] contains linkset iff linkset.[[Loads]] contains load.

- For each load in L, load.[[LinkSets]] is nonempty.

- For each linkset in LS,
if a Load Record j is a direct or indirect dependency
of any Load Record k in linkset.[[Loads]], then
j is also in linkset.[[Loads]].

These invariants should hold after every microtask. Guy, can you write a function to test them, call it from lots of places, and see if it shakes out more bugs?


I've added this invariant checking to the current polyfill implementation and everything worked out fine. See https://github.com/ModuleLoader/es6-module-loader/commit/f98950c3721f9c998f96ac5c0920c83a20854e5d for the code and test examples.

Note that the last invariant is not true. The linkSet retains the unlinked dependency graph only, clearing after each load. So I had to remove this check.

This fact is what can be (should be) exploited in the group linking algorithms since we know that the linkSet is basically our unlinked dependency graph, so we just have to consider those load records.


concerns old module spec.