P0021
Calls nest too deep: runaway recursion. The interpreter runs on a thread of its own with a 256 MiB stack, and a call panics instead of starting when calls already nest 50,000 deep, or when so little of that stack is left that the next call could overflow it. The process never crashes on deep recursion: oskac run exits with 101, and under oskac test only the test that recursed fails. Spans the call that would have gone too deep.
Machine-applicable fix: none.
Example
This program fails with P0021.
fn down(n: Int) -> Int {
1 + down(n - 1)
}
fn main() {
let depth = down(10)
}
Fixed
The same program, fixed.
fn down(n: Int) -> Int {
if n == 0 { 0 } else { 1 + down(n - 1) }
}
fn main() {
let depth = down(10)
}
Listed in the runtime notes. oskac explain P0021 prints this entry offline.