authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-05 15:31:34+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-06 20:09:45+03:00
log775e055b59366f60badfb77a420219691846314b
treef9a32fdd42363ecc14e787242efbf5e996262727
parent94039d66ed4fecb7defc5deeeedd7afa3b773f0c

Sema: generic function instantiation inherits parent's branch quota

Closes #12624

2 files changed, 32 insertions(+), 0 deletions(-)

src/Sema.zig+2
......@@ -6713,6 +6713,8 @@ fn instantiateGenericCall(
67136713 .comptime_args_fn_inst = module_fn.zir_body_inst,
67146714 .preallocated_new_func = new_module_func,
67156715 .is_generic_instantiation = true,
6716 .branch_quota = sema.branch_quota,
6717 .branch_count = sema.branch_count,
67166718 };
67176719 defer child_sema.deinit();
67186720
test/cases/compile_errors/generic_funciton_instantiation_inherits_parent_branch_quota.zig created+30
......@@ -0,0 +1,30 @@
1pub export fn entry1() void {
2 @setEvalBranchQuota(1001);
3 // Return type evaluation should inherit both the
4 // parent's branch quota and count meaning
5 // at least 2002 backwards branches are required.
6 comptime var i = 0;
7 inline while (i < 1000) : (i += 1) {}
8 _ = simple(10);
9}
10pub export fn entry2() void {
11 @setEvalBranchQuota(2001);
12 comptime var i = 0;
13 inline while (i < 1000) : (i += 1) {}
14 _ = simple(10);
15}
16fn simple(comptime n: usize) Type(n) {
17 return n;
18}
19fn Type(comptime n: usize) type {
20 if (n <= 1) return usize;
21 return Type(n - 1);
22}
23
24// error
25// backend=stage2
26// target=native
27//
28// :21:16: error: evaluation exceeded 1001 backwards branches
29// :21:16: note: use @setEvalBranchQuota() to raise the branch limit from 1001
30// :16:34: note: called from here