bend hangs (no verdict, ~1 GB/s memory growth) on a 5-line file with a recursive type alias
What you did
bend loop.bend --check-only
What happened
$ bend loop.bend --check-only
(no output, never returns; resident memory grows ~1.1 GB/s)
Under a 2 GB memory cap with timeout 20: killed (exit 137) after ~6 s, 0 bytes of output.
Under an 8 GB cap with timeout 5: exit 124, a silent hang.
--verdict, -o out.bendtt and a plain `bend loop.bend` behave the same: nothing is printed, and -o writes no file.
With F alone (without g), the file checks: ALL PROOFS CHECK, exit 0, 0.05 s.The file
def F() -> Type:
F -> F
def g() -> F:
x => xI'd expect ALL PROOFS CHECK. F -> F is a legal type: the THEORY header
(bend.ts#L168-L171)
allows negative recursive types, and relies on affinity rather than positivity. With the loop bounded
(step 1 below), bend2 accepts the file in 0.08 s, and the kernel accepts a hand-written
F : *1 = ∀x0 : F -> F, g : F = λx0 => x0.
Cause. def_check starts with const qs = tele_unbind(book, def.T).doms.map(...)
(bend.ts#L3694,
reached from book_valid at
L3845).
tele_unbind
(L1051-L1059)
whnf-opens every ∀ the type exposes. F unfolds to ∀_:F. F, whose codomain is F again, so the
loop pushes one domain per turn forever, although only qs[j] for j < def.n is ever read
(L3302-L3306).
The loop runs before g's body is read, so the body doesn't matter. The same hang happens with any of
these in place of g:
def g() -> F: ?TODO(the TODO is never reported);def g(x: F) -> F: x;import Base/def F() -> Type: Nat -> F/def g() -> F: x => 0n;type D is F: C{}afterF, which loops in the same way at L3792.
This isn't #973 (a written divergent redex) or #993 (an exponential cost): the type and the term are both in normal form.
Fix direction (tested in a scratch copy).
- Give
tele_unbinda bound,tele_unbind(book, T, max = Infinity), and passdef.nat L3694 andtld.nat L3792. The bound at L3694 changes no terminating behaviour. The bound at L3792 makes the declared kind "the tip afternparameters", as the comment at L3762-L3763 describes. Note that it therefore rejects the currently acceptedtype D is Nat -> Type: C{}. - Step 1 alone fixes only
--check-only:--verdictthen loops inspec_of. Apply the same bound in safe.ts at L369 (tld.n), L974 (lead), L1020 (the member's parameter count) and L1055 (tld.x). - Bound the η-long expansion in safe.ts
tree(L608-L611), which loops on the same alias when it appears as a field type rather than a def's tail. That is the safe.ts side, #1164. - Apply the same bound to comp.ts's
tele_unbindcallers (e.g. comp.ts L734, L1232, L2229, L2454, L3228). After steps 1-2,-o x.js/-o x.cstop with "the machine stack overflowed".
Impact. Liveness and resource exhaustion. It fails closed: nothing is accepted and the kernel is
never reached. The negative type doesn't give Empty either: bend2 rejects x => x(x) at
F = F -> Empty ("consumed more than once"), and the kernel rejects λx0 => (x0 x0) ("affine live
code"). But any tool that auto-checks untrusted .bend files without a memory cap (an editor
integration, a CI job, BendHub) can be taken down by this 5-line input.
bend --version
bend 2.0.32
uname -sm
Linux x86_64
clang --version (the first line)
No response
Source: HigherOrderCO/Bend