From 66d15d9d0974e1b493b717cf02deb435ebd13858 Mon Sep 17 00:00:00 2001 From: mlugg Date: Thu, 29 May 2025 01:27:37 +0100 Subject: [PATCH] link: make checking for failed types the responsibility of Compilation --- src/Compilation.zig | 21 +++++++++++++++++++++ src/Zcu/PerThread.zig | 8 -------- src/link.zig | 13 ------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index f51020c0ff..e51b3de1ad 100644 --- a/src/Compilation.zig +++ b/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| { diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index b10e6d7c41..137d93b82a 100644 --- a/src/Zcu/PerThread.zig +++ b/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); } diff --git a/src/link.zig b/src/link.zig index 68ea533eed..4b4c3c611b 100644 --- a/src/link.zig +++ b/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) {