You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A template passed through a ~ parameter bypasses descent and proves False{} == True{} #902
bun bend2/main.ts template_cycle.bend --check-only
What happened
All terms check.
The file contains a closed boom() -> Empty and derives False{} == True{} from it. It does not import Base and uses no @unsafe, FFI, law, hole or runtime backend.
The direct self-call control is rejected as expected:
During the generic check of loop, loop(~k) is the erased ~f argument, so the reference is checked dead and the self-call descent check does not run. Checking the closed call later creates loop~0, whose body creates bounce~0. The instantiated body of bounce~0 uses its opaque template argument live and becomes a call back to loop~0.
At that point loop~0 already exists as the in-progress placeholder installed by def_inst. Reusing that instance does not recheck that its body is still null, and the current lhs is bounce~0, so it is not recognized as a self-call either. The accepted live graph is therefore:
loop~0(u) = bounce~0(u)
bounce~0(u) = loop~0(u)
This is a two-definition cycle with no decreasing argument. It breaks the checker's weak-normalization claim and admits a closed inhabitant of Empty.
The file
type Empty is Data:
type Unit is Data:
Unit{}
type Key is Data:
Key{}
type Bit is Data:
False{}
True{}
def bounce(~f: Unit -> Empty, u: Unit) -> Empty:
f(u)
def loop(~k: Key, u: Unit) -> Empty:
bounce(~loop(~k), u)
def boom() -> Empty:
loop(~Key{}, Unit{})
def absurd(-A: Type, e: Empty) -> A:
match e:
def false_theorem() -> {False{} == True{} : Bit}:
absurd({False{} == True{} : Bit}, boom())
Two follow-ups confirm that this is not limited to the two-node example.
Adding main() -> Empty: boom() and importing Base lets both backends build. The generated JS and C programs both remain in the accepted recursion past a two-second timeout. The inhabitant is therefore the expected live infinite loop at runtime.
So rejecting re-entry into any in-progress instance would close this reproducer directly. A more general termination check needs to cover the whole instantiated call-graph SCC rather than only the current lhs or a caller/callee pair.
Templates are the one part I didn't formalize (yet) and they're full of holes. Thanks for the report, will fix this one now, but likely there will be more, sadly.
The cause was where you placed it. def_inst mints an instance as a bodiless placeholder while its body is checked. When bounce~0's body reached loop(~Key{}, u), the key already named loop~0, and the placeholder came back unchecked: the "filled definition" guard had looked at the template loop, which has a body, and the self-call guard compares against the current lhs, which was bounce~0.
Now a reuse of an instance whose body is still being checked, from any other lhs, is refused as a self-call that does not decrease: it is a call back into an instance on the check stack, and no column of the current lhs can show it shrinking. Your two-node and three-node files both stop at the loop inside ~loop(~k):
- expected : a decreasing self-call (arguments are read left to right: each passed unchanged until one shrinks)
- observed : loop
An instance that calls itself directly with a shrinking argument still checks. Instances are minted depth first, so with re-entry refused the live call graph of instances is a tree plus descending self-loops, the same shape plain defs already have (a forward reference is undefined, so mutual recursion between defs is refused too). Your two-node file is pinned as tests/check/template_inst_cycle.bend.
Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
Activity
jasisz commentedon Sep 20, 2026
Two follow-ups confirm that this is not limited to the two-node example.
Adding
main() -> Empty: boom()and importing Base lets both backends build. The generated JS and C programs both remain in the accepted recursion past a two-second timeout. The inhabitant is therefore the expected live infinite loop at runtime.A three-instance cycle also checks:
The checked instances form:
So rejecting re-entry into any in-progress instance would close this reproducer directly. A more general termination check needs to cover the whole instantiated call-graph SCC rather than only the current lhs or a caller/callee pair.
VictorTaelin commentedon Sep 20, 2026
Templates are the one part I didn't formalize (yet) and they're full of holes. Thanks for the report, will fix this one now, but likely there will be more, sadly.
jasisz commentedon Sep 20, 2026
I’ll take that as a hint and keep poking at templates ;)
An instance re-entered while its body is checked is a self-call that …
VictorTaelin commentedon Sep 20, 2026
Fixed in 2.0.21 (
bend update).The cause was where you placed it.
def_instmints an instance as a bodiless placeholder while its body is checked. Whenbounce~0's body reachedloop(~Key{}, u), the key already namedloop~0, and the placeholder came back unchecked: the "filled definition" guard had looked at the templateloop, which has a body, and the self-call guard compares against the current lhs, which wasbounce~0.Now a reuse of an instance whose body is still being checked, from any other lhs, is refused as a self-call that does not decrease: it is a call back into an instance on the check stack, and no column of the current lhs can show it shrinking. Your two-node and three-node files both stop at the
loopinside~loop(~k):An instance that calls itself directly with a shrinking argument still checks. Instances are minted depth first, so with re-entry refused the live call graph of instances is a tree plus descending self-loops, the same shape plain defs already have (a forward reference is undefined, so mutual recursion between defs is refused too). Your two-node file is pinned as
tests/check/template_inst_cycle.bend.Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
Merge canon/main (Bend 2.0.25+2) into the omen line
An instance re-entered while its body is checked is a self-call that …