Semantic Diff

#9473 Compile dependents again when a module's .cmj changes

2 commits

fafe0ccc3910bc376fa60897811ddc3d74b81abb..pr-9473

74bd719d2 · cknitt + Claude · Nov 29, 2026, 06:49 UTC

Compile dependents again when a module's .cmj changes

Why

Dependents read a module's .cmj: the values they copy in (true, false, null and undefined always, more with -bs-cross-module-opt), the arities they call with, and whether the module has side effects, which decides whether they import it. The build system only compared .cmi files, so a change the interface doesn't show left their JavaScript stale. Without a .resi this was mostly hidden, because the .cmi holds declaration locations; with one, every such change went unnoticed. This is the build-system part of #8689, and PR 2 of the plan in #8733. #9470 keeps line shifts from changing a .cmj that stores bodies.

modifiedRepresentation publishing a compile

mapping
Before publish_compiler_artifacts
After publish_compiler_artifacts
.cmi changed ↦ dependents compiled again.cmi changed ↦ dependents compiled again.cmj changed, .cmi unchanged ↦ nothing.cmj ↦ written by the compiler, checked to exist.cmj changed, .cmi unchanged ↦ dependents compiled again; the .cmi's modification time moves, for the next build.cmj ↦ held until the compile is published, written only when it changed, kept as before when the compile fails

modifiedJS dependent of a module with an interface

// A.resilet flag: bool// A.res, after the first build: was `let flag = true`let flag = falseConsole.log("effect")// B.reslet f = A.flag
js
Before B.mjs after the second build
After B.mjs after the second build
let f = true;import * as A from "./A.mjs"; let f = false; export {export { f, f,}}/* No side effect *//* A Not a pure module */

Review

  • Does watch mode compile more? Only when a .cmj changes. With default flags it holds no bodies, so it changes only when an exported value's arity, one of the four copied constants or the module's purity changes, and each of those changes the dependents' JavaScript.
  • Why move the .cmi's modification time? A later build decides from .cmi times whether dependents are current, so it sees the .cmj change too without reading every .cmj.
2c97086fc · cknitt + Claude · Nov 29, 2026, 09:01 UTC

Date the interface before writing a changed .cmj

A changed .cmj was written before its .cmi was dated. A build killed in between found the .cmj unchanged the next time and left the dependents stale, and a failed date reported the interface as unchanged. The .cmi is now dated, and the change recorded, right before the .cmj is written. A review by Claude (Fable model) found this.