Skip to content

Commit d4bc640

Browse files
committed
Zir: remove legacy error_set_decl variants
These instructions are not emitted by AstGen. They also would have no effect even if they did appear in ZIR: the Sema handling for these instructions creates a Decl which the name strategy is applied to, and proceeds to never use it. This pointless CPU heater is now gone, saving 2 ZIR tags in the process.
1 parent ec33705 commit d4bc640

File tree

4 files changed

+3
-39
lines changed

4 files changed

+3
-39
lines changed

lib/std/zig/AstGen.zig

-2
Original file line numberDiff line numberDiff line change
@@ -2728,8 +2728,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
27282728
.union_init,
27292729
.field_type_ref,
27302730
.error_set_decl,
2731-
.error_set_decl_anon,
2732-
.error_set_decl_func,
27332731
.enum_from_int,
27342732
.int_from_enum,
27352733
.type_info,

lib/std/zig/Zir.zig

-8
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ pub const Inst = struct {
372372
/// An error set type definition. Contains a list of field names.
373373
/// Uses the `pl_node` union field. Payload is `ErrorSetDecl`.
374374
error_set_decl,
375-
error_set_decl_anon,
376-
error_set_decl_func,
377375
/// Declares the beginning of a statement. Used for debug info.
378376
/// Uses the `dbg_stmt` union field. The line and column are offset
379377
/// from the parent declaration.
@@ -1078,8 +1076,6 @@ pub const Inst = struct {
10781076
.cmp_gt,
10791077
.cmp_neq,
10801078
.error_set_decl,
1081-
.error_set_decl_anon,
1082-
.error_set_decl_func,
10831079
.dbg_stmt,
10841080
.dbg_var_ptr,
10851081
.dbg_var_val,
@@ -1385,8 +1381,6 @@ pub const Inst = struct {
13851381
.cmp_gt,
13861382
.cmp_neq,
13871383
.error_set_decl,
1388-
.error_set_decl_anon,
1389-
.error_set_decl_func,
13901384
.decl_ref,
13911385
.decl_val,
13921386
.load,
@@ -1624,8 +1618,6 @@ pub const Inst = struct {
16241618
.@"try" = .pl_node,
16251619
.try_ptr = .pl_node,
16261620
.error_set_decl = .pl_node,
1627-
.error_set_decl_anon = .pl_node,
1628-
.error_set_decl_func = .pl_node,
16291621
.dbg_stmt = .dbg_stmt,
16301622
.dbg_var_ptr = .str_op,
16311623
.dbg_var_val = .str_op,

src/Sema.zig

+2-23
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,7 @@ fn analyzeBodyInner(
11561156
.round => try sema.zirUnaryMath(block, inst, .round, Value.round),
11571157
.trunc => try sema.zirUnaryMath(block, inst, .trunc_float, Value.trunc),
11581158

1159-
.error_set_decl => try sema.zirErrorSetDecl(block, inst, .parent),
1160-
.error_set_decl_anon => try sema.zirErrorSetDecl(block, inst, .anon),
1161-
.error_set_decl_func => try sema.zirErrorSetDecl(block, inst, .func),
1159+
.error_set_decl => try sema.zirErrorSetDecl(inst),
11621160

11631161
.add => try sema.zirArithmetic(block, inst, .add, true),
11641162
.addwrap => try sema.zirArithmetic(block, inst, .addwrap, true),
@@ -3468,17 +3466,14 @@ fn zirOpaqueDecl(
34683466

34693467
fn zirErrorSetDecl(
34703468
sema: *Sema,
3471-
block: *Block,
34723469
inst: Zir.Inst.Index,
3473-
name_strategy: Zir.Inst.NameStrategy,
34743470
) CompileError!Air.Inst.Ref {
34753471
const tracy = trace(@src());
34763472
defer tracy.end();
34773473

34783474
const mod = sema.mod;
34793475
const gpa = sema.gpa;
34803476
const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
3481-
const src = inst_data.src();
34823477
const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
34833478

34843479
var names: InferredErrorSet.NameMap = .{};
@@ -3495,23 +3490,7 @@ fn zirErrorSetDecl(
34953490
assert(!result.found_existing); // verified in AstGen
34963491
}
34973492

3498-
const error_set_ty = try mod.errorSetFromUnsortedNames(names.keys());
3499-
3500-
const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3501-
block,
3502-
src,
3503-
error_set_ty.toValue(),
3504-
name_strategy,
3505-
"error",
3506-
inst,
3507-
);
3508-
const new_decl = mod.declPtr(new_decl_index);
3509-
new_decl.owns_tv = true;
3510-
errdefer mod.abortAnonDecl(new_decl_index);
3511-
3512-
const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
3513-
try mod.finalizeAnonDecl(new_decl_index);
3514-
return decl_val;
3493+
return Air.internedToRef((try mod.errorSetFromUnsortedNames(names.keys())).toIntern());
35153494
}
35163495

35173496
fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {

src/print_zir.zig

+1-6
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,7 @@ const Writer = struct {
452452
.try_ptr,
453453
=> try self.writeTry(stream, inst),
454454

455-
.error_set_decl => try self.writeErrorSetDecl(stream, inst, .parent),
456-
.error_set_decl_anon => try self.writeErrorSetDecl(stream, inst, .anon),
457-
.error_set_decl_func => try self.writeErrorSetDecl(stream, inst, .func),
455+
.error_set_decl => try self.writeErrorSetDecl(stream, inst),
458456

459457
.switch_block,
460458
.switch_block_ref,
@@ -1968,13 +1966,10 @@ const Writer = struct {
19681966
self: *Writer,
19691967
stream: anytype,
19701968
inst: Zir.Inst.Index,
1971-
name_strategy: Zir.Inst.NameStrategy,
19721969
) !void {
19731970
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19741971
const extra = self.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
19751972

1976-
try stream.print("{s}, ", .{@tagName(name_strategy)});
1977-
19781973
try stream.writeAll("{\n");
19791974
self.indent += 2;
19801975

0 commit comments

Comments
 (0)