From ffc5242169d67840e0d1420b792696fc1b3d1722 Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Sun, 8 Feb 2026 14:04:51 +0000 Subject: [PATCH] Sema: small NPV fixes --- src/Sema.zig | 12 +----------- src/Type.zig | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index b0271ffde0..140e69fe6f 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -19400,7 +19400,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const ty = try sema.resolveType(block, operand_src, inst_data.operand); try sema.ensureLayoutResolved(ty, operand_src, .align_of); if (ty.isNoReturn(zcu)) { - return sema.fail(block, operand_src, "no align available for type '{f}'", .{ty.fmt(sema.pt)}); + return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(sema.pt)}); } return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?)); } @@ -33432,16 +33432,6 @@ fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type { return pt.errorSetFromUnsortedNames(names.keys()); } -/// Avoids crashing the compiler when asking if inferred allocations are noreturn. -fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool { - if (ref == .unreachable_value) return true; - if (ref.toIndex()) |inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(inst)]) { - .inferred_alloc, .inferred_alloc_comptime => return false, - else => {}, - }; - return sema.typeOf(ref).isNoReturn(sema.pt.zcu); -} - pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void { const pt = sema.pt; if (!pt.zcu.comp.config.incremental) return; diff --git a/src/Type.zig b/src/Type.zig index 3eb14f3b53..2348503765 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -790,11 +790,21 @@ pub fn hasWellDefinedLayout(ty: Type, zcu: *const Zcu) bool { /// function with this type can exist at runtime. /// Asserts that `ty` is a function type. pub fn fnHasRuntimeBits(fn_ty: Type, zcu: *Zcu) bool { + assertHasLayout(fn_ty, zcu); const fn_info = zcu.typeToFunc(fn_ty).?; if (fn_info.comptime_bits != 0) return false; for (fn_info.param_types.get(&zcu.intern_pool)) |param_ty| { if (param_ty == .generic_poison_type) return false; - if (Type.fromInterned(param_ty).comptimeOnly(zcu)) return false; + switch (Type.fromInterned(param_ty).classify(zcu)) { + .fully_comptime, + .partially_comptime, + .no_possible_value, + => return false, + + .one_possible_value, + .runtime, + => {}, + } } const ret_ty: Type = .fromInterned(fn_info.return_type); if (ret_ty.toIntern() == .generic_poison_type) { @@ -805,8 +815,16 @@ pub fn fnHasRuntimeBits(fn_ty: Type, zcu: *Zcu) bool { { return false; } - if (fn_info.return_type == .generic_poison_type) return false; - if (Type.fromInterned(fn_info.return_type).comptimeOnly(zcu)) return false; + switch (ret_ty.classify(zcu)) { + .fully_comptime, + .partially_comptime, + => return false, + + .no_possible_value, + .one_possible_value, + .runtime, + => {}, + } if (fn_info.cc == .@"inline") return false; return true; }