commit aaaae65066eede81263eeb6908b2d7f78c8931aa (tree)
parent a703238663a8d3c9067186f4ca6b8607a141a61c
Author: Motiejus <motiejus@jakstys.lt>
Date: Fri, 27 Feb 2026 04:04:24 +0000
sema: fix returnError position in BuiltinDecl processing order
Move returnError (BuiltinDecl index 3, kind=func) from after all type
resolutions back to right after CallingConvention (index 2), matching
the Zig compiler's BuiltinDecl enum ordering. The previous placement
after all types caused struct_type entries from StackTrace/SourceLocation
to shift returnError's func_type/func_decl to a later IP index than
the Zig compiler produces.
Corpus path IP comparison improves from 480/551 to 536/551 matching.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
| M | stage0/sema.c | | | 69 | +++++++++++++++++++++++++++++++++------------------------------------ |
1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/stage0/sema.c b/stage0/sema.c
@@ -5286,26 +5286,44 @@ static void resolveExportPreamble(void) {
// This resolves types in BuiltinDecl order: Signedness, AddressSpace,
// CallingConvention, returnError, StackTrace, SourceLocation, etc.
static void resolveBuiltinDeclTypes(uint32_t builtin_ns_idx) {
- // BuiltinDecl types in order (main stage only).
- // Each is looked up in std.builtin and resolved.
- static const char* const builtin_type_names[] = {
+ // BuiltinDecl types in order (main stage only), matching the
+ // BuiltinDecl enum: signedness=0, address_space=1,
+ // calling_convention=2, return_error=3, stack_trace=4, ...
+ //
+ // Phase 1: Union types (Signedness, AddressSpace, CallingConvention).
+ static const char* const union_type_names[] = {
"Signedness",
"AddressSpace",
"CallingConvention",
};
- uint32_t n_types
- = sizeof(builtin_type_names) / sizeof(builtin_type_names[0]);
- for (uint32_t i = 0; i < n_types; i++) {
- uint32_t nav
- = findNavInNamespace(builtin_ns_idx, builtin_type_names[i]);
+ uint32_t n_unions = sizeof(union_type_names) / sizeof(union_type_names[0]);
+ for (uint32_t i = 0; i < n_unions; i++) {
+ uint32_t nav = findNavInNamespace(builtin_ns_idx, union_type_names[i]);
if (nav != UINT32_MAX) {
(void)ensureNavValUpToDate(nav);
resolveUnionFullyC(nav);
}
}
- // Remaining BuiltinDecl types (main stage, type kind).
- static const char* const builtin_type_names2[] = {
+ // Phase 2: returnError (BuiltinDecl index 3, kind=func).
+ // Must come right after CallingConvention, matching the Zig compiler's
+ // BuiltinDecl processing order. Creates noinline fn() void type and
+ // func_decl.
+ {
+ uint32_t nav = findNavInNamespace(builtin_ns_idx, "returnError");
+ if (nav != UINT32_MAX) {
+ InternPoolIndex ft
+ = internFuncType(IP_INDEX_VOID_TYPE, 0, 0, true);
+ InternPoolIndex fd = internFuncDecl(nav, ft);
+ Nav* n = ipGetNav(nav);
+ n->resolved_type = fd;
+ InternPoolIndex ptr_ty = internPtrConst(ft);
+ (void)internNavPtr(ptr_ty, nav);
+ }
+ }
+
+ // Phase 3: Remaining BuiltinDecl types (StackTrace through Type).
+ static const char* const remaining_type_names[] = {
"StackTrace",
"SourceLocation",
"CallModifier",
@@ -5319,11 +5337,11 @@ static void resolveBuiltinDeclTypes(uint32_t builtin_ns_idx) {
"BranchHint",
"Type",
};
- uint32_t n_types2
- = sizeof(builtin_type_names2) / sizeof(builtin_type_names2[0]);
- for (uint32_t i = 0; i < n_types2; i++) {
+ uint32_t n_remaining
+ = sizeof(remaining_type_names) / sizeof(remaining_type_names[0]);
+ for (uint32_t i = 0; i < n_remaining; i++) {
uint32_t nav
- = findNavInNamespace(builtin_ns_idx, builtin_type_names2[i]);
+ = findNavInNamespace(builtin_ns_idx, remaining_type_names[i]);
if (nav != UINT32_MAX) {
(void)ensureNavValUpToDate(nav);
resolveStructFullyC(nav);
@@ -5331,7 +5349,7 @@ static void resolveBuiltinDeclTypes(uint32_t builtin_ns_idx) {
}
}
- // Nested Type.* types in BuiltinDecl order.
+ // Phase 4: Nested Type.* types in BuiltinDecl order.
// Ported from analyzeMemoizedState nested access pattern.
uint32_t type_nav = findNavInNamespace(builtin_ns_idx, "Type");
if (type_nav == UINT32_MAX)
@@ -5384,27 +5402,6 @@ static void resolveBuiltinDeclTypes(uint32_t builtin_ns_idx) {
for (uint32_t i = 0; i < n_children; i++) {
(void)resolveNestedTypeDecl(type_ns, type_children[i]);
}
-
- // returnError: kind=func. Create noinline fn() void type and func_decl.
- // Ported from analyzeMemoizedState .func handling +
- // getExpectedBuiltinFnType for .returnError.
- // NOTE: placed after all type resolutions because in the Zig compiler,
- // resolving the type declarations (StackTrace through Type.Declaration)
- // triggers sub-module loading that creates struct/enum entries, and
- // returnError's func_decl must come after those entries.
- {
- uint32_t nav = findNavInNamespace(builtin_ns_idx, "returnError");
- if (nav != UINT32_MAX) {
- // cc=0 is auto (CallingConvention.Tag first variant).
- InternPoolIndex ft
- = internFuncType(IP_INDEX_VOID_TYPE, 0, 0, true);
- InternPoolIndex fd = internFuncDecl(nav, ft);
- Nav* n = ipGetNav(nav);
- n->resolved_type = fd;
- InternPoolIndex ptr_ty = internPtrConst(ft);
- (void)internNavPtr(ptr_ty, nav);
- }
- }
}
// --- resolveStartComptimePreamble ---