Skip to content

Meta issue: Lean Kernel Logic renovation #14977

Open

Description

@arthur-adjedj

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)

Changes to large elimination

The main changes to whether a type largely eliminates compared to before is that

  • Recursive predicates like Acc do 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 having Acc's iota rule be a propositional equality rather than a definitional one is enough for Acc to 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 be Prop, 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 -- similarly

We 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

  1. joehendrix commented on Sep 3, 2026

    @joehendrix
    Contributor

    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) 0 will overflow in the Lean kernel because of the GMP support, but without the special cases would reduce to 0.

  2. added
    P-high
    on Sep 8, 2026
  3. SkySkimmer commented on Sep 21, 2026

    @SkySkimmer

    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. As far as I'm aware, the only reason this was originally added was to support Acc, which will not largely eliminate in the new criteria since it is recursive anyway. As such, I believe the condition around non-uniform parameters can be safely dropped.

    More generally a parameter can only be non-uniform if the type is recursive, ie parameters of non recursive types are all uniform.

  4. arthur-adjedj commented on Sep 21, 2026

    @arthur-adjedj
    ContributorAuthor

    Well-spotted, I've reworded this part accordingly. Thanks for the feedback :-)

  5. spitters commented on Nov 24, 2026

    @spitters

    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, every h : Acc x is definitionally equal to
    Acc.intro x (fun y r => Acc.inv h r), so a definitional iota rule fires on variables and
    unfolds forever (Abel–Coquand). lean4#14977 removes large elimination from Acc and from every
    Prop inductive that is recursive, mutual, or has a non-Prop field, and recovers Acc's
    eliminator through Classical.choice. That also removes eliminations that are valid in every
    proof-irrelevant model.

    Semantic criterion

    Let P_T be the inductive P declared in Type. Large elimination from P is sound when P_T
    is 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 mutual
    subsingletons such as PA (A) | mk (h : A → PA A) all satisfy it.

    Design

    The elaborator computes one flag per Prop inductive; the kernel checks it.

    1. Empty, eta (non-recursive structure, all fields Prop), rule K: large elimination with
      definitional iota, as in lean4#14977. These are propositions closed under finite limits with
      a strict initial object.
    2. Other syntactic subsingletons: an eliminator into Type that is an opaque primitive, with a
      propositional computation rule (a constant like Quot.sound). No definitional iota.
    3. The rest (∃, Nonempty): elimination into Prop only.

    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.choice term, which a transparent choice-based definition
    allows. 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 Prop and definitional irrelevance (a set model, as
    Metalean's, gives consistency) and normalization of the remaining conversion.

  6. nomeata commented on Nov 24, 2026

    @nomeata
    Collaborator

    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…)

  7. spitters commented on Nov 24, 2026

    @spitters

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions