Repository navigation
Description
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
- main:
ALL PROOFS CHECK. TheFalseinstance is1nand never namesh's root constant, so it never goes out. - A def specialized at a finite parameter also goes to --verdict as a λ-match on it, so the kernel checks that each value has an instance that fits its type (#1186) #1225:
SOME PROOFS FAIL,- only_true: names only_true_7e_h, out of scope: no model for only_true~h. The cover annotates every leaf withGapplied to every~column, so theFalseleaf namesonly_true~h : {False == True : Bool}, which has no model.
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 hasa's shape" fromaalone: 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<()>ataand<>atb, 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 usesh, 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