diff --git a/stage0/sema.c b/stage0/sema.c index 451b6307d5..4c22f1295b 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -10321,7 +10321,7 @@ static void analyzeMemoizedStateC(void) { // not Type and its children (15-35) which are resolved lazily. // Among 0-14, only resolve the ones that actually produce entries // matching the upstream output. - int memoized_limit = 6; // Signedness through SourceLocation + int memoized_limit = 3; // Signedness, AddressSpace, CallingConvention for (int i = 0; i < memoized_limit; i++) { const BuiltinDeclEntry* entry = &s_builtin_decl_entries[i]; @@ -12386,16 +12386,20 @@ SemaFuncAirList semaAnalyze(Sema* sema) { sema->file_idx = root_file_idx; (void)createFileRootStructC(root_file_idx, &sema->code); - // Evaluate start.zig's comptime blocks. The first block - // contains `_ = root;` which resolves @import("root") to - // the root module, creating ptr_nav ($136). + // Evaluate start.zig's comptime blocks fully, matching the + // Zig compiler's ensureComptimeUnitUpToDate. Set + // s_in_main_analysis so DECL_VAL resolves declarations + // lazily (needed for evaluating switch/if conditions that + // access builtin enum values like zig_backend, output_mode). if (start_file_idx != UINT32_MAX) { + s_in_main_analysis = true; uint32_t start_ns = s_file_namespace[start_file_idx]; const SemaNamespace* sns = &s_namespaces[start_ns]; for (uint32_t ci = 0; ci < sns->comptime_decl_count; ci++) { analyzeComptimeUnit( start_file_idx, sns->comptime_decls[ci]); } + s_in_main_analysis = false; } // Load the builtin module chain by resolving specific @@ -12425,9 +12429,19 @@ SemaFuncAirList semaAnalyze(Sema* sema) { fi++) { if (s_file_root_type[fi] == bval) { s_builtin_file_idx = fi; - // Resolve std/builtin.zig's imports - // ($139 std, $140 CG builtin). - resolveModuleDeclImports(fi, 1); + // Resolve std/builtin.zig's "builtin" + // import only (CG builtin module). + // Don't use resolveModuleDeclImports + // which resolves ALL imports including + // "assembly.zig" that the upstream + // doesn't access at this point. + { + uint32_t bns = s_file_namespace[fi]; + uint32_t bn + = findNavInNamespace(bns, "builtin"); + if (bn != UINT32_MAX) + (void)ensureNavValUpToDate(bn); + } break; } } @@ -12435,8 +12449,7 @@ SemaFuncAirList semaAnalyze(Sema* sema) { } } - // Trigger memoized state resolution after the full module - // chain is loaded. + // Trigger memoized state for CallingConvention etc. analyzeMemoizedStateC(); } else {