authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-27 19:22:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-28 04:30:27-04:00
log256ab68a97cb6a84278c78d93917ab5e8ae53209
treeb5838383e70b6c4c0e12a053def4f2af022ec68c
parent9ff9ea38ea2a7dc776bb2954d31109ec1c81d191

frontend: make Decl.zir_decl_index typed

This field had the wrong type. It's not a `Zir.Inst.Index`, it's actually a `Zir.OptionalExtraIndex`. Also, the former is currently aliased to `u32` while the latter is a nonexhaustive enum that gives us more type checking. This commit is preparation for making this field non-optional. Now it can be changed to `Zir.ExtraIndex` and then the compiler will point out all the places that the non-optional assumption is being violated.

5 files changed, 56 insertions(+), 42 deletions(-)

src/Autodoc.zig+9-9
...@@ -3925,7 +3925,7 @@ fn analyzeAllDecls(...@@ -3925,7 +3925,7 @@ fn analyzeAllDecls(
3925 {3925 {
3926 var it = original_it;3926 var it = original_it;
3927 while (it.next()) |d| {3927 while (it.next()) |d| {
3928 const decl_name_index = file.zir.extra[d.sub_index + 5];3928 const decl_name_index = file.zir.extra[@intFromEnum(d.sub_index) + 5];
3929 switch (decl_name_index) {3929 switch (decl_name_index) {
3930 0, 1, 2 => continue,3930 0, 1, 2 => continue,
3931 else => if (file.zir.string_bytes[decl_name_index] == 0) {3931 else => if (file.zir.string_bytes[decl_name_index] == 0) {
...@@ -3942,7 +3942,7 @@ fn analyzeAllDecls(...@@ -3942,7 +3942,7 @@ fn analyzeAllDecls(
3942 var it = original_it;3942 var it = original_it;
3943 var decl_indexes_slot = first_decl_indexes_slot;3943 var decl_indexes_slot = first_decl_indexes_slot;
3944 while (it.next()) |d| : (decl_indexes_slot += 1) {3944 while (it.next()) |d| : (decl_indexes_slot += 1) {
3945 const decl_name_index = file.zir.extra[d.sub_index + 5];3945 const decl_name_index = file.zir.extra[@intFromEnum(d.sub_index) + 5];
3946 switch (decl_name_index) {3946 switch (decl_name_index) {
3947 0 => {3947 0 => {
3948 const is_exported = @as(u1, @truncate(d.flags >> 1));3948 const is_exported = @as(u1, @truncate(d.flags >> 1));
...@@ -3969,7 +3969,7 @@ fn analyzeAllDecls(...@@ -3969,7 +3969,7 @@ fn analyzeAllDecls(
3969 // Third loop to analyze all remaining decls3969 // Third loop to analyze all remaining decls
3970 var it = original_it;3970 var it = original_it;
3971 while (it.next()) |d| {3971 while (it.next()) |d| {
3972 const decl_name_index = file.zir.extra[d.sub_index + 5];3972 const decl_name_index = file.zir.extra[@intFromEnum(d.sub_index) + 5];
3973 switch (decl_name_index) {3973 switch (decl_name_index) {
3974 0, 1 => continue, // skip over usingnamespace decls3974 0, 1 => continue, // skip over usingnamespace decls
3975 2 => continue, // skip decltests3975 2 => continue, // skip decltests
...@@ -3993,7 +3993,7 @@ fn analyzeAllDecls(...@@ -3993,7 +3993,7 @@ fn analyzeAllDecls(
3993 // Fourth loop to analyze decltests3993 // Fourth loop to analyze decltests
3994 it = original_it;3994 it = original_it;
3995 while (it.next()) |d| {3995 while (it.next()) |d| {
3996 const decl_name_index = file.zir.extra[d.sub_index + 5];3996 const decl_name_index = file.zir.extra[@intFromEnum(d.sub_index) + 5];
3997 switch (decl_name_index) {3997 switch (decl_name_index) {
3998 0, 1 => continue, // skip over usingnamespace decls3998 0, 1 => continue, // skip over usingnamespace decls
3999 2 => {},3999 2 => {},
...@@ -4028,7 +4028,7 @@ fn analyzeDecl(...@@ -4028,7 +4028,7 @@ fn analyzeDecl(
4028 const has_align = @as(u1, @truncate(d.flags >> 2)) != 0;4028 const has_align = @as(u1, @truncate(d.flags >> 2)) != 0;
4029 const has_section_or_addrspace = @as(u1, @truncate(d.flags >> 3)) != 0;4029 const has_section_or_addrspace = @as(u1, @truncate(d.flags >> 3)) != 0;
40304030
4031 var extra_index = d.sub_index;4031 var extra_index = @intFromEnum(d.sub_index);
4032 // const hash_u32s = file.zir.extra[extra_index..][0..4];4032 // const hash_u32s = file.zir.extra[extra_index..][0..4];
40334033
4034 extra_index += 4;4034 extra_index += 4;
...@@ -4158,8 +4158,8 @@ fn analyzeUsingnamespaceDecl(...@@ -4158,8 +4158,8 @@ fn analyzeUsingnamespaceDecl(
4158 const data = file.zir.instructions.items(.data);4158 const data = file.zir.instructions.items(.data);
41594159
4160 const is_pub = @as(u1, @truncate(d.flags)) != 0;4160 const is_pub = @as(u1, @truncate(d.flags)) != 0;
4161 const value_index = file.zir.extra[d.sub_index + 6];4161 const value_index = file.zir.extra[@intFromEnum(d.sub_index) + 6];
4162 const doc_comment_index = file.zir.extra[d.sub_index + 7];4162 const doc_comment_index = file.zir.extra[@intFromEnum(d.sub_index) + 7];
41634163
4164 // This is known to work because decl values are always block_inlines4164 // This is known to work because decl values are always block_inlines
4165 const value_pl_node = data[value_index].pl_node;4165 const value_pl_node = data[value_index].pl_node;
...@@ -4218,8 +4218,8 @@ fn analyzeDecltest(...@@ -4218,8 +4218,8 @@ fn analyzeDecltest(
4218) AutodocErrors!void {4218) AutodocErrors!void {
4219 const data = file.zir.instructions.items(.data);4219 const data = file.zir.instructions.items(.data);
42204220
4221 const value_index = file.zir.extra[d.sub_index + 6];4221 const value_index = file.zir.extra[@intFromEnum(d.sub_index) + 6];
4222 const decl_name_index = file.zir.extra[d.sub_index + 7];4222 const decl_name_index = file.zir.extra[@intFromEnum(d.sub_index) + 7];
42234223
4224 const value_pl_node = data[value_index].pl_node;4224 const value_pl_node = data[value_index].pl_node;
4225 const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src);4225 const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src);
src/Compilation.zig+1-1
...@@ -2267,7 +2267,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void...@@ -2267,7 +2267,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
2267 const decl = module.declPtr(decl_index);2267 const decl = module.declPtr(decl_index);
2268 assert(decl.deletion_flag);2268 assert(decl.deletion_flag);
2269 assert(decl.dependants.count() == 0);2269 assert(decl.dependants.count() == 0);
2270 assert(decl.zir_decl_index != 0);2270 assert(decl.zir_decl_index != .none);
22712271
2272 try module.clearDecl(decl_index, null);2272 try module.clearDecl(decl_index, null);
2273 }2273 }
src/Module.zig+26-27
...@@ -390,7 +390,7 @@ pub const Decl = struct {...@@ -390,7 +390,7 @@ pub const Decl = struct {
390 /// (the part that says "for every decls_len"). The first item at this index is390 /// (the part that says "for every decls_len"). The first item at this index is
391 /// the contents hash, followed by line, name, etc.391 /// the contents hash, followed by line, name, etc.
392 /// For anonymous decls and also the root Decl for a File, this is 0.392 /// For anonymous decls and also the root Decl for a File, this is 0.
393 zir_decl_index: Zir.Inst.Index,393 zir_decl_index: Zir.OptionalExtraIndex,
394394
395 /// Represents the "shallow" analysis status. For example, for decls that are functions,395 /// Represents the "shallow" analysis status. For example, for decls that are functions,
396 /// the function type is analyzed with this set to `in_progress`, however, the semantic396 /// the function type is analyzed with this set to `in_progress`, however, the semantic
...@@ -526,8 +526,8 @@ pub const Decl = struct {...@@ -526,8 +526,8 @@ pub const Decl = struct {
526 }526 }
527527
528 pub fn getNameZir(decl: Decl, zir: Zir) ?[:0]const u8 {528 pub fn getNameZir(decl: Decl, zir: Zir) ?[:0]const u8 {
529 assert(decl.zir_decl_index != 0);529 assert(decl.zir_decl_index != .none);
530 const name_index = zir.extra[decl.zir_decl_index + 5];530 const name_index = zir.extra[@intFromEnum(decl.zir_decl_index) + 5];
531 if (name_index <= 1) return null;531 if (name_index <= 1) return null;
532 return zir.nullTerminatedString(name_index);532 return zir.nullTerminatedString(name_index);
533 }533 }
...@@ -538,39 +538,39 @@ pub const Decl = struct {...@@ -538,39 +538,39 @@ pub const Decl = struct {
538 }538 }
539539
540 pub fn contentsHashZir(decl: Decl, zir: Zir) std.zig.SrcHash {540 pub fn contentsHashZir(decl: Decl, zir: Zir) std.zig.SrcHash {
541 assert(decl.zir_decl_index != 0);541 assert(decl.zir_decl_index != .none);
542 const hash_u32s = zir.extra[decl.zir_decl_index..][0..4];542 const hash_u32s = zir.extra[@intFromEnum(decl.zir_decl_index)..][0..4];
543 const contents_hash = @as(std.zig.SrcHash, @bitCast(hash_u32s.*));543 const contents_hash = @as(std.zig.SrcHash, @bitCast(hash_u32s.*));
544 return contents_hash;544 return contents_hash;
545 }545 }
546546
547 pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index {547 pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index {
548 assert(decl.zir_decl_index != 0);548 assert(decl.zir_decl_index != .none);
549 const zir = decl.getFileScope(mod).zir;549 const zir = decl.getFileScope(mod).zir;
550 return zir.extra[decl.zir_decl_index + 6];550 return zir.extra[@intFromEnum(decl.zir_decl_index) + 6];
551 }551 }
552552
553 pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref {553 pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
554 if (!decl.has_align) return .none;554 if (!decl.has_align) return .none;
555 assert(decl.zir_decl_index != 0);555 assert(decl.zir_decl_index != .none);
556 const zir = decl.getFileScope(mod).zir;556 const zir = decl.getFileScope(mod).zir;
557 return @as(Zir.Inst.Ref, @enumFromInt(zir.extra[decl.zir_decl_index + 8]));557 return @enumFromInt(zir.extra[@intFromEnum(decl.zir_decl_index) + 8]);
558 }558 }
559559
560 pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref {560 pub fn zirLinksectionRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
561 if (!decl.has_linksection_or_addrspace) return .none;561 if (!decl.has_linksection_or_addrspace) return .none;
562 assert(decl.zir_decl_index != 0);562 assert(decl.zir_decl_index != .none);
563 const zir = decl.getFileScope(mod).zir;563 const zir = decl.getFileScope(mod).zir;
564 const extra_index = decl.zir_decl_index + 8 + @intFromBool(decl.has_align);564 const extra_index = @intFromEnum(decl.zir_decl_index) + 8 + @intFromBool(decl.has_align);
565 return @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));565 return @enumFromInt(zir.extra[extra_index]);
566 }566 }
567567
568 pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref {568 pub fn zirAddrspaceRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
569 if (!decl.has_linksection_or_addrspace) return .none;569 if (!decl.has_linksection_or_addrspace) return .none;
570 assert(decl.zir_decl_index != 0);570 assert(decl.zir_decl_index != .none);
571 const zir = decl.getFileScope(mod).zir;571 const zir = decl.getFileScope(mod).zir;
572 const extra_index = decl.zir_decl_index + 8 + @intFromBool(decl.has_align) + 1;572 const extra_index = @intFromEnum(decl.zir_decl_index) + 8 + @intFromBool(decl.has_align) + 1;
573 return @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));573 return @enumFromInt(zir.extra[extra_index]);
574 }574 }
575575
576 pub fn relativeToLine(decl: Decl, offset: u32) u32 {576 pub fn relativeToLine(decl: Decl, offset: u32) u32 {
...@@ -578,7 +578,7 @@ pub const Decl = struct {...@@ -578,7 +578,7 @@ pub const Decl = struct {
578 }578 }
579579
580 pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {580 pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {
581 return @as(Ast.Node.Index, @bitCast(offset + @as(i32, @bitCast(decl.src_node))));581 return @bitCast(offset + @as(i32, @bitCast(decl.src_node)));
582 }582 }
583583
584 pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {584 pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {
...@@ -3051,7 +3051,7 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void {...@@ -3051,7 +3051,7 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void {
3051 defer inst_map.deinit(gpa);3051 defer inst_map.deinit(gpa);
3052 // Maps from old ZIR to new ZIR, the extra data index for the sub-decl item.3052 // Maps from old ZIR to new ZIR, the extra data index for the sub-decl item.
3053 // e.g. the thing that Decl.zir_decl_index points to.3053 // e.g. the thing that Decl.zir_decl_index points to.
3054 var extra_map: std.AutoHashMapUnmanaged(u32, u32) = .{};3054 var extra_map: std.AutoHashMapUnmanaged(Zir.ExtraIndex, Zir.ExtraIndex) = .{};
3055 defer extra_map.deinit(gpa);3055 defer extra_map.deinit(gpa);
30563056
3057 try mapOldZirToNew(gpa, old_zir, new_zir, &inst_map, &extra_map);3057 try mapOldZirToNew(gpa, old_zir, new_zir, &inst_map, &extra_map);
...@@ -3079,14 +3079,13 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void {...@@ -3079,14 +3079,13 @@ fn updateZirRefs(mod: *Module, file: *File, old_zir: Zir) !void {
3079 // to walk them but we do not need to modify this value.3079 // to walk them but we do not need to modify this value.
3080 // Anonymous decls should not be marked outdated. They will be re-generated3080 // Anonymous decls should not be marked outdated. They will be re-generated
3081 // if their owner decl is marked outdated.3081 // if their owner decl is marked outdated.
3082 if (decl.zir_decl_index != 0) {3082 if (decl.zir_decl_index.unwrap()) |old_zir_decl_index| {
3083 const old_zir_decl_index = decl.zir_decl_index;
3084 const new_zir_decl_index = extra_map.get(old_zir_decl_index) orelse {3083 const new_zir_decl_index = extra_map.get(old_zir_decl_index) orelse {
3085 try file.deleted_decls.append(gpa, decl_index);3084 try file.deleted_decls.append(gpa, decl_index);
3086 continue;3085 continue;
3087 };3086 };
3088 const old_hash = decl.contentsHashZir(old_zir);3087 const old_hash = decl.contentsHashZir(old_zir);
3089 decl.zir_decl_index = new_zir_decl_index;3088 decl.zir_decl_index = new_zir_decl_index.toOptional();
3090 const new_hash = decl.contentsHashZir(new_zir);3089 const new_hash = decl.contentsHashZir(new_zir);
3091 if (!std.zig.srcHashEql(old_hash, new_hash)) {3090 if (!std.zig.srcHashEql(old_hash, new_hash)) {
3092 try file.outdated_decls.append(gpa, decl_index);3091 try file.outdated_decls.append(gpa, decl_index);
...@@ -3195,7 +3194,7 @@ pub fn mapOldZirToNew(...@@ -3195,7 +3194,7 @@ pub fn mapOldZirToNew(
3195 old_zir: Zir,3194 old_zir: Zir,
3196 new_zir: Zir,3195 new_zir: Zir,
3197 inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index),3196 inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index),
3198 extra_map: *std.AutoHashMapUnmanaged(u32, u32),3197 extra_map: *std.AutoHashMapUnmanaged(Zir.ExtraIndex, Zir.ExtraIndex),
3199) Allocator.Error!void {3198) Allocator.Error!void {
3200 // Contain ZIR indexes of declaration instructions.3199 // Contain ZIR indexes of declaration instructions.
3201 const MatchedZirDecl = struct {3200 const MatchedZirDecl = struct {
...@@ -3220,7 +3219,7 @@ pub fn mapOldZirToNew(...@@ -3220,7 +3219,7 @@ pub fn mapOldZirToNew(
3220 try inst_map.put(gpa, match_item.old_inst, match_item.new_inst);3219 try inst_map.put(gpa, match_item.old_inst, match_item.new_inst);
32213220
3222 // Maps name to extra index of decl sub item.3221 // Maps name to extra index of decl sub item.
3223 var decl_map: std.StringHashMapUnmanaged(u32) = .{};3222 var decl_map: std.StringHashMapUnmanaged(Zir.ExtraIndex) = .{};
3224 defer decl_map.deinit(gpa);3223 defer decl_map.deinit(gpa);
32253224
3226 {3225 {
...@@ -3301,7 +3300,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3301,7 +3300,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3301 defer decl_prog_node.end();3300 defer decl_prog_node.end();
33023301
3303 const type_changed = blk: {3302 const type_changed = blk: {
3304 if (decl.zir_decl_index == 0 and !mod.declIsRoot(decl_index)) {3303 if (decl.zir_decl_index == .none and !mod.declIsRoot(decl_index)) {
3305 // Anonymous decl. We don't semantically analyze these.3304 // Anonymous decl. We don't semantically analyze these.
3306 break :blk false; // tv unchanged3305 break :blk false; // tv unchanged
3307 }3306 }
...@@ -4451,7 +4450,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -4451,7 +4450,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
4451 new_decl.is_exported = is_exported;4450 new_decl.is_exported = is_exported;
4452 new_decl.has_align = has_align;4451 new_decl.has_align = has_align;
4453 new_decl.has_linksection_or_addrspace = has_linksection_or_addrspace;4452 new_decl.has_linksection_or_addrspace = has_linksection_or_addrspace;
4454 new_decl.zir_decl_index = @as(u32, @intCast(decl_sub_index));4453 new_decl.zir_decl_index = @enumFromInt(decl_sub_index);
4455 new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive.4454 new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive.
4456 return;4455 return;
4457 }4456 }
...@@ -4485,7 +4484,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -4485,7 +4484,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
4485 decl.kind = kind;4484 decl.kind = kind;
4486 decl.has_align = has_align;4485 decl.has_align = has_align;
4487 decl.has_linksection_or_addrspace = has_linksection_or_addrspace;4486 decl.has_linksection_or_addrspace = has_linksection_or_addrspace;
4488 decl.zir_decl_index = @as(u32, @intCast(decl_sub_index));4487 decl.zir_decl_index = @enumFromInt(decl_sub_index);
4489 if (decl.getOwnedFunction(mod) != null) {4488 if (decl.getOwnedFunction(mod) != null) {
4490 switch (comp.bin_file.tag) {4489 switch (comp.bin_file.tag) {
4491 .coff, .elf, .macho, .plan9 => {4490 .coff, .elf, .macho, .plan9 => {
...@@ -4982,7 +4981,7 @@ pub fn allocateNewDecl(...@@ -4982,7 +4981,7 @@ pub fn allocateNewDecl(
4982 .@"addrspace" = .generic,4981 .@"addrspace" = .generic,
4983 .analysis = .unreferenced,4982 .analysis = .unreferenced,
4984 .deletion_flag = false,4983 .deletion_flag = false,
4985 .zir_decl_index = 0,4984 .zir_decl_index = .none,
4986 .src_scope = src_scope,4985 .src_scope = src_scope,
4987 .generation = 0,4986 .generation = 0,
4988 .is_pub = false,4987 .is_pub = false,
...@@ -5507,7 +5506,7 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {...@@ -5507,7 +5506,7 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {
5507 const decl = mod.declPtr(decl_index);5506 const decl = mod.declPtr(decl_index);
55085507
5509 // Remove from the namespace it resides in, preserving declaration order.5508 // Remove from the namespace it resides in, preserving declaration order.
5510 assert(decl.zir_decl_index != 0);5509 assert(decl.zir_decl_index != .none);
5511 _ = mod.namespacePtr(decl.src_namespace).decls.orderedRemoveAdapted(5510 _ = mod.namespacePtr(decl.src_namespace).decls.orderedRemoveAdapted(
5512 decl.name,5511 decl.name,
5513 DeclAdapter{ .mod = mod },5512 DeclAdapter{ .mod = mod },
src/Zir.zig+19-4
...@@ -63,6 +63,21 @@ pub const ExtraIndex = enum(u32) {...@@ -63,6 +63,21 @@ pub const ExtraIndex = enum(u32) {
63 imports,63 imports,
6464
65 _,65 _,
66
67 pub fn toOptional(i: ExtraIndex) OptionalExtraIndex {
68 return @enumFromInt(@intFromEnum(i));
69 }
70};
71
72pub const OptionalExtraIndex = enum(u32) {
73 compile_errors,
74 imports,
75 none = std.math.maxInt(u32),
76 _,
77
78 pub fn unwrap(oi: OptionalExtraIndex) ?ExtraIndex {
79 return if (oi == .none) null else @enumFromInt(@intFromEnum(oi));
80 }
66};81};
6782
68fn ExtraData(comptime T: type) type {83fn ExtraData(comptime T: type) type {
...@@ -3325,7 +3340,7 @@ pub const DeclIterator = struct {...@@ -3325,7 +3340,7 @@ pub const DeclIterator = struct {
33253340
3326 pub const Item = struct {3341 pub const Item = struct {
3327 name: [:0]const u8,3342 name: [:0]const u8,
3328 sub_index: u32,3343 sub_index: ExtraIndex,
3329 flags: u4,3344 flags: u4,
3330 };3345 };
33313346
...@@ -3341,7 +3356,7 @@ pub const DeclIterator = struct {...@@ -3341,7 +3356,7 @@ pub const DeclIterator = struct {
3341 const flags: u4 = @truncate(it.cur_bit_bag);3356 const flags: u4 = @truncate(it.cur_bit_bag);
3342 it.cur_bit_bag >>= 4;3357 it.cur_bit_bag >>= 4;
33433358
3344 const sub_index: u32 = @intCast(it.extra_index);3359 const sub_index: ExtraIndex = @enumFromInt(it.extra_index);
3345 it.extra_index += 5; // src_hash(4) + line(1)3360 it.extra_index += 5; // src_hash(4) + line(1)
3346 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);3361 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);
3347 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)3362 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)
...@@ -3453,8 +3468,8 @@ pub fn declIteratorInner(zir: Zir, extra_index: usize, decls_len: u32) DeclItera...@@ -3453,8 +3468,8 @@ pub fn declIteratorInner(zir: Zir, extra_index: usize, decls_len: u32) DeclItera
34533468
3454/// The iterator would have to allocate memory anyway to iterate. So here we populate3469/// The iterator would have to allocate memory anyway to iterate. So here we populate
3455/// an ArrayList as the result.3470/// an ArrayList as the result.
3456pub fn findDecls(zir: Zir, list: *std.ArrayList(Inst.Index), decl_sub_index: u32) !void {3471pub fn findDecls(zir: Zir, list: *std.ArrayList(Inst.Index), decl_sub_index: ExtraIndex) !void {
3457 const block_inst = zir.extra[decl_sub_index + 6];3472 const block_inst = zir.extra[@intFromEnum(decl_sub_index) + 6];
3458 list.clearRetainingCapacity();3473 list.clearRetainingCapacity();
34593474
3460 return zir.findDeclsInner(list, block_inst);3475 return zir.findDeclsInner(list, block_inst);
src/main.zig+1-1
...@@ -6632,7 +6632,7 @@ pub fn cmdChangelist(...@@ -6632,7 +6632,7 @@ pub fn cmdChangelist(
6632 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{};6632 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{};
6633 defer inst_map.deinit(gpa);6633 defer inst_map.deinit(gpa);
66346634
6635 var extra_map: std.AutoHashMapUnmanaged(u32, u32) = .{};6635 var extra_map: std.AutoHashMapUnmanaged(Zir.ExtraIndex, Zir.ExtraIndex) = .{};
6636 defer extra_map.deinit(gpa);6636 defer extra_map.deinit(gpa);
66376637
6638 try Module.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map, &extra_map);6638 try Module.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map, &extra_map);