From 4e35329313425266af3e2e27f8fcd258201c8d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 24 Feb 2026 22:34:46 +0000 Subject: [PATCH] sema: use InternPool index for __anon_ suffix (match upstream naming) Change the generic monomorphization naming from func_inst (ZIR instruction index) to func_val_ip (InternPool index), matching upstream's finishFuncInstance which uses @intFromEnum(func_index). Pass the func_val_ip through analyzeFuncBodyAndRecord and store it in SemaFuncAir.func_ip. The anon suffix now uses the same numbering scheme as upstream, though the actual numbers still differ because the C and Zig InternPools intern values in different order. Co-Authored-By: Claude Opus 4.6 (1M context) --- stage0/sema.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/stage0/sema.c b/stage0/sema.c index 39e2632fb1..7474cbf431 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -472,7 +472,8 @@ static uint8_t analyzeBodyRuntimeBreak( static uint16_t floatBits(TypeIndex ty); static void analyzeFuncBodyAndRecord(Sema* sema, SemaBlock* block, uint32_t func_inst, uint32_t name_idx, const AirInstRef* call_args, - uint32_t call_args_len, const TypeIndex* call_arg_types); + uint32_t call_args_len, const TypeIndex* call_arg_types, + InternPoolIndex func_val_ip); // getParamBody: extract param body from a param_block ZIR instruction. // Ported from lib/std/zig/Zir.zig getParamBody. @@ -4609,7 +4610,7 @@ static AirInstRef zirCall( } analyzeFuncBodyAndRecord(sema, block, func_inst, body_name_idx, is_generic ? arg_refs : NULL, is_generic ? args_len : 0, - arg_types_ptr); + arg_types_ptr, func_val_ip); } // Clean up cross-module state. @@ -5087,7 +5088,8 @@ static AirInstRef zirCall( // (from zirCall). name_idx is a string_bytes index for the function name. static void analyzeFuncBodyAndRecord(Sema* sema, SemaBlock* block, uint32_t func_inst, uint32_t name_idx, const AirInstRef* call_args, - uint32_t call_args_len, const TypeIndex* call_arg_types) { + uint32_t call_args_len, const TypeIndex* call_arg_types, + InternPoolIndex func_val_ip) { if (!sema->func_air_list) return; FuncZirInfo fi = parseFuncZir(sema, func_inst); @@ -5393,15 +5395,15 @@ static void analyzeFuncBodyAndRecord(Sema* sema, SemaBlock* block, if (name_idx != 0) { const char* name_ptr = (const char*)&sema->code.string_bytes[name_idx]; if (call_args) { - // Generic monomorphization: "root.{name}__anon_{func_inst}" - // Matches upstream naming from finishFuncInstance. - // The exact number differs from Zig; comparison strips it. + // Generic monomorphization: "root.{name}__anon_{ip_index}" + // Ported from InternPool.zig finishFuncInstance: + // "{f}__anon_{d}" with @intFromEnum(func_index). size_t fqn_len = (size_t)snprintf( - NULL, 0, "root.%s__anon_%u", name_ptr, func_inst); + NULL, 0, "root.%s__anon_%u", name_ptr, func_val_ip); func_name = malloc(fqn_len + 1); if (func_name) snprintf(func_name, fqn_len + 1, "root.%s__anon_%u", name_ptr, - func_inst); + func_val_ip); } else { size_t name_len = strlen(name_ptr); size_t fqn_len = 5 + name_len; // "root." + name @@ -5426,7 +5428,7 @@ static void analyzeFuncBodyAndRecord(Sema* sema, SemaBlock* block, } SemaFuncAir* entry = &list->items[list->len++]; entry->name = func_name; - entry->func_ip = IP_INDEX_NONE; + entry->func_ip = func_val_ip; entry->air.inst_tags = sema->air_inst_tags; entry->air.inst_datas = sema->air_inst_datas; entry->air.inst_len = sema->air_inst_len; @@ -5476,7 +5478,7 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) { return; analyzeFuncBodyAndRecord( - sema, block, inst, sema->cur_decl_name, NULL, 0, NULL); + sema, block, inst, sema->cur_decl_name, NULL, 0, NULL, IP_INDEX_NONE); } // zirStructDecl: process struct_decl extended instruction.