E1858: recursion in a verb with a stack limit

View source

meta stack_limit(bytes: N) promises that a verb never uses more than N bytes of stack (ADR-0103).

meta stack_limit(bytes: N) promises that a verb never uses more than N bytes of stack (ADR-0103). The compiler can only prove that bound when the call depth is bounded, so the initial contract rejects any recursion that is reachable from such a verb. This covers a verb that calls itself and verbs that call each other in a cycle. The error points at the call that closes the cycle.

Example

actus
meta stack_limit(bytes: 256u32)
verb recurse() -> Int {
    recurse();
    return 0;
}

verb main() {
}

Fix

Replace the recursion with a loop, so the stack use does not depend on the number of steps.

actus
meta stack_limit(bytes: 256u32)
verb count_down() -> Int {
    erg left = 4;
    loop {
        if left == 0 {
            break;
        }
        left = left - 1;
    }
    return left;
}

verb main() {
}
toml
[package]
name = "example"
version = "0.1.0"
edition = "alpha"
entry = "main"

[build]
target = "x86_64-unknown-linux-gnu"
profile = "debug"
runtime = "std"

Run actus explain E1858 in your terminal to read this entry offline. Browse Strict & toolchain or all error codes.