| ... | @@ -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 is | 390 | /// (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, |
| 394 | | 394 | |
| 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 semantic | 396 | /// 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 | } |
| 527 | | 527 | |
| 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 | } |
| 539 | | 539 | |
| 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 | } |
| 546 | | 546 | |
| 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 | } |
| 552 | | 552 | |
| 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 | } |
| 559 | | 559 | |
| 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 | } |
| 567 | | 567 | |
| 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 | } |
| 575 | | 575 | |
| 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 | } |
| 579 | | 579 | |
| 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 | } |
| 583 | | 583 | |
| 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); |
| 3056 | | 3056 | |
| 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-generated | 3080 | // 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); |
| 3221 | | 3220 | |
| 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); |
| 3225 | | 3224 | |
| 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(); |
| 3302 | | 3301 | |
| 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 unchanged | 3305 | 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); |
| 5508 | | 5507 | |
| 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 }, |