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

closes #11996
This commit is contained in:
VÖRÖSKŐI András 2022-07-07 19:05:56 +02:00 committed by Veikka Tuominen
parent 0c78ece1c9
commit 75c33ba85e
3 changed files with 18 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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