Appearance
Plan: prove the Go translator
Status: in progress · Date: 2026-11-09
The TypeScript translator is proved for every program it accepts. The Go translator is proved only for pure functions: those that take and return int, int64, bool and string values, and whose bodies declare and assign locals, read the package's literal constants and unchanged variables, use types declared over a basic type, build and change structs of those values, build, index and take the length of slices of them, test with if and switch, and return. The Go guide describes that part. Everything else still goes through the older string translation in tolean/Go/Translate.lean, which Lean cannot reason about, because it builds text with partial def.
This plan moves the rest of the Go subset onto the proved path, one construct at a time, until the string translation can be deleted. It is step 5 of the shared core plan, and it uses the state and exception pieces that step 3 of that plan adds to the IR.
The rules for every addition
Each construct keeps the rules that TypeScript's do.
- The Go specification defines the behavior. The interpreter in
tolean/Go/Spec/Eval.leanfollows the section that defines the construct, and a comment names it. Behavior that depends on the platform or the scheduler stays refused. - The translation sees every change to state. A value that two names can reach, such as the target of a pointer or the backing array of a slice, changes only where the translation can see the change.
- The proof covers it. Each construct extends
Pure.lean, the IR and its evaluator, and the interpreter, so thattranslate_soundholds for programs that use it.
What to add
A construct leaves these tables when the proved path translates it, and the Go guide documents it from then on.
Values and types
| Go | Lean | Refused |
|---|---|---|
Done: a const built with iota, earlier constants and the operators -, !, +, -, *, /, %, <<, >>, comparisons, && and ` | , specs that repeat the one before, and an unexported var` whose value is such a constant expression (decision) | |
An exported var, and a var whose initial value is no constant expression | A def | A call of a function that assigns a package-level var inside an expression, whose order against a read Go leaves unspecified; a package where a function that assigns one is not on the proved path, while a reached function uses one (decision) |
Done: a conversion of a string to a named type over string, and a named type over another named type (decision) | abbrev; the conversion is its operand | An integer converted to a string type, a cycle of types, and methods on a named type of a basic type |
Later: a named type over a composite type, such as type Pair [2]int or type Q P for a struct P | Needs arrays, and struct identity under a second name | Refused until then |
Done: == and != on structs, as decide (p = q) on a structure that derives DecidableEq; a keyed literal that leaves out fields, in field order, with zero values for the rest; and var s S without a value, as the code of S{} (decision) | The structure with the zero value of each field | |
A struct with a field outside int, int64, bool and string, a keyed literal that reorders fields, and an assignment to a nested field | A structure, and { s with f := e } for an assignment to a field | Embedded fields, and a struct that a pointer can reach |
Done: error, errors.New and fmt.Errorf with a literal format that starts with %w, and == or != with nil (decision) | Option GoError, as today; Go.isNil for a comparison with nil | Other uses of fmt and errors, comparing two errors that are not nil, package-level sentinel errors, and errors in struct fields or slices |
Statements and loops
| Go | Lean | Refused |
|---|---|---|
for i := a; i < b; i++, at any position, with bounds of literals, locals, len and +, -, * | A same-type integer list computed once from the bounds, lowered through the shared loop core to Body.fold. The bound must not refer to the counter and must stay unchanged by the header update and the body. Unlabeled break and continue in the body, also inside an if, a block or a switch, are proved; the output then uses forIn. | Labeled break and continue, a switch that both breaks and continues, other updates or tests, mixed-type bounds, and bodies that assign the counter or change what the bound reads |
for i < b { …; i++ } with no continue, a body that writes i only in the trailing i++, and a bound that does not read i | The counted loop for i' := i; i' < b; i'++ { i = i'; …; i++ }, proved equal in the interpreter by execStmt_while; i keeps its last value. See the decision record. | continue, other conditions or updates, return in the body, and every other condition loop, which has no termination measure |
Done: for _, x := range s over a local slice, with break and continue (decision) | Elements in order through the shared loop core, printed as List.foldl or forIn over s | A body that changes x or s, return in the body, nested loops, and ranging over anything but a local slice |
Done: for _, x := range e over a slice expression, such as a literal, s[a:] or a call (decision) | e is evaluated once, after its checks, then the elements go through the shared loop core | A body that changes x or a local that e reads, return in the body, nested loops, append(…) as e, and the index forms over anything but a local slice; certificates refuse it for now |
Later: for _, x := range over arrays, with return | The same, with the shared return carrier | Range over a map, channel or function iterator |
Done: for i := range s over a local slice (decision) | Go.upTo 0 (Go.sliceLen s) through the shared loop core | A body that changes i or s, return in the body, nested loops, and ranging over a string or anything but a local slice |
Done: for i, x := range s over a local slice (decision) | The index loop over Go.upTo 0 (Go.sliceLen s) whose body starts with x := s[i] | A body that changes i or s, an empty body, _ for either name, return in the body, nested loops, arrays, and ranging over anything but a local slice |
| Later: a loop inside a loop | Needs the frame proof that an inner loop keeps the outer bound: Eval.countedBodySafe refuses a body with a loop, and lifting that needs Proof/Bound.lean, Proof/Stmt.lean and Proof/LoopFrame.lean to cover an inner loop | Refused until then |
Later: x.f = e in a loop body | Eval.countedBodySafe accepts only assignments to locals, so the proof that the bound keeps its value does not cover a field assignment | Refused until then. A body may assign the whole struct, x = T{…} |
Done: an if or switch with an init statement v := e that returns on some path and has statements after it, such as if v := f(); v > 0 { return v }; return 0 | The let of the init statement in front of the if and the code after it, proved by the frame lemma of Proof/Unused.lean. See the decision record. | Code after the statement that reads the init statement's name (an outer local of that name), a name that is a package variable, and an init statement other than v := e. A plain block or a switch without an init statement that returns must still end its statements. |
Go supplies each loop head and its HeadSim, not a second fold proof. The shared interpreter requires brk and cont cases in Go's Outcome, and Go now has them. Its evaluator and soundness layers depend on step 6 of the shared-core plan; step 9 there records the loop work. Labeled jumps and goto remain refused. The loop-core decision does not change the separate work on switch and if.
Slices
| Go | Lean | Refused |
|---|---|---|
Done: x = append(x, …) on a local slice that the function owns (decision) | List T, with xs ++ [a, b] | append anywhere else, and on a slice that a parameter, another local or a call may share |
Done: make([]T, 0) and make([]T, 0, c) with a literal c up to 2^20 | [] | make with a nonzero or computed length, or a computed capacity |
| Done: slices of structs and keyed elements with growing literal keys (decision) | List P; the zeros of the gaps written out | Keys that are not literals or do not grow, keyed literals of structs, elided element types |
Done: xs[i] = e on an owned local, also in a counted loop over len(xs) (decision) | Go.sliceSet, List.set after a test of the index | A parameter or a shared slice, a slice that a range walks or that a counted bound reads other than by len(xs), xs[i] op= e |
| Done: slices of slices (decision) | List (List T) | xss[i][j] = e, keyed literals of slices, inner literals without their type |
Done: slice expressions xs[a:] and xs[:] (decision) | Go.sliceFrom, List.drop after a test of the bound | A high bound xs[a:b] or xs[a:b:c], which can reach past the length up to the capacity; strings; append or xs[i] = e on a slice that shares its array |
Later: xs[a:b] | Needs the capacity and the array in the slice value | Refused until then |
Later: xs == nil | Needs a nil flag on the slice value | Refused until then: the list model cannot tell a nil slice from an empty one, so it needs a flag in Eval.Val, the interpreter and the output type, which is larger than one step |
An index check inside the argument of a call or len, mixed in one statement with a check outside one, is refused: gc tests the argument's check first (decision). A statement whose slice bound xs[a:] comes after another check is refused too, because gc tests slice bounds first (decision). The rule applies inside the base and the bound of each slice, and to every value of return a, b and a, b := … (#394, #398). A slice whose base and bound both have checks is refused, since gc may test the bound first. Slices and checks that all sit inside the arguments of calls are kept when the slices come first (decision).
Methods and effects
| Go | Lean | Refused |
|---|---|---|
A method on a value receiver of a struct type, and calls x.M(…) | The function T.M that takes the receiver first, proved through the function proof; see the decision record | Pointer receivers, methods on other types, a method name that several types declare, calls of methods that can panic, method values |
Later: certificates for g[i][j][k] and chained indexes | The link proof of an index three levels deep exceeds the heartbeat limit, because it unfolds and splits each index again. It needs a link lemma for one index that the proof can compose (#406) | The certificate leaves the function out until then; the corpus package index3 checks that, and deepIndex allows only indexes whose slice and position the syntax shows |
| Later: certificates for pointer receivers | The proved path leaves out a method with a pointer receiver (r *T) (Eval.recvOf), so no certificate meets one. A certificate theorem waits until the proved path accepts it | Refused until then |
| A call of a method on an interface parameter, such as a store | A step in StateM State, as today, built from the shared piece for external calls | Interfaces that the package implements itself |
| Code that only feeds observability, such as tracing | Nothing: the translator erases it, as today, and a proof shows that the erased statements change no other value | |
Later: removing the string translator (Translate.lean) | The last step. The proved path must write every function that the string translator writes now, so that nothing falls back to it. The corpus package ledger needs the calls of methods on an interface parameter as StateM steps, errors from fmt.Errorf with arguments and (T, error) results as Option GoError, a return inside a loop, and the proof that erased statements change no other value. Every other Later row of these tables must be done too | The string translator writes what the proved path refuses, as the corpus package stringpath shows, until then |
Checks
| Check | What it does |
|---|---|
| Certificates | Prove the printer link for one file, as TypeScript's certificates do. "certify": true in tolean.json, or translate-go --certify, covers functions of int, bool, string, structs, slices, slices of slices and several results, and counted and range loops, also ones that can break, panic or call a function, loops over struct locals and struct elements, methods with a value receiver, and functions that read or assign package-level variables (decision). In a corpus package marked certified, every function has a theorem except the ones that its uncovered file lists, which must have none; the indexes that deepIndex leaves out are such entries (#406). Nested loops and pointer receivers wait on the proved path (see Statements and loops, and Methods and effects) |
Open questions
- The interpreter assumes that
intis 64 bits wide, as it is on every 64-bit platform. Should the translator refuseintand accept onlyint64, so that a claim holds on 32-bit platforms too? - Recursion: the proved path refuses a function that calls itself, because Lean would need a proof that the recursion ends. TypeScript's plan has the same open question.
This page is docs/plans/go-proofs.md at commit 5f1d031.
