diff --git a/src/Air.zig b/src/Air.zig index 2e45024919..5bbde22251 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -13,6 +13,7 @@ const Value = @import("Value.zig"); const Type = @import("Type.zig"); const InternPool = @import("InternPool.zig"); const Zcu = @import("Zcu.zig"); +const types_resolved = @import("Air/types_resolved.zig"); instructions: std.MultiArrayList(Inst).Slice, /// The meaning of this data is determined by `Inst.Tag` value. @@ -1899,4 +1900,6 @@ pub fn unwrapSwitch(air: *const Air, switch_inst: Inst.Index) UnwrappedSwitch { }; } -pub const typesFullyResolved = @import("Air/types_resolved.zig").typesFullyResolved; +pub const typesFullyResolved = types_resolved.typesFullyResolved; +pub const typeFullyResolved = types_resolved.checkType; +pub const valFullyResolved = types_resolved.checkVal; diff --git a/src/Air/types_resolved.zig b/src/Air/types_resolved.zig index f51e4c2aea..06258f9130 100644 --- a/src/Air/types_resolved.zig +++ b/src/Air/types_resolved.zig @@ -432,8 +432,10 @@ fn checkRef(ref: Air.Inst.Ref, zcu: *Zcu) bool { return checkVal(Value.fromInterned(ip_index), zcu); } -fn checkVal(val: Value, zcu: *Zcu) bool { - if (!checkType(val.typeOf(zcu), zcu)) return false; +pub fn checkVal(val: Value, zcu: *Zcu) bool { + const ty = val.typeOf(zcu); + if (!checkType(ty, zcu)) return false; + if (ty.toIntern() == .type_type and !checkType(val.toType(), zcu)) return false; // Check for lazy values switch (zcu.intern_pool.indexToKey(val.toIntern())) { .int => |int| switch (int.storage) { @@ -446,9 +448,11 @@ fn checkVal(val: Value, zcu: *Zcu) bool { } } -fn checkType(ty: Type, zcu: *Zcu) bool { +pub fn checkType(ty: Type, zcu: *Zcu) bool { const ip = &zcu.intern_pool; - return switch (ty.zigTypeTag(zcu)) { + return switch (ty.zigTypeTagOrPoison(zcu) catch |err| switch (err) { + error.GenericPoison => return true, + }) { .Type, .Void, .Bool, diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index b5038ff045..67e0e9ee8b 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -2560,12 +2560,17 @@ pub fn populateTestFunctions( pub fn linkerUpdateNav(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void { const zcu = pt.zcu; const comp = zcu.comp; + const ip = &zcu.intern_pool; const nav = zcu.intern_pool.getNav(nav_index); - const codegen_prog_node = zcu.codegen_prog_node.start(nav.fqn.toSlice(&zcu.intern_pool), 0); + const codegen_prog_node = zcu.codegen_prog_node.start(nav.fqn.toSlice(ip), 0); defer codegen_prog_node.end(); - if (comp.bin_file) |lf| { + if (!Air.valFullyResolved(zcu.navValue(nav_index), zcu)) { + // The value of this nav failed to resolve. This is a transitive failure. + // TODO: do we need to mark this failure anywhere? I don't think so, since compilation + // will fail due to the type error anyway. + } else if (comp.bin_file) |lf| { lf.updateNav(pt, nav_index) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, error.AnalysisFail => { @@ -2605,7 +2610,11 @@ pub fn linkerUpdateContainerType(pt: Zcu.PerThread, ty: InternPool.Index) !void const codegen_prog_node = zcu.codegen_prog_node.start(Type.fromInterned(ty).containerTypeName(ip).toSlice(ip), 0); defer codegen_prog_node.end(); - if (comp.bin_file) |lf| { + if (!Air.typeFullyResolved(Type.fromInterned(ty), zcu)) { + // This type failed to resolve. This is a transitive failure. + // TODO: do we need to mark this failure anywhere? I don't think so, since compilation + // will fail due to the type error anyway. + } else if (comp.bin_file) |lf| { lf.updateContainerType(pt, ty) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => |e| log.err("codegen type failed: {s}", .{@errorName(e)}),