authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-09-19 20:26:30+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-23 12:36:56-07:00
log8895025688b599a7082669234d40b26001bd9ed0
treed3e1083b5175c22fd5207338b11daff7ad5b4f21
parent4f215a6d2894182f90328e2aa213f92d8e479ec7

spirv: air wrap_errunion_payload


2 files changed, 27 insertions(+), 25 deletions(-)

src/codegen/spirv.zig+27-11
...@@ -1734,6 +1734,7 @@ pub const DeclGen = struct {...@@ -1734,6 +1734,7 @@ pub const DeclGen = struct {
1734 .unwrap_errunion_err => try self.airErrUnionErr(inst),1734 .unwrap_errunion_err => try self.airErrUnionErr(inst),
1735 .unwrap_errunion_payload => try self.airErrUnionPayload(inst),1735 .unwrap_errunion_payload => try self.airErrUnionPayload(inst),
1736 .wrap_errunion_err => try self.airWrapErrUnionErr(inst),1736 .wrap_errunion_err => try self.airWrapErrUnionErr(inst),
1737 .wrap_errunion_payload => try self.airWrapErrUnionPayload(inst),
17371738
1738 .is_null => try self.airIsNull(inst, .is_null),1739 .is_null => try self.airIsNull(inst, .is_null),
1739 .is_non_null => try self.airIsNull(inst, .is_non_null),1740 .is_non_null => try self.airIsNull(inst, .is_non_null),
...@@ -3216,20 +3217,35 @@ pub const DeclGen = struct {...@@ -3216,20 +3217,35 @@ pub const DeclGen = struct {
3216 }3217 }
32173218
3218 const payload_ty_ref = try self.resolveType(payload_ty, .indirect);3219 const payload_ty_ref = try self.resolveType(payload_ty, .indirect);
3219 var members = std.BoundedArray(IdRef, 2){};3220
3220 const payload_id = try self.spv.constUndef(payload_ty_ref);3221 var members: [2]IdRef = undefined;
3221 if (eu_layout.error_first) {3222 members[eu_layout.errorFieldIndex()] = operand_id;
3222 members.appendAssumeCapacity(operand_id);3223 members[eu_layout.payloadFieldIndex()] = try self.spv.constUndef(payload_ty_ref);
3223 members.appendAssumeCapacity(payload_id);3224
3224 // TODO: ABI padding?3225 const err_union_ty_ref = try self.resolveType(err_union_ty, .direct);
3225 } else {3226 return try self.constructStruct(err_union_ty_ref, &members);
3226 members.appendAssumeCapacity(payload_id);3227 }
3227 members.appendAssumeCapacity(operand_id);3228
3228 // TODO: ABI padding?3229 fn airWrapErrUnionPayload(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
3230 if (self.liveness.isUnused(inst)) return null;
3231
3232 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
3233 const err_union_ty = self.typeOfIndex(inst);
3234 const operand_id = try self.resolve(ty_op.operand);
3235 const payload_ty = self.typeOf(ty_op.operand);
3236 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
3237 const eu_layout = self.errorUnionLayout(payload_ty);
3238
3239 if (!eu_layout.payload_has_bits) {
3240 return try self.constInt(err_ty_ref, 0);
3229 }3241 }
32303242
3243 var members: [2]IdRef = undefined;
3244 members[eu_layout.errorFieldIndex()] = try self.constInt(err_ty_ref, 0);
3245 members[eu_layout.payloadFieldIndex()] = try self.convertToIndirect(payload_ty, operand_id);
3246
3231 const err_union_ty_ref = try self.resolveType(err_union_ty, .direct);3247 const err_union_ty_ref = try self.resolveType(err_union_ty, .direct);
3232 return try self.constructStruct(err_union_ty_ref, members.slice());3248 return try self.constructStruct(err_union_ty_ref, &members);
3233 }3249 }
32343250
3235 fn airIsNull(self: *DeclGen, inst: Air.Inst.Index, pred: enum { is_null, is_non_null }) !?IdRef {3251 fn airIsNull(self: *DeclGen, inst: Air.Inst.Index, pred: enum { is_null, is_non_null }) !?IdRef {
test/behavior/error.zig-14
...@@ -30,7 +30,6 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {...@@ -30,7 +30,6 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
3030
31test "error binary operator" {31test "error binary operator" {
32 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO32 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
33 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
3433
35 const a = errBinaryOperatorG(true) catch 3;34 const a = errBinaryOperatorG(true) catch 3;
36 const b = errBinaryOperatorG(false) catch 3;35 const b = errBinaryOperatorG(false) catch 3;
...@@ -62,14 +61,12 @@ pub fn baz() anyerror!i32 {...@@ -62,14 +61,12 @@ pub fn baz() anyerror!i32 {
6261
63test "error wrapping" {62test "error wrapping" {
64 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO63 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
65 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
6664
67 try expect((baz() catch unreachable) == 15);65 try expect((baz() catch unreachable) == 15);
68}66}
6967
70test "unwrap simple value from error" {68test "unwrap simple value from error" {
71 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO69 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
72 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
7370
74 const i = unwrapSimpleValueFromErrorDo() catch unreachable;71 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
75 try expect(i == 13);72 try expect(i == 13);
...@@ -80,7 +77,6 @@ fn unwrapSimpleValueFromErrorDo() anyerror!isize {...@@ -80,7 +77,6 @@ fn unwrapSimpleValueFromErrorDo() anyerror!isize {
8077
81test "error return in assignment" {78test "error return in assignment" {
82 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO79 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
83 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
8480
85 doErrReturnInAssignment() catch unreachable;81 doErrReturnInAssignment() catch unreachable;
86}82}
...@@ -103,7 +99,6 @@ test "syntax: optional operator in front of error union operator" {...@@ -103,7 +99,6 @@ test "syntax: optional operator in front of error union operator" {
103test "widen cast integer payload of error union function call" {99test "widen cast integer payload of error union function call" {
104 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;100 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
105 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO101 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
106 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
107102
108 const S = struct {103 const S = struct {
109 fn errorable() !u64 {104 fn errorable() !u64 {
...@@ -150,7 +145,6 @@ test "implicit cast to optional to error union to return result loc" {...@@ -150,7 +145,6 @@ test "implicit cast to optional to error union to return result loc" {
150}145}
151146
152test "fn returning empty error set can be passed as fn returning any error" {147test "fn returning empty error set can be passed as fn returning any error" {
153 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
154 entry();148 entry();
155 comptime entry();149 comptime entry();
156}150}
...@@ -243,7 +237,6 @@ fn testExplicitErrorSetCast(set1: Set1) !void {...@@ -243,7 +237,6 @@ fn testExplicitErrorSetCast(set1: Set1) !void {
243237
244test "comptime test error for empty error set" {238test "comptime test error for empty error set" {
245 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO239 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
246 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
247240
248 try testComptimeTestErrorEmptySet(1234);241 try testComptimeTestErrorEmptySet(1234);
249 try comptime testComptimeTestErrorEmptySet(1234);242 try comptime testComptimeTestErrorEmptySet(1234);
...@@ -279,7 +272,6 @@ test "inferred empty error set comptime catch" {...@@ -279,7 +272,6 @@ test "inferred empty error set comptime catch" {
279}272}
280273
281test "error inference with an empty set" {274test "error inference with an empty set" {
282 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
283 const S = struct {275 const S = struct {
284 const Struct = struct {276 const Struct = struct {
285 pub fn func() (error{})!usize {277 pub fn func() (error{})!usize {
...@@ -334,7 +326,6 @@ fn quux_1() !i32 {...@@ -334,7 +326,6 @@ fn quux_1() !i32 {
334326
335test "error: Zero sized error set returned with value payload crash" {327test "error: Zero sized error set returned with value payload crash" {
336 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO328 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
337 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
338329
339 _ = try foo3(0);330 _ = try foo3(0);
340 _ = try comptime foo3(0);331 _ = try comptime foo3(0);
...@@ -434,7 +425,6 @@ test "nested error union function call in optional unwrap" {...@@ -434,7 +425,6 @@ test "nested error union function call in optional unwrap" {
434test "return function call to error set from error union function" {425test "return function call to error set from error union function" {
435 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO426 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
436 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO427 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
437 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
438428
439 const S = struct {429 const S = struct {
440 fn errorable() anyerror!i32 {430 fn errorable() anyerror!i32 {
...@@ -670,7 +660,6 @@ test "peer type resolution of two different error unions" {...@@ -670,7 +660,6 @@ test "peer type resolution of two different error unions" {
670}660}
671661
672test "coerce error set to the current inferred error set" {662test "coerce error set to the current inferred error set" {
673 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
674 const S = struct {663 const S = struct {
675 fn foo() !void {664 fn foo() !void {
676 var a = false;665 var a = false;
...@@ -862,8 +851,6 @@ fn non_errorable() void {...@@ -862,8 +851,6 @@ fn non_errorable() void {
862}851}
863852
864test "catch within a function that calls no errorable functions" {853test "catch within a function that calls no errorable functions" {
865 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
866
867 non_errorable();854 non_errorable();
868}855}
869856
...@@ -895,7 +882,6 @@ test "field access of anyerror results in smaller error set" {...@@ -895,7 +882,6 @@ test "field access of anyerror results in smaller error set" {
895test "optional error union return type" {882test "optional error union return type" {
896 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO883 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
897 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO884 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
898 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
899885
900 const S = struct {886 const S = struct {
901 fn foo() ?anyerror!u32 {887 fn foo() ?anyerror!u32 {