commit 6ad6a58e5dcb2d127f980cfb9d3edd7cf1964852 (tree)
parent a60ffaf5b357cd85200fffba8bd0e98df5f91a16
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 13 Mar 2026 14:12:37 -0700
Configuration: fix bad serialization of PrefixedList and MultiList
Length zero is still serialized because there is no flag bit to hide the
length.
Diffstat:
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/BRANCH_TODO b/BRANCH_TODO
@@ -1,4 +1,4 @@
-* replace union(@This().Tag)
+* maxInt(u32) -> max_u32
* replace b.dupe() with string internment
* don't forget to add -listen arg back
* get zig init template working
diff --git a/lib/compiler/Maker/ScannedConfig.zig b/lib/compiler/Maker/ScannedConfig.zig
@@ -68,8 +68,8 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
Configuration.String => {
try s.value(field_value.slice(c), .{});
},
- Configuration.Deps => {
- try printValue(sc, s, []Configuration.Step.Index, field_value.slice(c));
+ Configuration.Deps.Index => {
+ try printValue(sc, s, []const Configuration.Step.Index, field_value.get(c).steps.slice);
},
Configuration.MaxRss => {
try s.value(field_value.toBytes(), .{});
diff --git a/lib/compiler/configurer.zig b/lib/compiler/configurer.zig
@@ -528,6 +528,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
const dep_steps = try arena.alloc(Configuration.Step.Index, step.dependencies.items.len);
for (dep_steps, step.dependencies.items) |*dest, src|
dest.* = @enumFromInt(s.step_map.getIndex(src).?);
+
const deps: Configuration.Deps.Index = @enumFromInt(try wc.addDeduped(@as(Configuration.Deps, .{
.steps = .{ .slice = dep_steps },
})));
diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig
@@ -346,7 +346,7 @@ pub const Wip = struct {
try wip.extra.ensureUnusedCapacity(gpa, extra_len);
const new_index = addExtraAssumeCapacity(wip, extra);
const len: u32 = @intCast(wip.extra.items.len - new_index);
-
+ assert(len != 0);
const gop = try wip.dedupe_table.getOrPutContext(gpa, .{
.index = new_index,
.len = len,
@@ -2417,9 +2417,15 @@ pub const Storage = enum {
inline else => |x| setExtraField(buffer, i, @TypeOf(x), x),
},
.extended => @compileError("TODO"),
- .flag_length_prefixed_list, .length_prefixed_list => {
+ .flag_length_prefixed_list => {
+ const len: u32 = @intCast(value.slice.len);
+ if (len == 0) return 0; // Flag bit hides the length prefix.
+ buffer[i] = len;
+ @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
+ return len + 1;
+ },
+ .length_prefixed_list => {
const len: u32 = @intCast(value.slice.len);
- if (len == 0) return 0;
buffer[i] = len;
@memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
return len + 1;
@@ -2431,7 +2437,6 @@ pub const Storage = enum {
},
.multi_list => {
const len: u32 = @intCast(value.mal.len);
- if (len == 0) return 0;
buffer[i] = len;
const fields = @typeInfo(Field.Elem).@"struct".fields;
inline for (0..fields.len) |field_i| @memcpy(