Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ5009: Recursion limit exceeded

    Nested Topaz calls exceeded the shared call-depth limit.

    Diagnostic and cause

    Link

    Recursion limit exceeded

    Family
    topaz
    Phase
    run
    Code
    TPZ5009

    Cause and conditions

    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.

    Response

    Check the base case and progress toward it. Rewrite deep recursion as a loop when the input can require many calls.

    Source evidence

    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.

    Rulediagnostics.tpz5009.p5.rule

    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.

    Why

    The same program reaches the same call-depth diagnostic on every target. Host stack size must not cause an earlier failure.

    Source evidence

    Response

    Link

    Check the base case and progress toward it. Rewrite deep recursion as a loop when the input can require many calls.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected program
    1. function descend(depth: int) -> int {
    2. if (depth == 0) {
    3. 0
    4. } else {
    5. descend(depth - 1)
    6. }
    7. }
    8. let result = descend(1001)
    Expected outputNonzero exit
    No stdout.
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • TPZ5009 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.

    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. function descend(depth: int) -> int {
    2. if (depth == 0) {
    3. 0
    4. } else {
    5. descend(depth - 1)
    6. }
    7. }
    8. let result = descend(10)
    Expected outputexit 0
    No stdout.
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Run the named-function and lambda runtime examples with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs.

    Source evidence

    A recursive lambda reaches the same call limit

    Link
    example.tpzA recursive lambda reaches the same call limit
    1. import std.io
    2. let mut descend: (int) -> int = (depth) => 0
    3. descend = (depth) => {
    4. if (depth == 0) {
    5. 0
    6. } else {
    7. descend(depth - 1)
    8. }
    9. }
    10. let result = descend(1001)
    11. io.writeLine("{result}")
    Expected outputNonzero exit
    No stdout.
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • TPZ5009 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.

    Source evidence

    A recursive lambda finishes below the call limit

    Link
    example.tpzA recursive lambda finishes below the call limit
    1. import std.io
    2. let mut descend: (int) -> int = (depth) => 0
    3. descend = (depth) => {
    4. if (depth == 0) {
    5. 0
    6. } else {
    7. descend(depth - 1)
    8. }
    9. }
    10. let result = descend(10)
    11. io.writeLine("{result}")
    Expected outputexit 0
    0
    
    $ topaz run example.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 0

    Run the named-function and lambda runtime examples with TOPAZ_BIN set using node docs/topaz-reference/templates/diagnostics-p5-runtime.product.mjs.

    Source evidence

    Menu

    Download