zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d728da32f41e7aa72b0d4ee42b2c33fc78257214 (tree)
parent a86f23824a35c845019b5c3a168884cc5b84924a
Author: Motiejus <motiejus@jakstys.lt>
Date:   Sat,  7 Mar 2026 07:27:28 +0000

sema: add comptime folding to zirBoolNot

Fold bool_true → bool_false and bool_false → bool_true at comptime,
matching src/Sema.zig zirBoolNot behavior.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
Mstage0/sema.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/stage0/sema.c b/stage0/sema.c @@ -1030,10 +1030,14 @@ static AirInstRef zirBitNot(Sema* sema, SemaBlock* block, uint32_t inst) { // zirBoolNot: handle bool_not ZIR instruction. // Ported from src/Sema.zig zirBoolNot. -// Emits AIR_INST_NOT with type = bool. static AirInstRef zirBoolNot(Sema* sema, SemaBlock* block, uint32_t inst) { ZirInstRef operand_ref = sema->code.inst_datas[inst].un_node.operand; AirInstRef operand = resolveInst(sema, operand_ref); + // Comptime folding: flip bool constants. + if (operand == AIR_REF_FROM_IP(IP_INDEX_BOOL_TRUE)) + return AIR_REF_FROM_IP(IP_INDEX_BOOL_FALSE); + if (operand == AIR_REF_FROM_IP(IP_INDEX_BOOL_FALSE)) + return AIR_REF_FROM_IP(IP_INDEX_BOOL_TRUE); AirInstData data; memset(&data, 0, sizeof(data)); data.ty_op.ty_ref = AIR_REF_FROM_IP(IP_INDEX_BOOL_TYPE);