mirror of
https://github.com/ziglang/zig.git
synced 2024-12-05 02:26:22 +00:00
Zir: move set_cold from Inst.Tag to Inst.Extended
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.
This commit is contained in:
parent
75ff34db9e
commit
d6bd00e855
@ -1187,10 +1187,6 @@ const NAV_MODES = {
|
||||
payloadHtml += "panic";
|
||||
break;
|
||||
}
|
||||
case "set_cold": {
|
||||
payloadHtml += "setCold";
|
||||
break;
|
||||
}
|
||||
case "set_runtime_safety": {
|
||||
payloadHtml += "setRuntimeSafety";
|
||||
break;
|
||||
|
@ -2609,8 +2609,9 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
|
||||
.extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) {
|
||||
.breakpoint,
|
||||
.fence,
|
||||
.set_align_stack,
|
||||
.set_float_mode,
|
||||
.set_align_stack,
|
||||
.set_cold,
|
||||
=> break :b true,
|
||||
else => break :b false,
|
||||
},
|
||||
@ -2658,7 +2659,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
|
||||
.validate_struct_init_comptime,
|
||||
.validate_array_init,
|
||||
.validate_array_init_comptime,
|
||||
.set_cold,
|
||||
.set_runtime_safety,
|
||||
.closure_capture,
|
||||
.memcpy,
|
||||
@ -8078,6 +8078,14 @@ fn builtinCall(
|
||||
});
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
.set_cold => {
|
||||
const order = try expr(gz, scope, ri, params[0]);
|
||||
const result = try gz.addExtendedPayload(.set_cold, Zir.Inst.UnNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
.operand = order,
|
||||
});
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
|
||||
.src => {
|
||||
const token_starts = tree.tokens.items(.start);
|
||||
@ -8111,7 +8119,6 @@ fn builtinCall(
|
||||
.bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int),
|
||||
.embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .const_slice_u8_type } }, params[0], .embed_file),
|
||||
.error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name),
|
||||
.set_cold => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_cold),
|
||||
.set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety),
|
||||
.sqrt => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .sqrt),
|
||||
.sin => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .sin),
|
||||
|
@ -1338,7 +1338,6 @@ fn walkInstruction(
|
||||
.embed_file,
|
||||
.error_name,
|
||||
.panic,
|
||||
.set_cold, // @check
|
||||
.set_runtime_safety, // @check
|
||||
.sqrt,
|
||||
.sin,
|
||||
|
18
src/Sema.zig
18
src/Sema.zig
@ -1167,6 +1167,11 @@ fn analyzeBodyInner(
|
||||
i += 1;
|
||||
continue;
|
||||
},
|
||||
.set_cold => {
|
||||
try sema.zirSetCold(block, extended);
|
||||
i += 1;
|
||||
continue;
|
||||
},
|
||||
.breakpoint => {
|
||||
if (!block.is_comptime) {
|
||||
_ = try block.addNoOp(.breakpoint);
|
||||
@ -1304,11 +1309,6 @@ fn analyzeBodyInner(
|
||||
i += 1;
|
||||
continue;
|
||||
},
|
||||
.set_cold => {
|
||||
try sema.zirSetCold(block, inst);
|
||||
i += 1;
|
||||
continue;
|
||||
},
|
||||
.set_runtime_safety => {
|
||||
try sema.zirSetRuntimeSafety(block, inst);
|
||||
i += 1;
|
||||
@ -5721,10 +5721,10 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
|
||||
gop.value_ptr.* = .{ .alignment = alignment, .src = src };
|
||||
}
|
||||
|
||||
fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
|
||||
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
|
||||
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
|
||||
const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand, "operand to @setCold must be comptime-known");
|
||||
fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
|
||||
const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
|
||||
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
|
||||
const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, "operand to @setCold must be comptime-known");
|
||||
const func = sema.func orelse return; // does nothing outside a function
|
||||
func.is_cold = is_cold;
|
||||
}
|
||||
|
10
src/Zir.zig
10
src/Zir.zig
@ -808,8 +808,6 @@ pub const Inst = struct {
|
||||
panic,
|
||||
/// Same as `panic` but forces comptime.
|
||||
panic_comptime,
|
||||
/// Implement builtin `@setCold`. Uses `un_node`.
|
||||
set_cold,
|
||||
/// Implement builtin `@setRuntimeSafety`. Uses `un_node`.
|
||||
set_runtime_safety,
|
||||
/// Implement builtin `@sqrt`. Uses `un_node`.
|
||||
@ -1187,7 +1185,6 @@ pub const Inst = struct {
|
||||
.bool_to_int,
|
||||
.embed_file,
|
||||
.error_name,
|
||||
.set_cold,
|
||||
.set_runtime_safety,
|
||||
.sqrt,
|
||||
.sin,
|
||||
@ -1323,7 +1320,6 @@ pub const Inst = struct {
|
||||
.validate_deref,
|
||||
.@"export",
|
||||
.export_value,
|
||||
.set_cold,
|
||||
.set_runtime_safety,
|
||||
.memcpy,
|
||||
.memset,
|
||||
@ -1561,7 +1557,7 @@ pub const Inst = struct {
|
||||
=> false,
|
||||
|
||||
.extended => switch (data.extended.opcode) {
|
||||
.breakpoint, .fence => true,
|
||||
.fence, .set_cold, .breakpoint => true,
|
||||
else => false,
|
||||
},
|
||||
};
|
||||
@ -1750,7 +1746,6 @@ pub const Inst = struct {
|
||||
.error_name = .un_node,
|
||||
.panic = .un_node,
|
||||
.panic_comptime = .un_node,
|
||||
.set_cold = .un_node,
|
||||
.set_runtime_safety = .un_node,
|
||||
.sqrt = .un_node,
|
||||
.sin = .un_node,
|
||||
@ -1979,6 +1974,9 @@ pub const Inst = struct {
|
||||
/// Implement builtin `@setAlignStack`.
|
||||
/// `operand` is payload index to `UnNode`.
|
||||
set_align_stack,
|
||||
/// Implements `@setCold`.
|
||||
/// `operand` is payload index to `UnNode`.
|
||||
set_cold,
|
||||
/// Implements the `@errSetCast` builtin.
|
||||
/// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
|
||||
err_set_cast,
|
||||
|
@ -196,7 +196,6 @@ const Writer = struct {
|
||||
.error_name,
|
||||
.panic,
|
||||
.panic_comptime,
|
||||
.set_cold,
|
||||
.set_runtime_safety,
|
||||
.sqrt,
|
||||
.sin,
|
||||
@ -503,6 +502,7 @@ const Writer = struct {
|
||||
.fence,
|
||||
.set_float_mode,
|
||||
.set_align_stack,
|
||||
.set_cold,
|
||||
.wasm_memory_size,
|
||||
.error_to_int,
|
||||
.int_to_error,
|
||||
|
Loading…
Reference in New Issue
Block a user