authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-08 14:04:51+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:10+00:00
logffc5242169d67840e0d1420b792696fc1b3d1722
tree3aa84fd640f75dd3ffe2b909e14ab0a95ed180b3
parent5c41b6db87702017791b824ec9d76d5da00c354b
signaturelock-open Commit is signed but in an unrecognized format.

Sema: small NPV fixes


2 files changed, 22 insertions(+), 14 deletions(-)

src/Sema.zig+1-11
......@@ -19400,7 +19400,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1940019400 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
1940119401 try sema.ensureLayoutResolved(ty, operand_src, .align_of);
1940219402 if (ty.isNoReturn(zcu)) {
19403 return sema.fail(block, operand_src, "no align available for type '{f}'", .{ty.fmt(sema.pt)});
19403 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(sema.pt)});
1940419404 }
1940519405 return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?));
1940619406}
......@@ -33432,16 +33432,6 @@ fn errorSetMerge(sema: *Sema, lhs: Type, rhs: Type) !Type {
3343233432 return pt.errorSetFromUnsortedNames(names.keys());
3343333433}
3343433434
33435/// Avoids crashing the compiler when asking if inferred allocations are noreturn.
33436fn isNoReturn(sema: *Sema, ref: Air.Inst.Ref) bool {
33437 if (ref == .unreachable_value) return true;
33438 if (ref.toIndex()) |inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(inst)]) {
33439 .inferred_alloc, .inferred_alloc_comptime => return false,
33440 else => {},
33441 };
33442 return sema.typeOf(ref).isNoReturn(sema.pt.zcu);
33443}
33444
3344533435pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {
3344633436 const pt = sema.pt;
3344733437 if (!pt.zcu.comp.config.incremental) return;
src/Type.zig+21-3
......@@ -790,11 +790,21 @@ pub fn hasWellDefinedLayout(ty: Type, zcu: *const Zcu) bool {
790790/// function with this type can exist at runtime.
791791/// Asserts that `ty` is a function type.
792792pub fn fnHasRuntimeBits(fn_ty: Type, zcu: *Zcu) bool {
793 assertHasLayout(fn_ty, zcu);
793794 const fn_info = zcu.typeToFunc(fn_ty).?;
794795 if (fn_info.comptime_bits != 0) return false;
795796 for (fn_info.param_types.get(&zcu.intern_pool)) |param_ty| {
796797 if (param_ty == .generic_poison_type) return false;
797 if (Type.fromInterned(param_ty).comptimeOnly(zcu)) return false;
798 switch (Type.fromInterned(param_ty).classify(zcu)) {
799 .fully_comptime,
800 .partially_comptime,
801 .no_possible_value,
802 => return false,
803
804 .one_possible_value,
805 .runtime,
806 => {},
807 }
798808 }
799809 const ret_ty: Type = .fromInterned(fn_info.return_type);
800810 if (ret_ty.toIntern() == .generic_poison_type) {
......@@ -805,8 +815,16 @@ pub fn fnHasRuntimeBits(fn_ty: Type, zcu: *Zcu) bool {
805815 {
806816 return false;
807817 }
808 if (fn_info.return_type == .generic_poison_type) return false;
809 if (Type.fromInterned(fn_info.return_type).comptimeOnly(zcu)) return false;
818 switch (ret_ty.classify(zcu)) {
819 .fully_comptime,
820 .partially_comptime,
821 => return false,
822
823 .no_possible_value,
824 .one_possible_value,
825 .runtime,
826 => {},
827 }
810828 if (fn_info.cc == .@"inline") return false;
811829 return true;
812830}