| author | |
| committer | |
| log | d6bd00e85500fa1a7909695ae5943be438f7521d |
| tree | 55999396212ade2f2494b585ceeb7af3e64ab13d |
| parent | 75ff34db9e93056482233f8476a06f78b4a2f3c2 |
If I could mark a builtin function as cold, I would mark @setCold as cold.
We have run out of `Zir.Inst.Tag`s so I had to move a tag from Zir.Inst.Tag to
Zir.Inst.Extended. This is because a new noreturn builtin will be added and
noreturn builtins cannot be part of Inst.Tag:
```
/// `noreturn` instructions may not go here; they must be part of the main `Tag` enum.
pub const Extended = enum(u16) {
```
Here's another reason I went for @setCold:
```
$ git grep setRuntimeSafety | wc -l
322
$ git grep setCold | wc -l
79
$ git grep setEvalBranchQuota | wc -l
82
```
This also simply removes @setCold from Autodoc and the docs frontend because
as far as I could understand it, builtins represented using Zir extended
instructions are not yet supported because I couldn't find
@setStackAlign or @setFloatMode there, either.6 files changed, 24 insertions(+), 24 deletions(-)
lib/docs/main.js-4| ... | ... | @@ -1187,10 +1187,6 @@ const NAV_MODES = { |
| 1187 | 1187 | payloadHtml += "panic"; |
| 1188 | 1188 | break; |
| 1189 | 1189 | } |
| 1190 | case "set_cold": { | |
| 1191 | payloadHtml += "setCold"; | |
| 1192 | break; | |
| 1193 | } | |
| 1194 | 1190 | case "set_runtime_safety": { |
| 1195 | 1191 | payloadHtml += "setRuntimeSafety"; |
| 1196 | 1192 | break; |
src/AstGen.zig+10-3| ... | ... | @@ -2609,8 +2609,9 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2609 | 2609 | .extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) { |
| 2610 | 2610 | .breakpoint, |
| 2611 | 2611 | .fence, |
| 2612 | .set_align_stack, | |
| 2613 | 2612 | .set_float_mode, |
| 2613 | .set_align_stack, | |
| 2614 | .set_cold, | |
| 2614 | 2615 | => break :b true, |
| 2615 | 2616 | else => break :b false, |
| 2616 | 2617 | }, |
| ... | ... | @@ -2658,7 +2659,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2658 | 2659 | .validate_struct_init_comptime, |
| 2659 | 2660 | .validate_array_init, |
| 2660 | 2661 | .validate_array_init_comptime, |
| 2661 | .set_cold, | |
| 2662 | 2662 | .set_runtime_safety, |
| 2663 | 2663 | .closure_capture, |
| 2664 | 2664 | .memcpy, |
| ... | ... | @@ -8078,6 +8078,14 @@ fn builtinCall( |
| 8078 | 8078 | }); |
| 8079 | 8079 | return rvalue(gz, ri, result, node); |
| 8080 | 8080 | }, |
| 8081 | .set_cold => { | |
| 8082 | const order = try expr(gz, scope, ri, params[0]); | |
| 8083 | const result = try gz.addExtendedPayload(.set_cold, Zir.Inst.UnNode{ | |
| 8084 | .node = gz.nodeIndexToRelative(node), | |
| 8085 | .operand = order, | |
| 8086 | }); | |
| 8087 | return rvalue(gz, ri, result, node); | |
| 8088 | }, | |
| 8081 | 8089 | |
| 8082 | 8090 | .src => { |
| 8083 | 8091 | const token_starts = tree.tokens.items(.start); |
| ... | ... | @@ -8111,7 +8119,6 @@ fn builtinCall( |
| 8111 | 8119 | .bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int), |
| 8112 | 8120 | .embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[0], .embed_file), |
| 8113 | 8121 | .error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name), |
| 8114 | .set_cold => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_cold), | |
| 8115 | 8122 | .set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety), |
| 8116 | 8123 | .sqrt => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .sqrt), |
| 8117 | 8124 | .sin => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .sin), |
src/Autodoc.zig-1| ... | ... | @@ -1338,7 +1338,6 @@ fn walkInstruction( |
| 1338 | 1338 | .embed_file, |
| 1339 | 1339 | .error_name, |
| 1340 | 1340 | .panic, |
| 1341 | .set_cold, // @check | |
| 1342 | 1341 | .set_runtime_safety, // @check |
| 1343 | 1342 | .sqrt, |
| 1344 | 1343 | .sin, |
src/Sema.zig+9-9| ... | ... | @@ -1167,6 +1167,11 @@ fn analyzeBodyInner( |
| 1167 | 1167 | i += 1; |
| 1168 | 1168 | continue; |
| 1169 | 1169 | }, |
| 1170 | .set_cold => { | |
| 1171 | try sema.zirSetCold(block, extended); | |
| 1172 | i += 1; | |
| 1173 | continue; | |
| 1174 | }, | |
| 1170 | 1175 | .breakpoint => { |
| 1171 | 1176 | if (!block.is_comptime) { |
| 1172 | 1177 | _ = try block.addNoOp(.breakpoint); |
| ... | ... | @@ -1304,11 +1309,6 @@ fn analyzeBodyInner( |
| 1304 | 1309 | i += 1; |
| 1305 | 1310 | continue; |
| 1306 | 1311 | }, |
| 1307 | .set_cold => { | |
| 1308 | try sema.zirSetCold(block, inst); | |
| 1309 | i += 1; | |
| 1310 | continue; | |
| 1311 | }, | |
| 1312 | 1312 | .set_runtime_safety => { |
| 1313 | 1313 | try sema.zirSetRuntimeSafety(block, inst); |
| 1314 | 1314 | i += 1; |
| ... | ... | @@ -5721,10 +5721,10 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 5721 | 5721 | gop.value_ptr.* = .{ .alignment = alignment, .src = src }; |
| 5722 | 5722 | } |
| 5723 | 5723 | |
| 5724 | fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | |
| 5725 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 5726 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 5727 | const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand, "operand to @setCold must be comptime-known"); | |
| 5724 | fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | |
| 5725 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | |
| 5726 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 5727 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, "operand to @setCold must be comptime-known"); | |
| 5728 | 5728 | const func = sema.func orelse return; // does nothing outside a function |
| 5729 | 5729 | func.is_cold = is_cold; |
| 5730 | 5730 | } |
src/Zir.zig+4-6| ... | ... | @@ -808,8 +808,6 @@ pub const Inst = struct { |
| 808 | 808 | panic, |
| 809 | 809 | /// Same as `panic` but forces comptime. |
| 810 | 810 | panic_comptime, |
| 811 | /// Implement builtin `@setCold`. Uses `un_node`. | |
| 812 | set_cold, | |
| 813 | 811 | /// Implement builtin `@setRuntimeSafety`. Uses `un_node`. |
| 814 | 812 | set_runtime_safety, |
| 815 | 813 | /// Implement builtin `@sqrt`. Uses `un_node`. |
| ... | ... | @@ -1187,7 +1185,6 @@ pub const Inst = struct { |
| 1187 | 1185 | .bool_to_int, |
| 1188 | 1186 | .embed_file, |
| 1189 | 1187 | .error_name, |
| 1190 | .set_cold, | |
| 1191 | 1188 | .set_runtime_safety, |
| 1192 | 1189 | .sqrt, |
| 1193 | 1190 | .sin, |
| ... | ... | @@ -1323,7 +1320,6 @@ pub const Inst = struct { |
| 1323 | 1320 | .validate_deref, |
| 1324 | 1321 | .@"export", |
| 1325 | 1322 | .export_value, |
| 1326 | .set_cold, | |
| 1327 | 1323 | .set_runtime_safety, |
| 1328 | 1324 | .memcpy, |
| 1329 | 1325 | .memset, |
| ... | ... | @@ -1561,7 +1557,7 @@ pub const Inst = struct { |
| 1561 | 1557 | => false, |
| 1562 | 1558 | |
| 1563 | 1559 | .extended => switch (data.extended.opcode) { |
| 1564 | .breakpoint, .fence => true, | |
| 1560 | .fence, .set_cold, .breakpoint => true, | |
| 1565 | 1561 | else => false, |
| 1566 | 1562 | }, |
| 1567 | 1563 | }; |
| ... | ... | @@ -1750,7 +1746,6 @@ pub const Inst = struct { |
| 1750 | 1746 | .error_name = .un_node, |
| 1751 | 1747 | .panic = .un_node, |
| 1752 | 1748 | .panic_comptime = .un_node, |
| 1753 | .set_cold = .un_node, | |
| 1754 | 1749 | .set_runtime_safety = .un_node, |
| 1755 | 1750 | .sqrt = .un_node, |
| 1756 | 1751 | .sin = .un_node, |
| ... | ... | @@ -1979,6 +1974,9 @@ pub const Inst = struct { |
| 1979 | 1974 | /// Implement builtin `@setAlignStack`. |
| 1980 | 1975 | /// `operand` is payload index to `UnNode`. |
| 1981 | 1976 | set_align_stack, |
| 1977 | /// Implements `@setCold`. | |
| 1978 | /// `operand` is payload index to `UnNode`. | |
| 1979 | set_cold, | |
| 1982 | 1980 | /// Implements the `@errSetCast` builtin. |
| 1983 | 1981 | /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand. |
| 1984 | 1982 | err_set_cast, |
src/print_zir.zig+1-1| ... | ... | @@ -196,7 +196,6 @@ const Writer = struct { |
| 196 | 196 | .error_name, |
| 197 | 197 | .panic, |
| 198 | 198 | .panic_comptime, |
| 199 | .set_cold, | |
| 200 | 199 | .set_runtime_safety, |
| 201 | 200 | .sqrt, |
| 202 | 201 | .sin, |
| ... | ... | @@ -503,6 +502,7 @@ const Writer = struct { |
| 503 | 502 | .fence, |
| 504 | 503 | .set_float_mode, |
| 505 | 504 | .set_align_stack, |
| 505 | .set_cold, | |
| 506 | 506 | .wasm_memory_size, |
| 507 | 507 | .error_to_int, |
| 508 | 508 | .int_to_error, |