XO1404: recursion among real-time functions
The call graph of real-time functions (core 6.5) must be acyclic, so that their stack depth is bounded. A function that calls itself, directly or through other real-time functions, is reported at the call that closes the cycle. Since real-time functions cannot call function values or interface methods, recursion through them is ruled out too. Rewrite the recursion as a loop with bound N and an explicit stack in a preallocated List.
Example
fn depth(n: Int) -> Int uses realtime {
if n == 0 { 0 } else { 1 + depth(n - 1) }
}Fix
fn depth(n: Int) -> Int uses realtime {
var d = 0
var i = n
while i > 0 bound 1000 {
d += 1
i -= 1
}
d
}Run xo explain XO1404 for this text in a terminal, or see
section 10.6 of the specification.