Diagnostic and cause
СсылкаRecursion limit exceeded
- Семейство
- topaz
- Этап
- run
- Код
TPZ5009
Причина и условия
Named program functions, lambdas, user callbacks, protocol methods, and receiver methods each count as one active call. Standard functions do not count. A user callback invoked by a standard function counts. A defer block does not add a call. A concurrent arm inherits the depth of the call that opened its group. Entering a counted call while 1000 calls are active produces TPZ5009 at the rejected call. An implementation must not exhaust its stack while fewer than 1000 counted calls are active.
Связанное правило · Counted calls and the runtime depth limit →Действия
Check the base case and progress toward it. Rewrite deep recursion as a loop when the input can require many calls.
Compiler phase: runtime.
Compiler explanation: Nested Topaz calls exceeded the shared call-depth limit.
Message templates are Pending. The explanation above is not an observed CLI message.
The program attempts to enter a counted call while 1000 counted calls are active.
Counted calls and the runtime depth limit
Named program functions, lambdas, user callbacks, protocol methods, and receiver methods each count as one active call. Standard functions do not count. A user callback invoked by a standard function counts. A defer block does not add a call. A concurrent arm inherits the depth of the call that opened its group. Entering a counted call while 1000 calls are active produces TPZ5009 at the rejected call. An implementation must not exhaust its stack while fewer than 1000 counted calls are active.
Причина
The same program reaches the same call-depth diagnostic on every target. Host stack size must not cause an earlier failure.
Response
СсылкаCheck the base case and progress toward it. Rewrite deep recursion as a loop when the input can require many calls.
Reproduction and verification
СсылкаRejected program
Ссылкаfunction descend(depth: int) -> int {if (depth == 0) {0} else {descend(depth - 1)}}let result = descend(1001)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
diagnostic-tpz5009 at
example.tpz:5:5
Run the named-function and lambda runtime examples with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs.
Repaired program
Ссылкаfunction descend(depth: int) -> int {if (depth == 0) {0} else {descend(depth - 1)}}let result = descend(10)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
Run the named-function and lambda runtime examples with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs.
A recursive lambda reaches the same call limit
Ссылкаimport std.iolet mut descend: (int) -> int = (depth) => 0descend = (depth) => {if (depth == 0) {0} else {descend(depth - 1)}}let result = descend(1001)io.writeLine("{result}")
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
diagnostic-tpz5009 at
example.tpz:7:5
Run the named-function and lambda runtime examples with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs.
A recursive lambda finishes below the call limit
Ссылкаimport std.iolet mut descend: (int) -> int = (depth) => 0descend = (depth) => {if (depth == 0) {0} else {descend(depth - 1)}}let result = descend(10)io.writeLine("{result}")
0
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
0
Run the named-function and lambda runtime examples with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs.