Verification

The Lean proofs live under proofs/. See proofs/README.md for the full theorem statements, premises, and proof structure.

Specification

Canolean/CanonicalLeanSource.lean specifies the canonical output as the unique minimum over all candidate layouts that Lean accepts, ordered by overflow past 100 Unicode scalar values, then newlines, then a deterministic tie-break. The proofs target that file directly without modifying it.

Main theorem

CanonicalProof.certified_emitter_canonical in proofs/CertifiedEmitter.lean proves

CanonicalLeanSource.CanonicalSource frontend input.contents source

for the string returned by the extracted emitter: Lean accepts source with the same syntax, tokens, and comments as the input, and no other accepted layout ranks better. certified_repaired_emitter_canonical proves the same result when break options were dropped before certification.

Verified Rust core

Charon and Aeneas extract src/layout_core.rs, src/ranked_core.rs, and src/canonical_core.rs into proofs/generated/CanonicalCore.lean, and the proofs apply directly to that extracted code:

Rust function Proof file What is proved
layout_core::verified LayoutProofs.lean When it returns true, every rule holds in every candidate layout.
layout_core::cover_verified CoverProofs.lean Every candidate of the original box is either inside the repaired box, breaks a required rule, or ranks strictly worse than the emitted layout.
ranked_core::verify RankedProofs.lean, RankedOptimality.lean A verified DP table determines the globally optimal layout.
ranked_core::emit RankedEmitter.lean The emitted text and break choices match that verified table.

Because the core checks the planner’s DP table directly, the planner itself does not need to be trusted.

proofs/check.sh replays every proof module through Lean’s leanchecker and audits every declaration across all 12 proof modules with Lean.collectAxioms, failing if any declaration depends on an axiom outside [propext, Classical.choice, Quot.sound]. CI likewise runs leanchecker and axiom-audit on the Canolean Lake library (Canolean/CanonicalLeanSource.lean and Canolean/GuardSemantics.lean). No sorry, admit, custom axioms, native_decide, or unchecked casts are used.

Parser assumption

Lean’s parser uses partial loops and environment extensions, so it can’t be reasoned about directly inside Lean. The proof stops at a single assumption about it (LayoutContract in proofs/LayoutRules.lean):

If Lean accepts a module, it accepts the same tokens and comments under any other whitespace of spaces and newlines that satisfies the module’s rules, and produces the same syntax tree.

This contract is tested against the real Lean parser rather than proved:

  • tests/ccf_corpus.rs formats all 159 Lean files in a pinned microsoft/CCF snapshot and checks that Lean parses each output back to the same syntax, tokens, and comments, and that formatting it a second time produces no changes.
  • tests/layout_rules.rs tests other candidate layouts besides the winner, plus random separator mutations that the rules still certify, across both CCF and Lean’s own sources.

Separately, Canolean/GuardSemantics.lean is checked against Lean 4.36.0’s parser to prove that each whitespace check tests the exact property our guards model (though not how the parser combines them).

Other assumptions

Applying the theorem to an actual run of canolean also relies on:

  • LayoutContract for the rules derived from the grammar.
  • Charon and Aeneas’s translation, Rust and Lean compiler and runtime semantics, and Aeneas’s standard-library models.
  • The unverified driver code: the Lean frontend adapter, role assignment, and string/scalar conversions.

The proofs do not cover out-of-memory errors, OS or I/O failures, or Lean elaboration/semantic equivalence. In --bundled-only mode, the frontend uses the bundled Lean environment without unresolved project imports rather than your Lake project environment.