Repository navigation
Conversation
Changelog💅 Polish
Semantic Diff1 commit · Full page ✏️ Inline other modules' functions early when an argument is a parameter6c39508 · cknitt + Claude · Dec 05, 2026, 09:56 UTC · edited
JS modified (a function argument next to a parameter) let mapped = (opt: option<int>) => opt->Option.map(x => x + 1)
function mapped(opt) {
if (opt !== undefined) {
- return Primitive_option.some((x => x + 1 | 0)(opt));
+ return Primitive_option.some(opt + 1 | 0);
}
}JS modified (a literal Some next to a parameter) let knownSome = (x: int, f) => Some(x)->Option.map(f)->Option.getOr(0)
function knownSome(x, f) {
- let opt = x;
- let opt$1 = opt !== undefined ? Primitive_option.some(f(Primitive_option.valFromOption(opt))) : undefined;
- if (opt$1 !== undefined) {
- return opt$1;
- } else {
- return 0;
- }
+ return Primitive_option.some(f(x));
}Review
|
|
@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. 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: 656,455,989 → 656,460,407 (±0.00%). Generated projects: 628,519,897 → 628,520,270 (±0.00%).
InstructionsIn total: 8,976,406,377 → 8,976,444,923 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,594,926 → 27,594,546 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 6c39508 compared with base daa4f2d in this run. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9536 +/- ##
=======================================
Coverage 82.67% 82.68%
=======================================
Files 469 469
Lines 66553 66575 +22
=======================================
+ Hits 55023 55047 +24
+ Misses 11530 11528 -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-9536 |
Why:
The alias pass inlined a call to another module's `@inline` function
only when no argument was a parameter of the caller. The check dates
from the initial export in 2016, when only functors stored their
bodies: it kept a functor that applies another functor to its unknown
argument from being inlined there, to limit code size. Since late
inlining was added, such calls were inlined anyway, only later, while
compiling to JavaScript. There the body missed the alias pass, so a
function argument was called instead of inlined and a `Some(x)`
argument was bound and unwrapped again. The pass now inlines these
calls like all others.
JS modified (a function argument next to a parameter):
Example:
let mapped = (opt: option<int>) => opt->Option.map(x => x + 1)
Before (js):
function mapped(opt) {
if (opt !== undefined) {
return Primitive_option.some((x => x + 1 | 0)(opt));
}
}
After (js):
function mapped(opt) {
if (opt !== undefined) {
return Primitive_option.some(opt + 1 | 0);
}
}
JS modified (a literal Some next to a parameter):
Example:
let knownSome = (x: int, f) => Some(x)->Option.map(f)->Option.getOr(0)
Before (js):
function knownSome(x, f) {
let opt = x;
let opt$1 = opt !== undefined ? Primitive_option.some(f(Primitive_option.valFromOption(opt))) : undefined;
if (opt$1 !== undefined) {
return opt$1;
} else {
return 0;
}
}
After (js):
function knownSome(x, f) {
return Primitive_option.some(f(x));
}
Review: What else changes? The generated JavaScript of the runtime and
Belt stays the same. In the tests, `pick(x, y, true)` now uses its known
flag (`inline_static_exit_cross_module_test`).
Review: Why does `addBumped` in `inline_assign_cross_module_test` get a
`let tmp = r`? Its `bumpTwice` updates a local ref, so its stored body
assigns `r`. Inlined late, the JavaScript generation saw that the second
copy assigns only `r$1`. Inlined early, the first copy's result is bound
to keep the order of evaluation, and the binding is substituted back only
if `r` can't change: the Lambda passes only know that `r` is assigned
somewhere, so `tmp` stays. The output is correct. The next PR in the
stack stops storing bodies that update a local ref, so `bumpTwice` is
called and this case goes away.
Review: Does `Primitive_option.some(f(x))` return the right value? Yes:
the payload is an `int`, so it is returned as it is. Not wrapping it at
all needs the type of the call's result.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq
Signed-off-by: Christoph Knittel <ck@cca.io>
b196ac5 to
6c39508
Compare
The alias pass did not inline a call to another module's
@inlinefunction when an argument was a parameter of the caller. This is the most common shape:let g = opt => opt->Option.map(f).The check dates from the initial export in 2016. Back then only functors stored their bodies, and it kept a functor that applies another functor to its unknown argument from being inlined there, to limit code size. Since late inlining was added, such calls were inlined anyway, only later, while compiling to JavaScript. There the body missed the alias pass, so a function argument was called instead of inlined, and a
Some(x)argument was bound and unwrapped again.The pass now inlines these calls like all others. The runtime and Belt JavaScript doesn't change. Three test outputs get better.
One gets a temporary it doesn't need:
addBumpedininline_assign_cross_module_testinlinesbumpTwice, which updates a local ref, so its stored body assignsr. Inlined early, the first copy's result is bound to keep the order of evaluation, and the Lambda passes only know thatris assigned somewhere, solet tmp = rstays. The output is correct, and the next PR (#9535) removes the case: bodies that update a local ref are no longer stored, sobumpTwiceis called.This is the bottom of a stack that moves all cross-module inlining into the alias pass and removes what that makes unnecessary.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq