commit 827cfd3e8a26747534ccf6f8aec6d2a0b2808e1f (tree)
parent 6694a76893010f13a1568b28cdc4581d01d9a85f
Author: Motiejus <motiejus@jakstys.lt>
Date: Fri, 27 Feb 2026 03:29:25 +0000
sema: defer returnError func_decl after type resolutions
Move returnError resolution to after all BuiltinDecl type resolutions
(StackTrace through Type.Declaration). In the Zig compiler, resolving
these types triggers sub-module loading that creates struct/enum IP
entries, and returnError's func_decl must come after those entries to
match the Zig compiler's IP ordering.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/stage0/sema.c b/stage0/sema.c
@@ -5304,23 +5304,6 @@ static void resolveBuiltinDeclTypes(uint32_t builtin_ns_idx) {
}
}
- // returnError: kind=func. Create noinline fn() void type and func_decl.
- // Ported from analyzeMemoizedState .func handling +
- // getExpectedBuiltinFnType for .returnError.
- {
- 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);
- }
- }
-
// Remaining BuiltinDecl types (main stage, type kind).
static const char* const builtin_type_names2[] = {
"StackTrace",
@@ -5401,6 +5384,27 @@ 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 ---