Sema: generic function instantiation inherits parent's branch quota

Closes #12624
This commit is contained in:
Veikka Tuominen
2022-10-05 15:31:34 +03:00
parent 94039d66ed
commit 775e055b59
2 changed files with 32 additions and 0 deletions

View File

@@ -6713,6 +6713,8 @@ fn instantiateGenericCall(
.comptime_args_fn_inst = module_fn.zir_body_inst,
.preallocated_new_func = new_module_func,
.is_generic_instantiation = true,
.branch_quota = sema.branch_quota,
.branch_count = sema.branch_count,
};
defer child_sema.deinit();

View File

@@ -0,0 +1,30 @@
pub export fn entry1() void {
@setEvalBranchQuota(1001);
// Return type evaluation should inherit both the
// parent's branch quota and count meaning
// at least 2002 backwards branches are required.
comptime var i = 0;
inline while (i < 1000) : (i += 1) {}
_ = simple(10);
}
pub export fn entry2() void {
@setEvalBranchQuota(2001);
comptime var i = 0;
inline while (i < 1000) : (i += 1) {}
_ = simple(10);
}
fn simple(comptime n: usize) Type(n) {
return n;
}
fn Type(comptime n: usize) type {
if (n <= 1) return usize;
return Type(n - 1);
}
// error
// backend=stage2
// target=native
//
// :21:16: error: evaluation exceeded 1001 backwards branches
// :21:16: note: use @setEvalBranchQuota() to raise the branch limit from 1001
// :16:34: note: called from here