Repository navigation
Keep bodies that call relative-path externals out of other modules - #9475
Conversation
|
@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. |
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Keep bodies that call relative-path externals out of other modules66d9f5d · cknitt + Claude · Nov 29, 2026, 07:18 UTC
JS modified (with -bs-cross-module-opt) // src/ffi/Hidden.res
@module("./helper.js") external raw: int => int = "raw"
@inline let wrapped = x => raw(x) + 1
// src/app/App.res
let direct = Hidden.raw(1)
let wrapped = Hidden.wrapped(2)
import * as Hidden from "../ffi/Hidden.mjs";
-import * as HelperJs from "./helper.js";
-let direct = HelperJs.raw(1);
+let direct = Hidden.raw(1);
-let wrapped = HelperJs.raw(2) + 1 | 0;
+let wrapped = Hidden.wrapped(2);Review
|
|
Codex Review: Didn't find any major issues. Nice work! 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". |
✅ Compiler benchmarksAllocated wordsIn total: 672,641,564 → 672,643,362 (±0.00%). Generated projects: 630,251,795 → 630,251,889 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,225,692,499 → 9,226,022,431 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,303,219 → 27,303,382 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 66d9f5d compared with base bcbd50d in this run. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## rebuild-on-cmj-change #9475 +/- ##
======================================================
Coverage 82.44% 82.45%
======================================================
Files 465 465
Lines 65961 65966 +5
======================================================
+ Hits 54383 54390 +7
+ Misses 11578 11576 -2
🚀 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-9475 |
bfab7c0 to
fb1d307
Compare
The changelog entries of #9475 and #9478 began with "With -bs-cross-module-opt", which this pull request removes. Both fixes apply to every inlined body, so the entries now say so without the flag. 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>
fb1d307 to
65e54b1
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs 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". |
65e54b1 to
0cdf1e6
Compare
Why:
An external with a package-relative path, such as
`@module("./helper.js")`, is imported relative to its own file. The
type checker keeps the external itself out of other modules, but with
-bs-cross-module-opt the wrapper it is exported through, and any small
function calling it, were stored in the .cmj and inlined into modules in
other directories, which then imported `./helper.js` relative to
themselves. This is PR 3 of the plan in #8733 (problem 2.8).
JS modified (with -bs-cross-module-opt):
Example:
// src/ffi/Hidden.res
@module("./helper.js") external raw: int => int = "raw"
@inline let wrapped = x => raw(x) + 1
// src/app/App.res
let direct = Hidden.raw(1)
let wrapped = Hidden.wrapped(2)
Before (js): src/app/App.mjs
import * as Hidden from "../ffi/Hidden.mjs";
import * as HelperJs from "./helper.js";
let direct = HelperJs.raw(1);
let wrapped = HelperJs.raw(2) + 1 | 0;
After (js): src/app/App.mjs
import * as Hidden from "../ffi/Hidden.mjs";
let direct = Hidden.raw(1);
let wrapped = Hidden.wrapped(2);
Review: Does inlining change otherwise? No. A body that calls an external
with a package path, such as `@module("node:path")`, is still inlined, and
the runtime's and Belt's JS, built with the flag, are unchanged.
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>
0cdf1e6 to
66d9f5d
Compare
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>
With
-bs-cross-module-opt, a function that calls an external with a relative path, such as@module("./helper.js"), is no longer stored in the.cmjfor other modules to inline. This is PR 3 of the plan in #8733 (problem 2.8).The import path of such an external is relative to its own file. The type checker already keeps the external itself out of other modules. But the wrapper it's exported through, and any small function calling it, were still stored. A module in another directory that used them then imported
./helper.jsrelative to itself:Now it calls
Hidden.raw(1)andHidden.wrapped(2), as it does without the flag. A body that calls an external with a package path, such as@module("node:path"), is still inlined. The runtime's and Belt's JavaScript, which are built with the flag, don't change.New test:
tests/build_tests/projects/cross_module_relative_externalbuilds such a project, checksApp.mjs, and runs it. It fails without this change.Part of stack #9486, after #9473. At this point in the stack, the bodies stored for other modules are those of
-bs-cross-module-opt; #9479 then stores@inlinebodies without the flag, and #9480 removes the flag. The guard here applies to all stored bodies, so it covers both.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D