commit 75c33ba85e47eec9f7257cfb972a54b22a5283eb (tree)
parent 0c78ece1c95164f4a321f5705b20896415336d02
Author: VÖRÖSKŐI András <voroskoi@gmail.com>
Date: Thu, 7 Jul 2022 19:05:56 +0200
Sema: add a note about @setEvalBranchQuota() when branch quota is exceeded
closes #11996
Diffstat:
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/Sema.zig b/src/Sema.zig
@@ -18427,7 +18427,20 @@ fn safetyPanic(
fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
sema.branch_count += 1;
if (sema.branch_count > sema.branch_quota) {
- return sema.fail(block, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota});
+ const msg = try sema.errMsg(
+ block,
+ src,
+ "evaluation exceeded {d} backwards branches",
+ .{sema.branch_quota},
+ );
+ try sema.errNote(
+ block,
+ src,
+ msg,
+ "use @setEvalBranchQuota() to raise the branch limit from {d}",
+ .{sema.branch_quota},
+ );
+ return sema.failWithOwnedErrorMsg(block, msg);
}
}
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp
@@ -5769,8 +5769,10 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) {
*bbc += 1;
if (*bbc > *quota) {
- ir_add_error_node(ira, source_node,
+ ErrorMsg *msg = ir_add_error_node(ira, source_node,
buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota));
+ add_error_note(ira->codegen, msg, source_node,
+ buf_sprintf("use @setEvalBranchQuota to raise branch limit from %" ZIG_PRI_usize, *quota));
return false;
}
return true;
diff --git a/test/cases/recursive_inline_function.1.zig b/test/cases/recursive_inline_function.1.zig
@@ -14,6 +14,7 @@ inline fn fibonacci(n: usize) usize {
// error
//
// :11:21: error: evaluation exceeded 1000 backwards branches
+// :11:21: note: use @setEvalBranchQuota() to raise the branch limit from 1000
// :11:40: note: called from here (6 times)
// :11:21: note: called from here (495 times)
// :5:24: note: called from here