Appearance
Tolean docs
Each page here is a Markdown file in the Tolean repository. This build is from commit 5f1d031.
Overview
- Tolean: Tolean translates source code into Lean 4, so that proofs about a program are about its real source.
Languages
- Go: Tolean translates Go code that has effects.
- PostgreSQL: Tolean translates PostgreSQL queries written for sqlc, with the schema that their migrations build.
- TypeScript: Tolean translates pure TypeScript functions into plain Lean functions.
Guides
- Build and check: Repository layout describes where each part of Tolean lives and how to add a language.
- Repository layout: Each language has its own front end and its own translator, and both are written in Lean.
- The project file: A project lists what to translate in
tolean.json, at its root. - The verification chain: What Tolean produces is a verification chain: a path from the source code that runs to theorems about it, where every link is proved, tested against a reference, or trusted.
- Using Tolean in a project: This page shows how to lay out a project that uses Tolean, for each language that Tolean supports.
- What Tolean trusts in Lean itself: Every link in the README's table of links also relies on parts of Lean.
Comparisons
- Tolean and Aeneas: Aeneas translates safe Rust into pure Lean, and Tolean took its central idea from it.
Plans
- Plan: a shared Tolean IR and shared monad pieces (in progress): TypeScript has the parts that let Lean prove a translator.
- Plan: asynchronous TypeScript and race conditions (planned, not built): Most TypeScript that talks to the outside world is
async, and Tolean refuses all of it today. - Plan: effects and trust boundaries in the translator core (planned, not built): Real code calls libraries that change the world outside the program.
- Plan: print the Tolean IR with Lean's own printers (planned, not built): The printer in
tolean/IR.leanwrites the Tolean IR as Lean text by hand. - Plan: prove the Go translator (in progress): The TypeScript translator is proved for every program it accepts.
- Plan: prove the SQL translator (in progress): The SQL translator is proved for
SELECTqueries only. - Plan: say which functions check their own inputs (planned, not built): A theorem about a function often has a precondition: it holds only for inputs that meet a condition.
- Plan: translate the pure TypeScript that real modules use (in progress): Pure TypeScript in practice uses much more of the language than the subset accepts.
Decisions
- Why Tolean writes Lean instead of SMT queries (accepted): Tolean turns TypeScript into Lean 4 definitions, and we write and check proofs about a program in Lean.
- The Tolean IR (accepted): The Tolean intermediate representation, or Tolean IR, is the form a program takes after Tolean translates it and before it becomes Lean text.
- A JS string is a list of UTF-16 code units (accepted): Tolean translates a TypeScript
stringtoJSString, a structure aroundList UInt16, and not to Lean'sString. - A sort means a stable merge sort under a consistent comparator (accepted): Tolean gives
xs.toSorted((a, b) => e)and[...xs].sort((a, b) => e)a meaning only when the comparator is consistent for the elements that it sorts. - The errors of a file are one inductive type of that file: Decided on 2026-11-11, with the pull request that translates error classes.
- A local function is lifted out, and each call passes the state (accepted): Tolean translates a function declaration at the top of another function's body into a Lean function of its own.
- Pass changed maps back to the caller (accepted design, partly implemented): A function that changes a caller's map should return the new map, and the caller should bind that result in place of its old map.
- Resolve project imports before translation (accepted): Tolean resolves relative TypeScript imports before it translates the program.
- Model regular expressions with ordered backtracking (partially implemented): Tolean will model the first TypeScript regular expressions with the continuation-passing matcher of ECMA-262 §22.2.2.
- Keep null and undefined distinct: An optional nullable value has type
JSNullish Tin Lean. - Load inherited TypeScript resolution options (accepted): The external config inputs decision supersedes the refusal of relative bases outside the project.
- Counted-loop certificates require a safe bound (accepted): A certificate for a function with a counted
forloop requires one precondition for each loop. - Accept separate readonly declarations in error classes: The parser normalizes a separate readonly declaration and its constructor assignment to the existing readonly parameter form.
- Give generic certificates a codec: A certificate for a generic function needs a way to encode each type parameter's values and decode them when a loop reads them back from the interpreter's environment.
- Resolve literal-key indexed access types statically: Issue #263 asks for
T['field']to reuse the type of a declared field. - Object patterns bind fields from one source value: Local
constandletdeclarations accept flat object patterns with identifier keys and optional renaming. - String-keyed records use ordered association lists:
Recorduses an ordered association list rather than a structure with a fixed set of fields. - Record shared TypeScript configs as project inputs (accepted): This supersedes the project boundary for relative bases in the inheritance decision.
- Project proofs use a fixed axiom policy: Tolean should accept project proofs of obligations whose statements it generates.
- Elaborate readonly classes before evaluation (implemented, validation in progress): Ordinary classes use static dispatch in the accepted slice.
- Keep recursion out of certificates for now: The translator may emit recursive Lean definitions when Lean proves that each recursive call decreases structurally.
- Start with catches that do not need a changed environment: We will add
try { … } catch (e) { … }first for try bodies that do not change outer variables. - Loop certificates compose through one result carrier (accepted): Loop certificates compose through
LoopResult, which distinguishes a returned value from a completed loop's state. - One shared loop core for every language (accepted): Every supported
forloop runs its body once per value of a list, in order, until the body breaks or returns. - Check
for … ofconst assignments at the loop body (accepted): The interpreter and translator use one source-level predicate to reject assignments to afor (const … of …)binding. - Go functions with several results (accepted): A Go function may return several values, as in
func DivMod(a, b int) (int, int), andq, r := DivMod(a, b)gives each to a local (Go specification, "Function types", "Return statements", "Assignment statements" and "Short variable declarations"). - Go named types on the proved path (accepted): The proved path now reads a type that a package declares over a predeclared type, such as
type Celsius int,type Open bool,type Name stringor the aliastype Count = int64, and conversions to such a type. - Go package-level constants on the proved path (accepted): A pure Go function may now read a constant that its package declares at the top level.
- Go package-level variables that nothing changes (accepted): The proved path now reads a package-level
varwhen no code can change it. - Go panics on the proved path (accepted): Go's integer
/and%panic when the divisor is zero. - Go strings as bytes (accepted): A Go string is a sequence of bytes.
- Go structs on the proved path (accepted): A pure Go function may now build a struct with a composite literal, read its fields and assign one field of a local struct.
- Translate Go's
switchas a chain ofifstatements (accepted): The proved Go translator writes an expression switch as a chain ofifstatements, and anifwith an init statement as a block that holds the init statement and a plainif. - Renamed imports and exports keep the declaration's name (accepted):
import { a as b },export { a as b } from "./x.ts"and a localexport { a as b }translate. - Value re-exports forward the original declaration (accepted): A value re-export, such as
export { double } from "./origin.ts", makes the re-exporting file's interface offer the declaration oforigin.tsitself. - Go calls of functions that can panic (accepted): The record on Go panics let a Go function panic on a division by zero, but refused every call of such a function.
- Sort conditions inside search callbacks (accepted): A call to a function that sorts by number keys gives its caller a condition over the arguments, such as "every key is finite".
- Go counted loops with computed bounds (accepted): The first proved counted loop stood only at the start of a function and took literal bounds, at most 256 iterations.
- Built-in RangeErrors whose message the program cannot read (accepted): Step 12 of the pure TypeScript plan needs a model of errors that built-in operations throw.
- Go package-level variables that the package changes (accepted): The proved path now translates a function that reads or assigns an unexported package-level variable that some code of the package changes.
- Go calls with several results that can panic, and named results (accepted): The record on several results refused
a, b := f()whenfcan panic, and named results. - Go slices on the proved path (accepted): A pure Go function may now take, return and build slices of
int,int64,boolandstring, read their length and index them. - Compile every generated certificate in CI: CI asks Lean to compile both the translation and the certificate whenever the TypeScript or Go certifier reports coverage in the checked corpus.
- Go
appendandmakeon owned slices (accepted): The slices decision put slices on the proved path as lists, and refused everything that changes a slice. - Go: certificates for the printer link (accepted): The Go translator is proved up to the printer: when the evaluator of the IR gives a value, the interpreter gives the same value.
- Go: the order of checks around calls and len (accepted): The differential test (seed 589164818, on the CI of #329) found a function whose translation panicked with
index out of range [1] with length 0where Go panicked withindex out of range [3] with length 0. - Go condition-only loops that count (accepted): Go has no
while;for cond { … }takes its place. - Go methods with a value receiver (accepted): The proved path refused every declaration with a receiver.
- Go range loops over local slices (accepted): The proved path had counted and condition-only loops, but refused every
rangestatement. - Go: slices of structs and keyed slice literals (accepted): Step 4 of the Go plan lists keyed elements, slices of structs and
xs == nilamong the slice expressions still to do. - Step 14 handles indirect state first, and final return expressions return a tuple (accepted): Step 14 of the plan asks for four things: general final return expressions in local functions that change captured variables, implicit transitive captures, longer chains of sibling calls, and value-returning callers that change state only through their siblings.
- Trust annotations (accepted): A plain
Recordinherits the properties ofObject.prototype, so Tolean refuses an unguarded read such as `counts[key] ?? - Go:
xs[i] = eon an owned slice (accepted): Step 4 of the Go plan listsxs[i] = eamong the slice operations left to do. - Go: slices of slices (accepted): Step 4 of the Go plan lists slices of slices as the next slice item.
- Go: slice expressions
xs[a:](accepted): Step 4 of the Go plan lists slice expressionsxs[a:b]as the next slice item. - Go: the order of slice bounds and other checks (accepted): The differential test (seed 3, on the CI of #371) found a function where the translation and the interpreter panicked with
index out of range [3] with length 0, but Go panicked withslice bounds out of range [1:0]. - Go: three differential failures on random seeds: Date: 2026-12-05
- Go: errors on the proved path (accepted): Until now only the unproved translator handled Go's
error. - Go named types: string conversions and chains (accepted): Follows Go named types on the proved path, which left out conversions to a type over
stringand types over other types of the package. - Go:
for _, x := range eover a slice expression: Date: 2026-12-05 - Grouped case labels in a switch (accepted): Issue #391 showed that Tolean refused a
switchlike this one as fallthrough: - Go constant expressions on the proved path (accepted): Follows Go package constants, which read only literal constants.
