commit 9926cf29f85c19a0ad4ecff70fb9074fdd8bb7ce (tree)
parent bcf6dcdf71b95eda5ff168fc40adebaafc338a22
Author: Motiejus <motiejus@jakstys.lt>
Date: Sun, 1 Mar 2026 19:28:31 +0000
stage0: enable start.zig comptime + CallingConvention resolution
Two key fixes toward closing the IP gap for return_integer.zig:
1. Enable s_in_main_analysis during start.zig comptime evaluation so
DECL_VAL resolves declarations lazily. This creates enum_literal
and enum_tag entries from evaluating switch/if conditions in
start.zig's comptime block (matching the upstream evaluator).
2. Call analyzeMemoizedStateC with memoized_limit=3 (Signedness,
AddressSpace, CallingConvention) to create the builtin type entries
that the upstream creates through ensureMemoizedStateResolved.
3. Only resolve std/builtin.zig's "builtin" import (CG builtin), not
all imports (avoids loading builtin/assembly.zig early).
4. Fix CG builtin namespace collision in ensureNavValUpToDate.
CLI output matches reference exactly (217 entries). Test path creates
2 fewer entries due to module loading order difference between CLI and
test framework (42:u32 at IP 214 vs reference 216). num_passing stays
at 5 pending resolution of this 2-entry test-vs-CLI discrepancy.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git 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 {