Skip to content

Commit 905660d

Browse files
nicolo-ribaudoljharb
authored andcommitted
Editorial: Replace [[DFSIndex]] with a local variable (#3625)
The [[DFSIndex]] field of module records is only ever read by `InnerModule*` algorithms, and only on the same module that the algorithm is called on. There is no need to have it as a field on the module record, and removing it helps by having on less piece of potentially mutable state to keep track of while reading the algorithms.
1 parent dd2c5c3 commit 905660d

File tree

1 file changed

+11
-69
lines changed

1 file changed

+11
-69
lines changed

spec.html

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26826,17 +26826,6 @@ <h1>Cyclic Module Records</h1>
2682626826
A throw completion representing the exception that occurred during evaluation. *undefined* if no exception occurred or if [[Status]] is not ~evaluated~.
2682726827
</td>
2682826828
</tr>
26829-
<tr>
26830-
<td>
26831-
[[DFSIndex]]
26832-
</td>
26833-
<td>
26834-
an integer or ~empty~
26835-
</td>
26836-
<td>
26837-
Auxiliary field used during Link and Evaluate only. If [[Status]] is either ~linking~ or ~evaluating~, this non-negative number records the point at which the module was first visited during the depth-first traversal of the dependency graph.
26838-
</td>
26839-
</tr>
2684026829
<tr>
2684126830
<td>
2684226831
[[DFSAncestorIndex]]
@@ -26845,7 +26834,7 @@ <h1>Cyclic Module Records</h1>
2684526834
an integer or ~empty~
2684626835
</td>
2684726836
<td>
26848-
Auxiliary field used during Link and Evaluate only. If [[Status]] is either ~linking~ or ~evaluating~, this is either the module's own [[DFSIndex]] or that of an "earlier" module in the same strongly connected component.
26837+
Auxiliary field used during Link and Evaluate only. If [[Status]] is either ~linking~ or ~evaluating~, this is either the module's depth-first traversal index or that of an "earlier" module in the same strongly connected component.
2684926838
</td>
2685026839
</tr>
2685126840
<tr>
@@ -26878,7 +26867,7 @@ <h1>Cyclic Module Records</h1>
2687826867
a Cyclic Module Record or ~empty~
2687926868
</td>
2688026869
<td>
26881-
The first visited module of the cycle, the root DFS ancestor of the strongly connected component. For a module not in a cycle, this would be the module itself. Once Evaluate has completed, a module's [[DFSAncestorIndex]] is the [[DFSIndex]] of its [[CycleRoot]].
26870+
The first visited module of the cycle, the root DFS ancestor of the strongly connected component. For a module not in a cycle, this would be the module itself. Once Evaluate has completed, a module's [[DFSAncestorIndex]] is the depth-first traversal index of its [[CycleRoot]].
2688226871
</td>
2688326872
</tr>
2688426873
<tr>
@@ -27174,7 +27163,7 @@ <h1>
2717427163
</h1>
2717527164
<dl class="header">
2717627165
<dt>description</dt>
27177-
<dd>It is used by Link to perform the actual linking process for _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as a module's [[DFSIndex]] and [[DFSAncestorIndex]] fields, keep track of the depth-first search (DFS) traversal. In particular, [[DFSAncestorIndex]] is used to discover strongly connected components (SCCs), such that all modules in an SCC transition to ~linked~ together.</dd>
27166+
<dd>It is used by Link to perform the actual linking process for _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as a module's [[DFSAncestorIndex]] field, keep track of the depth-first search (DFS) traversal. In particular, [[DFSAncestorIndex]] is used to discover strongly connected components (SCCs), such that all modules in an SCC transition to ~linked~ together.</dd>
2717827167
</dl>
2717927168

2718027169
<emu-alg>
@@ -27185,7 +27174,7 @@ <h1>
2718527174
1. Return _index_.
2718627175
1. Assert: _module_.[[Status]] is ~unlinked~.
2718727176
1. Set _module_.[[Status]] to ~linking~.
27188-
1. Set _module_.[[DFSIndex]] to _index_.
27177+
1. Let _moduleIndex_ be _index_.
2718927178
1. Set _module_.[[DFSAncestorIndex]] to _index_.
2719027179
1. Set _index_ to _index_ + 1.
2719127180
1. Append _module_ to _stack_.
@@ -27199,8 +27188,8 @@ <h1>
2719927188
1. Set _module_.[[DFSAncestorIndex]] to min(_module_.[[DFSAncestorIndex]], _requiredModule_.[[DFSAncestorIndex]]).
2720027189
1. Perform ? _module_.InitializeEnvironment().
2720127190
1. Assert: _module_ occurs exactly once in _stack_.
27202-
1. Assert: _module_.[[DFSAncestorIndex]] ≤ _module_.[[DFSIndex]].
27203-
1. If _module_.[[DFSAncestorIndex]] = _module_.[[DFSIndex]], then
27191+
1. Assert: _module_.[[DFSAncestorIndex]] ≤ _moduleIndex_.
27192+
1. If _module_.[[DFSAncestorIndex]] = _moduleIndex_, then
2720427193
1. Let _done_ be *false*.
2720527194
1. Repeat, while _done_ is *false*,
2720627195
1. Let _requiredModule_ be the last element of _stack_.
@@ -27263,7 +27252,7 @@ <h1>
2726327252
</h1>
2726427253
<dl class="header">
2726527254
<dt>description</dt>
27266-
<dd>It is used by Evaluate to perform the actual evaluation process for _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as _module_'s [[DFSIndex]] and [[DFSAncestorIndex]] fields, are used the same way as in InnerModuleLinking.</dd>
27255+
<dd>It is used by Evaluate to perform the actual evaluation process for _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as _module_'s [[DFSAncestorIndex]] field, are used the same way as in InnerModuleLinking.</dd>
2726727256
</dl>
2726827257

2726927258
<emu-alg>
@@ -27276,7 +27265,7 @@ <h1>
2727627265
1. If _module_.[[Status]] is ~evaluating~, return _index_.
2727727266
1. Assert: _module_.[[Status]] is ~linked~.
2727827267
1. Set _module_.[[Status]] to ~evaluating~.
27279-
1. Set _module_.[[DFSIndex]] to _index_.
27268+
1. Let _moduleIndex_ be _index_.
2728027269
1. Set _module_.[[DFSAncestorIndex]] to _index_.
2728127270
1. Set _module_.[[PendingAsyncDependencies]] to 0.
2728227271
1. Set _index_ to _index_ + 1.
@@ -27303,8 +27292,8 @@ <h1>
2730327292
1. Else,
2730427293
1. Perform ? <emu-meta effects="user-code">_module_.ExecuteModule()</emu-meta>.
2730527294
1. Assert: _module_ occurs exactly once in _stack_.
27306-
1. Assert: _module_.[[DFSAncestorIndex]] ≤ _module_.[[DFSIndex]].
27307-
1. If _module_.[[DFSAncestorIndex]] = _module_.[[DFSIndex]], then
27295+
1. Assert: _module_.[[DFSAncestorIndex]] ≤ _moduleIndex_.
27296+
1. If _module_.[[DFSAncestorIndex]] = _moduleIndex_, then
2730827297
1. Let _done_ be *false*.
2730927298
1. Repeat, while _done_ is *false*,
2731027299
1. Let _requiredModule_ be the last element of _stack_.
@@ -27526,14 +27515,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2752627515
<th>_E_</th>
2752727516
</tr>
2752827517
</thead>
27529-
<tr>
27530-
<th>[[DFSIndex]]</th>
27531-
<td>0</td>
27532-
<td>1</td>
27533-
<td>3</td>
27534-
<td>2</td>
27535-
<td>4</td>
27536-
</tr>
2753727518
<tr>
2753827519
<th>[[DFSAncestorIndex]]</th>
2753927520
<td>0</td>
@@ -27593,11 +27574,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2759327574
<th>_E_</th>
2759427575
</tr>
2759527576
</thead>
27596-
<tr>
27597-
<th>[[DFSIndex]]</th>
27598-
<td>3</td>
27599-
<td>4</td>
27600-
</tr>
2760127577
<tr>
2760227578
<th>[[DFSAncestorIndex]]</th>
2760327579
<td>0</td>
@@ -27643,12 +27619,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2764327619
<th>_D_</th>
2764427620
</tr>
2764527621
</thead>
27646-
<tr>
27647-
<th>[[DFSIndex]]</th>
27648-
<td>1</td>
27649-
<td>3</td>
27650-
<td>2</td>
27651-
</tr>
2765227622
<tr>
2765327623
<th>[[DFSAncestorIndex]]</th>
2765427624
<td>0</td>
@@ -27698,11 +27668,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2769827668
<th>_C_</th>
2769927669
</tr>
2770027670
</thead>
27701-
<tr>
27702-
<th>[[DFSIndex]]</th>
27703-
<td>0</td>
27704-
<td>3</td>
27705-
</tr>
2770627671
<tr>
2770727672
<th>[[DFSAncestorIndex]]</th>
2770827673
<td>0</td>
@@ -27747,11 +27712,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2774727712
<th>_B_</th>
2774827713
</tr>
2774927714
</thead>
27750-
<tr>
27751-
<th>[[DFSIndex]]</th>
27752-
<td>0</td>
27753-
<td>1</td>
27754-
</tr>
2775527715
<tr>
2775627716
<th>[[DFSAncestorIndex]]</th>
2775727717
<td>0</td>
@@ -27795,10 +27755,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2779527755
<th>_A_</th>
2779627756
</tr>
2779727757
</thead>
27798-
<tr>
27799-
<th>[[DFSIndex]]</th>
27800-
<td>0</td>
27801-
</tr>
2780227758
<tr>
2780327759
<th>[[DFSAncestorIndex]]</th>
2780427760
<td>0</td>
@@ -27838,11 +27794,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2783827794
<th>_C_</th>
2783927795
</tr>
2784027796
</thead>
27841-
<tr>
27842-
<th>[[DFSIndex]]</th>
27843-
<td>0</td>
27844-
<td>3</td>
27845-
</tr>
2784627797
<tr>
2784727798
<th>[[DFSAncestorIndex]]</th>
2784827799
<td>0</td>
@@ -27891,10 +27842,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2789127842
<th>_A_</th>
2789227843
</tr>
2789327844
</thead>
27894-
<tr>
27895-
<th>[[DFSIndex]]</th>
27896-
<td>0</td>
27897-
</tr>
2789827845
<tr>
2789927846
<th>[[DFSAncestorIndex]]</th>
2790027847
<td>0</td>
@@ -27939,11 +27886,6 @@ <h1>Example Cyclic Module Record Graphs</h1>
2793927886
<th>_B_</th>
2794027887
</tr>
2794127888
</thead>
27942-
<tr>
27943-
<th>[[DFSIndex]]</th>
27944-
<td>0</td>
27945-
<td>1</td>
27946-
</tr>
2794727889
<tr>
2794827890
<th>[[DFSAncestorIndex]]</th>
2794927891
<td>0</td>
@@ -28519,7 +28461,7 @@ <h1>
2851928461
1. Else,
2852028462
1. Append _ee_ to _indirectExportEntries_.
2852128463
1. Let _async_ be _body_ Contains `await`.
28522-
1. Return Source Text Module Record { [[Realm]]: _realm_, [[Environment]]: ~empty~, [[Namespace]]: ~empty~, [[CycleRoot]]: ~empty~, [[HasTLA]]: _async_, [[AsyncEvaluationOrder]]: ~unset~, [[TopLevelCapability]]: ~empty~, [[AsyncParentModules]]: « », [[PendingAsyncDependencies]]: ~empty~, [[Status]]: ~new~, [[EvaluationError]]: ~empty~, [[HostDefined]]: _hostDefined_, [[ECMAScriptCode]]: _body_, [[Context]]: ~empty~, [[ImportMeta]]: ~empty~, [[RequestedModules]]: _requestedModules_, [[LoadedModules]]: « », [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[DFSIndex]]: ~empty~, [[DFSAncestorIndex]]: ~empty~ }.
28464+
1. Return Source Text Module Record { [[Realm]]: _realm_, [[Environment]]: ~empty~, [[Namespace]]: ~empty~, [[CycleRoot]]: ~empty~, [[HasTLA]]: _async_, [[AsyncEvaluationOrder]]: ~unset~, [[TopLevelCapability]]: ~empty~, [[AsyncParentModules]]: « », [[PendingAsyncDependencies]]: ~empty~, [[Status]]: ~new~, [[EvaluationError]]: ~empty~, [[HostDefined]]: _hostDefined_, [[ECMAScriptCode]]: _body_, [[Context]]: ~empty~, [[ImportMeta]]: ~empty~, [[RequestedModules]]: _requestedModules_, [[LoadedModules]]: « », [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[DFSAncestorIndex]]: ~empty~ }.
2852328465
</emu-alg>
2852428466
<emu-note>
2852528467
<p>An implementation may parse module source text and analyse it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.</p>

0 commit comments

Comments
 (0)