aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-23 18:45:51 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-23 18:45:51 -0700
commit7378ce67dabf996f2d0927138f826dfb3d6fa05f (patch)
tree8db3025dfa20a9120c62b7c56796e75cbcecec3d /src/Module.zig
parent57539a26b4b1a118c9947116f2873ea3c0ced3da (diff)
downloadzig-7378ce67dabf996f2d0927138f826dfb3d6fa05f.tar.gz
zig-7378ce67dabf996f2d0927138f826dfb3d6fa05f.zip
Sema: introduce a type resolution queue
That happens after a function body is analyzed. This prevents circular dependency compile errors and yet a way to mark types that need to be fully resolved before a given function is sent to the codegen backend.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 7b27546f52..79d6343949 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -4837,6 +4837,9 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
// Finally we must resolve the return type and parameter types so that backends
// have full access to type information.
+ // Crucially, this happens *after* we set the function state to success above,
+ // so that dependencies on the function body will now be satisfied rather than
+ // result in circular dependency errors.
const src: LazySrcLoc = .{ .node_offset = 0 };
sema.resolveFnTypes(&inner_block, src, fn_ty_info) catch |err| switch (err) {
error.NeededSourceLocation => unreachable,
@@ -4847,6 +4850,20 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
else => |e| return e,
};
+ // Similarly, resolve any queued up types that were requested to be resolved for
+ // the backends.
+ for (sema.types_to_resolve.items) |inst_ref| {
+ const ty = sema.getTmpAir().getRefType(inst_ref);
+ sema.resolveTypeFully(&inner_block, src, ty) catch |err| switch (err) {
+ error.NeededSourceLocation => unreachable,
+ error.GenericPoison => unreachable,
+ error.ComptimeReturn => unreachable,
+ error.ComptimeBreak => unreachable,
+ error.AnalysisFail => {},
+ else => |e| return e,
+ };
+ }
+
return Air{
.instructions = sema.air_instructions.toOwnedSlice(),
.extra = sema.air_extra.toOwnedSlice(gpa),