Skip to content

safe: refute empty ~ columns in a specialized def's cover instead of leaving it out of scope #1544

Open

Description

@nicolas-abril

A ~ parameter whose type is empty at some value of an earlier finite ~ parameter leaves the def out of scope in --verdict. Instead, the kernel could check that the leaf can't be reached.

Repro

import Base

law only_true:
  for ~b: Bool
  for ~h: {b == True{} : Bool}
  Nat

def only_true(b, h):
  1n

def main() -> Nat:
  3n

On main, the same def fails as soon as the body uses h (return h at type {b == True{} : Bool}): the False instance is missing from the .bendtt. So an empty ~ column was already out of scope. #1225 makes it out of scope every time. ~e: {1n == 2n : Nat} fails the same way.

For now, #1225 leaves these cases out of scope on purpose.

Proposal: refute the leaf with an absurd

The kernel has J (%) and λ{}, so the cover can prove the leaf is unreachable instead of naming a constant that can't go out. This leaf checks on bendtt.lean:

Bool.ok : ∀x : Bool -> *1 =
  λ{(,): λt => λr => (λ{.False: <()>; λ{.True: <>; λ{}}} t)}

G : ∀-b : Bool -> ∀-h : {b == (.True, ()) : Bool} -> *1 =
  λ-b => λ-h => Bool

no : ∀h : {(.False, ()) == (.True, ()) : Bool} -> (G -(.False, ()) -h) =
  λh => ({λ{} : ∀x : <> -> (G -(.False, ()) -h)} (%h : x, p => (Bool.ok x); ()))

ALL PROOFS CHECK. As a control, the same refutation at {False == False} is rejected (expected: <> / observed: (Bool.ok (.False, ()))).

Sketch:

  • When a non-finite ~ column has no model, try to refute its type. For an equation {a == b}, build a motive "x has a's shape" from a alone: through pairs and labels, a's label maps to <()> and continues inside, and every other label maps to <>. The kernel checks that the motive is <()> at a and <> at b, so a wrong motive is rejected, never trusted. It has to look inside fields: {1n == 2n} differs only at depth 2.
  • The leaf becomes {λh. efq(%h : x, p => motive x; ()) : ∀h:H. G v h}, and that value's instance is skipped. This also helps defs whose body uses h, which main can't emit at all today.
  • When no refutation is found (a stuck equation, an opaque call), the def stays out of scope. "No model" doesn't mean empty: the model search is bounded.

Cost

safe.ts is at 23,340 ttok on #1225, against the 24k cap, so 660 are left. The estimate is about 500–700 ttok for equations only: ~300–450 for the refuter, ~150–200 to hook it into root_emit, plus comments. The cleanups from #1225's review (reuse lams, derive Quant's values from QS, pass column terms down) should free 100–200. Empty datatypes would need more.

Activity

  1. added
    enhancement
    later
    on Oct 13, 2026
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

    enhancementlater

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions