| ... | ... | @@ -362,7 +362,7 @@ pub const Decl = struct { |
| 362 | 362 | src_line: u32, |
| 363 | 363 | /// Index of the ZIR `declaration` instruction from which this `Decl` was created. |
| 364 | 364 | /// For the root `Decl` of a `File` and legacy anonymous decls, this is `.none`. |
| 365 | | zir_decl_index: Zir.Inst.OptionalIndex, |
| 365 | zir_decl_index: InternPool.TrackedInst.Index.Optional, |
| 366 | 366 | |
| 367 | 367 | /// Represents the "shallow" analysis status. For example, for decls that are functions, |
| 368 | 368 | /// the function type is analyzed with this set to `in_progress`, however, the semantic |
| ... | ... | @@ -428,16 +428,9 @@ pub const Decl = struct { |
| 428 | 428 | const Index = InternPool.DeclIndex; |
| 429 | 429 | const OptionalIndex = InternPool.OptionalDeclIndex; |
| 430 | 430 | |
| 431 | | /// Asserts that `zir_decl_index` is not `.none`. |
| 432 | | fn getDeclaration(decl: Decl, zir: Zir) Zir.Inst.Declaration { |
| 433 | | const zir_index = decl.zir_decl_index.unwrap().?; |
| 434 | | const pl_node = zir.instructions.items(.data)[@intFromEnum(zir_index)].pl_node; |
| 435 | | return zir.extraData(Zir.Inst.Declaration, pl_node.payload_index).data; |
| 436 | | } |
| 437 | | |
| 438 | 431 | pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies { |
| 439 | 432 | const zir = decl.getFileScope(zcu).zir; |
| 440 | | const zir_index = decl.zir_decl_index.unwrap().?; |
| 433 | const zir_index = decl.zir_decl_index.unwrap().?.resolve(&zcu.intern_pool); |
| 441 | 434 | const pl_node = zir.instructions.items(.data)[@intFromEnum(zir_index)].pl_node; |
| 442 | 435 | const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index); |
| 443 | 436 | return extra.data.getBodies(@intCast(extra.end), zir); |
| ... | ... | @@ -3471,7 +3464,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3471 | 3464 | @panic("TODO: update owner Decl"); |
| 3472 | 3465 | } |
| 3473 | 3466 | |
| 3474 | | const decl_inst = decl.zir_decl_index.unwrap().?; |
| 3467 | const decl_inst = decl.zir_decl_index.unwrap().?.resolve(ip); |
| 3475 | 3468 | |
| 3476 | 3469 | const gpa = mod.gpa; |
| 3477 | 3470 | const zir = decl.getFileScope(mod).zir; |
| ... | ... | @@ -4231,6 +4224,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4231 | 4224 | |
| 4232 | 4225 | if (kind == .@"usingnamespace") try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1); |
| 4233 | 4226 | |
| 4227 | const tracked_inst = try ip.trackZir(gpa, iter.parent_decl.getFileScope(zcu), decl_inst); |
| 4228 | |
| 4234 | 4229 | // We create a Decl for it regardless of analysis status. |
| 4235 | 4230 | const gop = try namespace.decls.getOrPutContextAdapted( |
| 4236 | 4231 | gpa, |
| ... | ... | @@ -4277,7 +4272,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4277 | 4272 | } |
| 4278 | 4273 | new_decl.is_pub = declaration.flags.is_pub; |
| 4279 | 4274 | new_decl.is_exported = declaration.flags.is_export; |
| 4280 | | new_decl.zir_decl_index = decl_inst.toOptional(); |
| 4275 | new_decl.zir_decl_index = tracked_inst.toOptional(); |
| 4281 | 4276 | new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive. |
| 4282 | 4277 | return; |
| 4283 | 4278 | } |
| ... | ... | @@ -4291,7 +4286,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4291 | 4286 | decl.is_pub = declaration.flags.is_pub; |
| 4292 | 4287 | decl.is_exported = declaration.flags.is_export; |
| 4293 | 4288 | decl.kind = kind; |
| 4294 | | decl.zir_decl_index = decl_inst.toOptional(); |
| 4289 | decl.zir_decl_index = tracked_inst.toOptional(); |
| 4295 | 4290 | if (decl.getOwnedFunction(zcu) != null) { |
| 4296 | 4291 | // TODO Look into detecting when this would be unnecessary by storing enough state |
| 4297 | 4292 | // in `Decl` to notice that the line number did not change. |