aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-07-29 11:18:48 +0100
committermlugg <mlugg@mlugg.co.uk>2025-07-29 15:52:19 +0100
commit0d482775cc58a086009e63b2dc288ed29904529e (patch)
tree125c49fcfeefe874f5d144e7683db7230797f238 /src/Sema.zig
parentd0bc5efba4979471f092a533c20ad04f9e730dec (diff)
downloadzig-0d482775cc58a086009e63b2dc288ed29904529e.tar.gz
zig-0d482775cc58a086009e63b2dc288ed29904529e.zip
Sema: don't rely on Liveness
We're currently experimenting with backends which effectively do their own liveness analysis, so this old trick of mine isn't necessarily valid anymore. However, we can fix that trivially: just make the "nop" instruction we jam into here have the right type. That way, the leftover field/element pointer instructions are perfectly valid, but still unused.
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 8200b2b234..ae7a50af3c 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -4113,14 +4113,13 @@ fn finishResolveComptimeKnownAllocPtr(
// We're almost done - we have the resolved comptime value. We just need to
// eliminate the now-dead runtime instructions.
- // We will rewrite the AIR to eliminate the alloc and all stores to it.
- // This will cause instructions deriving field pointers etc of the alloc to
- // become invalid, however, since we are removing all stores to those pointers,
- // they will be eliminated by Liveness before they reach codegen.
-
- // The specifics of this instruction aren't really important: we just want
- // Liveness to elide it.
- const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{ .ty = .u8_type, .operand = .zero_u8 } } };
+ // This instruction has type `alloc_ty`, meaning we can rewrite the `alloc` AIR instruction to
+ // this one to drop the side effect. We also need to rewrite the stores; we'll turn them to this
+ // too because it doesn't really matter what they become.
+ const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{
+ .ty = .fromIntern(alloc_ty.toIntern()),
+ .operand = .zero_usize,
+ } } };
sema.air_instructions.set(@intFromEnum(alloc_inst), nop_inst);
for (comptime_info.stores.items(.inst)) |store_inst| {