Repository navigation
Call instead of inlining a body that names a module the caller can't load - #9478
Conversation
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Call instead of inlining a body that names a module the caller can't load3a025b4 · cknitt + Claude · Nov 29, 2026, 07:52 UTC
JS modified (with -bs-cross-module-opt; app depends on p, p on q) // node_modules/p/src/PMod.res
@inline let f = x => QMod.g(x) + 1
@inline let k = x => x * 2
// app/src/App.res
let viaQ = PMod.f(2)
let local = PMod.k(2)
import * as PMod from "p/src/PMod.mjs";
let viaQ = PMod.f(2);
let local = 4;Review
|
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>
✅ Compiler benchmarksAllocated wordsIn total: 672,645,907 → 672,762,505 (+0.02%). Generated projects: 630,257,572 → 630,418,600 (+0.03%).
24 more changes
InstructionsIn total: 9,226,022,495 → 9,225,746,195 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,303,382 → 27,303,751 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 3a025b4 compared with base c4fcf27 in this run. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## no-relative-externals-in-cmj #9478 +/- ##
=============================================================
Coverage 82.45% 82.45%
=============================================================
Files 465 465
Lines 65966 65984 +18
=============================================================
+ Hits 54390 54406 +16
- Misses 11576 11578 +2
🚀 New features to boost your workflow:
|
|
@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. 👍 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". |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
b94c6de to
6e3616e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
6e3616e to
72eea42
Compare
…load
Why:
A body stored in a .cmj can name modules of packages its own package
depends on. A package depending on that one usually does not have them
on its load path, so inlining the body failed the build. This is PR 4
of the plan in #8733 (problem 2.9).
JS modified (with -bs-cross-module-opt; app depends on p, p on q):
Example:
// node_modules/p/src/PMod.res
@inline let f = x => QMod.g(x) + 1
@inline let k = x => x * 2
// app/src/App.res
let viaQ = PMod.f(2)
let local = PMod.k(2)
Before (diagnostic):
QMod not found, it means either the module does not exist or it is a namespace
After (js): app/src/App.mjs
import * as PMod from "p/src/PMod.mjs";
let viaQ = PMod.f(2);
let local = 4;
Review: Does looking a module up change the imports? No. The check reads
this compile's module cache and the load path, and does not register the
module, since registered modules with side effects get imported.
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>
72eea42 to
3a025b4
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>
A function body stored in a
.cmjfor other modules to inline can name modules of packages its own package depends on. A package that depends on it usually doesn't have those on its load path, so inlining the body failed the build:The caller now calls the function instead, as it would without a stored body. This is PR 4 of the plan in #8733 (problem 2.9). The check is in
Lam_compile_env.query_external_id_info, which every inlining site goes through. It looks a module up without registering it, since registered modules with side effects get imported.New test:
tests/build_tests/projects/cross_module_unloadable_module, whereappdepends onpandponq.PMod.f, which namesQMod, is called;PMod.k, which names no module, is still inlined. The test fails without this change.Part of stack #9486, after #9475. At this point the stored bodies are those of
-bs-cross-module-opt; from #9479 on they're@inlinebodies, which this covers too.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D