@setEvalBranchQuota

@setEvalBranchQuota

@setEvalBranchQuota(comptime new_quota: u32) void

Increase 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_without_setEvalBranchQuota_builtin.zig

test "foo" {
    comptime {
        var i = 0;
        while (i < 1001) : (i += 1) {}
    }
}

Shell

$ zig test test_without_setEvalBranchQuota_builtin.zig
docgen_tmp/test_without_setEvalBranchQuota_builtin.zig:4:9: error: evaluation exceeded 1000 backwards branches
        while (i < 1001) : (i += 1) {}
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
docgen_tmp/test_without_setEvalBranchQuota_builtin.zig:4:9: note: use @setEvalBranchQuota() to raise the branch limit from 1000

Now we use @setEvalBranchQuota:

test_setEvalBranchQuota_builtin.zig

test "foo" {
    comptime {
        @setEvalBranchQuota(1001);
        var i = 0;
        while (i < 1001) : (i += 1) {}
    }
}

Shell

$ zig test test_setEvalBranchQuota_builtin.zig
1/1 test_setEvalBranchQuota_builtin.test.foo... OK
All 1 tests passed.

See also:

  • comptime