leanfran compiles Lean 4 IR into Go source. The bundled runtime uses the Go standard library and supports 64-bit Linux and macOS. A generated package can be built with CGO_ENABLED=0.
langs/Go/Main.lean implements the leanfran-go CLI. langs/Go/LeanGo/EmitGo.lean collects reachable IR, emits Go, and assembles package initialization and command entry points.langs/Go/LeanGo/Marshal.lean inspects Lean signatures and constructor layouts and compiles proof deciders. Generate.lean emits public types, typed conversions, descriptors and function wrappers.langs/Go/cmd/leanfran/ implements the module tool. internal/embed/ scans Go with go/parser, reads the selected model types with go/types, and builds a Lake workspace for the embedded blocks. The batch generator uses the model's Go import path and fields to emit a codec against the original type.langs/Go/schema/ renders JSON and JSON Schema from generated descriptors. The root Go package provides validation errors and typed conversion combinators.langs/Go/rt/ implements the runtime. It uses rt.V for Lean objects and Go's fixed-width types for unboxed scalars. Arrays and strings use copy-on-write, and tail calls between functions use a trampoline.langs/Go/LeanGo/RuntimeExterns.lean lists the runtime symbols. The emitter reports missing names before producing output.langs/Go/LeanGoTest/ holds Lean fixtures for native and generated programs. langs/Go/testdata/ holds Go drivers for generated packages. langs/Go/test-out/ holds check artifacts.langs/Go/make/ registers check targets through CHECK_TARGETS. maint/Go/ contains the extern generator and the test scripts.lean-toolchain for compiler builds and native oracles. Check the toolchain's Lean sources and lean.h for the symbol, argument order, erased parameters, and ownership of each extern. Increment a retained value read from a container and leave borrowed arguments owned by the caller.make gen-externs and commit it with the runtime change.generatorVersion in Main.lean and GeneratorVersion in leanfran.go together. Regenerate the Go packages in samples/sum-to/arith/ and samples/pricing/pricing/ with the compiler commands from maint/Go/test-samples.sh. Run go tool leanfran sync in each embedded sample module with LEANFRAN_GO_CLI pointing to the rebuilt compiler.rt.V belongs to one goroutine. Generated package initializers mark their shared values persistent before publication. Each caller can construct its own inputs and call generated functions concurrently. Lean tasks run synchronously.*rt.InternalPanic. A Go caller can recover and call the library again. The generated command entry point handles this panic during initialization and execution, prints its diagnostic, and exits with status 1.gofumpt for handwritten Go and gofmt for generated Go. Run static checks and the native comparison in the backend shell.From the repository root, run the checks for Go 1.27 and 1.26 and build the Nix compiler package.
nix shell nixpkgs#gnumake -c make check BACKENDS=Go
nix build .#go
The check compares output, errors, and exit status with Lean's C backend. It also compares two independent runs of the compiler on the same input and checks the default package name for a nested Lean module. It exercises the numeric externs, seeded fuzz cases, tail and non-tail recursion, container update complexity, IR constructor coverage, and concurrent calls to a generated package under the Go race detector. It also checks the extern inventory, handwritten and generated code, and the samples. test-public compares generated Go with the native C backend and compares JSON Schema with the TypeScript backend for all three targets. It also checks validation, type mapping, cross-package generation, error handling, deterministic output, a million-element list, and the race detector.
nix develop .#go -c make -C langs/Go gen-externs
nix develop .#go126 -c make -C langs/Go fuzz SEED=42 N=2000
nix develop .#go -c make -C langs/Go samples
test-embed-scan checks literal scanning, source positions, and block dependencies. test-embed installs the CLI as a module tool in a fixture, checks round-trip models and tags, and verifies that failed proofs and syntax errors preserve the installed Go. It checks manifests with a PATH that contains Go alone. test-embed-samples rebuilds the two embedded modules, compares their generated files with the checkout, and compares the range sample with a native Lean C oracle.
The sum-to sample imports a generated package and calls it from Go. The greet-cli sample compiles a Lean main into a Go command and checks the greeting and usage paths. The pricing sample exercises generated public functions, proof validation and JSON. The sample executables are written to langs/Go/test-out/samples/.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |