Commit 75c33ba85e

VÖRÖSKŐI András <voroskoi@gmail.com>
2022-07-07 19:05:56
Sema: add a note about @setEvalBranchQuota() when branch quota is exceeded
closes #11996
1 parent 0c78ece
Changed files (3)
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;
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);
     }
 }
 
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