commit 4f3930dbe27b40ef42bb327482d7f0283f8b331b (tree)
parent 09e20ee1bb9655b3694dbc3930015c7cc2b42a37
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Fri, 20 Feb 2026 21:09:37 +0000
sema: resolve type refs through resolveInst instead of asserting pre-interned
Replace all remaining assert(ref < ZIR_REF_START_INDEX) patterns with
resolveInst + AIR_REF_TO_IP. This handles cases where type refs come
from instruction results (e.g. typeof_log2_int, type-returning generics)
rather than being pre-interned type literals.
Fixes: resolveFuncRetType single-instruction return type body,
param type body break_inline operand, and ptr_type element type refs
in both return type and param type paths.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/stage0/sema.c b/stage0/sema.c
@@ -1952,8 +1952,9 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
} else if (ret_ty_body_len == 1) {
ZirInstRef ret_ty_ref = sema->code.extra[ret_ty_ref_pos];
// For pre-interned refs, the ZIR ref == IP index.
- assert(ret_ty_ref < ZIR_REF_START_INDEX);
- sema->fn_ret_ty = ret_ty_ref;
+ // For inst refs, resolve through inst_map.
+ AirInstRef ret_air = resolveInst(sema, ret_ty_ref);
+ sema->fn_ret_ty = AIR_REF_TO_IP(ret_air);
} else if (ret_ty_body_len == 2) {
// Two-instruction return type body: [ptr_type, break_inline].
uint32_t ret_body_start = ret_ty_ref_pos; // set by both func and func_fancy paths
@@ -1967,8 +1968,8 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
uint32_t pi
= sema->code.inst_datas[first_inst].ptr_type.payload_index;
ZirInstRef elem_ty_ref = sema->code.extra[pi];
- assert(elem_ty_ref < ZIR_REF_START_INDEX);
- TypeIndex elem_ty = elem_ty_ref;
+ AirInstRef elem_air = resolveInst(sema, elem_ty_ref);
+ TypeIndex elem_ty = AIR_REF_TO_IP(elem_air);
uint32_t ip_flags = (uint32_t)zir_size & PTR_FLAGS_SIZE_MASK;
if (!(zir_flags & 0x02))
ip_flags |= PTR_FLAGS_IS_CONST;
@@ -2045,8 +2046,8 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
assert(type_tag == ZIR_INST_BREAK_INLINE);
ZirInstRef type_ref
= sema->code.inst_datas[type_inst].break_data.operand;
- assert(type_ref < ZIR_REF_START_INDEX); // pre-interned
- param_ty = type_ref;
+ AirInstRef type_air = resolveInst(sema, type_ref);
+ param_ty = AIR_REF_TO_IP(type_air);
} else if (type_body_len_p == 2) {
uint32_t first_inst = sema->code.extra[param_payload + 2];
ZirInstTag first_tag = sema->code.inst_tags[first_inst];
@@ -2059,8 +2060,8 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
uint32_t pi
= sema->code.inst_datas[first_inst].ptr_type.payload_index;
ZirInstRef elem_ty_ref = sema->code.extra[pi]; // PtrType.elem_type
- assert(elem_ty_ref < ZIR_REF_START_INDEX); // pre-interned
- TypeIndex elem_ty = elem_ty_ref;
+ AirInstRef elem_air = resolveInst(sema, elem_ty_ref);
+ TypeIndex elem_ty = AIR_REF_TO_IP(elem_air);
// Build IP PtrType key.
uint32_t ip_flags = (uint32_t)zir_size & PTR_FLAGS_SIZE_MASK;
if (!(zir_flags & 0x02)) // ZIR bit 1 = is_mutable; !is_mutable → const