authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-07-29 11:18:48+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-07-29 15:52:19+01:00
log0d482775cc58a086009e63b2dc288ed29904529e
tree125c49fcfeefe874f5d144e7683db7230797f238
parentd0bc5efba4979471f092a533c20ad04f9e730dec
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 7 insertions(+), 8 deletions(-)

src/Sema.zig+7-8
......@@ -4113,14 +4113,13 @@ fn finishResolveComptimeKnownAllocPtr(
41134113 // We're almost done - we have the resolved comptime value. We just need to
41144114 // eliminate the now-dead runtime instructions.
41154115
4116 // We will rewrite the AIR to eliminate the alloc and all stores to it.
4117 // This will cause instructions deriving field pointers etc of the alloc to
4118 // become invalid, however, since we are removing all stores to those pointers,
4119 // they will be eliminated by Liveness before they reach codegen.
4120
4121 // The specifics of this instruction aren't really important: we just want
4122 // Liveness to elide it.
4123 const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{ .ty = .u8_type, .operand = .zero_u8 } } };
4116 // This instruction has type `alloc_ty`, meaning we can rewrite the `alloc` AIR instruction to
4117 // this one to drop the side effect. We also need to rewrite the stores; we'll turn them to this
4118 // too because it doesn't really matter what they become.
4119 const nop_inst: Air.Inst = .{ .tag = .bitcast, .data = .{ .ty_op = .{
4120 .ty = .fromIntern(alloc_ty.toIntern()),
4121 .operand = .zero_usize,
4122 } } };
41244123
41254124 sema.air_instructions.set(@intFromEnum(alloc_inst), nop_inst);
41264125 for (comptime_info.stores.items(.inst)) |store_inst| {