authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-13 14:12:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
log6ad6a58e5dcb2d127f980cfb9d3edd7cf1964852
tree6e02b6fb17afbcb036434d41f74ca78c0ee1ec50
parenta60ffaf5b357cd85200fffba8bd0e98df5f91a16

Configuration: fix bad serialization of PrefixedList and MultiList

Length zero is still serialized because there is no flag bit to hide the length.

4 files changed, 13 insertions(+), 7 deletions(-)

BRANCH_TODO+1-1
......@@ -1,4 +1,4 @@
1* replace union(@This().Tag)
1* maxInt(u32) -> max_u32
22* replace b.dupe() with string internment
33* don't forget to add -listen arg back
44* get zig init template working
lib/compiler/Maker/ScannedConfig.zig+2-2
......@@ -68,8 +68,8 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
6868 Configuration.String => {
6969 try s.value(field_value.slice(c), .{});
7070 },
71 Configuration.Deps => {
72 try printValue(sc, s, []Configuration.Step.Index, field_value.slice(c));
71 Configuration.Deps.Index => {
72 try printValue(sc, s, []const Configuration.Step.Index, field_value.get(c).steps.slice);
7373 },
7474 Configuration.MaxRss => {
7575 try s.value(field_value.toBytes(), .{});
lib/compiler/configurer.zig+1
......@@ -528,6 +528,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
528528 const dep_steps = try arena.alloc(Configuration.Step.Index, step.dependencies.items.len);
529529 for (dep_steps, step.dependencies.items) |*dest, src|
530530 dest.* = @enumFromInt(s.step_map.getIndex(src).?);
531
531532 const deps: Configuration.Deps.Index = @enumFromInt(try wc.addDeduped(@as(Configuration.Deps, .{
532533 .steps = .{ .slice = dep_steps },
533534 })));
lib/std/Build/Configuration.zig+9-4
......@@ -346,7 +346,7 @@ pub const Wip = struct {
346346 try wip.extra.ensureUnusedCapacity(gpa, extra_len);
347347 const new_index = addExtraAssumeCapacity(wip, extra);
348348 const len: u32 = @intCast(wip.extra.items.len - new_index);
349
349 assert(len != 0);
350350 const gop = try wip.dedupe_table.getOrPutContext(gpa, .{
351351 .index = new_index,
352352 .len = len,
......@@ -2417,9 +2417,15 @@ pub const Storage = enum {
24172417 inline else => |x| setExtraField(buffer, i, @TypeOf(x), x),
24182418 },
24192419 .extended => @compileError("TODO"),
2420 .flag_length_prefixed_list, .length_prefixed_list => {
2420 .flag_length_prefixed_list => {
2421 const len: u32 = @intCast(value.slice.len);
2422 if (len == 0) return 0; // Flag bit hides the length prefix.
2423 buffer[i] = len;
2424 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
2425 return len + 1;
2426 },
2427 .length_prefixed_list => {
24212428 const len: u32 = @intCast(value.slice.len);
2422 if (len == 0) return 0;
24232429 buffer[i] = len;
24242430 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
24252431 return len + 1;
......@@ -2431,7 +2437,6 @@ pub const Storage = enum {
24312437 },
24322438 .multi_list => {
24332439 const len: u32 = @intCast(value.mal.len);
2434 if (len == 0) return 0;
24352440 buffer[i] = len;
24362441 const fields = @typeInfo(Field.Elem).@"struct".fields;
24372442 inline for (0..fields.len) |field_i| @memcpy(