authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-07 19:43:27+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 14:00:00+02:00
log4a6a024a4bd103cf7bf7e50a5ccf4103f4ce83a2
tree36411f3b31fc18c7d561c4efd1f421838f208bcf
parent89b1dafa7808d22eab78ea486f158f794da46a2c
signature Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: properly skip comptime function parameters


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

src/codegen/spirv.zig+14-7
...@@ -1242,14 +1242,19 @@ const DeclGen = struct {...@@ -1242,14 +1242,19 @@ const DeclGen = struct {
12421242
1243 const param_ty_refs = try self.gpa.alloc(CacheRef, fn_info.param_types.len);1243 const param_ty_refs = try self.gpa.alloc(CacheRef, fn_info.param_types.len);
1244 defer self.gpa.free(param_ty_refs);1244 defer self.gpa.free(param_ty_refs);
1245 for (param_ty_refs, fn_info.param_types.get(ip)) |*param_type, fn_param_type| {1245 var param_index: usize = 0;
1246 param_type.* = try self.resolveType(fn_param_type.toType(), .direct);1246 for (fn_info.param_types.get(ip)) |param_ty_index| {
1247 const param_ty = param_ty_index.toType();
1248 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
1249
1250 param_ty_refs[param_index] = try self.resolveType(param_ty, .direct);
1251 param_index += 1;
1247 }1252 }
1248 const return_ty_ref = try self.resolveType(fn_info.return_type.toType(), .direct);1253 const return_ty_ref = try self.resolveType(fn_info.return_type.toType(), .direct);
12491254
1250 const ty_ref = try self.spv.resolve(.{ .function_type = .{1255 const ty_ref = try self.spv.resolve(.{ .function_type = .{
1251 .return_type = return_ty_ref,1256 .return_type = return_ty_ref,
1252 .parameters = param_ty_refs,1257 .parameters = param_ty_refs[0..param_index],
1253 } });1258 } });
12541259
1255 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });1260 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
...@@ -1675,9 +1680,11 @@ const DeclGen = struct {...@@ -1675,9 +1680,11 @@ const DeclGen = struct {
1675 const fn_info = mod.typeToFunc(decl.ty).?;1680 const fn_info = mod.typeToFunc(decl.ty).?;
16761681
1677 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);1682 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);
1678 for (0..fn_info.param_types.len) |i| {1683 for (fn_info.param_types.get(ip)) |param_ty_index| {
1679 const param_type = fn_info.param_types.get(ip)[i];1684 const param_ty = param_ty_index.toType();
1680 const param_type_id = try self.resolveTypeId(param_type.toType());1685 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
1686
1687 const param_type_id = try self.resolveTypeId(param_ty);
1681 const arg_result_id = self.spv.allocId();1688 const arg_result_id = self.spv.allocId();
1682 try self.func.prologue.emit(self.spv.gpa, .OpFunctionParameter, .{1689 try self.func.prologue.emit(self.spv.gpa, .OpFunctionParameter, .{
1683 .id_result_type = param_type_id,1690 .id_result_type = param_type_id,
...@@ -3986,9 +3993,9 @@ const DeclGen = struct {...@@ -3986,9 +3993,9 @@ const DeclGen = struct {
3986 // Note: resolve() might emit instructions, so we need to call it3993 // Note: resolve() might emit instructions, so we need to call it
3987 // before starting to emit OpFunctionCall instructions. Hence the3994 // before starting to emit OpFunctionCall instructions. Hence the
3988 // temporary params buffer.3995 // temporary params buffer.
3989 const arg_id = try self.resolve(arg);
3990 const arg_ty = self.typeOf(arg);3996 const arg_ty = self.typeOf(arg);
3991 if (!arg_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;3997 if (!arg_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
3998 const arg_id = try self.resolve(arg);
39923999
3993 params[n_params] = arg_id;4000 params[n_params] = arg_id;
3994 n_params += 1;4001 n_params += 1;
test/behavior/struct.zig-6
...@@ -887,8 +887,6 @@ test "anonymous struct literal syntax" {...@@ -887,8 +887,6 @@ test "anonymous struct literal syntax" {
887}887}
888888
889test "fully anonymous struct" {889test "fully anonymous struct" {
890 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
891
892 const S = struct {890 const S = struct {
893 fn doTheTest() !void {891 fn doTheTest() !void {
894 try dump(.{892 try dump(.{
...@@ -911,8 +909,6 @@ test "fully anonymous struct" {...@@ -911,8 +909,6 @@ test "fully anonymous struct" {
911}909}
912910
913test "fully anonymous list literal" {911test "fully anonymous list literal" {
914 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
915
916 const S = struct {912 const S = struct {
917 fn doTheTest() !void {913 fn doTheTest() !void {
918 try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });914 try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
...@@ -1715,8 +1711,6 @@ test "extern struct field pointer has correct alignment" {...@@ -1715,8 +1711,6 @@ test "extern struct field pointer has correct alignment" {
1715}1711}
17161712
1717test "packed struct field in anonymous struct" {1713test "packed struct field in anonymous struct" {
1718 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1719
1720 const T = packed struct {1714 const T = packed struct {
1721 f1: bool = false,1715 f1: bool = false,
1722 };1716 };