Skip to content

Commit b1fbafd

Browse files
committed
update comment based on further research
1 parent 08843a0 commit b1fbafd

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,23 @@ where
744744
return true;
745745
}
746746
};
747-
// Equal mtimes could mean that the input was changed in that same second,
748-
// but *after* the output was generated. So this means they are stale.
749-
// In theory, cargo is using nanosecond precision throughout so this
750-
// should not make a difference -- but it was necessary to fix #5918.
747+
748+
// Note that equal mtimes are considered "stale". For filesystems with
749+
// not much timestamp precision like 1s this is a conservative approximation
750+
// to handle the case where a file is modified within the same second after
751+
// a build finishes. We want to make sure that incremental rebuilds pick that up!
752+
//
753+
// For filesystems with nanosecond precision it's been seen in the wild that
754+
// its "nanosecond precision" isn't really nanosecond-accurate. It turns out that
755+
// kernels may cache the current time so files created at different times actually
756+
// list the same nanosecond precision. Some digging on #5919 picked up that the
757+
// kernel caches the current time between timer ticks, which could mean that if
758+
// a file is updated at most 10ms after a build finishes then Cargo may not
759+
// pick up the build changes.
760+
//
761+
// All in all, the equality check here is a conservative assumption that,
762+
// if equal, files were changed just after a previous build finished.
763+
// It's hoped this doesn't cause too many issues in practice!
751764
if mtime2 >= mtime {
752765
info!("stale: {} -- {} vs {}", path.display(), mtime2, mtime);
753766
true

0 commit comments

Comments
 (0)