authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-18 01:30:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-18 01:30:57-07:00
logc0517bf1f6f6f7de0279e3766f414c5c8380bed7
treeaca1fd967986fbe18883adf8f50067f03b7dc5ae
parent56c81c713f749f858089e5bcdf9e6fac588bcf86

std.cache_hash: temporary workaround for mtime precision on linux

See #6082

1 files changed, 9 insertions(+), 11 deletions(-)

lib/std/cache_hash.zig+9-11
......@@ -451,10 +451,17 @@ fn isProblematicTimestamp(fs_clock: i128) bool {
451451 // to detect precision of seconds, because looking at the zero bits in base
452452 // 2 would not detect precision of the seconds value.
453453 const fs_sec = @intCast(i64, @divFloor(fs_clock, std.time.ns_per_s));
454 const fs_nsec = @intCast(i64, @mod(fs_clock, std.time.ns_per_s));
454 var fs_nsec = @intCast(i64, @mod(fs_clock, std.time.ns_per_s));
455455 var wall_sec = @intCast(i64, @divFloor(wall_clock, std.time.ns_per_s));
456456 var wall_nsec = @intCast(i64, @mod(wall_clock, std.time.ns_per_s));
457457
458 if (std.Target.current.os.tag == .linux) {
459 // TODO As a temporary measure while we figure out how to solve
460 // https://github.com/ziglang/zig/issues/6082, we cut the granularity of nanoseconds
461 // by a large amount.
462 fs_nsec &= @as(i64, -1) << 23;
463 }
464
458465 // First make all the least significant zero bits in the fs_clock, also zero bits in the wall clock.
459466 if (fs_nsec == 0) {
460467 wall_nsec = 0;
......@@ -466,16 +473,7 @@ fn isProblematicTimestamp(fs_clock: i128) bool {
466473 } else {
467474 wall_nsec &= @as(i64, -1) << @intCast(u6, @ctz(i64, fs_nsec));
468475 }
469 if (wall_nsec == fs_nsec and wall_sec == fs_sec)
470 return true;
471
472 // I have also observed precision problems at a millisecond granularity.
473 const fs_msec = @intCast(i64, @divFloor(fs_clock, std.time.ns_per_ms * 2));
474 const wall_msec = @intCast(i64, @divFloor(wall_clock, std.time.ns_per_ms * 2));
475 if (fs_msec == wall_msec)
476 return true;
477
478 return false;
476 return wall_nsec == fs_nsec and wall_sec == fs_sec;
479477}
480478
481479test "cache file and then recall it" {