Repository navigation
Leave source locations out of bodies stored in .cmj files - #9470
Conversation
Changelog🏠 Internal
Semantic Diff1 commit · Full page Leave source locations out of bodies stored in .cmj filesfafe0cc · cknitt + Claude · Nov 28, 2026, 20:48 UTC
Cmj modified (stored body) // A.res, compiled with -bs-cross-module-opt, then again with a blank
// line added at the top
@inline let g = x => x + 1
let h = x => x * 2
let flag = true
-A.cmj: 200 bytes, names /…/A.res
-after the line shift: A.cmj changes
+A.cmj: 170 bytes, names no file
+after the line shift: A.cmj is byte for byte the sameReview
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9470 +/- ##
=======================================
Coverage 82.44% 82.45%
=======================================
Files 465 465
Lines 65935 65961 +26
=======================================
+ Hits 54357 54385 +28
+ Misses 11578 11576 -2
🚀 New features to boost your workflow:
|
🎉 Compiler benchmarksAllocated wordsIn total: 672,527,634 → 672,518,210 (±0.00%). Generated projects: 630,046,858 → 630,047,529 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,225,541,339 → 9,225,692,490 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,316,430 → 27,303,219 (-0.05%). 🎉 Improvement: 2 outputs are more than 1% smaller.
Pull request fafe0cc compared with base 6b9bc07 in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9470 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.
Representation modified (publishing a compile):
Before (mapping): publish_compiler_artifacts
.cmi changed ↦ dependents compiled again
.cmj changed, .cmi unchanged ↦ nothing
.cmj ↦ written by the compiler, checked to exist
After (mapping): publish_compiler_artifacts
.cmi changed ↦ dependents compiled again
.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
JS modified (dependent of a module with an interface):
Example:
// A.resi
let flag: bool
// A.res, after the first build: was `let flag = true`
let flag = false
Console.log("effect")
// B.res
let f = A.flag
Before (js): B.mjs after the second build
let f = true;
export {
f,
}
/* No side effect */
After (js): B.mjs after the second build
import * as A from "./A.mjs";
let f = false;
export {
f,
}
/* 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.
Review: 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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
7b26dcc to
1ff5fd8
Compare
Why:
A function body stored in a .cmj for other modules to inline kept the
locations of its applications, primitives and functions, and
-no-keep-locs does not cover them. So with -bs-cross-module-opt a line
shift changed the .cmj, and the runtime's published .cmj files held the
absolute paths of the machine that built them. Rebuilding dependents when
a .cmj changes (#8733, PR 2) would then rebuild them on every line shift.
Nothing reads these locations once the body is inlined elsewhere.
Cmj modified (stored body):
Example:
// A.res, compiled with -bs-cross-module-opt, then again with a blank
// line added at the top
@inline let g = x => x + 1
let h = x => x * 2
let flag = true
Before (text):
A.cmj: 200 bytes, names /…/A.res
after the line shift: A.cmj changes
After (text):
A.cmj: 170 bytes, names no file
after the line shift: A.cmj is byte for byte the same
Review: Does inlining change? No. A dependent's JS is the same, and so is
the runtime's and Belt's.
Review: Why build through Lambda's constructors? The rest of
Lambda_traverse does, so a stored body is normalized like any other term.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
1ff5fd8 to
fafe0cc
Compare
* 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.
Representation modified (publishing a compile):
Before (mapping): publish_compiler_artifacts
.cmi changed ↦ dependents compiled again
.cmj changed, .cmi unchanged ↦ nothing
.cmj ↦ written by the compiler, checked to exist
After (mapping): publish_compiler_artifacts
.cmi changed ↦ dependents compiled again
.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
JS modified (dependent of a module with an interface):
Example:
// A.resi
let flag: bool
// A.res, after the first build: was `let flag = true`
let flag = false
Console.log("effect")
// B.res
let f = A.flag
Before (js): B.mjs after the second build
let f = true;
export {
f,
}
/* No side effect */
After (js): B.mjs after the second build
import * as A from "./A.mjs";
let f = false;
export {
f,
}
/* 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.
Review: 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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
* 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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
---------
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Function bodies stored in a
.cmjfor other modules to inline no longer keep source locations. This is PR 1 of the plan in #8733 (problem 2.10).Before, a stored body kept the locations of its applications, primitives and functions, and
-no-keep-locsdoesn't cover them. With-bs-cross-module-opt, which the runtime and Belt are built with, that meant:.cmj;.cmjfiles contained the absolute paths of the machine that built them.The next PR in the plan rebuilds dependents when a
.cmjchanges. Without this one, it would rebuild the direct dependents of a module with a.resion every line shift. Nothing reads these locations once a body is inlined in another module.The new
Lambda_traverse.drop_locationssets every location toLocation.none, building throughLambda's constructors like the rest of that module. Generated JavaScript doesn't change, for the runtime, Belt or the test suite.New tests: two cases in
ounit_lambda_traverse_tests.ml. One checks that a term with locations under nodes without them comes back with none. The other checks that a term without locations is handed back as it is.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D