Sema: small NPV fixes

This commit is contained in:
Matthew Lugg
2026-02-08 14:04:51 +00:00
parent 5c41b6db87
commit ffc5242169
2 changed files with 22 additions and 14 deletions
+1 -11
View File
@@ -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;
+21 -3
View File
@@ -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;
}