commit e1ec6d2ccf66ab37185a9cdd900ec5aa3f6cf6b5 (tree)
parent 364bdf2c5e2f0d5736146cf40982d3b7be871941
Author: Motiejus <motiejus@jakstys.lt>
Date: Thu, 5 Mar 2026 01:18:33 +0000
sema: fix skip_dedup_end and cc_start timing, clear 15 CC builtins (num_passing=100)
- Extend skip_dedup_end to full preamble items_len (not just
preamble_memoized_end) so CC sub-type entries created by
ensureCcMemoizedStateC are in the skip range
- Set preamble_cc_start AFTER CC union creation so main analysis
creates fresh CC union via skip_dedup
- Clear all 15 CC-phase builtins (not just 5) for main shard re-resolution
- Reset cc_memoized_resolved so ensureCcMemoizedStateC re-runs in main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat:
2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/stage0/sema.c b/stage0/sema.c
@@ -11882,13 +11882,25 @@ SemaFuncAirList semaAnalyze(Sema* sema) {
// memoized state entries in a separate shard. Any main
// analysis interning that matches a preamble entry will
// create a fresh entry instead of deduplicating.
+ //
+ // Extend skip_dedup_end to the full preamble (items_len),
+ // not just preamble_memoized_end. This covers CC sub-type
+ // entries created by ensureCcMemoizedStateC during preamble
+ // (e.g. from start.zig comptime @export). In Zig's sharded
+ // IP these are in the preamble shard and are NOT visible to
+ // main analysis, so main analysis creates fresh copies.
+ //
+ // Reset cc_memoized_resolved so ensureCcMemoizedStateC
+ // re-runs in main analysis with skip_dedup active, creating
+ // fresh CC sub-type entries at main analysis IP indices.
if (sema->zcu->preamble_memoized_end
> sema->zcu->preamble_memoized_start) {
sema->ip->skip_dedup_start
= sema->zcu->preamble_memoized_start;
- sema->ip->skip_dedup_end = sema->zcu->preamble_memoized_end;
+ sema->ip->skip_dedup_end = sema->ip->items_len;
sema->ip->cc_keep_start = sema->zcu->preamble_cc_start;
sema->ip->cc_keep_end = sema->zcu->preamble_cc_end;
+ sema->zcu->cc_memoized_resolved = false;
}
} else {
diff --git a/stage0/zcu_per_thread.c b/stage0/zcu_per_thread.c
@@ -1135,14 +1135,6 @@ void analyzeMemoizedStateC(Sema* sema) {
if (i == 1)
sema->zcu->preamble_skip_ptr_nav = true;
- // Track CC (builtin 2) range: these entries are in Zig's local
- // shard and should NOT be skipped during main analysis dedup.
- // u2 type and u2(0) are added explicitly after CC analysis so that
- // main analysis deduplicates against them (matching Zig's cc_keep
- // which includes u2 type and u2(0) from CC's enum tag analysis).
- if (i == 2)
- sema->zcu->preamble_cc_start = sema->ip->items_len - 1;
-
InternPoolIndex val = ensureNavValUpToDate(sema, nav);
if (val == IP_INDEX_NONE)
continue;
@@ -1150,6 +1142,13 @@ void analyzeMemoizedStateC(Sema* sema) {
if (i == 2) {
sema->zcu->preamble_skip_ptr_nav = false;
+ // Set cc_start AFTER CC union is created so the CC union type
+ // itself is in the skip_dedup range (not in cc_keep). Main
+ // analysis will create a fresh CC union via skip_dedup.
+ // Matches Zig's sharded IP: preamble shard has CC at one index,
+ // main analysis shard creates it fresh at another.
+ sema->zcu->preamble_cc_start = sema->ip->items_len;
+
// Create u2 type and u2(0) as preamble cc_keep items.
// Matches Zig's preamble CC analysis which creates these as
// side effects of analyzing the CC enum tag type (u2 is the
@@ -1215,8 +1214,10 @@ void ensureCcMemoizedStateC(Sema* sema) {
// layouts that Zig's per-shard IP emits during main analysis.
if (sema->zcu->preamble_memoized_end
> sema->zcu->preamble_memoized_start) {
- // Clear builtins 0-4 values so they're re-resolved.
- for (int i = 0; i < 5 && i < NUM_BUILTIN_DECL_MAIN; i++)
+ // Clear builtins 0-14 values so they're re-resolved fresh in
+ // main analysis. Matches Zig's per-shard isolation where main
+ // analysis creates fresh copies of all CC-phase builtins.
+ for (int i = 0; i < 15 && i < NUM_BUILTIN_DECL_MAIN; i++)
sema->zcu->builtin_decl_values[i] = IP_INDEX_NONE;
// Clear nav resolved_type for ALL navs resolved during preamble.