authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-03 15:04:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-04 17:42:21-07:00
log0342d5890d80f81178e2f725092b34157825f7a7
treec67119e81cad3fba43e24c49c5fab4933e5cd65b
parentfc1d90e2a1fdc92c020c3d1d6af6a3f768d8a9d2

std.Build.Cache: make IsDirectoryAmbiguous an assertion not error


1 files changed, 10 insertions(+), 18 deletions(-)

lib/std/Build/Cache.zig+10-18
...@@ -508,13 +508,6 @@ pub const Manifest = struct {...@@ -508,13 +508,6 @@ pub const Manifest = struct {
508 metadata_only: bool = false,508 metadata_only: bool = false,
509 };509 };
510510
511 pub const AddInputPathError = error{
512 /// The same file path has been added to the cache manifest both as a
513 /// directory and as a normal file, making the intended caching
514 /// behavior ambiguous.
515 IsDirectoryAmbiguous,
516 } || Allocator.Error;
517
518 /// Add a file or directory path as a dependency of process being cached.511 /// Add a file or directory path as a dependency of process being cached.
519 /// When `hit` is called, the contents will be checked to ensure512 /// When `hit` is called, the contents will be checked to ensure
520 /// that it matches the contents from previous times.513 /// that it matches the contents from previous times.
...@@ -530,7 +523,7 @@ pub const Manifest = struct {...@@ -530,7 +523,7 @@ pub const Manifest = struct {
530 ///523 ///
531 /// See also:524 /// See also:
532 /// * `addPathPost`525 /// * `addPathPost`
533 pub fn addInputPath(m: *Manifest, path: Path, options: AddInputPathOptions) AddInputPathError!InputPath.Index {526 pub fn addInputPath(m: *Manifest, path: Path, options: AddInputPathOptions) Allocator.Error!InputPath.Index {
534 const gpa = m.cache.gpa;527 const gpa = m.cache.gpa;
535 try m.files.ensureUnusedCapacity(gpa, 1);528 try m.files.ensureUnusedCapacity(gpa, 1);
536 try m.input_paths.ensureUnusedCapacity(gpa, 1);529 try m.input_paths.ensureUnusedCapacity(gpa, 1);
...@@ -573,8 +566,10 @@ pub const Manifest = struct {...@@ -573,8 +566,10 @@ pub const Manifest = struct {
573 existing_header.inode = stat.inode;566 existing_header.inode = stat.inode;
574 existing_header.mtime = stat.mtime;567 existing_header.mtime = stat.mtime;
575 }568 }
576 if (existing_header.flags.is_directory != options.is_directory)569 // If it trips, the same file path has been added to the cache
577 return error.IsDirectoryAmbiguous;570 // manifest both as a directory and as a normal file, making the
571 // intended caching behavior ambiguous.
572 assert(existing_header.flags.is_directory == options.is_directory);
578 if (!options.metadata_only)573 if (!options.metadata_only)
579 existing_header.flags.metadata_only = false;574 existing_header.flags.metadata_only = false;
580 } else {575 } else {
...@@ -1078,12 +1073,7 @@ pub const Manifest = struct {...@@ -1078,12 +1073,7 @@ pub const Manifest = struct {
1078 metadata_only: bool = false,1073 metadata_only: bool = false,
1079 };1074 };
10801075
1081 pub const AddPathPostError = error{1076 pub const AddPathPostError = Io.Cancelable || Allocator.Error;
1082 /// The same file path has been added to the cache manifest both as a
1083 /// directory and as a normal file, making the intended caching
1084 /// behavior ambiguous.
1085 IsDirectoryAmbiguous,
1086 } || Io.Cancelable || Allocator.Error;
10871077
1088 /// Add a file as a dependency of process being cached, after cache miss1078 /// Add a file as a dependency of process being cached, after cache miss
1089 /// occurs.1079 /// occurs.
...@@ -1126,8 +1116,10 @@ pub const Manifest = struct {...@@ -1126,8 +1116,10 @@ pub const Manifest = struct {
1126 m.contents.shrinkRetainingCapacity(prev_contents_len);1116 m.contents.shrinkRetainingCapacity(prev_contents_len);
1127 const existing_off = gop.key_ptr.*;1117 const existing_off = gop.key_ptr.*;
1128 const header = existing_off.get(m);1118 const header = existing_off.get(m);
1129 if (header.flags.is_directory != is_directory)1119 // If it trips, the same file path has been added to the cache
1130 return error.IsDirectoryAmbiguous;1120 // manifest both as a directory and as a normal file, making the
1121 // intended caching behavior ambiguous.
1122 assert(header.flags.is_directory == is_directory);
1131 if (!options.metadata_only)1123 if (!options.metadata_only)
1132 header.flags.metadata_only = false;1124 header.flags.metadata_only = false;
1133 break :h header;1125 break :h header;