authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-15 16:37:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-15 16:37:06-07:00
logc3cdf484072d84f32e19c9286071a913269c90e9
treea0be35e5e6b163f80eb94d4e8131d6de1754d1a6
parent2c18bccf4428a6e23ed5c5572243337a560af9b5

Configuration: store unlazy dependencies differently

steps are many; unlazy dependencies are few

4 files changed, 57 insertions(+), 24 deletions(-)

lib/compiler/Maker.zig+16-8
......@@ -1608,16 +1608,24 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
16081608
16091609 if (configuration.unlazy_deps.len != 0) {
16101610 var any_errors = false;
1611 for (configuration.unlazy_deps) |hash_string| {
1612 const hash = hash_string.slice(&configuration);
1613 assert(hash.len != 0);
1614 if (hash.len > Package.Hash.max_len) {
1615 log.err("invalid digest (length {d} exceeds maximum): {q}", .{ hash.len, hash });
1611 for (configuration.unlazy_deps) |unlazy_dep| {
1612 if (unlazy_dep.step.unwrap()) |step_index| {
1613 log.err("TODO implement step-associated lazy dependencies in maker", .{});
16161614 any_errors = true;
1617 continue;
1615 _ = step_index;
1616 } else {
1617 for (unlazy_dep.list.slice(&configuration)) |hash_string| {
1618 const hash = hash_string.slice(&configuration);
1619 assert(hash.len != 0);
1620 if (hash.len > Package.Hash.max_len) {
1621 log.err("invalid digest (length {d} exceeds maximum): {q}", .{ hash.len, hash });
1622 any_errors = true;
1623 continue;
1624 }
1625 log.info("fetching lazy dependency {s}", .{hash});
1626 try unlazy_set.put(arena, .fromSlice(hash), {});
1627 }
16181628 }
1619 log.info("fetching lazy dependency {s}", .{hash});
1620 try unlazy_set.put(arena, .fromSlice(hash), {});
16211629 }
16221630 if (any_errors) return error.FailedButCacheIntact;
16231631 if (options.system_pkg_dir_path) |p| {
lib/compiler/Maker/ScannedConfig.zig+3-1
......@@ -55,7 +55,9 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
5555 {
5656 var tf = try s.beginTupleField("unlazy_deps", .{});
5757 for (c.unlazy_deps) |dep| {
58 try tf.field(dep.slice(c), .{});
58 var field = try tf.beginStructField(.{});
59 try printStruct(sc, &field, Configuration.UnlazyDep, dep);
60 try field.end();
5961 }
6062 try tf.end();
6163 }
lib/std/Build/Configuration.zig+26-4
......@@ -11,7 +11,7 @@ const native_endian = builtin.target.cpu.arch.endian();
1111string_bytes: []u8,
1212steps: []Step,
1313path_deps: []PathDep,
14unlazy_deps: []String,
14unlazy_deps: []UnlazyDep,
1515system_integrations: []SystemIntegration,
1616available_options: []AvailableOption,
1717search_prefixes: []String,
......@@ -52,7 +52,7 @@ pub const Wip = struct {
5252 targets_table: TargetsTable = .empty,
5353
5454 string_bytes: std.ArrayList(u8) = .empty,
55 unlazy_deps: std.ArrayList(String) = .empty,
55 unlazy_deps: std.ArrayList(UnlazyDep) = .empty,
5656 system_integrations: std.ArrayList(SystemIntegration) = .empty,
5757 available_options: std.ArrayList(AvailableOption) = .empty,
5858 steps: std.ArrayList(Step) = .empty,
......@@ -495,12 +495,17 @@ pub const AvailableOption = extern struct {
495495 };
496496};
497497
498pub const UnlazyDep = extern struct {
499 /// none indicates not associated with any particular step.
500 step: Step.OptionalIndex,
501 list: StringList,
502};
503
498504pub const Step = extern struct {
499505 name: String,
500506 owner: Package.Index,
501507 deps: Deps.Index,
502508 max_rss: MaxRss,
503 unlazy_deps: OptionalStringList,
504509 extended: Storage.Extended(Flags, union(Tag) {
505510 check_file: CheckFile,
506511 compile: Compile,
......@@ -529,6 +534,23 @@ pub const Step = extern struct {
529534 }
530535 };
531536
537 pub const OptionalIndex = enum(u32) {
538 none = max_u32,
539 _,
540
541 pub fn unwrap(this: @This()) ?Index {
542 return switch (this) {
543 .none => null,
544 else => @fromBackingInt(@intCast(@backingInt(this))),
545 };
546 }
547
548 pub fn ptr(i: @This(), c: *const Configuration) ?*const Step {
549 if (i == .none) return null;
550 return &c.steps[@backingInt(i)];
551 }
552 };
553
532554 /// Shared by all steps.
533555 pub const Flags = packed struct(u32) {
534556 tag: Tag,
......@@ -3156,7 +3178,7 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {
31563178 .string_bytes = try arena.alloc(u8, header.string_bytes_len),
31573179 .steps = try arena.alloc(Step, header.steps_len),
31583180 .path_deps = try arena.alloc(PathDep, header.path_deps_len),
3159 .unlazy_deps = try arena.alloc(String, header.unlazy_deps_len),
3181 .unlazy_deps = try arena.alloc(UnlazyDep, header.unlazy_deps_len),
31603182 .system_integrations = try arena.alloc(SystemIntegration, header.system_integrations_len),
31613183 .available_options = try arena.alloc(AvailableOption, header.available_options_len),
31623184 .search_prefixes = try arena.alloc(String, header.search_prefixes_len),
lib/std/Build/Serialize.zig+12-11
......@@ -681,22 +681,23 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi
681681 .owner = try s.builderToPackage(step.owner),
682682 .deps = deps,
683683 .max_rss = .fromBytes(step.max_rss),
684 .unlazy_deps = if (step.unlazy_deps.count() != 0)
685 .init(try wc.addStringListInterned(step.unlazy_deps.keys()))
686 else
687 .none,
688684 .extended = @fromBackingInt(extended),
689685 });
686
687 if (step.unlazy_deps.count() != 0) {
688 try wc.unlazy_deps.append(gpa, .{
689 .step = @fromBackingInt(@intCast(wc.steps.items.len - 1)),
690 .list = try wc.addStringListInterned(step.unlazy_deps.keys()),
691 });
692 }
690693 }
691694 }
692695
693 {
694 // TODO exchange graph.unlazy_deps.keys with the wc.unlazy_deps array list without copying
695 // MultiArrayList should support this when there is only 1 non zero sized struct field
696 const unlazy_deps = graph.unlazy_deps.keys();
697 try wc.unlazy_deps.ensureTotalCapacityPrecise(gpa, unlazy_deps.len);
698 assert(wc.unlazy_deps.items.len == 0);
699 wc.unlazy_deps.appendSliceAssumeCapacity(unlazy_deps);
696 if (graph.unlazy_deps.count() != 0) {
697 try wc.unlazy_deps.append(gpa, .{
698 .step = .none,
699 .list = try wc.addStringListInterned(graph.unlazy_deps.keys()),
700 });
700701 }
701702
702703 try wc.write(writer, .{