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(
1842718427fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
1842818428 sema.branch_count += 1;
1842918429 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);
1843118444 }
1843218445}
1843318446
src/stage1/ir.cpp+3-1
......@@ -5769,8 +5769,10 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) {
57695769
57705770 *bbc += 1;
57715771 if (*bbc > *quota) {
5772 ir_add_error_node(ira, source_node,
5772 ErrorMsg *msg = ir_add_error_node(ira, source_node,
57735773 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));
57745776 return false;
57755777 }
57765778 return true;
test/cases/recursive_inline_function.1.zig+1
......@@ -14,6 +14,7 @@ inline fn fibonacci(n: usize) usize {
1414// error
1515//
1616// :11:21: error: evaluation exceeded 1000 backwards branches
17// :11:21: note: use @setEvalBranchQuota() to raise the branch limit from 1000
1718// :11:40: note: called from here (6 times)
1819// :11:21: note: called from here (495 times)
1920// :5:24: note: called from here