aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-06-18 04:41:02 +0100
committermlugg <mlugg@mlugg.co.uk>2024-06-18 04:48:24 +0100
commit0486aa5081eee589edce79b721f35fadf2de1625 (patch)
tree6d27bacdf27943c6c2e0edbc24243dd7f0cf769b /src
parentedf14777bae56c3a6a155c59f793dc432656c1de (diff)
downloadzig-0486aa5081eee589edce79b721f35fadf2de1625.tar.gz
zig-0486aa5081eee589edce79b721f35fadf2de1625.zip
Zir: provide absolute node for `reify`
Since we track `reify` instructions across incremental updates, it is acceptable to treat it as the baseline for a relative source location. This turns out to be a good idea, since it makes it easy to define the source location for a reified type.
Diffstat (limited to 'src')
-rw-r--r--src/Module.zig1
-rw-r--r--src/Sema.zig16
-rw-r--r--src/print_zir.zig5
-rw-r--r--src/type.zig19
4 files changed, 23 insertions, 18 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 31b022fd37..3faa1b8780 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -2374,6 +2374,7 @@ pub const LazySrcLoc = struct {
.union_decl => zir.extraData(Zir.Inst.UnionDecl, inst.data.extended.operand).data.src_node,
.enum_decl => zir.extraData(Zir.Inst.EnumDecl, inst.data.extended.operand).data.src_node,
.opaque_decl => zir.extraData(Zir.Inst.OpaqueDecl, inst.data.extended.operand).data.src_node,
+ .reify => zir.extraData(Zir.Inst.Reify, inst.data.extended.operand).data.node,
else => unreachable,
},
else => unreachable,
diff --git a/src/Sema.zig b/src/Sema.zig
index 6714af7685..c34004e200 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -21210,10 +21210,22 @@ fn zirReify(
const ip = &mod.intern_pool;
const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
- const src = block.nodeOffset(extra.node);
+ const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
+ const src: LazySrcLoc = .{
+ .base_node_inst = tracked_inst,
+ .offset = LazySrcLoc.Offset.nodeOffset(0),
+ };
+ const operand_src: LazySrcLoc = .{
+ .base_node_inst = tracked_inst,
+ .offset = .{
+ .node_offset_builtin_call_arg = .{
+ .builtin_call_node = 0, // `tracked_inst` is precisely the `reify` instruction, so offset is 0
+ .arg_index = 0,
+ },
+ },
+ };
const type_info_ty = try sema.getBuiltinType("Type");
const uncasted_operand = try sema.resolveInst(extra.operand);
- const operand_src = block.builtinCallArgSrc(extra.node, 0);
const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
.needed_comptime_reason = "operand to @Type must be comptime-known",
diff --git a/src/print_zir.zig b/src/print_zir.zig
index 0e2fe17736..b32ea5ffe9 100644
--- a/src/print_zir.zig
+++ b/src/print_zir.zig
@@ -586,7 +586,10 @@ const Writer = struct {
try stream.print("{d}, ", .{inst_data.src_line});
try self.writeInstRef(stream, inst_data.operand);
try stream.writeAll(")) ");
- try self.writeSrcNode(stream, inst_data.node);
+ const prev_parent_decl_node = self.parent_decl_node;
+ self.parent_decl_node = inst_data.node;
+ defer self.parent_decl_node = prev_parent_decl_node;
+ try self.writeSrcNode(stream, 0);
},
.builtin_extern,
diff --git a/src/type.zig b/src/type.zig
index 546234db37..215320ad79 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3336,22 +3336,11 @@ pub const Type = struct {
const ip = &zcu.intern_pool;
return .{
.base_node_inst = switch (ip.indexToKey(ty.toIntern())) {
- .struct_type => |info| switch (info) {
- .declared => ip.loadStructType(ty.toIntern()).zir_index.unwrap() orelse return null,
- else => return null,
- },
- .union_type => |info| switch (info) {
- .declared => ip.loadUnionType(ty.toIntern()).zir_index,
- else => return null,
- },
- .opaque_type => |info| switch (info) {
- .declared => ip.loadOpaqueType(ty.toIntern()).zir_index,
- else => return null,
- },
- .enum_type => |info| switch (info) {
- .declared => ip.loadEnumType(ty.toIntern()).zir_index.unwrap().?,
+ .struct_type, .union_type, .opaque_type, .enum_type => |info| switch (info) {
+ .declared => |d| d.zir_index,
+ .reified => |r| r.zir_index,
.generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index, // must be declared since we can't generate tags when reifying
- else => return null,
+ .empty_struct => return null,
},
else => return null,
},