authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-28 11:58:23+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:14+00:00
logc64755fb2f3178b4f593ef9f2cb54beef03af36f
tree2d0cad90a5b52d2621bbd6b8ecdf207994f2ecd8
parent978f7fb1ff1cdb36f48b774516aa09ab6a1dfbc0
signaturelock-open Commit is signed but in an unrecognized format.

Type: fix assertion failure


1 files changed, 10 insertions(+), 7 deletions(-)

src/Type.zig+10-7
...@@ -3094,7 +3094,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool...@@ -3094,7 +3094,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool
3094 if (ty.isSlice(zcu)) return false;3094 if (ty.isSlice(zcu)) return false;
3095 const child_ty = ty.childType(zcu);3095 const child_ty = ty.childType(zcu);
3096 if (child_ty.zigTypeTag(zcu) == .@"fn") {3096 if (child_ty.zigTypeTag(zcu) == .@"fn") {
3097 return ty.isConstPtr(zcu) and child_ty.validateExtern(.other, zcu);3097 return ty.isConstPtr(zcu) and validateExternCallconv(child_ty.fnCallingConvention(zcu));
3098 }3098 }
3099 return true;3099 return true;
3100 },3100 },
...@@ -3104,12 +3104,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool...@@ -3104,12 +3104,7 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool
3104 },3104 },
3105 .@"fn" => {3105 .@"fn" => {
3106 if (position != .other) return false;3106 if (position != .other) return false;
3107 // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI.3107 return validateExternCallconv(ty.fnCallingConvention(zcu));
3108 // The goal is to experiment with more integrated CPU/GPU code.
3109 if (ty.fnCallingConvention(zcu) == .nvptx_kernel) {
3110 return true;
3111 }
3112 return !target_util.fnCallConvAllowsZigTypes(ty.fnCallingConvention(zcu));
3113 },3108 },
3114 .@"enum" => {3109 .@"enum" => {
3115 const enum_obj = zcu.intern_pool.loadEnumType(ty.toIntern());3110 const enum_obj = zcu.intern_pool.loadEnumType(ty.toIntern());
...@@ -3155,6 +3150,14 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool...@@ -3155,6 +3150,14 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool
3155 .optional => ty.isPtrLikeOptional(zcu),3150 .optional => ty.isPtrLikeOptional(zcu),
3156 };3151 };
3157}3152}
3153fn validateExternCallconv(cc: std.builtin.CallingConvention) bool {
3154 return switch (cc) {
3155 // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI.
3156 // The goal is to experiment with more integrated CPU/GPU code.
3157 .nvptx_kernel => true,
3158 else => !target_util.fnCallConvAllowsZigTypes(cc),
3159 };
3160}
31583161
3159/// Asserts that `ty` has resolved layout.3162/// Asserts that `ty` has resolved layout.
3160pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {3163pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {