authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-01-25 11:12:26+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:07+00:00
log792830d69cd335a49de97b617d3f668aa544b181
tree956fad2e9de39fd1cec658053ffb4a6e70398a3c
parent510ea6f61f93c722c4cb2c2b39605201cc2f9c32
signaturelock-open Commit is signed but in an unrecognized format.

std: work around language changes


6 files changed, 23 insertions(+), 16 deletions(-)

lib/std/elf.zig+2-2
...@@ -1071,7 +1071,7 @@ pub const Elf32 = struct {...@@ -1071,7 +1071,7 @@ pub const Elf32 = struct {
1071 pub const Shdr = extern struct {1071 pub const Shdr = extern struct {
1072 name: Word,1072 name: Word,
1073 type: SHT,1073 type: SHT,
1074 flags: packed struct { shf: SHF },1074 flags: packed struct(Word) { shf: SHF },
1075 addr: Elf32.Addr,1075 addr: Elf32.Addr,
1076 offset: Elf32.Off,1076 offset: Elf32.Off,
1077 size: Word,1077 size: Word,
...@@ -1161,7 +1161,7 @@ pub const Elf64 = struct {...@@ -1161,7 +1161,7 @@ pub const Elf64 = struct {
1161 pub const Shdr = extern struct {1161 pub const Shdr = extern struct {
1162 name: Word,1162 name: Word,
1163 type: SHT,1163 type: SHT,
1164 flags: packed struct { shf: SHF, unused: Word = 0 },1164 flags: packed struct(Xword) { shf: SHF, unused: Word = 0 },
1165 addr: Elf64.Addr,1165 addr: Elf64.Addr,
1166 offset: Elf64.Off,1166 offset: Elf64.Off,
1167 size: Xword,1167 size: Xword,
lib/std/meta.zig+1-1
...@@ -315,7 +315,7 @@ test declarationInfo {...@@ -315,7 +315,7 @@ test declarationInfo {
315 try testing.expect(comptime mem.eql(u8, info.name, "a"));315 try testing.expect(comptime mem.eql(u8, info.name, "a"));
316 }316 }
317}317}
318pub fn fields(comptime T: type) switch (@typeInfo(T)) {318pub inline fn fields(comptime T: type) switch (@typeInfo(T)) {
319 .@"struct" => []const Type.StructField,319 .@"struct" => []const Type.StructField,
320 .@"union" => []const Type.UnionField,320 .@"union" => []const Type.UnionField,
321 .@"enum" => []const Type.EnumField,321 .@"enum" => []const Type.EnumField,
lib/std/multi_array_list.zig+14-8
...@@ -19,7 +19,11 @@ const testing = std.testing;...@@ -19,7 +19,11 @@ const testing = std.testing;
19/// For unions you can call `.items(.tags)` or `.items(.data)`.19/// For unions you can call `.items(.tags)` or `.items(.data)`.
20pub fn MultiArrayList(comptime T: type) type {20pub fn MultiArrayList(comptime T: type) type {
21 return struct {21 return struct {
22 bytes: [*]align(@alignOf(T)) u8 = undefined,22 /// This pointer is always aligned to the boundary `sizes.big_align`; this is not specified
23 /// in the type to avoid `MultiArrayList(T)` depending on the alignment of `T` because this
24 /// can lead to dependency loops. See `allocatedBytes` which `@alignCast`s this pointer to
25 /// the correct type.
26 bytes: [*]u8 = undefined,
23 len: usize = 0,27 len: usize = 0,
24 capacity: usize = 0,28 capacity: usize = 0,
2529
...@@ -133,10 +137,8 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -133,10 +137,8 @@ pub fn MultiArrayList(comptime T: type) type {
133 if (self.ptrs.len == 0 or self.capacity == 0) {137 if (self.ptrs.len == 0 or self.capacity == 0) {
134 return .{};138 return .{};
135 }139 }
136 const unaligned_ptr = self.ptrs[sizes.fields[0]];
137 const aligned_ptr: [*]align(@alignOf(Elem)) u8 = @alignCast(unaligned_ptr);
138 return .{140 return .{
139 .bytes = aligned_ptr,141 .bytes = self.ptrs[sizes.fields[0]],
140 .len = self.len,142 .len = self.len,
141 .capacity = self.capacity,143 .capacity = self.capacity,
142 };144 };
...@@ -179,6 +181,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -179,6 +181,7 @@ pub fn MultiArrayList(comptime T: type) type {
179 const fields = meta.fields(Elem);181 const fields = meta.fields(Elem);
180 /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.182 /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.
181 /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index.183 /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index.
184 /// `sizes.big_align` is the overall alignment of the allocation, which equals the maximum field alignment.
182 const sizes = blk: {185 const sizes = blk: {
183 const Data = struct {186 const Data = struct {
184 size: usize,187 size: usize,
...@@ -186,12 +189,14 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -186,12 +189,14 @@ pub fn MultiArrayList(comptime T: type) type {
186 alignment: usize,189 alignment: usize,
187 };190 };
188 var data: [fields.len]Data = undefined;191 var data: [fields.len]Data = undefined;
192 var big_align: usize = 1;
189 for (fields, 0..) |field_info, i| {193 for (fields, 0..) |field_info, i| {
190 data[i] = .{194 data[i] = .{
191 .size = @sizeOf(field_info.type),195 .size = @sizeOf(field_info.type),
192 .size_index = i,196 .size_index = i,
193 .alignment = if (@sizeOf(field_info.type) == 0) 1 else field_info.alignment,197 .alignment = if (@sizeOf(field_info.type) == 0) 1 else field_info.alignment,
194 };198 };
199 big_align = @max(big_align, @alignOf(field_info.type));
195 }200 }
196 const Sort = struct {201 const Sort = struct {
197 fn lessThan(context: void, lhs: Data, rhs: Data) bool {202 fn lessThan(context: void, lhs: Data, rhs: Data) bool {
...@@ -210,6 +215,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -210,6 +215,7 @@ pub fn MultiArrayList(comptime T: type) type {
210 break :blk .{215 break :blk .{
211 .bytes = sizes_bytes,216 .bytes = sizes_bytes,
212 .fields = field_indexes,217 .fields = field_indexes,
218 .big_align = mem.Alignment.fromByteUnits(big_align),
213 };219 };
214 };220 };
215221
...@@ -452,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -452,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {
452 assert(new_len <= self.capacity);458 assert(new_len <= self.capacity);
453 assert(new_len <= self.len);459 assert(new_len <= self.len);
454460
455 const other_bytes = gpa.alignedAlloc(u8, .of(Elem), capacityInBytes(new_len)) catch {461 const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch {
456 const self_slice = self.slice();462 const self_slice = self.slice();
457 inline for (fields, 0..) |field_info, i| {463 inline for (fields, 0..) |field_info, i| {
458 if (@sizeOf(field_info.type) != 0) {464 if (@sizeOf(field_info.type) != 0) {
...@@ -533,7 +539,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -533,7 +539,7 @@ pub fn MultiArrayList(comptime T: type) type {
533 /// `new_capacity` must be greater or equal to `len`.539 /// `new_capacity` must be greater or equal to `len`.
534 pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void {540 pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void {
535 assert(new_capacity >= self.len);541 assert(new_capacity >= self.len);
536 const new_bytes = try gpa.alignedAlloc(u8, .of(Elem), capacityInBytes(new_capacity));542 const new_bytes = try gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_capacity));
537 if (self.len == 0) {543 if (self.len == 0) {
538 gpa.free(self.allocatedBytes());544 gpa.free(self.allocatedBytes());
539 self.bytes = new_bytes.ptr;545 self.bytes = new_bytes.ptr;
...@@ -650,8 +656,8 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -650,8 +656,8 @@ pub fn MultiArrayList(comptime T: type) type {
650 return elem_bytes * capacity;656 return elem_bytes * capacity;
651 }657 }
652658
653 fn allocatedBytes(self: Self) []align(@alignOf(Elem)) u8 {659 fn allocatedBytes(self: Self) []align(sizes.big_align.toByteUnits()) u8 {
654 return self.bytes[0..capacityInBytes(self.capacity)];660 return @alignCast(self.bytes[0..capacityInBytes(self.capacity)]);
655 }661 }
656662
657 fn FieldType(comptime field: Field) type {663 fn FieldType(comptime field: Field) type {
lib/std/os/linux.zig+1-1
...@@ -7113,7 +7113,7 @@ pub const io_uring_buf_reg = extern struct {...@@ -7113,7 +7113,7 @@ pub const io_uring_buf_reg = extern struct {
7113 flags: Flags,7113 flags: Flags,
7114 resv: [3]u64,7114 resv: [3]u64,
71157115
7116 pub const Flags = packed struct {7116 pub const Flags = packed struct(u16) {
7117 _0: u1 = 0,7117 _0: u1 = 0,
7118 /// Incremental buffer consumption.7118 /// Incremental buffer consumption.
7119 inc: bool,7119 inc: bool,
lib/std/testing.zig+2-3
...@@ -950,9 +950,8 @@ test "expectEqualDeep primitive type" {...@@ -950,9 +950,8 @@ test "expectEqualDeep primitive type" {
950}950}
951951
952test "expectEqualDeep pointer" {952test "expectEqualDeep pointer" {
953 const a = 1;953 try comptime expectEqualDeep(&1, &1);
954 const b = 1;954 try expectEqualDeep(&@as(u32, 1), &@as(u32, 1));
955 try expectEqualDeep(&a, &b);
956}955}
957956
958test "expectEqualDeep composite type" {957test "expectEqualDeep composite type" {
lib/std/zon/Serializer.zig+3-1
...@@ -793,9 +793,11 @@ test checkValueDepth {...@@ -793,9 +793,11 @@ test checkValueDepth {
793 try expectValueDepthEquals(2, @as(?u32, 1));793 try expectValueDepthEquals(2, @as(?u32, 1));
794 try expectValueDepthEquals(1, @as(?u32, null));794 try expectValueDepthEquals(1, @as(?u32, null));
795 try expectValueDepthEquals(1, null);795 try expectValueDepthEquals(1, null);
796 try expectValueDepthEquals(2, &1);
797 try expectValueDepthEquals(3, &@as(?u32, 1));796 try expectValueDepthEquals(3, &@as(?u32, 1));
798797
798 // The pointer drops the implicit comptime-ness, so we need to specify 'comptime' here
799 try comptime expectValueDepthEquals(2, &1);
800
799 const Union = union(enum) {801 const Union = union(enum) {
800 x: u32,802 x: u32,
801 y: struct { x: u32 },803 y: struct { x: u32 },