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
Stage-A: no tail-call rewrite, deep self-recursion overflows the stack #951
The Python host rewrites a self tail call into a loop. Stage-A emits plain recursion.
function down_to(n: i32) -> i32 {
if n <= 0 { return 0 } else { return down_to(n - 1) }
}
function main() -> i32 { return down_to(1000000) }
Observed: return down_to((n - 1)); in the C, and the binary segfaults (signal 11) at depth 1,000,000.
Reproduce with the Stage-A compiler built from compiler/bootstrap/flowc_stage_a.c:
cc -O2 -o compiler/build/flowc_bootstrap compiler/bootstrap/flowc_stage_a.c
FLOWC_BUNDLE=1 FLOWC_DIR=. FLOWC_IN=repro.flow FLOWC_OUT=repro.c compiler/build/flowc_bootstrap
cc -O0 -o repro repro.c -lm && ./repro; echo $?
The Python host (./flow test-lang) handles the same program correctly.
Found while porting the Python run tests to tests/lang/. The Python test stays until this is fixed: tests/unit/test_tco_shim.py::test_deep_tail_recursion_runs_without_stack_overflow.
Activity
fix(stage-a): turn self tail calls into jumps
fix(stage-a): turn self tail calls into jumps
Stage-A: fix the bugs blocking the Python-to-Flow test port (#966)