ECMA-262 in Lean

A record of the branch proposal-defer-import-eval · site/proposal-defer-import-eval.json

Applying a proposal

What it takes to apply a TC39 proposal to this specification, shown on tc39/proposal-defer-import-eval: the text merged, what was written by hand, what was regenerated, what the merge found, and the results.

What was done

The proposal tc39/proposal-defer-import-eval, at its commit 6fefd29, was applied to ECMA-262 at b1eaed82f in a branch of this repository, proposal-defer-import-eval (from main): the proposal's text merged into the specification's, the Lean specification regenerated from the result, the engine built and its claims checked, and the proposal's test262 tests run.

How a proposal is applied

  1. Pin it. The proposal's repository is a submodule, external/proposal-defer-import-eval, at 6fefd29, and one line of spec/proposals.txt names it with its answers file.
  2. Merge it. scripts/apply_proposal.py reads the proposal's spec.emu as a diff against ECMA-262: it matches each clause by its id and each block of the clause by its old text (the block with its <ins> dropped and its <del> kept), which must be the base's; it inserts the proposal's new clauses and removes the ones it deletes. Where the old text is not the base's, or an inserted block's place is not shown, it refuses and asks: the answers file (spec/proposals/defer-import-eval/resolutions.txt) answers each question, one line each.
  3. The text. scripts/spec_text.py makes the text every generator, check and page reads: ECMA-262 with the proposals of spec/proposals.txt applied, remade whenever an input changes.
  4. Readings. A sentence of the proposal that the generator cannot read as it stands gets a reading in the overlay, as any sentence of ECMA-262 does.
  5. Regenerate. python3 scripts/gen_spec.py --write --gen target/release/spec-gen and python3 scripts/jsgrammar.py --write --gen target/release/jsgrammar --readings spec/formal/readings.emu --readings spec/formal/syntax.emu --json spec/formal/json.emu write lean/Ecma/Gen, lean/Ecma/Grammar/Gen and their id tables from the text (python3 scripts/spec_text.py --report says what the merge did).
  6. Build and check. lake build, the axiom check of the claims, python3 scripts/quick_check.py, and test262 with the proposal's feature no longer in [skip-features].

What was written by hand

FileAddedRemoved
.gitmodules+3−0
external/proposal-defer-import-eval (new)+1−0
spec/proposals.txt+2−0
spec/proposals/defer-import-eval/README.md (new)+25−0
spec/proposals/defer-import-eval/resolutions.txt (new)+27−0
spec/formal/defer-import.emu (new)+102−0
spec/formal/fields.emu+1−1
spec/formal/lists.emu+4−4
spec/formal/permanent.emu+0−1
spec/formal/realm.emu+2−3
spec/formal/decisions.md+31−0
spec/formal/phrase-unreviewed.txt+9−1
spec/formal/readings-restating.txt+11−3
tests/run/frontend_not_ecmascript.js+3−2
tests/run/import_defer_basic.js+3−6
tests/run/import_defer_dynamic.js+2−5
tests/run/import_defer_tla.js+3−6
tests/test262/full.conf+0−1
tests/test262/sample.conf+0−1
tests/test262/suite.conf+0−1

Hand-written Lean: 0 files changed under lean/ outside its generated directories.

The answers to the merge (10)

AnswerThe question the merge askedWhy this answer
ignore sec-LoadRequestedModules 1the clause's header (<dl class="header">) has no markup but is not the base'sthe proposal abbreviates it: it drops the <dt>description</dt> (and, in InnerModuleLoading and InnerModuleLinking, every entry). It changes nothing there, so the base's header stays
ignore sec-InnerModuleLoading 1the clause's header (<dl class="header">) has no markup but is not the base'sthe proposal abbreviates it: it drops the <dt>description</dt> (and, in InnerModuleLoading and InnerModuleLinking, every entry). It changes nothing there, so the base's header stays
ignore sec-moduledeclarationlinking 1the clause's header (<dl class="header">) has no markup but is not the base'sthe proposal abbreviates it: it drops the <dt>description</dt> (and, in InnerModuleLoading and InnerModuleLinking, every entry). It changes nothing there, so the base's header stays
ignore sec-InnerModuleLinking 1the clause's header (<dl class="header">) has no markup but is not the base'sthe proposal abbreviates it: it drops the <dt>description</dt> (and, in InnerModuleLoading and InnerModuleLinking, every entry). It changes nothing there, so the base's header stays
place sec-InnerModuleLoading 2 after 2the proposal inserts a note (<emu-note> all <ins>) but omits the header and the algorithm around it: before or after the algorithm?after it (base block 2 is the algorithm): a note on an algorithm follows it, as everywhere in the text, and the note speaks of the algorithm's steps
place sec-InnerModuleLinking 2 after 2the proposal inserts a note (<emu-note> all <ins>) but omits the header and the algorithm around it: before or after the algorithm?after it (base block 2 is the algorithm): a note on an algorithm follows it, as everywhere in the text, and the note speaks of the algorithm's steps
rebase sec-source-text-module-record-initialize-environment 2InitializeEnvironment's steps: the proposal's old text lacks two of the base's lines, Assert: _exportEntry_.[[ExportName]] is not *null*. (1.a) and Assert: _importEntry_.[[ImportName]] is a String. (7.c.i)the base is newer than the proposal's copy; the proposal's changes (GetModuleNamespace's new phase argument, twice, and the ~deferred-namespace~ branch of 7.c.iii) touch other lines, so the three-way merge applies them to the base with no conflict and both Asserts stay
rebase sec-resolveexport 2ResolveExport's steps: the proposal's old text has an Else, after Return ResolvedBinding Record { … ~namespace~ }. that the base no longer hasthe same: the base dropped it, the proposal's change (the ~deferred-namespace~ branch) is elsewhere in the algorithm, and the merge applies it to the base's lines
rebase-take sec-abstract-module-records 4Module Record Fields: the table differs as a whole (the base gained a <thead>), and row by row too, at [[Namespace]]'s Meaningthe proposal rewrote that cell without <ins>/<del>: the link to #sec-module-namespace-objects (a clause it deletes) becomes #sec-module-namespace-exotic-objects, and "whose [[Deferred]] slot is false," is added. That is the proposal's change, so its line wins where it differs from the base; the base's <thead> stays.
rename ModuleRequestsEqual ModuleRequestsKeyEquala warning: ModuleRequestsEqual, whose clause the proposal removes (del-sec-ModuleRequestsEqual), is still used in 6 clauses the proposal does not showthe proposal's new clause ModuleRequestsKeyEqual takes over the old one's id (oldids="sec-ModuleRequestsEqual"), with the same steps, and the proposal renames the two uses it shows; the other seven uses (Realm Record and Script Record [[LoadedModules]], Cyclic Module Record [[LoadedModules]], InnerModuleLoading 2.d.ii, GetImportedModule 1, HostLoadImportedModule's requirements) are renamed with it.

The readings (14)

Each reading says what a sentence of the proposal means, in the notation the generator reads: 10 new, 3 re-anchored, 1 replaced. The proposal's sentence is quoted from the merged text, found by the hash the overlay records; the reasons are the branch's report's.

Clause, stepThe proposal's sentence, as the merged text has itThe reading
10.4.6.6 [[DefineOwnProperty]], step 1
new

If IsSymbolLikeNamespaceKey(propertyKey, obj), return ! OrdinaryDefineOwnProperty(obj, propertyKey, propertyDesc).

  1. If IsSymbolLikeNamespaceKey(propertyKey, obj) is true, return ! OrdinaryDefineOwnProperty(obj, propertyKey, propertyDesc).
Why the generator could not read it unaided: a Boolean call used bare as a condition. ECMA-262 never writes one, so the notation has no such form
10.4.6.7 [[HasProperty]], step 1
new

If IsSymbolLikeNamespaceKey(propertyKey, obj), return ! OrdinaryHasProperty(obj, propertyKey).

  1. If IsSymbolLikeNamespaceKey(propertyKey, obj) is true, return ! OrdinaryHasProperty(obj, propertyKey).
Why the generator could not read it unaided: a Boolean call used bare as a condition. ECMA-262 never writes one, so the notation has no such form
10.4.6.8 [[Get]], step 1
new

If IsSymbolLikeNamespaceKey(propertyKey, obj), then

  1. If IsSymbolLikeNamespaceKey(propertyKey, obj) is true, then
    1. Return ! OrdinaryGet(obj, propertyKey, receiver).
Why the generator could not read it unaided: a Boolean call used bare as a condition. ECMA-262 never writes one, so the notation has no such form
10.4.6.10 [[Delete]], step 1
new

If IsSymbolLikeNamespaceKey(propertyKey, obj), then

  1. If IsSymbolLikeNamespaceKey(propertyKey, obj) is true, then
    1. Return ! OrdinaryDelete(obj, propertyKey).
Why the generator could not read it unaided: a Boolean call used bare as a condition. ECMA-262 never writes one, so the notation has no such form
16.2.1.5.1.2 ReadyForSyncExecution, step 5
new

If IsModuleSCCEvaluated(module), return true.

  1. If IsModuleSCCEvaluated(module) is true, return true.
Why the generator could not read it unaided: a Boolean call used bare as a condition. ECMA-262 never writes one, so the notation has no such form
16.2.1.13 GetModuleNamespace, step 2
new

If phase is defer, let namespace be module.[[DeferredNamespace]]. Else, let namespace be module.[[Namespace]].

  1. If phase is defer, let namespace be module.[[DeferredNamespace]]; else let namespace be module.[[Namespace]].
Why the generator could not read it unaided: an inline conditional written as two sentences. The text writes "…; else let …" everywhere else
13.3.10.5 ContinueDynamicImport, step 6.d.iv
new

For each Module Record dep of evaluationList, append dep.Evaluate() to asyncDepsEvaluationPromises.

  1. For each Module Record dep of evaluationList, do
    1. Append dep.Evaluate() to asyncDepsEvaluationPromises.
Why the generator could not read it unaided: a For each with an inline body, which the text writes nowhere else
16.2.1.6.1.3 Evaluate, step 1
new

Assert: None of module or any of its recursive dependencies have [[Status]] set to evaluating, linking, unlinked, or new.

  1. Let pending be « module ».
  2. Let seen be a new empty List.
  3. Repeat, while pending is not empty,
    1. Let m be the first element of pending.
    2. Remove the first element from pending.
    3. If seen does not contain m and m is a Cyclic Module Record, then
      1. Append m to seen.
      2. Assert: m.[[Status]] is one of linked, evaluating-async, or evaluated.
      3. For each ModuleRequest Record request of m.[[RequestedModules]], do
        1. Append GetImportedModule(m, request) to pending.
Why the generator could not read it unaided: "recursive dependencies" is defined nowhere. There is no model operation for it, so this is the one new loop
16.2.1.9 GetImportedModule, step 1
re-anchored

Let records be a List consisting of each LoadedModuleRequest Record r of referrer.[[LoadedModules]] such that ModuleRequestsKeyEqual(r, request) is true.

  1. Let records be a new empty List.
  2. For each LoadedModuleRequest Record r of referrer.[[LoadedModules]], do
    1. If ModuleRequestsKeyEqual(r, request) is true, append r to records.
Why the generator could not read it unaided: the rename changed the step's hash, so the reading lost its anchor
13.3.10.4 EvaluateImportCall, step 9.f
re-anchored

Sort attrs according to the lexicographic order of their [[Key]] field, treating the value of each such field as a sequence of UTF-16 code unit values. NOTE: This sorting is observable only in that hosts are prohibited from changing behaviour based on the order in which attributes are enumerated.

  1. Let rest be a copy of attrs.
  2. Let sorted be a new empty List.
  3. Repeat, while rest is not empty,
    1. Let least be the first element of rest.
    2. For each element a of rest, do
      1. If ! IsLessThan(a.[[Key]], least.[[Key]], true) is true, set least to a.
    3. Append least to sorted.
    4. Remove least from rest.
  4. Set attrs to sorted.
Why the generator could not read it unaided: the step was renumbered
16.2.1.6.1.3.1 InnerModuleEvaluation, step 18.b.iv
re-anchored

Assert: requiredModule.[[AsyncEvaluationOrder]] is either an integer or unset.

  1. Assert: requiredModule.[[AsyncEvaluationOrder]] is an integer or requiredModule.[[AsyncEvaluationOrder]] is unset.
Why the generator could not read it unaided: the step was renumbered
10.4.6.12 ModuleNamespaceCreate, step 9
replaced

Create an own data property of namespace named %Symbol.toStringTag% whose [[Value]] is toStringTag and whose [[Writable]], [[Enumerable]], and [[Configurable]] attributes are false.

  1. Perform OwnPropertyCreate(namespace, %Symbol.toStringTag%, PropertyDescriptor { [[Value]]: toStringTag, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }, data).
Why the generator could not read it unaided: the old reading created the properties of §28.3, which the proposal deletes; the new sentence has no phrase ("CreateOwnProperty, unclassified")
8.2.1 BoundNames
new

No row for ImportDeclaration : `import` `defer` NameSpaceImport FromClause WithClause? `;`.

  1. Return the BoundNames of NameSpaceImport.
Why the generator could not read it unaided: the proposal's text does not give it; the reading gives what test262's tests of the proposal require
16.2.1.8.1 CreateDefaultExportSyntheticModule, step 3
new

Return the Synthetic Module Record { [[Realm]]: realm, [[Environment]]: empty, [[Namespace]]: empty, [[HostDefined]]: undefined, [[ExportNames]]: « "default" », [[EvaluationSteps]]: setDefaultExport }.

  1. Return the Synthetic Module Record { [[Realm]]: realm, [[Environment]]: empty, [[Namespace]]: empty, [[DeferredNamespace]]: empty, [[HostDefined]]: undefined, [[ExportNames]]: « "default" », [[EvaluationSteps]]: setDefaultExport }.
Why the generator could not read it unaided: the proposal's text does not give it; the reading gives what test262's tests of the proposal require

Other changes to the overlay:

What regenerating changed

18 generated modules, +1,555 −1,106 lines, nobody edited:

DirectoryModulesAddedRemovedModules
lean/Ecma/Gen13+1,197−775Decls, Phrases, Phrases_DeferImport (new), Realm, S10_4_part2, S13_3, S16_2_part1, S16_2_part2, S16_2_part3, S27_5_part1, S27_5_part2, Tables_1, Tables_2
lean/Ecma/Grammar/Gen5+358−331Index, Symbols, Syntactic1, Syntactic2, SyntacticProd

The id tables only gained lines, retired lines, or gave a kept number a new name; no number moved:

TableNewRetiredRenamed
clause-ids.txt1121
enum-ids.txt300
erratum-ids.txt1330
field-ids.txt300
nt-ids.txt100
prod-ids.txt840
sdo-ids.txt200
table-ids.txt500

Because every number the generated data uses is kept (How it works), the regenerated modules differ only where the proposal changes the text, and every proof that names an algorithm by its number still names the same algorithm.

What the merge found in the proposal's text

Run with no answers, the merge refuses 9 times and warns 1 time. The refusals, by what the answer found them to be:

RefusalCount
a context block that is not the base's (an abbreviated header)4
an inserted block whose place is not shown2
old text that is not the base's: the base changed after the proposal was written2
old text that is not the base's: the proposal changed it without marking it1

The warning: ModuleRequestsEqual (sec-ModuleRequestsEqual, removed (sec-ModuleRequestsEqual)) is still used in 6 clause(s): sec-GetImportedModule, sec-HostLoadImportedModule, sec-InnerModuleLoading, sec-code-realms, sec-cyclic-module-records, sec-script-records; answer with `rename ModuleRequestsEqual NEW` if the proposal renames it.

With the answers, it changes 26 clauses, inserts 11, removes 2 and copies 3 figures; every one of the proposal's 129 <ins> texts is in the result, none of its 57 <del> texts is left, and the clause tree is the base's less the removed clauses plus the inserted ones.

For the merge to ask nothing, a proposal's text would reproduce whole blocks (no abbreviated headers; an inserted note shown with the algorithm before it), be written against the current ECMA-262, mark every change with <ins> and <del>, and rename a removed operation at every call or say that the rest are renamed with it.

The results

test262. The 252 tests of the feature import-defer at test262 2e58f87d8: 251 pass, 1 skip (not run: language/import/import-defer/evaluation-triggers/ignore-private-name-access.js, feature nonextensible-applies-to-private).

DirectoryPassNot passingSkipped
language/expressions/assignmenttargettype2
language/expressions/dynamic-import147
language/import/import-defer1021

The claims. On the branch, Engine.implements and Engine.run_sound rest on propext, Classical.choice, Quot.sound alone (no native_decide pins); the same list as without the proposal.

The programs. Each of the proposal's three example programs, under the proposal's build and under the specification's (both checked when this site was built):

ProgramWith the proposalThe specification
tests/run/import_defer_basic.jsnormal: undefined
[object Deferred Module]
main starts; heavy evaluates; read 42; read again 42
throw: SyntaxError
tests/run/import_defer_dynamic.jsnormal: undefined
promise settled; then in ns: false; dep evaluates; x is 1
throw: SyntaxError
tests/run/import_defer_tla.jsnormal: undefined
before access: b, e, d, a
after access: b, e, d, a, f, c
throw: SyntaxError

Try it

The debugger has the proposal's build: under it each program runs and pauses in the proposal's algorithms; under the specification's it is a SyntaxError.