Nim incremental compilation cache does not rebuild after timestamp‑preserving source edits
0 reputation · 13 Nov 2020, 16:23 UTC
0 reputation · 13 Nov 2020, 16:23 UTC
The goal is to guarantee that modifications to Nim source files are detected for incremental builds even when the file’s modification timestamp does not change.
Currently the nimcache mechanism relies on file timestamps to decide whether a cached object file is up‑to‑date; certain editors or version‑control commands can leave timestamps unchanged while the source content differs, causing the compiler to reuse stale object files.
It is unclear whether the compiler should supplement timestamp checks with content‑based hashes, listen to build‑system change notifications, or adopt another strategy, and how such changes would affect build performance and correctness.
Should the Nim compiler add a content hash check to timestamp validation for cache validity? Could a build‑system hook be used to signal changes without relying on timestamps? What are the trade‑offs between faster incremental builds and the risk of using stale code?
35275 reputation · 14 Nov 2020, 02:42 UTC
The Nim compiler does not automatically add a content‑based hash to its incremental cache; it relies solely on file modification timestamps. If a source file is edited while its timestamp stays the same, the cached object file is considered up‑to‑date and stale code may be reused.
git checkout --preserve-timestamps) can cause this mismatch.When the timestamp does not change, the compiler’s timestamp‑only check fails to detect the content change, so it reuses the existing .o file from nimcache. This leads to stale builds unless the cache is cleared or forced to rebuild.
nim -v. If you are on a recent build that includes the experimental flag --incremental:hash, you can enable hash‑based validation.nim c --incremental:hash yourfile.nim and verify that a timestamp‑preserving edit triggers a rebuild.nimcache directory (rm -rf nimcache) or invoke a full rebuild (nim c --forceBuild yourfile.nim) after any operation that may preserve timestamps.touch sourcefile.nim) after a timestamp‑preserving change, ensuring the mtime updates and the cache is invalidated.Ask: Are you able to use the --incremental:hash flag on your Nim toolchain? Knowing this determines whether the hash‑based approach is viable for you.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.