Skip to content

A zero-argument recursive type definition checks, but --verdict and -o stack-overflow elaborating it #1164

Closed

Description

@yavuzerayut

What you did

BEND_NO_TELEMETRY=1 bend omega2.bend --check-only (passes), then BEND_NO_TELEMETRY=1 bend omega2.bend --verdict

What happened

--check-only prints ALL PROOFS CHECK, but --verdict (and -o x.bendtt too, so it is the elaborator, not the kernel binary) exits 1 with:

Error: the machine stack overflowed (a deep recursion, or a literal too large to expand)

No .bendtt file is written. A type definition whose body names itself with no argument (F below) is accepted by bend2, and elaborating om's domain seems to unfold F forever.

The file

import Base

def F() -> Type:
  @-x: F -> Empty

def om(f: @-x: F -> Empty) -> Empty:
  f(f)

(f(f) checks: the operand sits at f's erased domain, so the second use of f is not counted.)

bend --version

bend 2.0.32

uname -sm

Darwin arm64

clang --version (the first line)

Apple clang version 17.0.0 (clang-1700.0.13.5)

Activity

  1. nicolas-abril commented on Sep 29, 2026

    @nicolas-abril
    Collaborator

    Reproduced on main (2.0.34). The overflow is in safe.ts's η-long elaboration, not in om's domain. F goes out as a plain reference, and def om(f: @-x: F -> Empty) -> Unit: Unit{} elaborates fine.

    safe.ts writes every term of a function type η-long, because bend2 converts up to η and the kernel doesn't. For f(f), arg_term (safe.ts:1128) η-expands the argument f at type F to λ-x => f(x), with x : F. Elaborating that body applies f to x, which is another argument of type F, so it η-expands again, and this never stops. tree's rule for leaves of a function type loops the same way: def om(f: @-x: F -> Empty) -> @-x: F -> Empty: f also overflows.

    This isn't specific to self-application. Any type def that unfolds to a function over itself has an infinite η-long form. A positive, continuation-style one checks in bend2 and overflows the elaborator in the same place:

    import Base
    
    def G() -> Type:
      (G -> U32) -> U32
    
    def run(g: G, k: G -> U32) -> U32:
      g(k)

    Recursion through the codomain has the same infinite η-long form, and there bend2's own checker already hangs, before safe.ts runs. Declaring the type checks instantly, but passing a value of it through a def keeps --check-only running indefinitely (killed after 15 s, and after 4 min on a first try):

    import Base
    
    def Sink() -> Type:
      U32 -> Sink
    
    def keep(s: Sink) -> Sink:
      s

    A likely fix for safe.ts: stop η-expanding at a recursive type def that is already being expanded on the current path, and leave the term as it is. The kernel type-checks non-η-long terms without trouble; η-long form only matters for equations bend2 closed by η. Written by hand into the .bendtt, both om : ∀x0 : ∀-x1 : F -> Empty -> Empty = λx0 => (x0 -λ-x1 => (x0 -x1)) and λx0 => (x0 -x0) print ALL PROOFS CHECK.

  2. added
    later
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    later

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions