Repository navigation
Description
This plan was worked out in collaboration with @nomeata.
Motivation
This summer's crop of implementation issues affecting the soundness of the kernel suggests that we should consider making changes to the kernel logic that make it easer to implement a bug-free kernel, that make verification of the kernel more feasible, and that play better with the module system.
One way to make the kernel simpler to implement and (hopefully) verify is to avoid inference and heuristics in the kernel, make its interface more explicit and leave these choices to the elaborator. This avoids implementation bugs where different code paths make accidentally different changes.
Concretely, we would like to achieve the following
- A decidable, transitive definitional equality algorithm
- Feature selection for inductives (large elimination, rule-K, projections, eta) is done by the elaborator and communicated explicitly, the kernel only checks.
- Such features are enabled/disabled once in general, not per-user and per-instantiation (e.g. which projections are allowed), for a simpler implementation and less corner cases
- Proofs never have to be reduced during type checking, so that the module system can omit proofs reliably
- Level comparison is complete, so that meta programs and encodings work reliably
Items
To achieve these, we plan to make the following changes: (Some points to be pulled into their own issues and just linked here)
- Complete level comparison algorithm (cf. Mario Carneiro’s research)
- Fixes to eta-related issues:
- Expand the unit-like criteria to handle Pi types of which the codomain is unit-like, and structures whose fields are all unit-like or proof-irrelevant (feat: extend unit-like criteria for eta #15372).
- Expand the condition for which the major of a recursor can be eta-expanded to handle subsingleton types (feat: eta-expand recursor major for subsingleton structures #15371).
- Eta-expand partial recursor applications when the major is missing and is an eta-expandable structure (feat: eta-expand partial recursor apps for structures/K-like types #15374).
- Eta-expand partial constructor applications during conversion when necessary (feat: eta-expand partial structure constructors #15373).
- Quotients of propositions should live in Type, not Prop (feat: make
Quotlive inSort (max 1 u)rather thanSort u#15023) -
whnfshould only ever be called on terms that are known to not be proofs, e.g inis_def_eq,is_def_eq_proof_irrelshould be called before thewhnf_corecalls, not after. (feat: don't reduce proofs inis_def_eq_core#15103) - Recursive predicates like
Accshould not have large-elimination (see next section) (feat: no large elim of recursive Prop inductives in the kernel #13851) - Inductive declarations are now declared with the following features explicitly via boolean flags. The kernel(s) then check against these features to ensure their validity (feat: feature flags for inductive declarations #16595):
- Impredicativity: If true, the type must only live in Prop, its constructor fields may then be of a larger universe. If false, every field must always live in a universe smaller or equal than that of the type being defined.
- Projections exist: true only if the type has one constructor, is non-indexed and is not impredicative.
- Eta rule applies: true only if projections exist and the type is not recursive.
- Rule-K applies: true if the type always lives in
Prop, is non-impredicative, non-mutual, only has one constructor and no field (e.gEq) (This flag already exists in the type's recursor). - Large elimination: Recursor eliminates into any sort. True if a type either never lives in
Prop, or is not mutual, not impredicative and either has:
- no constructor (e.g.False)
- eta (i.e. is a non-recursive structure, e.g.And,PSigma)
- rule K (i.e. has one constructor with no fields, e.g.Eq)
- Recursors that only eliminate to
Propshould not store, compute and useRecursorRules (feat: feature flags for inductive declarations #16595) -
theorems are opaque (fix: make theorems opaque to the kernel as well #14896)
Changes to large elimination
The main changes to whether a type largely eliminates compared to before is that
- Recursive predicates like
Accdo not have large elimination anymore. This is currently a source of undecidability for definitional equality, the large eliminator (and a propositional version of its iota rule) can be recovered using the axiom of choice (see lean4#13851). The following paper justifies that havingAcc's iota rule be a propositional equality rather than a definitional one is enough forAccto not cause undecidability of type-checking in Lean. - Sort-polymorphic structures now have large elimination, fixing a gap where for some types, some projections existed but could not be defined using their recursors lean4#7637. The reasoning for accepting this is that such structures must be non-impredicative, meaning each field's universe is always smaller or equal to that of the type getting defined. In particular, when instantiating the type to
Prop, every field's universe must also beProp, in which case the type is a syntactic subsingleton, making its large elimination okay. - In the existing criteria, Prop inductive types with a single constructor and for which every field is either a Prop or a non-uniform parameter are large-eliminating. Lean does not have a concrete notion of non-uniform parameters, and instead makes a syntactic check for such parameters only in the large elimination check for Prop inductive types. Since all parameters in a non-recursive type are necessarily uniform, and recursive Prop types do not largely eliminate anymore, the non-uniformity check can be dropped entirely.
Changes to projections
The main change to projections is that structure types living in Prop and whose fields are not all Props do not have projections anymore. This means that the following examples do not work anymore:
structure Foo : Prop where
n : Nat
p : True
variable (x : Foo)
#check x.2 -- used to work, would now fail
variable (y : ∃ (_ : True), True)
#check y.1 -- similarly
#check y.2 -- similarlyWe believe this to be okay, as such projections 1. can be recovered using the (non-largely eliminating) recursors for such types and 2. have no computational content anyway since they must return proofs. Changes to the elaborator can be made to recover the old behaviour for such projections at the user-level.
Furthermore, this change means that a structure will either have projections for every field of its constructor, or none at all.
This change ensures that less information is inferred at call-sites when type-checking a term, making things like projections and eta be checked consistently upon defining inductive types instead.
Plan of attack
Where we remove features, we can adjust the library and meta code to avoid them already now or at any time (e.g. #14892, #14925). The kernel changes we would prefer to bundle into a single release, together with an update of the ndjson output format (new flags). Kernel Arena tests and external checkers should only need one update.
Activity
joehendrix commentedon Sep 3, 2026
If you are making a comprehensive overhaul, I think it'd be good to document what level of laziness is expected (particularly for beta reduction).
If I recall correctly, there are some special cases for arithmetic. For example,
Nat.mul (ackermann 4) 0will overflow in the Lean kernel because of the GMP support, but without the special cases would reduce to0.SkySkimmer commentedon Sep 21, 2026
More generally a parameter can only be non-uniform if the type is recursive, ie parameters of non recursive types are all uniform.
arthur-adjedj commentedon Sep 21, 2026
Well-spotted, I've reworded this part accordingly. Thanks for the feedback :-)
Add corner cases for the planned eta changes to the official kernel (#…
feat: eta-expand partial structure constructors (leanprover#15373)
feat: don't reduce proofs in `is_def_eq_core` (leanprover#15103)
feat: extend unit-like criteria for eta (leanprover#15372)
feat: eta-expand recursor major for subsingleton structures (leanprov…
test: expect the kernel to decline projections of indexed types
Add official-nightly, bump official to v4.35.0, drop parse-only (#357)
feat: no large elim of recursive Prop inductives in the kernel (leanp…
chore: pin lean4lean and nanoda forks without large elimination of re…
fix: make theorems opaque to the kernel as well (leanprover#14896)
spitters commentedon Nov 24, 2026
After a bit of conversation with my robot to link this to a more semantic criterion, we came up with.
This distills some of the ideas from the HoTT world in relation to strict equality.
I can try to do a proper reference search, if you believe this could be an interesting line of ideas.
Large elimination from subsingletons with propositional iota
Problem
In a proof-irrelevant
Prop, everyh : Acc xis definitionally equal toAcc.intro x (fun y r => Acc.inv h r), so a definitional iota rule fires on variables andunfolds forever (Abel–Coquand). lean4#14977 removes large elimination from
Accand from everyPropinductive that is recursive, mutual, or has a non-Propfield, and recoversAcc'seliminator through
Classical.choice. That also removes eliminations that are valid in everyproof-irrelevant model.
Semantic criterion
Let
P_Tbe the inductivePdeclared inType. Large elimination fromPis sound whenP_Tis a proposition: then
P ≅ ‖P_T‖ ≅ P_T, and the eliminator is the inverse of this isomorphism(unique choice, no choice axiom). Lean's syntactic subsingleton test is a decidable sufficient
condition for it.
Acc(given funext),Ex n ≅ Σ m, m = n, and recursive or mutualsubsingletons such as
PA (A) | mk (h : A → PA A)all satisfy it.Design
The elaborator computes one flag per
Propinductive; the kernel checks it.Prop), rule K: large elimination withdefinitional iota, as in lean4#14977. These are propositions closed under finite limits with
a strict initial object.
Typethat is an opaque primitive, with apropositional computation rule (a constant like
Quot.sound). No definitional iota.∃,Nonempty): elimination intoProponly.Algorithmic properties
Definitional equality never reduces a proof and has no iota at class 2, so it stays decidable
and transitive; class 1 is the case lean4#14977 keeps. Conversion cost equals lean4#14977's: in
both, the class-2 recursor applied to anything is stuck. The primitive is opaque, so lazy delta
never unfolds it into a
Classical.choiceterm, which a transparent choice-based definitionallows. The declaration check is the existing syntactic subsingleton test, linear in the
constructor types.
Costs
A new primitive kind in the kernel and in independent checkers. A proof obligation: soundness of
the propositional rule with impredicative
Propand definitional irrelevance (a set model, asMetalean's, gives consistency) and normalization of the remaining conversion.
nomeata commentedon Nov 24, 2026
That's AI text, right? I find it hard to read. Can you give me a human summary of what you are trying to say? (And we asked for comments two months ago…)
spitters commentedon Nov 24, 2026
@nomeata I missed the RFC two months ago. Sorry.
In short, following the tradition of semantic models of type theory (HoTT, ...), one can allow more large eliminations than you allow in your proposal, while still preserving the good properties that you desire. An efficient implementation should be possible.
I can try to elaborate, but it would be good to know how familiar you are with this tradition. HoTT, SProp in Rocq, XTT, etc
nomeata commentedon Nov 24, 2026
Let’s move to https://leanprover.zulipchat.com/#narrow/channel/621470-lean4lean/topic/Lean.20Kernel.20Renovation/with/643092334
feat: eta-expand partial recursor apps for structures/K-like types (l…