Repository navigation
TypedPython: recursion with CPython's RecursionError (#57) - #101
Merged
Merged
Conversation
tp_enter_call/tp_leave_call wrap every compiled impl: a per-thread count of compiled frames is added to the Python frame depth and checked against sys.getrecursionlimit() (RecursionError 'maximum recursion depth exceeded'), then Py_EnterRecursiveCall guards the C stack. leave runs on every exit (ok, error, deopt). The verifier and front end accept call cycles; a cycle through a may_deopt callee stays legal only in pure functions. Mixed interpreted/compiled frames fail at the same total depth (no offset measured). Divergences recorded in design §4.3.3: the C-stack guard's message at huge limits, and per-module counters. Red: verify 2, frontend 2, recursion 3+10 errors. Green: recursion 13/13 (incl. ASan/UBSan), suite 725. Mutation (leave only on ok): 5 fail. Closes #57
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #57
Feature added
Compiled functions can now recurse, directly or through other compiled functions, with CPython's
RecursionErrorsemantics.tp_enter_call/tp_leave_callrun on every compiled function's entry and every exit (ok, error, deopt).sys.getrecursionlimit(); over the limit,RecursionError: maximum recursion depth exceededis raised.Py_EnterRecursiveCallkeeps the process from crashing whatever the limit is set to.Test added
test_recursion.py, 13 tests, compared with interpreted CPython:Results: red 3 failed + 10 errors; green 13/13; whole suite 725. Removing
tp_leave_callfrom the error and deopt paths makes 5 tests fail.Measured
... in compiled code; 3.14:Stack overflow ...);Not done
binary-trees still compiles nothing.
makeandcheckare skipped forNoneconstants and theNodeclass, which is the fixed-layout class item (N-11), not recursion.Note
The sub-agent's first full-suite run had 14 failures and 12 errors in Pyrefly-using tests (
pyrefly wrote no readable type report). They passed when re-run. The cause is unknown; it may be temp-directory contention under the shared lock.