This is an implementation of the Lean 4 kernel written in (mostly) pure Lean 4. It is derived directly from the C++ kernel implementation, and as such likely shares some implementation bugs with it (it's not really an independent implementation), although it also benefits from the same algorithmic performance improvements existing in the C++ Lean kernel.
The project also houses some metatheory regarding the Lean system, in the same general direction as the MetaCoq project.
To compile the code, you will need Lean, or more specifically elan
, the Lean version manager, which will make sure you have the right version of lean as specified in the lean-toolchain file. Assuming you have elan, the project can be compiled with:
lake build
This builds all components but you can also build them separately:
lake build Lean4Lean
builds theLean4Lean
library interface, and does not include any of the proofs.lake build lean4lean
(note the capitalization!) builds thelean4lean
command line tool, again without building proofs.lake build Lean4Lean.Theory
contains the Lean metatheory and properties.lake build Lean4Lean.Verify
is the proof that theLean4Lean
implementation satisfies theLean4Lean.Theory
abstract specification.
After lake build lean4lean
, the executable will be in .lake/build/bin/lean4lean
. Because it requires some environment variables to be set for search paths which are provided by lake, you should evaluate it like lake env .lake/build/bin/lean4lean
.
If you run this as is (with no additional arguments), it will check every olean in the lean4lean
package itself, which is probably not what you want. To check a different Lean package you should navigate the directory of the target project, then use lake env path/to/lean4lean/.lake/build/bin/lean4lean <args>
to run lean4lean
in the context of the target project. The command line arguments are:
lean4lean [--fresh] [--verbose] [--compare] [MOD]
MOD
: an optional lean module name, likeLean4Lean.Verify
. If provided, the specified module will be checked (single-threaded); otherwise, all modules on the Lean search path will be checked (multithreaded).--fresh
: Only valid when aMOD
is provided. In this mode, the module and all its imports will be rebuilt from scratch, checking all dependencies of the module. The behavior without the flag is to only check the module itself, assuming all imports are correct.--verbose
: shows the name of each declaration before adding it to the environment. Useful to know if the kernel got stuck on something.--compare
: If lean4lean takes more than a second on a given definition, we also check the C++ kernel performance to see if it is also slow on the same definition and report if lean4lean is abnormally slow in comparison.
Main.lean
: command line appLean4Lean
: source filesEnvironment.lean
: library entry pointTypeChecker.lean
: main recursive functionInductive
Add.lean
: constructing inductive recursorsReduce.lean
: inductive iota rules
Quot.lean
: quotient types handlingUnionFind.lean
: a union-find data structureStd
: stuff that should exist upstreamTheory
: lean metatheoryVLevel.lean
: level expressionsVExpr.lean
: expressions (boring de Bruijn variable theorems are here)VDecl.lean
: declarationsVEnv.lean
: environmentMeta.lean
: elaborator producingVExpr
sInductive.lean
: inductive typesQuot.lean
: quotient typesTyping
Basic.lean
: The typing relation itselfLemmas.lean
: theorems about the typing relationMeta.lean
: tactic for proving typing judgmentsStrong.lean
: proof that you can have all the inductive hypothesesStratified.lean
: (experimental) stratified typing judgmentStratifiedUntyped.lean
(experimental) another stratified typing judgmentUniqueTyping.lean
: conjectures about the typing relationParallelReduction.lean
: (experimental) stuff related to church-rosserEnv.lean
: typing for environments
Verify
: relation between the metatheory and the kernelAxioms.lean
: theorems about upstream opaques that shouldn't be opaqueUnionFind.lean
: proof of correctness of union-findVLCtx.lean
: a "translation context" suitable for translating expressionsLocalContext.lean
: properties of lean'sLocalContext
typeNameGenerator.lean
: properties of the fresh name generatorTyping
Expr.lean
: translating expressions (TrExpr
is here)Lemmas.lean
: properties ofTrExpr
ConditionallyTyped.lean
: properties of expressions in caches that may be out of scope
Environment.lean
: translating environments