Repository navigation
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #8689 +/- ##
==========================================
+ Coverage 82.15% 82.17% +0.01%
==========================================
Files 456 456
Lines 65658 65668 +10
==========================================
+ Hits 53942 53960 +18
+ Misses 11716 11708 -8
🚀 New features to boost your workflow:
|
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-8689 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24646c5cb8
ℹ️ 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".
24646c5 to
08056a9
Compare
Changelog🚀 New Feature
Semantic Diff9 commits · Full page ✏️ Enable selective cross-module inlining for Option helpersbb8a422 · cknitt · Sep 28, 2026, 06:04 UTC · edited
✏️ Inline additional Option helpers across modulese33d56d · cknitt · Sep 28, 2026, 07:46 UTC · edited Option's filter, mapOr, getOr, orElse, isSome and isNone use ✏️ Document cross-module inlining featurecd458ae · cknitt · Sep 28, 2026, 07:49 UTC · edited Add the changelog fragment for ✏️ Refresh Option inlining snapshots after clean buildd44363e · cknitt · Sep 28, 2026, 07:55 UTC · edited A clean build of the tests inlines the Option helpers in more places than the incremental build the snapshots were made with. ✏️ Track CMJ changes for cross-module inlining008acbd · cknitt · Sep 28, 2026, 09:19 UTC · edited Rewatch now compares the .cmj itself instead of a separate .cmj.inline digest: exported JavaScript metadata, inline bodies included, can change without changing the .cmi, and callers compiled against the old .cmj are then stale. ✏️ Read CMJ digest header for incremental rebuildsb08d5b8 · cknitt · Sep 28, 2026, 09:53 UTC · edited The compiler writes the digest of a .cmj's contents in its first 16 bytes, so Rewatch can read that instead of hashing the whole file. Recompile dependents of a changed CMJ in the OCaml build systemb2066b0 · cknitt + Claude · Oct 27, 2026, 07:15 UTC
Publishing a byte-different CMJ now marks dependents dirty like a changed CMI, and the startup freshness check compares a dependent's CMT with the later of its dependency's CMI and CMJ. Review
Treat catch binders as bound in Lam_closure.free_variables01e3b54 · cknitt + Claude · Oct 29, 2026, 09:51 UTC Answers the Codex finding that an |
|
@codex review |
Codex Review SummaryThis 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. Another round soon, please! 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". |
5899ffe to
1dbd977
Compare
1dbd977 to
ccb2418
Compare
Changelog🚀 New Feature
Semantic Diff1 commit · Full page Inline functions marked
|
✅ Compiler benchmarksAllocated wordsIn total: 639,850,535 → 640,002,299 (+0.02%). Generated projects: 629,815,831 → 629,994,347 (+0.03%).
(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions. InstructionsIn total: 9,210,478,558 → 9,210,764,267 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 25,919,386 → 25,921,527 (+0.01%).
(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions. Pull request e0deeff compared with base 91d74a0 in this run. |
ccb2418 to
cb452e3
Compare
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8689 |
Why:
Calls to small stdlib helpers such as `Option.map` stay calls into
`Stdlib_Option` unless the whole build enables cross-module
optimization. `@inline(crossModule)` marks a closed function whose body
the .cmj exports, so other modules inline its calls as they would a
local function. Option's forEach, map, flatMap, filter, mapOr, getOr,
orElse, isSome and isNone use it.
JS modified (Option helper calls):
Example:
let bign = BigInt.fromFloat(Number.MAX_VALUE)->Option.getOr(0n)
Before (js):
let bign = Stdlib_Option.getOr(Stdlib_BigInt.fromFloat(Number.MAX_VALUE), 0n);
After (js):
let opt = Stdlib_BigInt.fromFloat(Number.MAX_VALUE);
let bign = opt !== undefined ? Primitive_option.valFromOption(opt) : 0n;
Diagnostic modified (@inline payload):
Example:
@inline(sometimes)
let f = x => x
Before (diagnostic):
illegal payload for attribute @inline.
It must be either empty, 'always' or 'never'
After (diagnostic):
illegal payload for attribute @inline.
It must be empty, 'always', 'never' or 'crossModule'
An async or directed function, or one capturing local values, is rejected
with an error. The build system recompiles dependents when a module's .cmj
changes, not only its .cmi, since an inline body can change without its
type. A changed .cmj also updates the .cmi's modification time, so the
next build sees the change too.
Review: Does every implementation change now recompile dependents? Only
those whose .cmj bytes change.
Review: Why does Lam_closure.free_variables change? Its `Ltrywith` case
never bound the exception, so a function whose `catch` reads it counted as
capturing a local value and was rejected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gKsWykY6KH4QSJ9Wrs
Signed-off-by: Christoph Knittel <ck@cca.io>
cb452e3 to
e0deeff
Compare
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>
|
Superseded by stack #9486, the plan in #8733:
Closing in favor of those. |
* 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>
Why:
`@inline` on a function inlined its calls only in its own module.
Other modules inlined it only with -bs-cross-module-opt, which also
inlined every small closed function, annotated or not. `@inline` now
means the same in every module: an exported `@inline` function or
functor stores its body in the .cmj, and other modules inline it,
flag or not. The Option helpers that #8689 marked are `@inline`. This
is PR 5 of the plan in #8733 (proposal 3) and replaces the compiler
part of #8689, without the `@inline(crossModule)` payload.
JS modified (another module, without -bs-cross-module-opt):
Example:
// A.res
@inline let g = x => x + 1
let h = x => x * 2
// B.res
let a = A.g(3)
let b = A.h(4)
Before (js): B
let a = A.g(3);
let b = A.h(4);
After (js): B
let b = A.h(4);
let a = 4;
JS modified (an Option helper):
Example:
// tests/belt_tests/src/bs_stack_test.res
while current->Option.isSome { … }
Before (js):
while (Stdlib_Option.isSome(current)) {
After (js):
while (current !== undefined) {
Representation modified (which bodies a .cmj stores):
Before (mapping): Lam_stats_export.values_of_export, Js_cmj_format.get_result
true, false, null, undefined ↦ always
@inline function or functor, closed ↦ with -bs-cross-module-opt
other closed function under size 5, closed functor ↦ with -bs-cross-module-opt
After (mapping): Lam_stats_export.values_of_export, Js_cmj_format.get_result
true, false, null, undefined ↦ always
@inline function or functor, closed, not async, no directive ↦ always
other closed function under size 5, closed functor ↦ with -bs-cross-module-opt
Review: What keeps a body from being stored? It must be closed, since it
is copied without its environment, not async and without a directive, and
it must not call a relative-path external (#9475). A caller that can't
load a module the body names calls the function instead (#9478).
Review: Which functions does this cover? Those defined at the top level
of a module. A function in a nested module (`module M = { @inline let f
= … }`) and an `@inline let rec` are still inlined only in their own
module.
Review: Does the caller rebuild when the body changes? Yes, through the
changed .cmj (#9473); tests/build_tests/projects/inline_function_rebuild
edits a body on the same line, which leaves the .cmi as it is.
Review: Can a JS global be captured by the import of a module whose uses
were all inlined? Not any more. Such a module is still imported when it has
side effects, so `Js_pass_external_shadow` now counts the modules imported
for their side effects as bindings in scope (`Lam_compile_env.side_effect_modules`,
which `populate_required_modules` uses too). Before, it saw only the modules
the generated code still named and printed the global bare, which then read
the import (inline_shadowed_import_test.res). Found by marking every function
in tests/tests `@inline`.
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Add
@inline(crossModule)to opt individual functions into cross-module inlining, and use it for selectedOptionhelpers.Inlining copies a function’s body into its callers. If that body changes but its type does not, the caller must still be rebuilt; checking only the
.cmitype signature would leave the old body in the generated JavaScript.The compiler stores exported inline bodies in the existing
.cmjfile, alongside other JavaScript compilation metadata. Rewatch now compares the digest already stored in that file’s header before and after compiling a module. If it changes, Rewatch rebuilds dependents. This keeps implementation details out of.cmiand requires no new artifact. A.cmjchange unrelated to inlining may also cause a dependent rebuild.