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 {
10711071 pub const Shdr = extern struct {
10721072 name: Word,
10731073 type: SHT,
1074 flags: packed struct { shf: SHF },
1074 flags: packed struct(Word) { shf: SHF },
10751075 addr: Elf32.Addr,
10761076 offset: Elf32.Off,
10771077 size: Word,
......@@ -1161,7 +1161,7 @@ pub const Elf64 = struct {
11611161 pub const Shdr = extern struct {
11621162 name: Word,
11631163 type: SHT,
1164 flags: packed struct { shf: SHF, unused: Word = 0 },
1164 flags: packed struct(Xword) { shf: SHF, unused: Word = 0 },
11651165 addr: Elf64.Addr,
11661166 offset: Elf64.Off,
11671167 size: Xword,
lib/std/meta.zig+1-1
......@@ -315,7 +315,7 @@ test declarationInfo {
315315 try testing.expect(comptime mem.eql(u8, info.name, "a"));
316316 }
317317}
318pub fn fields(comptime T: type) switch (@typeInfo(T)) {
318pub inline fn fields(comptime T: type) switch (@typeInfo(T)) {
319319 .@"struct" => []const Type.StructField,
320320 .@"union" => []const Type.UnionField,
321321 .@"enum" => []const Type.EnumField,
lib/std/multi_array_list.zig+14-8
......@@ -19,7 +19,11 @@ const testing = std.testing;
1919/// For unions you can call `.items(.tags)` or `.items(.data)`.
2020pub fn MultiArrayList(comptime T: type) type {
2121 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,
2327 len: usize = 0,
2428 capacity: usize = 0,
2529
......@@ -133,10 +137,8 @@ pub fn MultiArrayList(comptime T: type) type {
133137 if (self.ptrs.len == 0 or self.capacity == 0) {
134138 return .{};
135139 }
136 const unaligned_ptr = self.ptrs[sizes.fields[0]];
137 const aligned_ptr: [*]align(@alignOf(Elem)) u8 = @alignCast(unaligned_ptr);
138140 return .{
139 .bytes = aligned_ptr,
141 .bytes = self.ptrs[sizes.fields[0]],
140142 .len = self.len,
141143 .capacity = self.capacity,
142144 };
......@@ -179,6 +181,7 @@ pub fn MultiArrayList(comptime T: type) type {
179181 const fields = meta.fields(Elem);
180182 /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.
181183 /// `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.
182185 const sizes = blk: {
183186 const Data = struct {
184187 size: usize,
......@@ -186,12 +189,14 @@ pub fn MultiArrayList(comptime T: type) type {
186189 alignment: usize,
187190 };
188191 var data: [fields.len]Data = undefined;
192 var big_align: usize = 1;
189193 for (fields, 0..) |field_info, i| {
190194 data[i] = .{
191195 .size = @sizeOf(field_info.type),
192196 .size_index = i,
193197 .alignment = if (@sizeOf(field_info.type) == 0) 1 else field_info.alignment,
194198 };
199 big_align = @max(big_align, @alignOf(field_info.type));
195200 }
196201 const Sort = struct {
197202 fn lessThan(context: void, lhs: Data, rhs: Data) bool {
......@@ -210,6 +215,7 @@ pub fn MultiArrayList(comptime T: type) type {
210215 break :blk .{
211216 .bytes = sizes_bytes,
212217 .fields = field_indexes,
218 .big_align = mem.Alignment.fromByteUnits(big_align),
213219 };
214220 };
215221
......@@ -452,7 +458,7 @@ pub fn MultiArrayList(comptime T: type) type {
452458 assert(new_len <= self.capacity);
453459 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 {
456462 const self_slice = self.slice();
457463 inline for (fields, 0..) |field_info, i| {
458464 if (@sizeOf(field_info.type) != 0) {
......@@ -533,7 +539,7 @@ pub fn MultiArrayList(comptime T: type) type {
533539 /// `new_capacity` must be greater or equal to `len`.
534540 pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void {
535541 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));
537543 if (self.len == 0) {
538544 gpa.free(self.allocatedBytes());
539545 self.bytes = new_bytes.ptr;
......@@ -650,8 +656,8 @@ pub fn MultiArrayList(comptime T: type) type {
650656 return elem_bytes * capacity;
651657 }
652658
653 fn allocatedBytes(self: Self) []align(@alignOf(Elem)) u8 {
654 return self.bytes[0..capacityInBytes(self.capacity)];
659 fn allocatedBytes(self: Self) []align(sizes.big_align.toByteUnits()) u8 {
660 return @alignCast(self.bytes[0..capacityInBytes(self.capacity)]);
655661 }
656662
657663 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 {
71137113 flags: Flags,
71147114 resv: [3]u64,
71157115
7116 pub const Flags = packed struct {
7116 pub const Flags = packed struct(u16) {
71177117 _0: u1 = 0,
71187118 /// Incremental buffer consumption.
71197119 inc: bool,
lib/std/testing.zig+2-3
......@@ -950,9 +950,8 @@ test "expectEqualDeep primitive type" {
950950}
951951
952952test "expectEqualDeep pointer" {
953 const a = 1;
954 const b = 1;
955 try expectEqualDeep(&a, &b);
953 try comptime expectEqualDeep(&1, &1);
954 try expectEqualDeep(&@as(u32, 1), &@as(u32, 1));
956955}
957956
958957test "expectEqualDeep composite type" {
lib/std/zon/Serializer.zig+3-1
......@@ -793,9 +793,11 @@ test checkValueDepth {
793793 try expectValueDepthEquals(2, @as(?u32, 1));
794794 try expectValueDepthEquals(1, @as(?u32, null));
795795 try expectValueDepthEquals(1, null);
796 try expectValueDepthEquals(2, &1);
797796 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
799801 const Union = union(enum) {
800802 x: u32,
801803 y: struct { x: u32 },