authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-10 01:22:54+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-15 00:57:52+01:00
loge39cc0dff7fff510c3d72f61947b977589ea5583
tree5d7c405520d5c898c46a517820bd331526b7852d
parent82a934bb912241809ac8029e1fa5843092a7fdf6
signaturelock-open Commit is signed but in an unrecognized format.

Zir: use absolute nodes for declarations and type declarations

The justification for using relative source nodes in ZIR is that it allows source locations -- which may be serialized across incremental updates -- to be relative to the source location of their containing declaration. However, having those "baseline" instructions themselves be relative to their own parent is counterproductive, since the source location updating problem is only being moved to `Decl`. Storing the absolute node here instead makes more sense, since it allows for this source location update logic to be elided entirely in the future by storing a `TrackedInst.Index` to resolve a source location relative to rather than a `Decl.Index`.

5 files changed, 123 insertions(+), 98 deletions(-)

lib/std/zig/AstGen.zig+25-12
...@@ -4011,7 +4011,7 @@ fn fnDecl(...@@ -4011,7 +4011,7 @@ fn fnDecl(
40114011
4012 // We insert this at the beginning so that its instruction index marks the4012 // We insert this at the beginning so that its instruction index marks the
4013 // start of the top level declaration.4013 // start of the top level declaration.
4014 const decl_inst = try gz.makeBlockInst(.declaration, fn_proto.ast.proto_node);4014 const decl_inst = try gz.makeDeclaration(fn_proto.ast.proto_node);
4015 astgen.advanceSourceCursorToNode(decl_node);4015 astgen.advanceSourceCursorToNode(decl_node);
40164016
4017 var decl_gz: GenZir = .{4017 var decl_gz: GenZir = .{
...@@ -4393,7 +4393,7 @@ fn globalVarDecl(...@@ -4393,7 +4393,7 @@ fn globalVarDecl(
4393 const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var;4393 const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var;
4394 // We do this at the beginning so that the instruction index marks the range start4394 // We do this at the beginning so that the instruction index marks the range start
4395 // of the top level declaration.4395 // of the top level declaration.
4396 const decl_inst = try gz.makeBlockInst(.declaration, node);4396 const decl_inst = try gz.makeDeclaration(node);
43974397
4398 const name_token = var_decl.ast.mut_token + 1;4398 const name_token = var_decl.ast.mut_token + 1;
4399 astgen.advanceSourceCursorToNode(node);4399 astgen.advanceSourceCursorToNode(node);
...@@ -4555,7 +4555,7 @@ fn comptimeDecl(...@@ -4555,7 +4555,7 @@ fn comptimeDecl(
45554555
4556 // Up top so the ZIR instruction index marks the start range of this4556 // Up top so the ZIR instruction index marks the start range of this
4557 // top-level declaration.4557 // top-level declaration.
4558 const decl_inst = try gz.makeBlockInst(.declaration, node);4558 const decl_inst = try gz.makeDeclaration(node);
4559 wip_members.nextDecl(decl_inst);4559 wip_members.nextDecl(decl_inst);
4560 astgen.advanceSourceCursorToNode(node);4560 astgen.advanceSourceCursorToNode(node);
45614561
...@@ -4607,7 +4607,7 @@ fn usingnamespaceDecl(...@@ -4607,7 +4607,7 @@ fn usingnamespaceDecl(
4607 };4607 };
4608 // Up top so the ZIR instruction index marks the start range of this4608 // Up top so the ZIR instruction index marks the start range of this
4609 // top-level declaration.4609 // top-level declaration.
4610 const decl_inst = try gz.makeBlockInst(.declaration, node);4610 const decl_inst = try gz.makeDeclaration(node);
4611 wip_members.nextDecl(decl_inst);4611 wip_members.nextDecl(decl_inst);
4612 astgen.advanceSourceCursorToNode(node);4612 astgen.advanceSourceCursorToNode(node);
46134613
...@@ -4651,7 +4651,7 @@ fn testDecl(...@@ -4651,7 +4651,7 @@ fn testDecl(
46514651
4652 // Up top so the ZIR instruction index marks the start range of this4652 // Up top so the ZIR instruction index marks the start range of this
4653 // top-level declaration.4653 // top-level declaration.
4654 const decl_inst = try gz.makeBlockInst(.declaration, node);4654 const decl_inst = try gz.makeDeclaration(node);
46554655
4656 wip_members.nextDecl(decl_inst);4656 wip_members.nextDecl(decl_inst);
4657 astgen.advanceSourceCursorToNode(node);4657 astgen.advanceSourceCursorToNode(node);
...@@ -13071,6 +13071,21 @@ const GenZir = struct {...@@ -13071,6 +13071,21 @@ const GenZir = struct {
13071 return new_index;13071 return new_index;
13072 }13072 }
1307313073
13074 /// Note that this returns a `Zir.Inst.Index` not a ref.
13075 /// Does *not* append the block instruction to the scope.
13076 /// Leaves the `payload_index` field undefined. Use `setDeclaration` to finalize.
13077 fn makeDeclaration(gz: *GenZir, node: Ast.Node.Index) !Zir.Inst.Index {
13078 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
13079 try gz.astgen.instructions.append(gz.astgen.gpa, .{
13080 .tag = .declaration,
13081 .data = .{ .declaration = .{
13082 .src_node = node,
13083 .payload_index = undefined,
13084 } },
13085 });
13086 return new_index;
13087 }
13088
13074 /// Note that this returns a `Zir.Inst.Index` not a ref.13089 /// Note that this returns a `Zir.Inst.Index` not a ref.
13075 /// Leaves the `payload_index` field undefined.13090 /// Leaves the `payload_index` field undefined.
13076 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {13091 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
...@@ -13117,7 +13132,7 @@ const GenZir = struct {...@@ -13117,7 +13132,7 @@ const GenZir = struct {
13117 .fields_hash_1 = fields_hash_arr[1],13132 .fields_hash_1 = fields_hash_arr[1],
13118 .fields_hash_2 = fields_hash_arr[2],13133 .fields_hash_2 = fields_hash_arr[2],
13119 .fields_hash_3 = fields_hash_arr[3],13134 .fields_hash_3 = fields_hash_arr[3],
13120 .src_node = gz.nodeIndexToRelative(args.src_node),13135 .src_node = args.src_node,
13121 });13136 });
1312213137
13123 if (args.captures_len != 0) {13138 if (args.captures_len != 0) {
...@@ -13177,7 +13192,7 @@ const GenZir = struct {...@@ -13177,7 +13192,7 @@ const GenZir = struct {
13177 .fields_hash_1 = fields_hash_arr[1],13192 .fields_hash_1 = fields_hash_arr[1],
13178 .fields_hash_2 = fields_hash_arr[2],13193 .fields_hash_2 = fields_hash_arr[2],
13179 .fields_hash_3 = fields_hash_arr[3],13194 .fields_hash_3 = fields_hash_arr[3],
13180 .src_node = gz.nodeIndexToRelative(args.src_node),13195 .src_node = args.src_node,
13181 });13196 });
1318213197
13183 if (args.tag_type != .none) {13198 if (args.tag_type != .none) {
...@@ -13238,7 +13253,7 @@ const GenZir = struct {...@@ -13238,7 +13253,7 @@ const GenZir = struct {
13238 .fields_hash_1 = fields_hash_arr[1],13253 .fields_hash_1 = fields_hash_arr[1],
13239 .fields_hash_2 = fields_hash_arr[2],13254 .fields_hash_2 = fields_hash_arr[2],
13240 .fields_hash_3 = fields_hash_arr[3],13255 .fields_hash_3 = fields_hash_arr[3],
13241 .src_node = gz.nodeIndexToRelative(args.src_node),13256 .src_node = args.src_node,
13242 });13257 });
1324313258
13244 if (args.tag_type != .none) {13259 if (args.tag_type != .none) {
...@@ -13285,9 +13300,7 @@ const GenZir = struct {...@@ -13285,9 +13300,7 @@ const GenZir = struct {
13285 assert(args.src_node != 0);13300 assert(args.src_node != 0);
1328613301
13287 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);13302 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);
13288 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{13303 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{ .src_node = args.src_node });
13289 .src_node = gz.nodeIndexToRelative(args.src_node),
13290 });
1329113304
13292 if (args.captures_len != 0) {13305 if (args.captures_len != 0) {
13293 astgen.extra.appendAssumeCapacity(args.captures_len);13306 astgen.extra.appendAssumeCapacity(args.captures_len);
...@@ -13897,7 +13910,7 @@ fn setDeclaration(...@@ -13897,7 +13910,7 @@ fn setDeclaration(
13897 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,13910 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,
13898 },13911 },
13899 };13912 };
13900 astgen.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node.payload_index = try astgen.addExtra(extra);13913 astgen.instructions.items(.data)[@intFromEnum(decl_inst)].declaration.payload_index = try astgen.addExtra(extra);
13901 if (extra.flags.has_doc_comment) {13914 if (extra.flags.has_doc_comment) {
13902 try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));13915 try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));
13903 }13916 }
lib/std/zig/Zir.zig+26-11
...@@ -287,7 +287,7 @@ pub const Inst = struct {...@@ -287,7 +287,7 @@ pub const Inst = struct {
287 /// namespace type, e.g. within a `struct_decl` instruction. It represents a287 /// namespace type, e.g. within a `struct_decl` instruction. It represents a
288 /// single source declaration (`const`/`var`/`fn`), containing the name,288 /// single source declaration (`const`/`var`/`fn`), containing the name,
289 /// attributes, type, and value of the declaration.289 /// attributes, type, and value of the declaration.
290 /// Uses the `pl_node` union field. Payload is `Declaration`.290 /// Uses the `declaration` union field. Payload is `Declaration`.
291 declaration,291 declaration,
292 /// Implements `suspend {...}`.292 /// Implements `suspend {...}`.
293 /// Uses the `pl_node` union field. Payload is `Block`.293 /// Uses the `pl_node` union field. Payload is `Block`.
...@@ -1596,7 +1596,7 @@ pub const Inst = struct {...@@ -1596,7 +1596,7 @@ pub const Inst = struct {
1596 .block = .pl_node,1596 .block = .pl_node,
1597 .block_comptime = .pl_node,1597 .block_comptime = .pl_node,
1598 .block_inline = .pl_node,1598 .block_inline = .pl_node,
1599 .declaration = .pl_node,1599 .declaration = .declaration,
1600 .suspend_block = .pl_node,1600 .suspend_block = .pl_node,
1601 .bool_not = .un_node,1601 .bool_not = .un_node,
1602 .bool_br_and = .pl_node,1602 .bool_br_and = .pl_node,
...@@ -2370,6 +2370,16 @@ pub const Inst = struct {...@@ -2370,6 +2370,16 @@ pub const Inst = struct {
2370 /// The index being accessed.2370 /// The index being accessed.
2371 idx: u32,2371 idx: u32,
2372 },2372 },
2373 declaration: struct {
2374 /// This node provides a new absolute baseline node for all instructions within this struct.
2375 src_node: Ast.Node.Index,
2376 /// index into extra to a `Declaration` payload.
2377 payload_index: u32,
2378
2379 pub fn src(self: @This()) LazySrcLoc {
2380 return .{ .node_abs = self.src_node };
2381 }
2382 },
23732383
2374 // Make sure we don't accidentally add a field to make this union2384 // Make sure we don't accidentally add a field to make this union
2375 // bigger than expected. Note that in Debug builds, Zig is allowed2385 // bigger than expected. Note that in Debug builds, Zig is allowed
...@@ -2408,6 +2418,7 @@ pub const Inst = struct {...@@ -2408,6 +2418,7 @@ pub const Inst = struct {
2408 defer_err_code,2418 defer_err_code,
2409 save_err_ret_index,2419 save_err_ret_index,
2410 elem_val_imm,2420 elem_val_imm,
2421 declaration,
2411 };2422 };
2412 };2423 };
24132424
...@@ -3018,10 +3029,11 @@ pub const Inst = struct {...@@ -3018,10 +3029,11 @@ pub const Inst = struct {
3018 fields_hash_1: u32,3029 fields_hash_1: u32,
3019 fields_hash_2: u32,3030 fields_hash_2: u32,
3020 fields_hash_3: u32,3031 fields_hash_3: u32,
3021 src_node: i32,3032 /// This node provides a new absolute baseline node for all instructions within this struct.
3033 src_node: Ast.Node.Index,
30223034
3023 pub fn src(self: StructDecl) LazySrcLoc {3035 pub fn src(self: StructDecl) LazySrcLoc {
3024 return LazySrcLoc.nodeOffset(self.src_node);3036 return .{ .node_abs = self.src_node };
3025 }3037 }
30263038
3027 pub const Small = packed struct {3039 pub const Small = packed struct {
...@@ -3150,10 +3162,11 @@ pub const Inst = struct {...@@ -3150,10 +3162,11 @@ pub const Inst = struct {
3150 fields_hash_1: u32,3162 fields_hash_1: u32,
3151 fields_hash_2: u32,3163 fields_hash_2: u32,
3152 fields_hash_3: u32,3164 fields_hash_3: u32,
3153 src_node: i32,3165 /// This node provides a new absolute baseline node for all instructions within this struct.
3166 src_node: Ast.Node.Index,
31543167
3155 pub fn src(self: EnumDecl) LazySrcLoc {3168 pub fn src(self: EnumDecl) LazySrcLoc {
3156 return LazySrcLoc.nodeOffset(self.src_node);3169 return .{ .node_abs = self.src_node };
3157 }3170 }
31583171
3159 pub const Small = packed struct {3172 pub const Small = packed struct {
...@@ -3198,10 +3211,11 @@ pub const Inst = struct {...@@ -3198,10 +3211,11 @@ pub const Inst = struct {
3198 fields_hash_1: u32,3211 fields_hash_1: u32,
3199 fields_hash_2: u32,3212 fields_hash_2: u32,
3200 fields_hash_3: u32,3213 fields_hash_3: u32,
3201 src_node: i32,3214 /// This node provides a new absolute baseline node for all instructions within this struct.
3215 src_node: Ast.Node.Index,
32023216
3203 pub fn src(self: UnionDecl) LazySrcLoc {3217 pub fn src(self: UnionDecl) LazySrcLoc {
3204 return LazySrcLoc.nodeOffset(self.src_node);3218 return .{ .node_abs = self.src_node };
3205 }3219 }
32063220
3207 pub const Small = packed struct {3221 pub const Small = packed struct {
...@@ -3230,10 +3244,11 @@ pub const Inst = struct {...@@ -3230,10 +3244,11 @@ pub const Inst = struct {
3230 /// 2. capture: Capture, // for every captures_len3244 /// 2. capture: Capture, // for every captures_len
3231 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction3245 /// 3. decl: Index, // for every decls_len; points to a `declaration` instruction
3232 pub const OpaqueDecl = struct {3246 pub const OpaqueDecl = struct {
3233 src_node: i32,3247 /// This node provides a new absolute baseline node for all instructions within this struct.
3248 src_node: Ast.Node.Index,
32343249
3235 pub fn src(self: OpaqueDecl) LazySrcLoc {3250 pub fn src(self: OpaqueDecl) LazySrcLoc {
3236 return LazySrcLoc.nodeOffset(self.src_node);3251 return .{ .node_abs = self.src_node };
3237 }3252 }
32383253
3239 pub const Small = packed struct {3254 pub const Small = packed struct {
...@@ -4046,7 +4061,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -4046,7 +4061,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
40464061
4047pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, u32 } {4062pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, u32 } {
4048 assert(zir.instructions.items(.tag)[@intFromEnum(inst)] == .declaration);4063 assert(zir.instructions.items(.tag)[@intFromEnum(inst)] == .declaration);
4049 const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].pl_node;4064 const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].declaration;
4050 const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);4065 const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);
4051 return .{4066 return .{
4052 extra.data,4067 extra.data,
src/Module.zig+6-7
...@@ -413,8 +413,8 @@ pub const Decl = struct {...@@ -413,8 +413,8 @@ pub const Decl = struct {
413 pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies {413 pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies {
414 const zir = decl.getFileScope(zcu).zir;414 const zir = decl.getFileScope(zcu).zir;
415 const zir_index = decl.zir_decl_index.unwrap().?.resolve(&zcu.intern_pool);415 const zir_index = decl.zir_decl_index.unwrap().?.resolve(&zcu.intern_pool);
416 const pl_node = zir.instructions.items(.data)[@intFromEnum(zir_index)].pl_node;416 const declaration = zir.instructions.items(.data)[@intFromEnum(zir_index)].declaration;
417 const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index);417 const extra = zir.extraData(Zir.Inst.Declaration, declaration.payload_index);
418 return extra.data.getBodies(@intCast(extra.end), zir);418 return extra.data.getBodies(@intCast(extra.end), zir);
419 }419 }
420420
...@@ -4255,12 +4255,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4255,12 +4255,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4255 const zir = namespace.file_scope.zir;4255 const zir = namespace.file_scope.zir;
4256 const ip = &zcu.intern_pool;4256 const ip = &zcu.intern_pool;
42574257
4258 const pl_node = zir.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node;4258 const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration;
4259 const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index);4259 const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index);
4260 const declaration = extra.data;4260 const declaration = extra.data;
42614261
4262 const line = iter.parent_decl.src_line + declaration.line_offset;4262 const line = iter.parent_decl.src_line + declaration.line_offset;
4263 const decl_node = iter.parent_decl.relativeToNodeIndex(pl_node.src_node);
42644263
4265 // Every Decl needs a name.4264 // Every Decl needs a name.
4266 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {4265 const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) {
...@@ -4348,14 +4347,14 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4348,14 +4347,14 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4348 const was_exported = decl.is_exported;4347 const was_exported = decl.is_exported;
4349 assert(decl.kind == kind); // ZIR tracking should preserve this4348 assert(decl.kind == kind); // ZIR tracking should preserve this
4350 decl.name = decl_name;4349 decl.name = decl_name;
4351 decl.src_node = decl_node;4350 decl.src_node = inst_data.src_node;
4352 decl.src_line = line;4351 decl.src_line = line;
4353 decl.is_pub = declaration.flags.is_pub;4352 decl.is_pub = declaration.flags.is_pub;
4354 decl.is_exported = declaration.flags.is_export;4353 decl.is_exported = declaration.flags.is_export;
4355 break :decl_index .{ was_exported, decl_index };4354 break :decl_index .{ was_exported, decl_index };
4356 } else decl_index: {4355 } else decl_index: {
4357 // Create and set up a new Decl.4356 // Create and set up a new Decl.
4358 const new_decl_index = try zcu.allocateNewDecl(namespace_index, decl_node);4357 const new_decl_index = try zcu.allocateNewDecl(namespace_index, inst_data.src_node);
4359 const new_decl = zcu.declPtr(new_decl_index);4358 const new_decl = zcu.declPtr(new_decl_index);
4360 new_decl.kind = kind;4359 new_decl.kind = kind;
4361 new_decl.name = decl_name;4360 new_decl.name = decl_name;
src/Sema.zig+33-30
...@@ -2835,7 +2835,7 @@ fn zirStructDecl(...@@ -2835,7 +2835,7 @@ fn zirStructDecl(
28352835
2836 const new_decl_index = try sema.createAnonymousDeclTypeNamed(2836 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2837 block,2837 block,
2838 src,2838 extra.data.src_node,
2839 Value.fromInterned(wip_ty.index),2839 Value.fromInterned(wip_ty.index),
2840 small.name_strategy,2840 small.name_strategy,
2841 "struct",2841 "struct",
...@@ -2872,7 +2872,7 @@ fn zirStructDecl(...@@ -2872,7 +2872,7 @@ fn zirStructDecl(
2872fn createAnonymousDeclTypeNamed(2872fn createAnonymousDeclTypeNamed(
2873 sema: *Sema,2873 sema: *Sema,
2874 block: *Block,2874 block: *Block,
2875 src: LazySrcLoc,2875 src_node: std.zig.Ast.Node.Index,
2876 val: Value,2876 val: Value,
2877 name_strategy: Zir.Inst.NameStrategy,2877 name_strategy: Zir.Inst.NameStrategy,
2878 anon_prefix: []const u8,2878 anon_prefix: []const u8,
...@@ -2883,31 +2883,17 @@ fn createAnonymousDeclTypeNamed(...@@ -2883,31 +2883,17 @@ fn createAnonymousDeclTypeNamed(
2883 const gpa = sema.gpa;2883 const gpa = sema.gpa;
2884 const namespace = block.namespace;2884 const namespace = block.namespace;
2885 const src_decl = zcu.declPtr(block.src_decl);2885 const src_decl = zcu.declPtr(block.src_decl);
2886 const src_node = src_decl.relativeToNodeIndex(src.node_offset.x);
2887 const new_decl_index = try zcu.allocateNewDecl(namespace, src_node);2886 const new_decl_index = try zcu.allocateNewDecl(namespace, src_node);
2888 errdefer zcu.destroyDecl(new_decl_index);2887 errdefer zcu.destroyDecl(new_decl_index);
28892888
2890 switch (name_strategy) {2889 switch (name_strategy) {
2891 .anon => {2890 .anon => {}, // handled after switch
2892 // It would be neat to have "struct:line:column" but this name has
2893 // to survive incremental updates, where it may have been shifted down
2894 // or up to a different line, but unchanged, and thus not unnecessarily
2895 // semantically analyzed.
2896 // This name is also used as the key in the parent namespace so it cannot be
2897 // renamed.
2898
2899 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2900 src_decl.name.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2901 }, .no_embedded_nulls) catch unreachable;
2902 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2903 return new_decl_index;
2904 },
2905 .parent => {2891 .parent => {
2906 const name = zcu.declPtr(block.src_decl).name;2892 const name = zcu.declPtr(block.src_decl).name;
2907 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);2893 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2908 return new_decl_index;2894 return new_decl_index;
2909 },2895 },
2910 .func => {2896 .func => func_strat: {
2911 const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip));2897 const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip));
2912 const zir_tags = sema.code.instructions.items(.tag);2898 const zir_tags = sema.code.instructions.items(.tag);
29132899
...@@ -2927,7 +2913,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2927,7 +2913,7 @@ fn createAnonymousDeclTypeNamed(
2927 // function and the name doesn't matter since it will later2913 // function and the name doesn't matter since it will later
2928 // result in a compile error.2914 // result in a compile error.
2929 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch2915 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch
2930 return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null);2916 break :func_strat; // fall through to anon strat
29312917
2932 if (arg_i != 0) try writer.writeByte(',');2918 if (arg_i != 0) try writer.writeByte(',');
29332919
...@@ -2969,9 +2955,24 @@ fn createAnonymousDeclTypeNamed(...@@ -2969,9 +2955,24 @@ fn createAnonymousDeclTypeNamed(
2969 },2955 },
2970 else => {},2956 else => {},
2971 };2957 };
2972 return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null);2958 // fall through to anon strat
2973 },2959 },
2974 }2960 }
2961
2962 // anon strat handling.
2963
2964 // It would be neat to have "struct:line:column" but this name has
2965 // to survive incremental updates, where it may have been shifted down
2966 // or up to a different line, but unchanged, and thus not unnecessarily
2967 // semantically analyzed.
2968 // This name is also used as the key in the parent namespace so it cannot be
2969 // renamed.
2970
2971 const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2972 src_decl.name.fmt(ip), anon_prefix, @intFromEnum(new_decl_index),
2973 }, .no_embedded_nulls) catch unreachable;
2974 try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2975 return new_decl_index;
2975}2976}
29762977
2977fn zirEnumDecl(2978fn zirEnumDecl(
...@@ -2991,7 +2992,6 @@ fn zirEnumDecl(...@@ -2991,7 +2992,6 @@ fn zirEnumDecl(
2991 var extra_index: usize = extra.end;2992 var extra_index: usize = extra.end;
29922993
2993 const src = extra.data.src();2994 const src = extra.data.src();
2994 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
29952995
2996 const tag_type_ref = if (small.has_tag_type) blk: {2996 const tag_type_ref = if (small.has_tag_type) blk: {
2997 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);2997 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
...@@ -3071,7 +3071,7 @@ fn zirEnumDecl(...@@ -3071,7 +3071,7 @@ fn zirEnumDecl(
30713071
3072 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3072 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3073 block,3073 block,
3074 src,3074 extra.data.src_node,
3075 Value.fromInterned(wip_ty.index),3075 Value.fromInterned(wip_ty.index),
3076 small.name_strategy,3076 small.name_strategy,
3077 "enum",3077 "enum",
...@@ -3140,14 +3140,17 @@ fn zirEnumDecl(...@@ -3140,14 +3140,17 @@ fn zirEnumDecl(
3140 };3140 };
3141 defer enum_block.instructions.deinit(sema.gpa);3141 defer enum_block.instructions.deinit(sema.gpa);
31423142
3143 // This source location applies in the context of `enum_block`.
3144 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
3145
3143 if (body.len != 0) {3146 if (body.len != 0) {
3144 _ = try sema.analyzeInlineBody(&enum_block, body, inst);3147 _ = try sema.analyzeInlineBody(&enum_block, body, inst);
3145 }3148 }
31463149
3147 if (tag_type_ref != .none) {3150 if (tag_type_ref != .none) {
3148 const ty = try sema.resolveType(block, tag_ty_src, tag_type_ref);3151 const ty = try sema.resolveType(&enum_block, tag_ty_src, tag_type_ref);
3149 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {3152 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {
3150 return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});3153 return sema.fail(&enum_block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});
3151 }3154 }
3152 break :ty ty;3155 break :ty ty;
3153 } else if (fields_len == 0) {3156 } else if (fields_len == 0) {
...@@ -3342,7 +3345,7 @@ fn zirUnionDecl(...@@ -3342,7 +3345,7 @@ fn zirUnionDecl(
33423345
3343 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3346 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3344 block,3347 block,
3345 src,3348 extra.data.src_node,
3346 Value.fromInterned(wip_ty.index),3349 Value.fromInterned(wip_ty.index),
3347 small.name_strategy,3350 small.name_strategy,
3348 "union",3351 "union",
...@@ -3430,7 +3433,7 @@ fn zirOpaqueDecl(...@@ -3430,7 +3433,7 @@ fn zirOpaqueDecl(
34303433
3431 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3434 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3432 block,3435 block,
3433 src,3436 extra.data.src_node,
3434 Value.fromInterned(wip_ty.index),3437 Value.fromInterned(wip_ty.index),
3435 small.name_strategy,3438 small.name_strategy,
3436 "opaque",3439 "opaque",
...@@ -21658,7 +21661,7 @@ fn zirReify(...@@ -21658,7 +21661,7 @@ fn zirReify(
2165821661
21659 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21662 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
21660 block,21663 block,
21661 src,21664 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
21662 Value.fromInterned(wip_ty.index),21665 Value.fromInterned(wip_ty.index),
21663 name_strategy,21666 name_strategy,
21664 "opaque",21667 "opaque",
...@@ -21858,7 +21861,7 @@ fn reifyEnum(...@@ -21858,7 +21861,7 @@ fn reifyEnum(
2185821861
21859 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21862 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
21860 block,21863 block,
21861 src,21864 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
21862 Value.fromInterned(wip_ty.index),21865 Value.fromInterned(wip_ty.index),
21863 name_strategy,21866 name_strategy,
21864 "enum",21867 "enum",
...@@ -22005,7 +22008,7 @@ fn reifyUnion(...@@ -22005,7 +22008,7 @@ fn reifyUnion(
2200522008
22006 const new_decl_index = try sema.createAnonymousDeclTypeNamed(22009 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
22007 block,22010 block,
22008 src,22011 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
22009 Value.fromInterned(wip_ty.index),22012 Value.fromInterned(wip_ty.index),
22010 name_strategy,22013 name_strategy,
22011 "union",22014 "union",
...@@ -22264,7 +22267,7 @@ fn reifyStruct(...@@ -22264,7 +22267,7 @@ fn reifyStruct(
2226422267
22265 const new_decl_index = try sema.createAnonymousDeclTypeNamed(22268 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
22266 block,22269 block,
22267 src,22270 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
22268 Value.fromInterned(wip_ty.index),22271 Value.fromInterned(wip_ty.index),
22269 name_strategy,22272 name_strategy,
22270 "struct",22273 "struct",
src/print_zir.zig+33-38
...@@ -1390,9 +1390,14 @@ const Writer = struct {...@@ -1390,9 +1390,14 @@ const Writer = struct {
1390 }1390 }
13911391
1392 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1392 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1393 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));1393 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
13941394
1395 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);1395 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);
1396
1397 const prev_parent_decl_node = self.parent_decl_node;
1398 self.parent_decl_node = extra.data.src_node;
1399 defer self.parent_decl_node = prev_parent_decl_node;
1400
1396 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{1401 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
1397 extra.data.fields_hash_0,1402 extra.data.fields_hash_0,
1398 extra.data.fields_hash_1,1403 extra.data.fields_hash_1,
...@@ -1465,10 +1470,6 @@ const Writer = struct {...@@ -1465,10 +1470,6 @@ const Writer = struct {
1465 if (decls_len == 0) {1470 if (decls_len == 0) {
1466 try stream.writeAll("{}, ");1471 try stream.writeAll("{}, ");
1467 } else {1472 } else {
1468 const prev_parent_decl_node = self.parent_decl_node;
1469 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1470 defer self.parent_decl_node = prev_parent_decl_node;
1471
1472 try stream.writeAll("{\n");1473 try stream.writeAll("{\n");
1473 self.indent += 2;1474 self.indent += 2;
1474 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1475 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1546,8 +1547,6 @@ const Writer = struct {...@@ -1546,8 +1547,6 @@ const Writer = struct {
1546 }1547 }
1547 }1548 }
15481549
1549 const prev_parent_decl_node = self.parent_decl_node;
1550 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1551 try stream.writeAll("{\n");1550 try stream.writeAll("{\n");
1552 self.indent += 2;1551 self.indent += 2;
15531552
...@@ -1595,18 +1594,22 @@ const Writer = struct {...@@ -1595,18 +1594,22 @@ const Writer = struct {
1595 try stream.writeAll(",\n");1594 try stream.writeAll(",\n");
1596 }1595 }
15971596
1598 self.parent_decl_node = prev_parent_decl_node;
1599 self.indent -= 2;1597 self.indent -= 2;
1600 try stream.writeByteNTimes(' ', self.indent);1598 try stream.writeByteNTimes(' ', self.indent);
1601 try stream.writeAll("})");1599 try stream.writeAll("})");
1602 }1600 }
1603 try self.writeSrcNode(stream, extra.data.src_node);1601 try self.writeSrcNode(stream, 0);
1604 }1602 }
16051603
1606 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1604 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1607 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));1605 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
16081606
1609 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);1607 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);
1608
1609 const prev_parent_decl_node = self.parent_decl_node;
1610 self.parent_decl_node = extra.data.src_node;
1611 defer self.parent_decl_node = prev_parent_decl_node;
1612
1610 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{1613 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
1611 extra.data.fields_hash_0,1614 extra.data.fields_hash_0,
1612 extra.data.fields_hash_1,1615 extra.data.fields_hash_1,
...@@ -1670,10 +1673,6 @@ const Writer = struct {...@@ -1670,10 +1673,6 @@ const Writer = struct {
1670 if (decls_len == 0) {1673 if (decls_len == 0) {
1671 try stream.writeAll("{}");1674 try stream.writeAll("{}");
1672 } else {1675 } else {
1673 const prev_parent_decl_node = self.parent_decl_node;
1674 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1675 defer self.parent_decl_node = prev_parent_decl_node;
1676
1677 try stream.writeAll("{\n");1676 try stream.writeAll("{\n");
1678 self.indent += 2;1677 self.indent += 2;
1679 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1678 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1690,7 +1689,7 @@ const Writer = struct {...@@ -1690,7 +1689,7 @@ const Writer = struct {
16901689
1691 if (fields_len == 0) {1690 if (fields_len == 0) {
1692 try stream.writeAll("})");1691 try stream.writeAll("})");
1693 try self.writeSrcNode(stream, extra.data.src_node);1692 try self.writeSrcNode(stream, 0);
1694 return;1693 return;
1695 }1694 }
1696 try stream.writeAll(", ");1695 try stream.writeAll(", ");
...@@ -1698,8 +1697,6 @@ const Writer = struct {...@@ -1698,8 +1697,6 @@ const Writer = struct {
1698 const body = self.code.bodySlice(extra_index, body_len);1697 const body = self.code.bodySlice(extra_index, body_len);
1699 extra_index += body.len;1698 extra_index += body.len;
17001699
1701 const prev_parent_decl_node = self.parent_decl_node;
1702 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1703 try self.writeBracedDecl(stream, body);1700 try self.writeBracedDecl(stream, body);
1704 try stream.writeAll(", {\n");1701 try stream.writeAll(", {\n");
17051702
...@@ -1763,17 +1760,21 @@ const Writer = struct {...@@ -1763,17 +1760,21 @@ const Writer = struct {
1763 try stream.writeAll(",\n");1760 try stream.writeAll(",\n");
1764 }1761 }
17651762
1766 self.parent_decl_node = prev_parent_decl_node;
1767 self.indent -= 2;1763 self.indent -= 2;
1768 try stream.writeByteNTimes(' ', self.indent);1764 try stream.writeByteNTimes(' ', self.indent);
1769 try stream.writeAll("})");1765 try stream.writeAll("})");
1770 try self.writeSrcNode(stream, extra.data.src_node);1766 try self.writeSrcNode(stream, 0);
1771 }1767 }
17721768
1773 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1769 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1774 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));1770 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17751771
1776 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);1772 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);
1773
1774 const prev_parent_decl_node = self.parent_decl_node;
1775 self.parent_decl_node = extra.data.src_node;
1776 defer self.parent_decl_node = prev_parent_decl_node;
1777
1777 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{1778 const fields_hash: std.zig.SrcHash = @bitCast([4]u32{
1778 extra.data.fields_hash_0,1779 extra.data.fields_hash_0,
1779 extra.data.fields_hash_1,1780 extra.data.fields_hash_1,
...@@ -1835,10 +1836,6 @@ const Writer = struct {...@@ -1835,10 +1836,6 @@ const Writer = struct {
1835 if (decls_len == 0) {1836 if (decls_len == 0) {
1836 try stream.writeAll("{}, ");1837 try stream.writeAll("{}, ");
1837 } else {1838 } else {
1838 const prev_parent_decl_node = self.parent_decl_node;
1839 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1840 defer self.parent_decl_node = prev_parent_decl_node;
1841
1842 try stream.writeAll("{\n");1839 try stream.writeAll("{\n");
1843 self.indent += 2;1840 self.indent += 2;
1844 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1841 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1856,12 +1853,9 @@ const Writer = struct {...@@ -1856,12 +1853,9 @@ const Writer = struct {
1856 const body = self.code.bodySlice(extra_index, body_len);1853 const body = self.code.bodySlice(extra_index, body_len);
1857 extra_index += body.len;1854 extra_index += body.len;
18581855
1859 const prev_parent_decl_node = self.parent_decl_node;
1860 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1861 try self.writeBracedDecl(stream, body);1856 try self.writeBracedDecl(stream, body);
1862 if (fields_len == 0) {1857 if (fields_len == 0) {
1863 try stream.writeAll(", {})");1858 try stream.writeAll(", {})");
1864 self.parent_decl_node = prev_parent_decl_node;
1865 } else {1859 } else {
1866 try stream.writeAll(", {\n");1860 try stream.writeAll(", {\n");
18671861
...@@ -1900,12 +1894,11 @@ const Writer = struct {...@@ -1900,12 +1894,11 @@ const Writer = struct {
1900 }1894 }
1901 try stream.writeAll(",\n");1895 try stream.writeAll(",\n");
1902 }1896 }
1903 self.parent_decl_node = prev_parent_decl_node;
1904 self.indent -= 2;1897 self.indent -= 2;
1905 try stream.writeByteNTimes(' ', self.indent);1898 try stream.writeByteNTimes(' ', self.indent);
1906 try stream.writeAll("})");1899 try stream.writeAll("})");
1907 }1900 }
1908 try self.writeSrcNode(stream, extra.data.src_node);1901 try self.writeSrcNode(stream, 0);
1909 }1902 }
19101903
1911 fn writeOpaqueDecl(1904 fn writeOpaqueDecl(
...@@ -1915,6 +1908,11 @@ const Writer = struct {...@@ -1915,6 +1908,11 @@ const Writer = struct {
1915 ) !void {1908 ) !void {
1916 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));1909 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
1917 const extra = self.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);1910 const extra = self.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
1911
1912 const prev_parent_decl_node = self.parent_decl_node;
1913 self.parent_decl_node = extra.data.src_node;
1914 defer self.parent_decl_node = prev_parent_decl_node;
1915
1918 var extra_index: usize = extra.end;1916 var extra_index: usize = extra.end;
19191917
1920 const captures_len = if (small.has_captures_len) blk: {1918 const captures_len = if (small.has_captures_len) blk: {
...@@ -1948,10 +1946,6 @@ const Writer = struct {...@@ -1948,10 +1946,6 @@ const Writer = struct {
1948 if (decls_len == 0) {1946 if (decls_len == 0) {
1949 try stream.writeAll("{})");1947 try stream.writeAll("{})");
1950 } else {1948 } else {
1951 const prev_parent_decl_node = self.parent_decl_node;
1952 self.parent_decl_node = self.relativeToNodeIndex(extra.data.src_node);
1953 defer self.parent_decl_node = prev_parent_decl_node;
1954
1955 try stream.writeAll("{\n");1949 try stream.writeAll("{\n");
1956 self.indent += 2;1950 self.indent += 2;
1957 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1951 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
...@@ -1959,7 +1953,7 @@ const Writer = struct {...@@ -1959,7 +1953,7 @@ const Writer = struct {
1959 try stream.writeByteNTimes(' ', self.indent);1953 try stream.writeByteNTimes(' ', self.indent);
1960 try stream.writeAll("})");1954 try stream.writeAll("})");
1961 }1955 }
1962 try self.writeSrcNode(stream, extra.data.src_node);1956 try self.writeSrcNode(stream, 0);
1963 }1957 }
19641958
1965 fn writeErrorSetDecl(1959 fn writeErrorSetDecl(
...@@ -2729,11 +2723,16 @@ const Writer = struct {...@@ -2729,11 +2723,16 @@ const Writer = struct {
2729 }2723 }
27302724
2731 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2725 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2732 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2726 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].declaration;
2733 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);2727 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);
2734 const doc_comment: ?Zir.NullTerminatedString = if (extra.data.flags.has_doc_comment) dc: {2728 const doc_comment: ?Zir.NullTerminatedString = if (extra.data.flags.has_doc_comment) dc: {
2735 break :dc @enumFromInt(self.code.extra[extra.end]);2729 break :dc @enumFromInt(self.code.extra[extra.end]);
2736 } else null;2730 } else null;
2731
2732 const prev_parent_decl_node = self.parent_decl_node;
2733 defer self.parent_decl_node = prev_parent_decl_node;
2734 self.parent_decl_node = inst_data.src_node;
2735
2737 if (extra.data.flags.is_pub) try stream.writeAll("pub ");2736 if (extra.data.flags.is_pub) try stream.writeAll("pub ");
2738 if (extra.data.flags.is_export) try stream.writeAll("export ");2737 if (extra.data.flags.is_export) try stream.writeAll("export ");
2739 switch (extra.data.name) {2738 switch (extra.data.name) {
...@@ -2757,10 +2756,6 @@ const Writer = struct {...@@ -2757,10 +2756,6 @@ const Writer = struct {
2757 try stream.print(" line(+{d}) hash({})", .{ extra.data.line_offset, std.fmt.fmtSliceHexLower(&src_hash_bytes) });2756 try stream.print(" line(+{d}) hash({})", .{ extra.data.line_offset, std.fmt.fmtSliceHexLower(&src_hash_bytes) });
27582757
2759 {2758 {
2760 const prev_parent_decl_node = self.parent_decl_node;
2761 defer self.parent_decl_node = prev_parent_decl_node;
2762 self.parent_decl_node = self.relativeToNodeIndex(inst_data.src_node);
2763
2764 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);2759 const bodies = extra.data.getBodies(@intCast(extra.end), self.code);
27652760
2766 try stream.writeAll(" value=");2761 try stream.writeAll(" value=");
...@@ -2783,7 +2778,7 @@ const Writer = struct {...@@ -2783,7 +2778,7 @@ const Writer = struct {
2783 }2778 }
27842779
2785 try stream.writeAll(") ");2780 try stream.writeAll(") ");
2786 try self.writeSrc(stream, inst_data.src());2781 try self.writeSrcNode(stream, 0);
2787 }2782 }
27882783
2789 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2784 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {