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,4 +1,4 @@
1* replace union(@This().Tag)1* maxInt(u32) -> max_u32
2* replace b.dupe() with string internment2* replace b.dupe() with string internment
3* don't forget to add -listen arg back3* don't forget to add -listen arg back
4* get zig init template working4* 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...@@ -68,8 +68,8 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
68 Configuration.String => {68 Configuration.String => {
69 try s.value(field_value.slice(c), .{});69 try s.value(field_value.slice(c), .{});
70 },70 },
71 Configuration.Deps => {71 Configuration.Deps.Index => {
72 try printValue(sc, s, []Configuration.Step.Index, field_value.slice(c));72 try printValue(sc, s, []const Configuration.Step.Index, field_value.get(c).steps.slice);
73 },73 },
74 Configuration.MaxRss => {74 Configuration.MaxRss => {
75 try s.value(field_value.toBytes(), .{});75 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 {...@@ -528,6 +528,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
528 const dep_steps = try arena.alloc(Configuration.Step.Index, step.dependencies.items.len);528 const dep_steps = try arena.alloc(Configuration.Step.Index, step.dependencies.items.len);
529 for (dep_steps, step.dependencies.items) |*dest, src|529 for (dep_steps, step.dependencies.items) |*dest, src|
530 dest.* = @enumFromInt(s.step_map.getIndex(src).?);530 dest.* = @enumFromInt(s.step_map.getIndex(src).?);
531
531 const deps: Configuration.Deps.Index = @enumFromInt(try wc.addDeduped(@as(Configuration.Deps, .{532 const deps: Configuration.Deps.Index = @enumFromInt(try wc.addDeduped(@as(Configuration.Deps, .{
532 .steps = .{ .slice = dep_steps },533 .steps = .{ .slice = dep_steps },
533 })));534 })));
lib/std/Build/Configuration.zig+9-4
...@@ -346,7 +346,7 @@ pub const Wip = struct {...@@ -346,7 +346,7 @@ pub const Wip = struct {
346 try wip.extra.ensureUnusedCapacity(gpa, extra_len);346 try wip.extra.ensureUnusedCapacity(gpa, extra_len);
347 const new_index = addExtraAssumeCapacity(wip, extra);347 const new_index = addExtraAssumeCapacity(wip, extra);
348 const len: u32 = @intCast(wip.extra.items.len - new_index);348 const len: u32 = @intCast(wip.extra.items.len - new_index);
349349 assert(len != 0);
350 const gop = try wip.dedupe_table.getOrPutContext(gpa, .{350 const gop = try wip.dedupe_table.getOrPutContext(gpa, .{
351 .index = new_index,351 .index = new_index,
352 .len = len,352 .len = len,
...@@ -2417,9 +2417,15 @@ pub const Storage = enum {...@@ -2417,9 +2417,15 @@ pub const Storage = enum {
2417 inline else => |x| setExtraField(buffer, i, @TypeOf(x), x),2417 inline else => |x| setExtraField(buffer, i, @TypeOf(x), x),
2418 },2418 },
2419 .extended => @compileError("TODO"),2419 .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 => {
2421 const len: u32 = @intCast(value.slice.len);2428 const len: u32 = @intCast(value.slice.len);
2422 if (len == 0) return 0;
2423 buffer[i] = len;2429 buffer[i] = len;
2424 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));2430 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
2425 return len + 1;2431 return len + 1;
...@@ -2431,7 +2437,6 @@ pub const Storage = enum {...@@ -2431,7 +2437,6 @@ pub const Storage = enum {
2431 },2437 },
2432 .multi_list => {2438 .multi_list => {
2433 const len: u32 = @intCast(value.mal.len);2439 const len: u32 = @intCast(value.mal.len);
2434 if (len == 0) return 0;
2435 buffer[i] = len;2440 buffer[i] = len;
2436 const fields = @typeInfo(Field.Elem).@"struct".fields;2441 const fields = @typeInfo(Field.Elem).@"struct".fields;
2437 inline for (0..fields.len) |field_i| @memcpy(2442 inline for (0..fields.len) |field_i| @memcpy(