zig

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

commit 0382b80680570dcf8510daaf7ad93a99001088cd (tree)
parent e7f63fa4920783b8d9e835b52e36ab6078d80fd4
Author: Motiejus <motiejus@jakstys.lt>
Date:   Sat, 28 Feb 2026 03:58:02 +0000

sema: fix Log2Int func_type dedup to eliminate 2 extra IP entries

The Log2Int generic function in std.math was creating a func_type
with return_type=generic_poison, which didn't match any existing
func_type entry. Changed to return_type=type (matching what
analyzeNavValC creates) so ipIntern deduplicates with the existing
entry. This eliminates 2 extra entries (func_type + ptr_type) that
were shifting all subsequent IP indices by +2.

Reduces IP gap for neghf2.zig (corpus test #4) from 29 to 35
(paradoxically larger gap number because the 2 extra entries were
partially compensating for missing entries, but the entries are now
correctly positioned).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Diffstat:
Mstage0/sema.c | 20+++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/stage0/sema.c b/stage0/sema.c @@ -6625,19 +6625,13 @@ static void triggerArchModuleCascade( uint32_t log2int_nav = findNavInNamespace(math_ns, "Log2Int"); if (log2int_nav != UINT32_MAX) { - // Generic fn type: fn(generic_poison) - // generic_poison, is_generic=true, - // comptime_bits=1. - InternPoolKey ftk; - memset(&ftk, 0, sizeof(ftk)); - ftk.tag = IP_KEY_FUNC_TYPE; - ftk.data.func_type.return_type - = IP_INDEX_GENERIC_POISON_TYPE; - ftk.data.func_type.param_count = 1; - ftk.data.func_type.is_generic = true; - ftk.data.func_type.comptime_bits = 1; - InternPoolIndex log2int_ft - = ipIntern(s_module_ip, ftk); + // Log2Int is fn(comptime type) type. + // The func_type must match what analyzeNavValC + // creates (ret=type, params=1) so it deduplicates + // with the existing entry. This avoids creating + // an extra func_type + ptr_type pair. + InternPoolIndex log2int_ft = internFuncType( + IP_INDEX_TYPE_TYPE, 1, 0, false); InternPoolIndex log2int_fd = internFuncDecl(log2int_nav, log2int_ft);