Repository navigation
Conversation
Changelog💅 Polish
Semantic Diff1 commit · Full page Put arguments read once into inlined bodies directly516009a · cknitt + Claude · Dec 03, 2026, 19:19 UTC
JS modified (literal and function arguments) let called = []
Ok(3)->Result.forEach(i => called->Array.push(i))
let merged = Array.concatAll([[1], arr])
let called = [];
-let f = i => {
- called.push(i);
-};
-f(3);
+called.push(3);
function merge(arr) {
- let arrays = [
- [1],
- arr
- ];
- return [].concat(...arrays);
+ return [].concat([1], arr);
} |
✅ Compiler benchmarksAllocated wordsIn total: 653,178,413 → 653,169,005 (±0.00%). Generated projects: 627,296,569 → 627,293,948 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 8,966,820,894 → 8,966,803,087 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,449,936 → 27,449,924 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 516009a compared with base 7968a96 in this run. |
Why:
Calls to other modules' functions are inlined in two places. When an
argument is a parameter of the caller, inlining waits until the
JavaScript is generated, and a pure argument the body reads once takes
the parameter's place. Otherwise `lam_pass_remove_alias` inlines the call
early and bound every argument to a variable first; it did the same when
applying a function directly. Both now substitute like the late path.
JS modified (literal and function arguments):
Example:
let called = []
Ok(3)->Result.forEach(i => called->Array.push(i))
let merged = Array.concatAll([[1], arr])
Before (js):
let called = [];
let f = i => {
called.push(i);
};
f(3);
function merge(arr) {
let arrays = [
[1],
arr
];
return [].concat(...arrays);
}
After (js):
let called = [];
called.push(3);
function merge(arr) {
return [].concat([1], arr);
}
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>
820b806 to
516009a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9517 +/- ##
==========================================
+ Coverage 82.54% 82.56% +0.01%
==========================================
Files 468 468
Lines 66226 66228 +2
==========================================
+ Hits 54665 54678 +13
+ Misses 11561 11550 -11
🚀 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-9517 |
When a function from another module is inlined, an argument that has no side effects and that the body uses once now goes straight into the body, instead of into a variable first.
The compiler inlines such calls in two places. If an argument is a parameter of the calling function, inlining waits until JavaScript generation, and that step already substitutes these arguments. Otherwise
lam_pass_remove_aliasinlines the call early, and it bound every argument that isn't a constant to a variable. It did the same for a function applied directly. Both now use the same substitution as the late step (propagate_beta_reduce_with_map).Before:
After:
The other changed test outputs are of the same kind. Evaluation order is unchanged: an argument still moves only when the existing checks allow it, so
inline_arg_order_cross_module_teststill reads the variable before the call that increments it.Part of the inlining follow-ups (#8733), and a prerequisite for replacing
@as(json)arguments with@inlinefunctions (next PR).🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq