Skip to content

Close remaining rewatch build.lock gaps#8410

Open
cknitt wants to merge 1 commit intomasterfrom
lock-fix-2
Open

Close remaining rewatch build.lock gaps#8410
cknitt wants to merge 1 commit intomasterfrom
lock-fix-2

Conversation

@cknitt
Copy link
Copy Markdown
Member

@cknitt cknitt commented May 5, 2026

Motivation

This is a follow-up to the earlier build.lock fixes. Those changes covered the main rescript build path, but rescript watch still had artifact-mutating paths that could run without holding build.lock.

That matters because initialize_build is not read-only: it reads prior compile state and runs cleanup_previous_build, which can remove stale compiler assets and generated JS under lib/bs. cleanup_after_build and write_build_ninja also mutate build artifacts.

Without this follow-up, a watch process could still race with an in-flight rescript build during these remaining paths.

Newly Covered Paths

This PR adds build.lock coverage for these remaining watch cases:

  • Watch startup initialization

    • watcher::start calls initialize_build to discover packages and source folders before entering the watch loop.
    • This now runs under build.lock because initialization may clean previous build artifacts.
  • Watch full rebuild reinitialization

    • A full rebuild can be triggered by config changes, renames, creates, deletes, or editor atomic-save events.
    • That path calls initialize_build again to rebuild package/module state.
    • This now runs under build.lock.
  • Watch full rebuild artifact writes

    • After reinitialization, the full rebuild compiles and writes build.ninja.
    • Those operations now stay inside the same build.lock boundary.
  • Watch shutdown cleanup

    • When watch exits via Ctrl-C or because watch.lock is removed, it calls cleanup_after_build.
    • That cleanup now runs under build.lock.

Locking Model

  • rescript build holds build.lock across initialization, compilation, cleanup, and build.ninja writes.
  • watch incremental rebuilds call public incremental_build, which acquires build.lock.
  • watch full rebuilds acquire build.lock before reinitialization and then call the unlocked incremental build body.
  • watch startup initialization and shutdown cleanup now also acquire build.lock.
  • rescript clean already acquires build.lock in the CLI entrypoint.

Callers that already hold build.lock use incremental_build_without_lock, so this avoids duplicate locking and self-deadlocks.

@cknitt
Copy link
Copy Markdown
Member Author

cknitt commented May 5, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt cknitt requested review from jfrolich and nojaf and removed request for nojaf May 5, 2026 08:56
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 1328836

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.

2 participants