From a8bdfd6507b0e3510d5f9a8f6760616e3216eae1 Mon Sep 17 00:00:00 2001 From: Motiejus Date: Sun, 8 Mar 2026 07:03:40 +0000 Subject: [PATCH] sema: replace TODO silent fallbacks with UNIMPLEMENTED - zirBuiltinValue: unhandled builtin_value kinds now crash with UNIMPLEMENTED instead of silently returning VOID_VALUE - zirModRem: detect signed integer types and fail with UNIMPLEMENTED instead of silently treating as @rem Convention: never use "TODO ... return VOID_VALUE". Handle known cases explicitly, UNIMPLEMENTED for the rest. Co-Authored-By: Claude Opus 4.6 --- stage0/sema.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/stage0/sema.c b/stage0/sema.c index 7651e0f8d2..88fcf62000 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -2471,9 +2471,18 @@ static AirInstRef zirRem(Sema* sema, SemaBlock* block, uint32_t inst) { // zirModRem: handle plain '%' operator (may be mod or rem depending on types). // Ported from src/Sema.zig zirModRem. static AirInstRef zirModRem(Sema* sema, SemaBlock* block, uint32_t inst) { - // Ported from Sema.zig zirModRem: for unsigned types, same as @rem. - // Signed types would need distinct handling (mod vs rem ambiguity). - // TODO: check signedness and UNIMPLEMENTED for signed types. + // Ported from Sema.zig zirModRem: for unsigned integers, '%' is + // equivalent to @rem. For signed integers, '%' is @mod which + // needs distinct handling (not yet ported). + uint32_t payload_index = sema->code.inst_datas[inst].pl_node.payload_index; + AirInstRef lhs = resolveInst(sema, sema->code.extra[payload_index]); + TypeIndex lhs_ty = semaTypeOf(sema, lhs); + if (lhs_ty != IP_INDEX_COMPTIME_INT_TYPE + && sema->ip->items[lhs_ty].tag == IP_KEY_INT_TYPE) { + InternPoolKey k = ipIndexToKey(sema->ip, lhs_ty); + if (k.data.int_type.signedness == 1) + UNIMPLEMENTED("zirModRem: signed integer mod"); + } return zirRem(sema, block, inst); } @@ -11324,8 +11333,8 @@ static AirInstRef zirExtended(Sema* sema, SemaBlock* block, uint32_t inst) { } } } - // TODO: implement remaining builtin_value kinds - return AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE); + UNIMPLEMENTED("zirBuiltinValue: unimplemented builtin_value kind"); + return AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE); // unreachable } UNIMPLEMENTED("zirExtended: unimplemented extended opcode"); return AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE); // unreachable