diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-06-10 01:22:54 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-06-15 00:57:52 +0100 |
| commit | e39cc0dff7fff510c3d72f61947b977589ea5583 (patch) | |
| tree | 5d7c405520d5c898c46a517820bd331526b7852d /src/Module.zig | |
| parent | 82a934bb912241809ac8029e1fa5843092a7fdf6 (diff) | |
| download | zig-e39cc0dff7fff510c3d72f61947b977589ea5583.tar.gz zig-e39cc0dff7fff510c3d72f61947b977589ea5583.zip | |
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`.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/Module.zig b/src/Module.zig index ef410fad4e..83406c36a4 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -413,8 +413,8 @@ pub const Decl = struct { pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies { const zir = decl.getFileScope(zcu).zir; const zir_index = decl.zir_decl_index.unwrap().?.resolve(&zcu.intern_pool); - const pl_node = zir.instructions.items(.data)[@intFromEnum(zir_index)].pl_node; - const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index); + const declaration = zir.instructions.items(.data)[@intFromEnum(zir_index)].declaration; + const extra = zir.extraData(Zir.Inst.Declaration, declaration.payload_index); return extra.data.getBodies(@intCast(extra.end), zir); } @@ -4255,12 +4255,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void const zir = namespace.file_scope.zir; const ip = &zcu.intern_pool; - const pl_node = zir.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node; - const extra = zir.extraData(Zir.Inst.Declaration, pl_node.payload_index); + const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration; + const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index); const declaration = extra.data; const line = iter.parent_decl.src_line + declaration.line_offset; - const decl_node = iter.parent_decl.relativeToNodeIndex(pl_node.src_node); // Every Decl needs a name. 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 const was_exported = decl.is_exported; assert(decl.kind == kind); // ZIR tracking should preserve this decl.name = decl_name; - decl.src_node = decl_node; + decl.src_node = inst_data.src_node; decl.src_line = line; decl.is_pub = declaration.flags.is_pub; decl.is_exported = declaration.flags.is_export; break :decl_index .{ was_exported, decl_index }; } else decl_index: { // Create and set up a new Decl. - const new_decl_index = try zcu.allocateNewDecl(namespace_index, decl_node); + const new_decl_index = try zcu.allocateNewDecl(namespace_index, inst_data.src_node); const new_decl = zcu.declPtr(new_decl_index); new_decl.kind = kind; new_decl.name = decl_name; |
