@setEvalBranchQuota

@setEvalBranchQuota

@setEvalBranchQuota(new_quota: u32)

Changes the maximum number of backwards branches that compile-time code execution can use before giving up and making a compile error.

If the new_quota is smaller than the default quota (1000) or a previously explicitly set quota, it is ignored.

Example:

test.zig

test "foo" {
    comptime {
        var i = 0;
        while (i < 1001) : (i += 1) {}
    }
}
``` ```
$ zig test test.zig
./docgen_tmp/test.zig:4:9: error: evaluation exceeded 1000 backwards branches
        while (i < 1001) : (i += 1) {}
        ^
./docgen_tmp/test.zig:1:12: note: referenced here
test "foo" {
           ^

Now we use @setEvalBranchQuota:

test.zig

test "foo" {
    comptime {
        @setEvalBranchQuota(1001);
        var i = 0;
        while (i < 1001) : (i += 1) {}
    }
}
``` ```
$ zig test test.zig
Test [1/1] test "foo"...

All 1 tests passed.

See also:

  • comptime