authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-14 00:32:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-16 13:12:47-07:00
log3bb9f1847b373256f495fdc602c5ab6a9f6e7724
tree572d4d77193db1f537c6ba46c0637409286df2bb
parenta014c1a2876acf93a11cf4c1fdd255939ee0c6e0

std.Build.Cache: add transitionToMissDiscovered in addDiscoveredManifest


2 files changed, 39 insertions(+), 26 deletions(-)

lib/std/Build/Cache.zig+37-24
......@@ -1675,11 +1675,12 @@ pub const Manifest = struct {
16751675 FileSystemFailure,
16761676 } || Allocator.Error || Io.Cancelable;
16771677
1678 /// Add a file as a dependency of process being cached, after cache miss
1679 /// occurs.
1678 /// Add a file or directory as a dependency of process being cached, after cache miss occurs.
16801679 ///
16811680 /// See also:
16821681 /// * `addInputPath`
1682 /// * `addDiscoveredDepFile`
1683 /// * `addDiscoveredManifest`
16831684 pub fn addDiscoveredPath(m: *Manifest, options: AddDiscoveredPathOptions) AddDiscoveredPathError!void {
16841685 assert(m.manifest_file != null);
16851686 transitionToMissDiscovered(m);
......@@ -1788,6 +1789,11 @@ pub const Manifest = struct {
17881789 dep_tokenizer: DepTokenizer.Token,
17891790 };
17901791
1792 /// Add a GNU make style dep file as a dependency of process being cached, after cache miss occurs.
1793 ///
1794 /// See also:
1795 /// * `addDiscoveredPath
1796 /// * `addDiscoveredManifest`
17911797 pub fn addDiscoveredDepFile(
17921798 m: *Manifest,
17931799 path: Path,
......@@ -2077,7 +2083,7 @@ pub const Manifest = struct {
20772083 m.* = undefined;
20782084 }
20792085
2080 pub fn populateFileSystemInputs(man: *Manifest, buf: *std.ArrayList(u8)) Allocator.Error!void {
2086 pub fn populateFileSystemInputs(man: *const Manifest, buf: *std.ArrayList(u8)) Allocator.Error!void {
20812087 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);
20822088 buf.clearRetainingCapacity();
20832089 const gpa = man.cache.gpa;
......@@ -2096,42 +2102,49 @@ pub const Manifest = struct {
20962102 }
20972103 }
20982104
2099 pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [5]u8) Allocator.Error!void {
2100 const gpa = other.cache.gpa;
2101 assert(other.manifest_file != null);
2102 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);
2103 assert(man.cache.prefixes_len == 5);
2105 /// Add the full set of paths from another `Manifest` as a dependency of process being cached, after cache miss
2106 /// occurs.
2107 ///
2108 /// See also:
2109 /// * `addDiscoveredPath
2110 /// * `addDiscoveredDepFile`
2111 pub fn addDiscoveredManifest(m: *Manifest, discovered: *const Manifest, prefix_map: [5]u8) Allocator.Error!void {
2112 const gpa = m.cache.gpa;
2113 assert(m.manifest_file != null);
2114 transitionToMissDiscovered(m);
2115 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == discovered.cache.prefixes_len);
2116 assert(discovered.cache.prefixes_len == 5);
21042117
2105 const orig_files_len = other.files.count();
2106 const orig_contents_len = other.contents.items.len;
2118 const orig_files_len = m.files.count();
2119 const orig_contents_len = m.contents.items.len;
21072120 errdefer {
2108 other.files.shrinkRetainingCapacityContext(orig_files_len, .{ .contents = other.contents.items });
2109 other.contents.shrinkRetainingCapacity(orig_contents_len);
2121 m.files.shrinkRetainingCapacityContext(orig_files_len, .{ .contents = m.contents.items });
2122 m.contents.shrinkRetainingCapacity(orig_contents_len);
21102123 }
21112124
2112 for (man.files.keys(), 0..) |off, file_index| {
2113 try other.files.ensureUnusedCapacityContext(gpa, 1, .{ .contents = other.contents.items });
2125 for (discovered.files.keys(), 0..) |off, file_index| {
2126 try m.files.ensureUnusedCapacityContext(gpa, 1, .{ .contents = m.contents.items });
21142127
2115 const next_off = if (file_index < man.files.count())
2116 @backingInt(man.files.keys()[file_index + 1])
2128 const next_off = if (file_index < discovered.files.count())
2129 @backingInt(discovered.files.keys()[file_index + 1])
21172130 else
2118 man.contents.items.len;
2131 discovered.contents.items.len;
21192132
2120 const copy_bytes = man.contents.items[@backingInt(off)..next_off];
2121 const prev_contents_len: File.Offset = @fromBackingInt(@intCast(other.contents.items.len));
2122 try other.contents.appendSlice(gpa, copy_bytes);
2133 const copy_bytes = discovered.contents.items[@backingInt(off)..next_off];
2134 const prev_contents_len: File.Offset = @fromBackingInt(@intCast(m.contents.items.len));
2135 try m.contents.appendSlice(gpa, copy_bytes);
21232136
2124 const gop = other.files.getOrPutAssumeCapacityContext(prev_contents_len, .{
2125 .contents = other.contents.items,
2137 const gop = m.files.getOrPutAssumeCapacityContext(prev_contents_len, .{
2138 .contents = m.contents.items,
21262139 });
21272140
21282141 if (gop.found_existing) {
2129 other.contents.shrinkRetainingCapacity(@backingInt(prev_contents_len));
2142 m.contents.shrinkRetainingCapacity(@backingInt(prev_contents_len));
21302143 continue;
21312144 }
21322145
21332146 // Flags are already copied but the prefix is supposed to be filtered by `prefix_map`.
2134 const other_file = prev_contents_len.get(other.contents.items);
2147 const other_file = prev_contents_len.get(m.contents.items);
21352148 other_file.flags.prefix = @intCast(prefix_map[other_file.flags.prefix]);
21362149 }
21372150 }
src/Compilation.zig+2-2
......@@ -2835,7 +2835,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
28352835 if (comp.parent_whole_cache) |pwc| {
28362836 try pwc.mutex.lock(io);
28372837 defer pwc.mutex.unlock(io);
2838 try man.populateOtherManifest(pwc.manifest, pwc.prefix_map);
2838 try pwc.manifest.addDiscoveredManifest(&man, pwc.prefix_map);
28392839 }
28402840
28412841 comp.last_update_was_cache_hit = true;
......@@ -3046,7 +3046,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
30463046 if (comp.parent_whole_cache) |pwc| {
30473047 try pwc.mutex.lock(io);
30483048 defer pwc.mutex.unlock(io);
3049 try man.populateOtherManifest(pwc.manifest, pwc.prefix_map);
3049 try pwc.manifest.addDiscoveredManifest(&man, pwc.prefix_map);
30503050 }
30513051
30523052 const bin_digest = man.missDigest();