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 {...@@ -1608,16 +1608,24 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
16081608
1609 if (configuration.unlazy_deps.len != 0) {1609 if (configuration.unlazy_deps.len != 0) {
1610 var any_errors = false;1610 var any_errors = false;
1611 for (configuration.unlazy_deps) |hash_string| {1611 for (configuration.unlazy_deps) |unlazy_dep| {
1612 const hash = hash_string.slice(&configuration);1612 if (unlazy_dep.step.unwrap()) |step_index| {
1613 assert(hash.len != 0);1613 log.err("TODO implement step-associated lazy dependencies in maker", .{});
1614 if (hash.len > Package.Hash.max_len) {
1615 log.err("invalid digest (length {d} exceeds maximum): {q}", .{ hash.len, hash });
1616 any_errors = true;1614 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 }
1618 }1628 }
1619 log.info("fetching lazy dependency {s}", .{hash});
1620 try unlazy_set.put(arena, .fromSlice(hash), {});
1621 }1629 }
1622 if (any_errors) return error.FailedButCacheIntact;1630 if (any_errors) return error.FailedButCacheIntact;
1623 if (options.system_pkg_dir_path) |p| {1631 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 {...@@ -55,7 +55,9 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
55 {55 {
56 var tf = try s.beginTupleField("unlazy_deps", .{});56 var tf = try s.beginTupleField("unlazy_deps", .{});
57 for (c.unlazy_deps) |dep| {57 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();
59 }61 }
60 try tf.end();62 try tf.end();
61 }63 }
lib/std/Build/Configuration.zig+26-4
...@@ -11,7 +11,7 @@ const native_endian = builtin.target.cpu.arch.endian();...@@ -11,7 +11,7 @@ const native_endian = builtin.target.cpu.arch.endian();
11string_bytes: []u8,11string_bytes: []u8,
12steps: []Step,12steps: []Step,
13path_deps: []PathDep,13path_deps: []PathDep,
14unlazy_deps: []String,14unlazy_deps: []UnlazyDep,
15system_integrations: []SystemIntegration,15system_integrations: []SystemIntegration,
16available_options: []AvailableOption,16available_options: []AvailableOption,
17search_prefixes: []String,17search_prefixes: []String,
...@@ -52,7 +52,7 @@ pub const Wip = struct {...@@ -52,7 +52,7 @@ pub const Wip = struct {
52 targets_table: TargetsTable = .empty,52 targets_table: TargetsTable = .empty,
5353
54 string_bytes: std.ArrayList(u8) = .empty,54 string_bytes: std.ArrayList(u8) = .empty,
55 unlazy_deps: std.ArrayList(String) = .empty,55 unlazy_deps: std.ArrayList(UnlazyDep) = .empty,
56 system_integrations: std.ArrayList(SystemIntegration) = .empty,56 system_integrations: std.ArrayList(SystemIntegration) = .empty,
57 available_options: std.ArrayList(AvailableOption) = .empty,57 available_options: std.ArrayList(AvailableOption) = .empty,
58 steps: std.ArrayList(Step) = .empty,58 steps: std.ArrayList(Step) = .empty,
...@@ -495,12 +495,17 @@ pub const AvailableOption = extern struct {...@@ -495,12 +495,17 @@ pub const AvailableOption = extern struct {
495 };495 };
496};496};
497497
498pub const UnlazyDep = extern struct {
499 /// none indicates not associated with any particular step.
500 step: Step.OptionalIndex,
501 list: StringList,
502};
503
498pub const Step = extern struct {504pub const Step = extern struct {
499 name: String,505 name: String,
500 owner: Package.Index,506 owner: Package.Index,
501 deps: Deps.Index,507 deps: Deps.Index,
502 max_rss: MaxRss,508 max_rss: MaxRss,
503 unlazy_deps: OptionalStringList,
504 extended: Storage.Extended(Flags, union(Tag) {509 extended: Storage.Extended(Flags, union(Tag) {
505 check_file: CheckFile,510 check_file: CheckFile,
506 compile: Compile,511 compile: Compile,
...@@ -529,6 +534,23 @@ pub const Step = extern struct {...@@ -529,6 +534,23 @@ pub const Step = extern struct {
529 }534 }
530 };535 };
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
532 /// Shared by all steps.554 /// Shared by all steps.
533 pub const Flags = packed struct(u32) {555 pub const Flags = packed struct(u32) {
534 tag: Tag,556 tag: Tag,
...@@ -3156,7 +3178,7 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {...@@ -3156,7 +3178,7 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {
3156 .string_bytes = try arena.alloc(u8, header.string_bytes_len),3178 .string_bytes = try arena.alloc(u8, header.string_bytes_len),
3157 .steps = try arena.alloc(Step, header.steps_len),3179 .steps = try arena.alloc(Step, header.steps_len),
3158 .path_deps = try arena.alloc(PathDep, header.path_deps_len),3180 .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),
3160 .system_integrations = try arena.alloc(SystemIntegration, header.system_integrations_len),3182 .system_integrations = try arena.alloc(SystemIntegration, header.system_integrations_len),
3161 .available_options = try arena.alloc(AvailableOption, header.available_options_len),3183 .available_options = try arena.alloc(AvailableOption, header.available_options_len),
3162 .search_prefixes = try arena.alloc(String, header.search_prefixes_len),3184 .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...@@ -681,22 +681,23 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi
681 .owner = try s.builderToPackage(step.owner),681 .owner = try s.builderToPackage(step.owner),
682 .deps = deps,682 .deps = deps,
683 .max_rss = .fromBytes(step.max_rss),683 .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,
688 .extended = @fromBackingInt(extended),684 .extended = @fromBackingInt(extended),
689 });685 });
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 }
690 }693 }
691 }694 }
692695
693 {696 if (graph.unlazy_deps.count() != 0) {
694 // TODO exchange graph.unlazy_deps.keys with the wc.unlazy_deps array list without copying697 try wc.unlazy_deps.append(gpa, .{
695 // MultiArrayList should support this when there is only 1 non zero sized struct field698 .step = .none,
696 const unlazy_deps = graph.unlazy_deps.keys();699 .list = try wc.addStringListInterned(graph.unlazy_deps.keys()),
697 try wc.unlazy_deps.ensureTotalCapacityPrecise(gpa, unlazy_deps.len);700 });
698 assert(wc.unlazy_deps.items.len == 0);
699 wc.unlazy_deps.appendSliceAssumeCapacity(unlazy_deps);
700 }701 }
701702
702 try wc.write(writer, .{703 try wc.write(writer, .{