Skip to content

Rewatch: use a single timestamp per compile pass#8428

Merged
fhammerschmidt merged 3 commits into
masterfrom
rewatch-fix-timestamp
May 17, 2026
Merged

Rewatch: use a single timestamp per compile pass#8428
fhammerschmidt merged 3 commits into
masterfrom
rewatch-fix-timestamp

Conversation

@cknitt
Copy link
Copy Markdown
Member

@cknitt cknitt commented May 17, 2026

Fixes #8412

Summary

Fix unnecessary recompilation/touching of downstream output files in rewatch incremental builds.

The DAG scheduler introduced by #8374 buffers completed module results and then processes them in deterministic module-name order. During that result processing, each successful module previously received fresh last_compiled_cmi / last_compiled_cmt values via SystemTime::now().

That made the in-memory compile timestamps depend on result processing order rather than dependency order. If a dependency was processed after one of its dependents, the next incremental build could observe:

dependent.last_compiled_cmt < dependency.last_compiled_cmt

mark_modules_with_expired_deps_dirty interprets that as a stale dependent and marks it dirty. In watch mode this caused unrelated downstream modules, such as app startup/root modules, to be recompiled and their generated .mjs files touched. Tools like Vite then saw those touched files and performed a full reload instead of fast refresh.

Fix

Use a single shared compile_timestamp for all successful modules processed in a single compile pass.

This preserves the existing behavior that successful modules are marked current after the pass, including modules that were checked but short-circuited as clean, while removing artificial ordering between modules completed in the same pass.

With a single timestamp, modules processed during the same build no longer make each other look stale on the next incremental rebuild.

@cknitt cknitt requested a review from jfrolich May 17, 2026 10:51
match dependent_module.source_type {
SourceType::SourceFile(_) => {
match (module.last_compiled_cmt, module.last_compiled_cmt) {
match (module.last_compiled_cmt, module.last_compiled_cmi) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated typo that Codex detected

@fhammerschmidt fhammerschmidt enabled auto-merge (squash) May 17, 2026 11:07
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8428

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8428

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8428

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8428

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8428

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8428

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8428

commit: 76a695e

Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
@fhammerschmidt fhammerschmidt merged commit 88136c0 into master May 17, 2026
26 checks passed
@fhammerschmidt fhammerschmidt deleted the rewatch-fix-timestamp branch May 17, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rescript 13.0.0-alpha.4: unnecessary output files touched, breaking Vite fast refresh

3 participants