authorgravatar for voroskoi@gmail.comVÖRÖSKŐI András <voroskoi@gmail.com> 2022-07-07 19:05:56+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-08 02:13:33+03:00
log75c33ba85e47eec9f7257cfb972a54b22a5283eb
tree521fbfb604ee9ba9e258cfaa182f755962069099
parent0c78ece1c95164f4a321f5705b20896415336d02

Sema: add a note about @setEvalBranchQuota() when branch quota is exceeded

closes #11996

3 files changed, 18 insertions(+), 2 deletions(-)

src/Sema.zig+14-1
...@@ -18427,7 +18427,20 @@ fn safetyPanic(...@@ -18427,7 +18427,20 @@ fn safetyPanic(
18427fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {18427fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
18428 sema.branch_count += 1;18428 sema.branch_count += 1;
18429 if (sema.branch_count > sema.branch_quota) {18429 if (sema.branch_count > sema.branch_quota) {
18430 return sema.fail(block, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota});18430 const msg = try sema.errMsg(
18431 block,
18432 src,
18433 "evaluation exceeded {d} backwards branches",
18434 .{sema.branch_quota},
18435 );
18436 try sema.errNote(
18437 block,
18438 src,
18439 msg,
18440 "use @setEvalBranchQuota() to raise the branch limit from {d}",
18441 .{sema.branch_quota},
18442 );
18443 return sema.failWithOwnedErrorMsg(block, msg);
18431 }18444 }
18432}18445}
1843318446
src/stage1/ir.cpp+3-1
...@@ -5769,8 +5769,10 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) {...@@ -5769,8 +5769,10 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) {
57695769
5770 *bbc += 1;5770 *bbc += 1;
5771 if (*bbc > *quota) {5771 if (*bbc > *quota) {
5772 ir_add_error_node(ira, source_node,5772 ErrorMsg *msg = ir_add_error_node(ira, source_node,
5773 buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota));5773 buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota));
5774 add_error_note(ira->codegen, msg, source_node,
5775 buf_sprintf("use @setEvalBranchQuota to raise branch limit from %" ZIG_PRI_usize, *quota));
5774 return false;5776 return false;
5775 }5777 }
5776 return true;5778 return true;
test/cases/recursive_inline_function.1.zig+1
...@@ -14,6 +14,7 @@ inline fn fibonacci(n: usize) usize {...@@ -14,6 +14,7 @@ inline fn fibonacci(n: usize) usize {
14// error14// error
15//15//
16// :11:21: error: evaluation exceeded 1000 backwards branches16// :11:21: error: evaluation exceeded 1000 backwards branches
17// :11:21: note: use @setEvalBranchQuota() to raise the branch limit from 1000
17// :11:40: note: called from here (6 times)18// :11:40: note: called from here (6 times)
18// :11:21: note: called from here (495 times)19// :11:21: note: called from here (495 times)
19// :5:24: note: called from here20// :5:24: note: called from here