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>
This commit is contained in:
2026-03-07 07:27:28 +00:00
parent a86f23824a
commit d728da32f4

View File

@@ -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);