Inside the engine

The core — DOM, parsers, cascade, layout, painting — is pure Lean. The parts that cannot be pure — text shaping, the GPU, the network, media, and the JavaScript engine pages run on — are Rust, behind one explicit interface to that core.

Scripts on V8, and on Lean

Pages run on V8 through Web IDL bindings generated from the specifications' IDL, and every DOM member's behaviour is the Lean core's. The same pages also run on leanjs, the Lean interpreter the proofs are about: slower, and deterministic.

Drawn on the GPU

Display lists rasterized by Vello on the GPU; composited layers whose transform and opacity animations the window samples at every display refresh.

Incremental, and checked

Restyle, layout and paint redo only what changed. Incremental layout is proven equal to layout from scratch (below); the faster copies the browser runs are checked against fresh runs and are being proved one by one.

A process per tab

Each page's event loop runs in its own process; cross-origin iframes get a script engine of their own, same-origin ones share their parent's; dedicated workers run on threads.

WebGL, canvas, media

WebGL 1 and 2 on wgpu; 2D canvases moved to the GPU when redrawn often; MP3, AAC, FLAC, Vorbis and Opus, HLS, Media Source Extensions with H.264 and VP9 video, and Encrypted Media Extensions.

These run in Rust beside the core, as recorded exceptions to its rule.

The system's network

HTTP/2 and HTTP/3 through macOS's networking stack and certificate verifier, an HTTP cache on disk, CORS, WebSockets, and cookies by context: SameSite, and third-party cookies blocked as Safari blocks them.

Incremental layout, proven Telescope/Layout/Flow.lean lines 9803–9808
/-- Incremental layout is layout. -/
theorem layoutFrom_eq (c : LayoutCache) (root : Box) (icbW icbH : Au) (fuel : Nat) :
    (layoutFrom c root icbW icbH fuel).1 = layout root icbW icbH c.metrics fuel := by
  simp only [layoutFrom, layout, layoutEnv, LEnv.withTexts_eq, Memo.Cache.run_eq,
    (measureFrom_valid c.metrics fuel c.remeasured.1 _ root c.remeasured.2).2]
  rfl

Laying out again from the last layout's cache gives exactly what laying out from scratch gives, for every cache, box tree and viewport. The engine is developed on macOS; it and its test suites also build and run on Linux.

Translated from the specs

Each algorithm is translated from its specification a step at a time, carries a spec: link to the section it implements, and numbers its steps as the spec does. Here is how a document's character encoding is chosen, from the HTML Standard's encoding sniffing algorithm.

The encoding sniffing algorithm Telescope/HTML/Sniff.lean lines 213–238
/-- A document's encoding from its bytes and its `Content-Type` (empty: none): a byte order mark,
the transport layer's `charset`, a prescan; else its same-origin container document's encoding
(`parent`); else UTF-8 for bytes that are valid UTF-8, else windows-1252 (LIMITATION,
docs/decisions.md L39: no detection beyond that).
spec: https://html.spec.whatwg.org/multipage/parsing.html#encoding-sniffing-algorithm -/
def sniff (bytes : ByteArray) (contentType : String) (parent : Option String := none) : String :=
  -- 1. a BOM
  match bomSniff bytes with
  | some e => e
  | none =>
  -- (a JSON document: UTF-8; DEVIATION, docs/decisions.md D16)
  if jsonMime contentType then "UTF-8" else
  -- 4. the transport layer's encoding
  match (charsetParam contentType).bind getEncoding with
  | some e => e
  | none =>
  -- 5–6. a prescan
  match prescan bytes with
  | some e => e
  | none =>
  -- 7. a same-origin container document's encoding
  match parent with
  | some e => e
  | none =>
  -- 9. the default
  if (String.fromUTF8? bytes).isSome then "UTF-8" else "windows-1252"
  • Browsers over spec text. Where the specification and every browser disagree, as Web Platform Tests show, Telescope matches the browsers, marks the code DEVIATION and records why in docs/decisions.md; above, JSON documents are UTF-8 (D16). Known shortfalls are marked LIMITATION and listed there too (L39).
  • Total functions only. No partial, sorry or unsafe: recursion is structural, well-founded, or bounded by fuel with an argument for why the bound suffices.
  • No floating point. Lengths are integers of 1/60 px, CSS numbers exact decimals, and JavaScript Numbers exact dyadic values rounded as IEEE 754 rounds.
  • Fast code proven equal to the reference. An optimized version replaces the readable one through Lean's @[csimp], which requires a proof that the two are equal.
  • Checked. tools/spec.py rejects a spec step without its anchor and impure code in the core.