Skip to content

Lua stack depth outside the Prolog engine: shen.curry, post-reader walkers, user non-tail recursion (~12k frames) #93

Closed

Description

@pyrex41

This follows up #85 and #88. #90 removes the native Prolog engine's own depth limit by running deep proofs on fresh coroutine stacks, and #91 makes the reader iterative. Several capcov repros still overflow LuaJIT's fixed ~65500-slot Lua stack. The overflow now happens outside the Prolog engine and the reader, in non-tail-recursive Lua code: kernel KL tree walkers and user code. shen-go 1f587de succeeds on all of them, because it has a growable stack.

Results with #89, #90 and #91 merged together:

repro shen-lua shen-go where it overflows
(shen.typecheck (mk 3000) peano), peano datatype from #85 shen: stack overflow peano shen.curry / shen.map-h (typecheck preprocessing), 4673 frames each
an accumulator mk building a 4000–5000-element [cons N Acc] and typechecking it as [list number] stack overflow ok same: shen.curry
(length [1 2 ... 4000]), list literal [string "reader"]:26: stack overflow ok 4000 after the reader: shen.find-types, then shen.process-applications (shen.map-h / shen.special-case); limit is ~3400 elements
(define depth N -> (if (= N 0) 0 (+ 1 (depth (- N 1))))) (depth 12000) [string "shen:depth"]:1: stack overflow (5000 and 8000 work) 12000, and 100000 works too user non-tail recursion
mk from #85 at 5000/10000 [string "shen:mk"]:1: stack overflow ok user non-tail recursion

All of these hit the same limit: each Lua frame takes stack slots and the stack can't grow past ~65500 slots. Possible directions:

Generated by Claude Code

Activity

  1. added a commit that references this issue on Oct 19, 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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions