The engine's claim, from lean/Engine/Claims.lean and lean/Ecma/Implements.lean
What is proved
The specification layer defines what it is to implement the specification. The engine is proved to meet that definition, and so every run of the engine is a run of the specification's machine, or a stop at a limit of the engine's own. This page states the claim, then lists what is proved, what is trusted, what is owed, and what is outside it.
The definition: Ecma.Implements
An implementation (Implementation) has values (a model), a host, algorithms of its own beside the specification's, and its own transition between the machine's configurations. Its transition may take many of the specification's steps at once, or compute one differently. It implements the specification when three conditions hold:
-- lean/Ecma/Implements.lean, in namespace Ecmastructure Implements (I : Implementation M) : Prop where /-- its values are the specification's: the model's laws -/ model : Model.Laws M ∧ Model.UnicodeLaws M ∧ Model.ParentLaws M /-- its host meets every requirement the specification makes of a host -/ host : Host.WF I.host /-- each transition it takes from a configuration the specification's machine reaches is some transitions of that machine, and where it ends, that machine's run ends so; or it gives up at a limit of its own (it never answers otherwise than the specification) -/ step : ∀ rd chk c, Reached (I.spec rd chk) c → match I.step rd chk c with | .inl c' => Steps (I.spec rd chk) c c' | .inr f => Runs (I.spec rd chk) c f ∨ f = .stop .implLimit
- model
Its values obey the model's laws (
Model.Laws, 116 laws, among themnumfor the 12 laws of Numbers andbytesfor the 9 laws of Data Blocks), the Unicode laws (Model.UnicodeLaws, 7), and the Parse Node parent laws (Model.ParentLaws, 4).- host
Its host obeys every law the specification makes of a host (
Host.WF, 72 laws).- step
For every choice of errata's readings and of whether Asserts are checked: from any configuration the specification's machine reaches (
Reached), a transition the implementation takes is zero or more transitions of the specification's machine; where the implementation ends, the specification's machine ends from there with the same result; or the implementation stops at a limit of its own (.stop .implLimit). It never answers otherwise than the specification.
The theorems, verbatim
The engine as an implementation, Engine.implementation o cells mc accel, is the engine's model Impl, its host under the options o over the cells cells, the host's own algorithms, and its transition with the store's ceiling mc, with or without its shortcuts (accel). Both theorems are in lean/Engine/Proofs/Model.lean and have no hypothesis beyond what they state.
The engine implements the specification
-- lean/Engine/Proofs/Model.lean, in namespace Enginetheorem implements (o : Engine.Host.HostOpts) (cells : Engine.Host.Cells) (mc : Option Nat) (accel : Bool) : Implements (implementation o cells mc accel)
For every option set of the host, every allocation of its cells, every store ceiling, with or without the shortcuts, the engine is an implementation of the specification in the sense above.
Every run of the engine is the specification's
-- lean/Engine/Proofs/Model.lean, in namespace Enginetheorem run_sound (o : Engine.Host.HostOpts) (cells : Engine.Host.Cells) (mc : Option Nat) (accel : Bool) (rd : ErratumId → Reading) (chk : Bool) (units : Thunk Engine.Machine.Units) (ob : Engine.Machine.Obs) (s : State Impl) (k : Call Impl) (f : Final Impl) (hs : s.frames = []) (h : Machine.runT (setupAt (hostBy o cells) mc accel rd chk) units ob (start s k) = some f) : Runs (Ctx.spec (Spec.program hostAlgs) (hostBy o cells) rd chk) (start s k) f ∨ f = .stop .implLimit
If the engine's run loop (runT), started on a call in a state with no suspended execution context, returns a result f, then the specification's machine, with the specification's program, the engine's host and the same readings, has a run from the same configuration that ends with f; or f is a stop at an implementation limit. A companion, Engine.run_sound_reached, says the same from any configuration the specification's machine reaches, which covers the later runs a program makes (its jobs, and the program after its preludes).
Proved, trusted, owed, outside
Proved What the theorems establish
- The engine's values obey the model's laws and the Unicode laws (
Engine.Impl.laws,Engine.Impl.unicodeLaws). - The engine's host obeys the 72 host laws under every option set (
Engine.SpecHost.wfBy). - The code table the engine runs is the specification's program, with the host's algorithms where the specification defines none (
Engine.P'_eq). - Each transition of the engine, shortcuts included, is the specification's at every configuration the specification's machine reaches; every row of the shortcut table is proved, and the 55 equations on the generated program that the shortcuts rely on are checked at run time (
Engine.Machine.pinsOk; if any failed,Engine.setupAtwould runEngine.Machine.plain). - The laws of a Parse Node's parent (
Engine.Claims.parentLaws) and of its children and descendants (Engine.Claims.nodeLaws). - The set-ups covered:
ecma-runby default and with--no-accel, under every--checked,--reading,--erratum,--literal,--max-heap, every host option (--host-seed,--web-browser,--annex-b,--can-block,--resize-in-place), and with the trace,--sitesand--cover.
Trusted Relied on, not proved
- Lean's 3 standard axioms,
propext,Classical.choice,Quot.sound, and Lean's kernel and compiler. - The
implemented_byoverrides: the run loop's observers (traceOut,noteOut,noteStep, the identity to the logic), and the model's binary64 operationsaddHw,mulHw,divHw, and Parent'streeIndex,treeHeight,parentFast. - The driver between runs: the realm's set-up, each prelude and the program as a run of its own, the snapshots and
--serve's caches. None of them writes the suspended execution contexts, so each run starts from a configurationReachedcovers. That is read in the code, not proved.
Owed Stated, not proved
- The parser's laws,
Model.ParseLaws: a Parse Node the parser gives is a parse of the text under the grammar, and where it gives none there is none. - With them,
Model.CoverLaws: the node a cover gives is a parse of the cover's source text with the goal. - Neither is part of
Implements, and no claim on this page depends on them.
Outside Not covered by the claim
- The step debugger's loop (
Debugger.Machine.runW, apartialdefinition):ecma-dbgruns the same machine, but its loop is not proved. - Test results: the theorem says nothing about which test262 tests pass.
What the theorem does not say
- That the Lean is the English. The correspondence between
lean/Ecmaand spec.html is not a theorem. It rests on standing checks: the generator reproduces the HTML's text from its data, the Lean printer prints every generated item back to spec.html or the overlay byte for byte (scripts/bijection.py), and every law's quotation is found in its clause (scripts/law_quotes.py). The readings of the overlay and of each law are read by people, not proved. - That every program gets an answer. The theorem is about the runs the engine's loop returns. A run may also stop at an implementation limit (the store's ceiling, a number too large to compute), and such a stop is allowed by the claim. A run that does not end has no result to compare.
- That the parser is right. The parser's laws are owed. What is proved of a parse is that its nodes' children are their productions' occurrences (
Engine.Claims.nodeLaws), not that it is the grammar's parse of the text. - That each law is exactly its sentence. Two host laws read their sentence more strictly than it is written, and are for the list of proposed normative changes; two read theirs more weakly: see the host's laws.
The engine as an implementation
From lean/Engine/Claims.lean: the host's algorithms (hostAlgs: its built-in functions, the agent API's, HostLoadImportedModule, the algorithms that run a program), none at an id the specification defines; the host under the options o; and the transition Engine.Machine.stepE: a stop at the store's ceiling, else the shortcut table's answer where one answers (none with accel false, or if Engine.Machine.pinsOkThunk were false), else the specification's step.
-- lean/Engine/Claims.lean, in namespace Enginedef implementation (o : Engine.Host.HostOpts) (cells : Engine.Host.Cells) (mc : Option Nat) (accel : Bool := true) : Ecma.Implementation Impl where extras := hostAlgs host := hostBy o cells step rd chk := Engine.Machine.stepE (setupAt (hostBy o cells) mc accel rd chk)