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 {...@@ -1675,11 +1675,12 @@ pub const Manifest = struct {
1675 FileSystemFailure,1675 FileSystemFailure,
1676 } || Allocator.Error || Io.Cancelable;1676 } || Allocator.Error || Io.Cancelable;
16771677
1678 /// Add a file as a dependency of process being cached, after cache miss1678 /// Add a file or directory as a dependency of process being cached, after cache miss occurs.
1679 /// occurs.
1680 ///1679 ///
1681 /// See also:1680 /// See also:
1682 /// * `addInputPath`1681 /// * `addInputPath`
1682 /// * `addDiscoveredDepFile`
1683 /// * `addDiscoveredManifest`
1683 pub fn addDiscoveredPath(m: *Manifest, options: AddDiscoveredPathOptions) AddDiscoveredPathError!void {1684 pub fn addDiscoveredPath(m: *Manifest, options: AddDiscoveredPathOptions) AddDiscoveredPathError!void {
1684 assert(m.manifest_file != null);1685 assert(m.manifest_file != null);
1685 transitionToMissDiscovered(m);1686 transitionToMissDiscovered(m);
...@@ -1788,6 +1789,11 @@ pub const Manifest = struct {...@@ -1788,6 +1789,11 @@ pub const Manifest = struct {
1788 dep_tokenizer: DepTokenizer.Token,1789 dep_tokenizer: DepTokenizer.Token,
1789 };1790 };
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`
1791 pub fn addDiscoveredDepFile(1797 pub fn addDiscoveredDepFile(
1792 m: *Manifest,1798 m: *Manifest,
1793 path: Path,1799 path: Path,
...@@ -2077,7 +2083,7 @@ pub const Manifest = struct {...@@ -2077,7 +2083,7 @@ pub const Manifest = struct {
2077 m.* = undefined;2083 m.* = undefined;
2078 }2084 }
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 {
2081 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);2087 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);
2082 buf.clearRetainingCapacity();2088 buf.clearRetainingCapacity();
2083 const gpa = man.cache.gpa;2089 const gpa = man.cache.gpa;
...@@ -2096,42 +2102,49 @@ pub const Manifest = struct {...@@ -2096,42 +2102,49 @@ pub const Manifest = struct {
2096 }2102 }
2097 }2103 }
20982104
2099 pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [5]u8) Allocator.Error!void {2105 /// Add the full set of paths from another `Manifest` as a dependency of process being cached, after cache miss
2100 const gpa = other.cache.gpa;2106 /// occurs.
2101 assert(other.manifest_file != null);2107 ///
2102 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);2108 /// See also:
2103 assert(man.cache.prefixes_len == 5);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();2118 const orig_files_len = m.files.count();
2106 const orig_contents_len = other.contents.items.len;2119 const orig_contents_len = m.contents.items.len;
2107 errdefer {2120 errdefer {
2108 other.files.shrinkRetainingCapacityContext(orig_files_len, .{ .contents = other.contents.items });2121 m.files.shrinkRetainingCapacityContext(orig_files_len, .{ .contents = m.contents.items });
2109 other.contents.shrinkRetainingCapacity(orig_contents_len);2122 m.contents.shrinkRetainingCapacity(orig_contents_len);
2110 }2123 }
21112124
2112 for (man.files.keys(), 0..) |off, file_index| {2125 for (discovered.files.keys(), 0..) |off, file_index| {
2113 try other.files.ensureUnusedCapacityContext(gpa, 1, .{ .contents = other.contents.items });2126 try m.files.ensureUnusedCapacityContext(gpa, 1, .{ .contents = m.contents.items });
21142127
2115 const next_off = if (file_index < man.files.count())2128 const next_off = if (file_index < discovered.files.count())
2116 @backingInt(man.files.keys()[file_index + 1])2129 @backingInt(discovered.files.keys()[file_index + 1])
2117 else2130 else
2118 man.contents.items.len;2131 discovered.contents.items.len;
21192132
2120 const copy_bytes = man.contents.items[@backingInt(off)..next_off];2133 const copy_bytes = discovered.contents.items[@backingInt(off)..next_off];
2121 const prev_contents_len: File.Offset = @fromBackingInt(@intCast(other.contents.items.len));2134 const prev_contents_len: File.Offset = @fromBackingInt(@intCast(m.contents.items.len));
2122 try other.contents.appendSlice(gpa, copy_bytes);2135 try m.contents.appendSlice(gpa, copy_bytes);
21232136
2124 const gop = other.files.getOrPutAssumeCapacityContext(prev_contents_len, .{2137 const gop = m.files.getOrPutAssumeCapacityContext(prev_contents_len, .{
2125 .contents = other.contents.items,2138 .contents = m.contents.items,
2126 });2139 });
21272140
2128 if (gop.found_existing) {2141 if (gop.found_existing) {
2129 other.contents.shrinkRetainingCapacity(@backingInt(prev_contents_len));2142 m.contents.shrinkRetainingCapacity(@backingInt(prev_contents_len));
2130 continue;2143 continue;
2131 }2144 }
21322145
2133 // Flags are already copied but the prefix is supposed to be filtered by `prefix_map`.2146 // 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);
2135 other_file.flags.prefix = @intCast(prefix_map[other_file.flags.prefix]);2148 other_file.flags.prefix = @intCast(prefix_map[other_file.flags.prefix]);
2136 }2149 }
2137 }2150 }
src/Compilation.zig+2-2
...@@ -2835,7 +2835,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2835,7 +2835,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2835 if (comp.parent_whole_cache) |pwc| {2835 if (comp.parent_whole_cache) |pwc| {
2836 try pwc.mutex.lock(io);2836 try pwc.mutex.lock(io);
2837 defer pwc.mutex.unlock(io);2837 defer pwc.mutex.unlock(io);
2838 try man.populateOtherManifest(pwc.manifest, pwc.prefix_map);2838 try pwc.manifest.addDiscoveredManifest(&man, pwc.prefix_map);
2839 }2839 }
28402840
2841 comp.last_update_was_cache_hit = true;2841 comp.last_update_was_cache_hit = true;
...@@ -3046,7 +3046,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -3046,7 +3046,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
3046 if (comp.parent_whole_cache) |pwc| {3046 if (comp.parent_whole_cache) |pwc| {
3047 try pwc.mutex.lock(io);3047 try pwc.mutex.lock(io);
3048 defer pwc.mutex.unlock(io);3048 defer pwc.mutex.unlock(io);
3049 try man.populateOtherManifest(pwc.manifest, pwc.prefix_map);3049 try pwc.manifest.addDiscoveredManifest(&man, pwc.prefix_map);
3050 }3050 }
30513051
3052 const bin_digest = man.missDigest();3052 const bin_digest = man.missDigest();