| ... | @@ -132,6 +132,10 @@ dependencies: std.array_hash_map.Auto(InternPool.Dependee, void) = .empty, | ... | @@ -132,6 +132,10 @@ dependencies: std.array_hash_map.Auto(InternPool.Dependee, void) = .empty, |
| 132 | /// by `analyzeCall`. | 132 | /// by `analyzeCall`. |
| 133 | allow_memoize: bool = true, | 133 | allow_memoize: bool = true, |
| 134 | | 134 | |
| | 135 | /// The largest quota requested by `@setEvalBranchQuota` within the comptime call |
| | 136 | /// currently being analyzed. |
| | 137 | quota_request: u32 = 0, |
| | 138 | |
| 135 | /// The `BranchHint` for the current branch of runtime control flow. | 139 | /// The `BranchHint` for the current branch of runtime control flow. |
| 136 | /// This state is on `Sema` so that `cold` hints can be propagated up through blocks with less special handling. | 140 | /// This state is on `Sema` so that `cold` hints can be propagated up through blocks with less special handling. |
| 137 | branch_hint: ?std.lang.BranchHint = null, | 141 | branch_hint: ?std.lang.BranchHint = null, |
| ... | @@ -4914,7 +4918,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi | ... | @@ -4914,7 +4918,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 4914 | const src = block.nodeOffset(inst_data.src_node); | 4918 | const src = block.nodeOffset(inst_data.src_node); |
| 4915 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, .u32, .{ .simple = .operand_setEvalBranchQuota })); | 4919 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, .u32, .{ .simple = .operand_setEvalBranchQuota })); |
| 4916 | sema.branch_quota = @max(sema.branch_quota, quota); | 4920 | sema.branch_quota = @max(sema.branch_quota, quota); |
| 4917 | sema.allow_memoize = false; | 4921 | sema.quota_request = @max(sema.quota_request, quota); |
| 4918 | } | 4922 | } |
| 4919 | | 4923 | |
| 4920 | fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 4924 | fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -7218,6 +7222,7 @@ fn analyzeCall( | ... | @@ -7218,6 +7222,7 @@ fn analyzeCall( |
| 7218 | .arg_values = memoized_arg_values, | 7222 | .arg_values = memoized_arg_values, |
| 7219 | .result = undefined, // ignored by hash+eql | 7223 | .result = undefined, // ignored by hash+eql |
| 7220 | .branch_count = undefined, // ignored by hash+eql | 7224 | .branch_count = undefined, // ignored by hash+eql |
| | 7225 | .branch_quota = undefined, // ignored by hash+eql |
| 7221 | }, | 7226 | }, |
| 7222 | }) orelse break :memoize; | 7227 | }) orelse break :memoize; |
| 7223 | const memoized_call = ip.indexToKey(memoized_call_index).memoized_call; | 7228 | const memoized_call = ip.indexToKey(memoized_call_index).memoized_call; |
| ... | @@ -7227,6 +7232,8 @@ fn analyzeCall( | ... | @@ -7227,6 +7232,8 @@ fn analyzeCall( |
| 7227 | break :memoize; | 7232 | break :memoize; |
| 7228 | } | 7233 | } |
| 7229 | sema.branch_count += memoized_call.branch_count; | 7234 | sema.branch_count += memoized_call.branch_count; |
| | 7235 | sema.branch_quota = @max(sema.branch_quota, memoized_call.branch_quota); |
| | 7236 | sema.quota_request = @max(sema.quota_request, memoized_call.branch_quota); |
| 7230 | const result = Air.internedToRef(memoized_call.result); | 7237 | const result = Air.internedToRef(memoized_call.result); |
| 7231 | if (ensure_result_used) { | 7238 | if (ensure_result_used) { |
| 7232 | try sema.ensureResultUsed(block, sema.typeOf(result), call_src); | 7239 | try sema.ensureResultUsed(block, sema.typeOf(result), call_src); |
| ... | @@ -7353,6 +7360,10 @@ fn analyzeCall( | ... | @@ -7353,6 +7360,10 @@ fn analyzeCall( |
| 7353 | defer sema.allow_memoize = old_allow_memoize and sema.allow_memoize; | 7360 | defer sema.allow_memoize = old_allow_memoize and sema.allow_memoize; |
| 7354 | sema.allow_memoize = true; | 7361 | sema.allow_memoize = true; |
| 7355 | | 7362 | |
| | 7363 | const old_quota_request = sema.quota_request; |
| | 7364 | defer sema.quota_request = @max(old_quota_request, sema.quota_request); |
| | 7365 | sema.quota_request = 0; |
| | 7366 | |
| 7356 | // Store the current eval branch count so we can find out how many eval branches | 7367 | // Store the current eval branch count so we can find out how many eval branches |
| 7357 | // the comptime call caused. | 7368 | // the comptime call caused. |
| 7358 | const old_branch_count = sema.branch_count; | 7369 | const old_branch_count = sema.branch_count; |
| ... | @@ -7388,6 +7399,7 @@ fn analyzeCall( | ... | @@ -7388,6 +7399,7 @@ fn analyzeCall( |
| 7388 | .arg_values = memoized_arg_values, | 7399 | .arg_values = memoized_arg_values, |
| 7389 | .result = result_val.toIntern(), | 7400 | .result = result_val.toIntern(), |
| 7390 | .branch_count = sema.branch_count - old_branch_count, | 7401 | .branch_count = sema.branch_count - old_branch_count, |
| | 7402 | .branch_quota = sema.quota_request, |
| 7391 | } }); | 7403 | } }); |
| 7392 | } | 7404 | } |
| 7393 | } | 7405 | } |