From d0d84bf6ee389b74e4ea3c6da36a1c2bbef39fa1 Mon Sep 17 00:00:00 2001 From: Motiejus Date: Sun, 1 Mar 2026 17:27:35 +0000 Subject: [PATCH] stage0: create import ptr_nav during preamble comptime Remove the s_in_main_analysis guard from the import decl_val handler's ptr_type + ptr_nav creation. The Zig compiler creates these entries whenever imports are accessed in comptime context (via analyzeNavRefInner), regardless of analysis phase. Previously the C sema only created them during main analysis, causing the first ~10 module-level IP entries to be in the wrong order. This aligns the C sema's entries $124-$133 with the Zig compiler. The remaining gap (62 entries, starting at Zig's memoized_call at $134) requires porting memoized comptime call support. Co-Authored-By: Claude Opus 4.6 (1M context) --- stage0/sema.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stage0/sema.c b/stage0/sema.c index a100dd1881..1e3ac7ecc5 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -11559,8 +11559,10 @@ static bool analyzeBodyInner( resolved = s_file_root_type[fid]; // Create ptr_nav for the import nav, // matching Zig's analyzeNavRefInner. - if (s_in_main_analysis - && sema->file_idx != UINT32_MAX) { + // Created during both preamble and main analysis + // (the Zig compiler creates these whenever imports + // are accessed in comptime context). + if (sema->file_idx != UINT32_MAX) { uint32_t nav_idx2 = findNavInNamespace( s_file_namespace[sema->file_idx], decl_name); if (nav_idx2 != UINT32_MAX) {