I haven’t get the sure answer via web searching, but the following code verifies my guess, though, I’m still not sure about the exact rules.
fn sum(v: u64) @TypeOf(v) {
var r = v;
if (v > 1) {
var i = v-1;
while (i > 0) {
r += i;
i -= 1;
}
}
return r;
}
pub fn main() void {
const n = 10_000;
{
@setEvalBranchQuota(n); // This line works (for the next sum call).
}
{
const x = comptime sum(n);
@import("std").debug.print("x = {}\n", .{ x });
}
opaque {
fn foo() void {
@setEvalBranchQuota(n); // This line doesn't work (for the next sum call).
}
}.foo();
{
const y = comptime sum(n);
@import("std").debug.print("y = {}\n", .{ y });
}
}