Repository navigation
BendTT: a comparison is done when both sides are already the same, and first runs with every def rigid - #1892
Conversation
…d first runs with every def rigid, as bend2's term_compare fits unfolded both sides before comparing, with no equality check, so a type def whose unfolding names itself (F = ∀-x:F -> <>) never finished comparing to itself: F against F unfolded to the same ∀ and compared the domains, F against F again, until the stack overflowed. Even id : F -> F = λx => x failed this way. fits now checks U = T before unfolding and again after, and conv checks a = b after unfolding too (it already did before). Ctx.fit and the Rfl check run the comparison first against an empty book, where no def unfolds, then against the real one, each from the same fuel, the way bend2's term_compare runs a rigid pass first. Each check only turns a failure into a success, so --verdict rejects nothing it accepted. Proofs: the new equality branches are crefl or a join of the two weak heads; sees_nil (an empty book is seen by any) lets rigid_sound reuse fits_sound and conv_sound for both passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lorenzobattistela
left a comment
There was a problem hiding this comment.
Thanks, this looks right to me. The proofs hold, each new branch only turns a failure into a success, and I ran it merged onto main 757180e: repo 54/54, test 1752/1752, perf 124/124, ping 81/81, safe 1135 agree / 0 false reject. The 53 --verdict tests take about the same time on both kernels (6.46 s vs 6.19 s locally).
A few points, none blocking:
-
The shortcut only fires when the two sides are the same term. An applied recursive type whose arguments differ by one unfolding still overflows on both kernels:
U1 : *(.Q2) = <A> U2 : *(.Q2) = U1 H : ∀-x0 : *(.Q1) -> *(.Q1) = λ-x0 => ∀-x1 : (H -x0) -> x0 id : ∀x0 : (H -U1) -> (H -U2) = λx0 => x0fitsunfolds H(U1) and H(U2) to ∀s whose domains are H(U2) vs H(U1) again, and those are never equal. The rigid pass doesn't help, because U1 vs U2 compares two different refs. With(H -U1) -> (H -U1)it checks here and overflows on main, so the fix is specific to identical sides. Comparing same-head applications argument by argument before unfolding (lazy delta at each node, as bend2 does) would also cover this. Fine as a follow-up if you'd rather keep this PR small, but the description's "applied recursive types" claim should say it needs identical arguments. -
Related and already on main: fuel doesn't bound stack depth, so any comparison that never ends (this one, or the F vs G case you mention) aborts the bendtt process instead of giving a clean "out of fuel" rejection. Not this PR's job, but worth an issue.
-
Small cleanups:
Term.parts's last arm (| a, b => if a = b then some [] else none) can no longer returnsome [], sinceconvnow checksa = bjust before calling it. It could returnnoneinstead.- The
if a = b/if U = Tafter unfolding repeats a full structural walk even when unfolding took no step. Book.of []is rebuilt on everyTerm.rigidcall. A namedBook.nil, reused bysees_nil, would mirror bend2'sRIGID.
-
Nothing pins
id : F -> Ftoday, so a later refactor could drop theU = Tcheck with every gate green. Please make sure the elaborator PR adds the #1164 cases as --verdict tests.
…igid pass uses a named Book.nil
|
Thanks. Points 3 and 4: 3. 87f93dd
4. #1896 already adds Points 1 and 2 aren't addressed yet. The cluster, safe and hub gates weren't run. |
…t Book.nil unfolds no def Co-Authored-By: Claude Opus 5.5 <[email protected]>
…endlang#1164) A type def whose unfolding names itself (F = @-x: F -> Empty, G's domain G -> U32, H(A) = @-x: H(A) -> A) has an infinite η-long form: η-expanding a term of it binds a variable of the same type, which η-expands again. --verdict and -o overflowed the stack writing om(f) = f(f) at F. eta_finite walks a type's ∀s, domains and codomains, and fails when a def (also at the head of an application) appears inside its own unfolding. A tree leaf outside a Σ chain, and a call's argument, go η-long only at a finite type; at an infinite one the term goes out whole. The kernel needs bendlang#1892 to compare such types; with it om, keep, run and keep_h check. An equation bend2 closes by η at such a type, {f == (x => f(x)) : F}, now fails --verdict instead of overflowing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Part of #1164 (the kernel half; the elaborator half is a separate PR). Alternative to #1815's kernel change.
What
Term.fitsunfolded both sides to their weak heads before comparing, with no equality check. A type def whose unfolding names itself, likeF = ∀-x:F -> <>, therefore never finished comparing to itself:FagainstFunfolds to the same∀, compares the domains,FagainstFagain, until the stack overflows. Evenid : ∀x0 : F -> F = λx0 => x0overflows onmain.Term.convdoesn't have this problem because it checksa = bfirst;fitsdidn't.This brings the kernel's comparison closer to bend2's
term_compare:fitschecksU = Tbefore unfolding, asconvalready did witha = b. When both sides unfold to the same term, the comparison one level down starts with the same check, so there is no second check after unfolding.Term.rigid fruns a comparison first againstBook.nil(the empty book, where no def unfolds), then against the real book, each pass from the same fuel (so a comparison can now spend up to 2 ×FUEL). It's used where the checker starts a comparison (Ctx.fit, and theRflcheck of an equation), as bend2 runs its rigid pass at the top ofterm_compare.The new check only turns a failure into a success, and the full pass starts from the same fuel, so
--verdictcan't reject anythingmainaccepted.Compared with #1815's
sameRefshortcut, theU = Tcheck also covers applied recursive types with identical arguments: forH(A) = ∀-x:H(A) -> A,λx => x : H(x0) -> H(x0)still overflows #1815's kernel and checks here. Arguments that differ only by unfolding (H(U1)vsH(U2)withU2 = U1) still overflow; that needs comparing arguments before unfolding, left for a follow-up.Proofs
fits_soundiscrefl.sees_nil:Book.nilis seen by any book.rigid_soundreusesfits_soundandconv_soundunchanged for both passes.lean bend2/bendtt.lean: no errors, nosorry, the same 62 warnings asmain.Checks
Hand-written
.bendttfiles on the built kernel (mainoverflows on all the accepted ones):om : ∀x0 : ∀-x0:F -> <> -> <> = λx0 => (x0 -x0), and its η-long formkeep,runfrom #1164, η-long and notid : F -> F,id : F -> ∀-x0:F -> <>id : ∀-x0:*1 -> ∀x1:(H x0) -> (H x0) = λ-x0 => λx1 => x1boom : <> = (om om)bad2 : ∀x0:F -> ∀x1:F -> <> = λx0 => x0Fagainst a separate but identical-lookingG = ∀-x0:G -> <>--verdictover all 1763 files intests/,main's kernel vs this one (both withmain's elaborator): identical output on every file (1134 check, 629 fail), total time 465 s vs 461 s, no file more than 2 s slower. On the cluster, merged ontomainfad0bb9 (87f93dd): repo 54/54, test 1771/1771, ping 81/81, perf passes (it doesn't run the kernel), safe 1143 agree / 0 false reject. The hub corpus wasn't run.No
.bendtest here: onmain, every.bendfile with a recursive function type overflows insafe.ts's η-long elaboration before reaching the kernel. The #1164 examples become--verdicttests in the elaborator PR, which needs this one to pass them.bun gates/repo.ts: 54 / 54.🤖 Generated with Claude Code