authorgravatar for alichraghi@noreply.codeberg.orgAli Cheraghi <alichraghi@noreply.codeberg.org> 2026-06-28 18:25:43+02:00
committergravatar for alichraghi@noreply.codeberg.orgAli Cheraghi <alichraghi@noreply.codeberg.org> 2026-06-28 18:25:43+02:00
log902b71eafa9c92d01a6c0195dfdc5a59294dfe20
tree5e47d5a3ed96a6b22a6d29a6fca3bcf41403bb5a
parente0e145048d4b7b80bdbf15c78b33dea06edadc0a
parentbae68c8a458690a7fedeed7541f80b960a4bd1f6

Merge pull request 'Type: allow vectors in externs for SPIR-V target' (#35953) from alichraghi/zig:master into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35953

23 files changed, 42 insertions(+), 43 deletions(-)

lib/std/Target/spirv.zig+18-6
......@@ -1766,32 +1766,44 @@ pub const all_features = blk: {
17661766 result[@intFromEnum(Feature.v1_1)] = .{
17671767 .llvm_name = null,
17681768 .description = "Enable v1_1 Extension.",
1769 .dependencies = featureSet(&[_]Feature{}),
1769 .dependencies = featureSet(&[_]Feature{
1770 .v1_0,
1771 }),
17701772 };
17711773 result[@intFromEnum(Feature.v1_2)] = .{
17721774 .llvm_name = null,
17731775 .description = "Enable v1_2 Extension.",
1774 .dependencies = featureSet(&[_]Feature{}),
1776 .dependencies = featureSet(&[_]Feature{
1777 .v1_1,
1778 }),
17751779 };
17761780 result[@intFromEnum(Feature.v1_3)] = .{
17771781 .llvm_name = null,
17781782 .description = "Enable v1_3 Extension.",
1779 .dependencies = featureSet(&[_]Feature{}),
1783 .dependencies = featureSet(&[_]Feature{
1784 .v1_2,
1785 }),
17801786 };
17811787 result[@intFromEnum(Feature.v1_4)] = .{
17821788 .llvm_name = null,
17831789 .description = "Enable v1_4 Extension.",
1784 .dependencies = featureSet(&[_]Feature{}),
1790 .dependencies = featureSet(&[_]Feature{
1791 .v1_3,
1792 }),
17851793 };
17861794 result[@intFromEnum(Feature.v1_5)] = .{
17871795 .llvm_name = null,
17881796 .description = "Enable v1_5 Extension.",
1789 .dependencies = featureSet(&[_]Feature{}),
1797 .dependencies = featureSet(&[_]Feature{
1798 .v1_4,
1799 }),
17901800 };
17911801 result[@intFromEnum(Feature.v1_6)] = .{
17921802 .llvm_name = null,
17931803 .description = "Enable v1_6 Extension.",
1794 .dependencies = featureSet(&[_]Feature{}),
1804 .dependencies = featureSet(&[_]Feature{
1805 .v1_5,
1806 }),
17951807 };
17961808 result[@intFromEnum(Feature.variable_pointers)] = .{
17971809 .llvm_name = null,
src/Sema.zig+1
......@@ -27032,6 +27032,7 @@ fn elemPtrOneLayerOnly(
2703227032 .vector => try sema.elemPtrVector(block, indexable_src, indexable, elem_index_src, elem_index, init),
2703327033 .array => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),
2703427034 .@"struct" => try sema.tupleElemPtr(block, indexable_src, indexable, elem_index, elem_index_src),
27035 .spirv => try sema.elemPtrSpirvRuntimeArray(block, indexable, elem_index),
2703527036 else => unreachable, // Guaranteed by checkIndexable
2703627037 };
2703727038 try sema.checkKnownAllocPtr(block, indexable, elem_ptr);
src/Type.zig+4-1
......@@ -3087,7 +3087,10 @@ pub fn validateExtern(ty: Type, position: ExternPosition, zcu: *const Zcu) bool
30873087 .frame,
30883088 => false,
30893089
3090 .vector => position == .param_ty or position == .ret_ty,
3090 .vector => {
3091 if (zcu.getTarget().cpu.arch.isSpirV()) return true;
3092 return position == .param_ty or position == .ret_ty;
3093 },
30913094
30923095 .void => switch (position) {
30933096 .ret_ty,
src/codegen/spirv/CodeGen.zig+2-11
......@@ -1881,17 +1881,8 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
18811881 const parent_ptr_ty = try oac.parent.ptrType(pt);
18821882 const result_ty_id = try cg.resolveType(oac.new_ptr_ty, .direct);
18831883
1884 if (parent_ptr_ty.childType(zcu).isVector(zcu)) {
1885 // Vector element ptr accesses are derived as offset_and_cast.
1886 // We can just use OpAccessChain.
1887 const child_size = oac.new_ptr_ty.childType(zcu).abiSize(zcu);
1888 if (oac.byte_offset % child_size == 0) {
1889 return cg.accessChain(
1890 result_ty_id,
1891 parent_ptr_id,
1892 &.{@intCast(@divExact(oac.byte_offset, child_size))},
1893 );
1894 }
1884 if (oac.new_ptr_ty.ptrInfo(zcu).flags.vector_index != .none) {
1885 return parent_ptr_id;
18951886 }
18961887
18971888 if (oac.byte_offset == 0) {
test/behavior/align.zig-1
......@@ -432,7 +432,6 @@ test "read 128-bit field from default aligned struct in stack memory" {
432432 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
433433 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
434434 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
435 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
436435
437436 var default_aligned = DefaultAligned{
438437 .nevermind = 1,
test/behavior/array.zig-1
......@@ -1077,7 +1077,6 @@ test "initialize sentinel-terminated slice with reference to empty array initial
10771077}
10781078
10791079test "initialize sentinel-terminated many-pointer with reference to empty array initializer" {
1080 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
10811080 const a: [*:0]const u8 = &.{};
10821081 comptime assert(a[0] == 0);
10831082}
test/behavior/cast.zig-2
......@@ -433,8 +433,6 @@ test "implicit cast from *[N]T to [*c]T" {
433433}
434434
435435test "*usize to *void" {
436 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
437
438436 var i = @as(usize, 0);
439437 const v: *void = @ptrCast(&i);
440438 v.* = {};
test/behavior/destructure.zig-2
......@@ -94,8 +94,6 @@ test "destructure from labeled block" {
9494}
9595
9696test "destructure tuple value" {
97 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
98
9997 const tup: struct { f32, u32, i64 } = .{ 10.0, 20, 30 };
10098 const x, const y, const z = tup;
10199
test/behavior/error.zig-2
......@@ -145,8 +145,6 @@ test "implicit cast to optional to error union to return result loc" {
145145}
146146
147147test "fn returning empty error set can be passed as fn returning any error" {
148 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
149
150148 entry();
151149 comptime entry();
152150}
test/behavior/eval.zig-2
......@@ -1445,8 +1445,6 @@ test "struct in comptime false branch is not evaluated" {
14451445}
14461446
14471447test "result of nested switch assigned to variable" {
1448 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; // TODO
1449
14501448 var zds: u32 = 0;
14511449 zds = switch (zds) {
14521450 0 => switch (zds) {
test/behavior/fn.zig-1
......@@ -292,7 +292,6 @@ fn voidFun(a: i32, b: void, c: i32, d: void) !void {
292292
293293test "call function with empty string" {
294294 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
295 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
296295
297296 acceptsString("");
298297}
test/behavior/generics.zig-1
......@@ -519,7 +519,6 @@ test "call generic function with from function called by the generic function" {
519519 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
520520 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
521521 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
522 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
523522
524523 const GET = struct {
525524 key: []const u8,
test/behavior/globals.zig-1
......@@ -16,7 +16,6 @@ var vpos = @Vector(2, f32){ 0.0, 0.0 };
1616test "store to global vector" {
1717 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
1818 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
2019
2120 try expect(vpos[1] == 0.0);
2221 vpos = @Vector(2, f32){ 0.0, 1.0 };
test/behavior/inline_switch.zig+1-1
......@@ -81,7 +81,7 @@ test "inline else bool" {
8181
8282test "inline else error" {
8383 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
84 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
84
8585 const Err = error{ a, b, c };
8686 var a = Err.a;
8787 _ = &a;
test/behavior/math.zig-1
......@@ -1389,7 +1389,6 @@ fn testOr(comptime T: type, a: T, b: T, expected: T) !void {
13891389test "or > 128 bits" {
13901390 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
13911391 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
1392 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
13931392
13941393 try testOr(u140, 0, 1 << 139, 1 << 139);
13951394 try testOr(u140, (1 << 70) | 0xa, (1 << 69) | 0x5, (1 << 70) | (1 << 69) | 0xf);
test/behavior/muladd.zig-1
......@@ -101,7 +101,6 @@ test "vector f16" {
101101 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
102102 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
103103 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
104 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
105104
106105 try comptime vector16();
107106 try vector16();
test/behavior/optional.zig-1
......@@ -426,7 +426,6 @@ test "optional pointer to zero bit optional payload" {
426426 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
427427 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
428428 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
429 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
430429
431430 const B = struct {
432431 fn foo(_: *@This()) void {}
test/behavior/slice.zig-3
......@@ -787,8 +787,6 @@ test "slice bounds in comptime concatenation" {
787787}
788788
789789test "slice sentinel access at comptime" {
790 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
791
792790 {
793791 const str0 = &[_:0]u8{ '1', '2', '3' };
794792 const slice0: [:0]const u8 = str0;
......@@ -809,7 +807,6 @@ test "slice sentinel access at comptime" {
809807test "slicing array with sentinel as end index" {
810808 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
811809 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
812
813810 const S = struct {
814811 fn do() !void {
815812 var array = [_:0]u8{ 1, 2, 3, 4 };
test/behavior/struct.zig-1
......@@ -567,7 +567,6 @@ test "bit field access" {
567567 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
568568 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
569569 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
570 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
571570 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO
572571
573572 var data = bit_field_1;
test/behavior/switch.zig+2-1
......@@ -314,7 +314,6 @@ fn testSwitchEnumPtrCapture() !void {
314314
315315test "switch handles all cases of number" {
316316 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
317 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
318317
319318 try testSwitchHandleAllCases();
320319 try comptime testSwitchHandleAllCases();
......@@ -1576,6 +1575,8 @@ test "repeated switch analysis overrides previous analysis results" {
15761575}
15771576
15781577test "union field pointer capture preserves alignment in inline prong" {
1578 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
1579
15791580 const U = union(enum) {
15801581 a: u32,
15811582 b: u32,
test/behavior/tuple.zig-1
......@@ -242,7 +242,6 @@ test "tuple in tuple passed to generic function" {
242242test "coerce tuple to tuple" {
243243 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
244244 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
245 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
246245
247246 const T = @Tuple(&.{u8});
248247 const S = struct {
test/behavior/vector.zig-1
......@@ -414,7 +414,6 @@ test "vector @splat" {
414414}
415415
416416test "load vector elements via comptime index" {
417 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
418417 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
419418 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
420419
tools/update_cpu_features.zig+14-1
......@@ -80,7 +80,20 @@ const spirv_extra_features = blk: {
8080 feature.* = .{
8181 .zig_name = name,
8282 .desc = "Enable " ++ name ++ " extension",
83 .deps = &.{},
83 .deps = if (std.mem.eql(u8, name, "v1_6"))
84 &.{"v1_5"}
85 else if (std.mem.eql(u8, name, "v1_5"))
86 &.{"v1_4"}
87 else if (std.mem.eql(u8, name, "v1_4"))
88 &.{"v1_3"}
89 else if (std.mem.eql(u8, name, "v1_3"))
90 &.{"v1_2"}
91 else if (std.mem.eql(u8, name, "v1_2"))
92 &.{"v1_1"}
93 else if (std.mem.eql(u8, name, "v1_1"))
94 &.{"v1_0"}
95 else
96 &.{},
8497 };
8598 }
8699