Commit 66d15d9d09

mlugg <mlugg@mlugg.co.uk>
2025-05-29 02:27:37
link: make checking for failed types the responsibility of Compilation
1 parent 2fb6f5c
Changed files (3)
src/Zcu/PerThread.zig
@@ -1739,14 +1739,6 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: *A
     const codegen_prog_node = zcu.codegen_prog_node.start(nav.fqn.toSlice(ip), 0);
     defer codegen_prog_node.end();
 
-    if (!air.typesFullyResolved(zcu)) {
-        // A type we depend on failed to resolve. This is a transitive failure.
-        // Correcting this failure will involve changing a type this function
-        // depends on, hence triggering re-analysis of this function, so this
-        // interacts correctly with incremental compilation.
-        return;
-    }
-
     legalize: {
         try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index) orelse break :legalize);
     }
src/Compilation.zig
@@ -4553,12 +4553,33 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
                 }
             }
             assert(nav.status == .fully_resolved);
+            if (!Air.valFullyResolved(zcu.navValue(nav_index), zcu)) {
+                // Type resolution failed in a way which affects this `Nav`. This is a transitive
+                // failure, but it doesn't need recording, because this `Nav` semantically depends
+                // on the failed type, so when it is changed the `Nav` will be updated.
+                return;
+            }
             comp.dispatchLinkTask(tid, .{ .link_nav = nav_index });
         },
         .link_func => |func| {
+            const zcu = comp.zcu.?;
+            if (!func.air.typesFullyResolved(zcu)) {
+                // Type resolution failed in a way which affects this function. This is a transitive
+                // failure, but it doesn't need recording, because this function semantically depends
+                // on the failed type, so when it is changed the function is updated.
+                return;
+            }
             comp.dispatchLinkTask(tid, .{ .link_func = func });
         },
         .link_type => |ty| {
+            const zcu = comp.zcu.?;
+            if (zcu.failed_types.fetchSwapRemove(ty)) |*entry| entry.value.deinit(zcu.gpa);
+            if (!Air.typeFullyResolved(.fromInterned(ty), zcu)) {
+                // Type resolution failed in a way which affects this type. This is a transitive
+                // failure, but it doesn't need recording, because this type semantically depends
+                // on the failed type, so when that is changed, this type will be updated.
+                return;
+            }
             comp.dispatchLinkTask(tid, .{ .link_type = ty });
         },
         .update_line_number => |ti| {
src/link.zig
@@ -1424,12 +1424,6 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
             const zcu = comp.zcu.?;
             const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid));
             defer pt.deactivate();
-            if (!Air.valFullyResolved(zcu.navValue(nav_index), zcu)) {
-                // Type resolution failed in a way which affects this `Nav`. This is a transitive
-                // failure, but it doesn't need recording, because this `Nav` semantically depends
-                // on the failed type, so when it is changed the `Nav` will be updated.
-                return;
-            }
             if (zcu.llvm_object) |llvm_object| {
                 llvm_object.updateNav(pt, nav_index) catch |err| switch (err) {
                     error.OutOfMemory => diags.setAllocFailure(),
@@ -1473,13 +1467,6 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void {
             const zcu = comp.zcu.?;
             const pt: Zcu.PerThread = .activate(zcu, @enumFromInt(tid));
             defer pt.deactivate();
-            if (zcu.failed_types.fetchSwapRemove(ty)) |*entry| entry.value.deinit(zcu.gpa);
-            if (!Air.typeFullyResolved(.fromInterned(ty), zcu)) {
-                // Type resolution failed in a way which affects this type. This is a transitive
-                // failure, but it doesn't need recording, because this type semantically depends
-                // on the failed type, so when that is changed, this type will be updated.
-                return;
-            }
             if (zcu.llvm_object == null) {
                 if (comp.bin_file) |lf| {
                     lf.updateContainerType(pt, ty) catch |err| switch (err) {