Repository navigation
Description
What you did
bun bend2/main.ts repro.bend --check-only, then bun bend2/main.ts repro.bend --verdict
What happened
On main (e5527d5):
$ bun bend2/main.ts repro.bend --check-only
ALL PROOFS CHECK
Use --verdict for mathematical validity.
$ bun bend2/main.ts repro.bend --verdict
SOME PROOFS FAIL
In passed:
expected: Nat
observed: Σx3 : <False, True> -> (Bool.arms x3)
Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. Your proofs may or may not be correct, and we cannot validate them yet. This will be addressed in a future update. Meanwhile, feel free to open an issue to report this bug.
The file
import Base
type Fact<-P: Type> is Data:
Fact{-proof: P}
type Box<-P: Type> is Data:
Box{}
def Cells() -> Type:
@+b: Bool -> {b == b : Bool}
def cells(-keeps: @+n: Nat -> {n == n : Nat}) -> Fact<Cells()>:
Fact{b => {==}}
def take(-p: Cells()) -> Box<Cells()>:
Box{}
def passed(-kf: @+n: Nat -> Fact<{n == n : Nat}>) -> Box<Cells()>:
take({\{Fact: q => q} : Fact<Cells()> -> Cells()}(
cells(n => {\{Fact: q => q} : Fact<{n == n : Nat}> -> {n == n : Nat}}(kf(n)))))bend --version
2.0.37 (tag v2.0.37, 4ff8545). Same result on main at e5527d5 and on PR #1657 at 4d5f662. Each version's kernel was built from its own bendtt.lean with Lean 4.34.0 (the PR doesn't change bendtt.lean). On 2.0.37, --verdict fails the same way, but without the In passed: expected/observed lines.
uname -sm
Linux x86_64
clang --version (the first line)
No clang on PATH; clang-19 --version: Ubuntu clang version 19.1.1 (1ubuntu1~24.04.2). --verdict doesn't use it: it returns at main.ts:308, before cc_find.
Diagnosis
The argument of take is an application, and its type Cells() is a function type. So arg_term makes it η-long: safe.ts:1332-1340 calls eta (safe.ts:953-955), which wraps the argument in a new binder, λ+x1 : Bool. That moves the inner n => ... down one level, from x1 to x2. Its body moves with it. The Nat annotations on the inner eliminator don't move and still say x1, which is now the Bool. From -o:
passed = λ-x0 => (take -λ+x1 => ({…} : ∀x2 : (Fact -Cells) -> Cells}
(cells -λ+x2 => ({…} : ∀x3 : (Fact -{x1 == x1 : Nat}) -> {x1 == x1 : Nat}} (x0 +x2))) +x1))
The η-expanded form written by hand (below) emits the same term, character for character, except for {x2 == x2 : Nat} in those two places, and it passes. So the kernel is right to reject this term: it really is ill-typed.
To find where the stale level comes from, I dumped the argument at arg_term's eta branch. The λ bodies in it use whatever variable they are instantiated with. But the annotations bend2 attached to the inner eliminator (Var("_", -1) with v set) hold n as Var(n, 1), a fixed level. I didn't trace where bend.ts writes those annotations.
Here the stale level gives an ill-typed term, so a valid proof gets rejected. I didn't look for a case where the stale level lands on a binder whose type fits and the term is accepted.
tree also calls eta, at safe.ts:772 and safe.ts:879. I didn't test those paths.
Workaround
Writing the η-expanded argument by hand passes --check-only and --verdict on all three versions above:
take(b => {\{Fact: q => q} : Fact<Cells()> -> Cells()}(
cells(n => {\{Fact: q => q} : Fact<{n == n : Nat}> -> {n == n : Nat}}(kf(n))))(b))Related
- --verdict rejects a reused proof after reconstructing a constructor with a function field #1623 / PR fix(safe): preserve neutral function fields in constructors #1657: the same trigger (
arg_termη-expands a function-typed argument) with a different failure. There the expanded fieldλx => f(x)doesn't convert withf. PR fix(safe): preserve neutral function fields in constructors #1657 stops η-expanding constructor fields. With the PR applied, my first version of this bug, where the proof goes into aFact{...}field, passes. This file still fails, because the proof is an ordinary erased argument. I'm filing it separately so it stays open if fix(safe): preserve neutral function fields in constructors #1657 closes --verdict rejects a reused proof after reconstructing a constructor with a function field #1623. - --verdict fails on programs bend2 accepts: safe.ts splices terms at stale binder levels, so scope_move captures and uses over-counts #1168 (closed by 0187512, together with A Kind-spliced lambda can make the all-green emitted book compute the unused column's value (kernel-certified 7n vs source 3n) #1178): the same kind of bug, a term built at one depth and placed at another. That fix covers specialized arguments, not
eta.
Activity
subst keeps a variable below its depth, so eta's fix fits under safe.…
A def's body goes to --verdict through its lowered form once, so its …
A def's body goes to --verdict through its lowered form once, so its …