Repository navigation
Conversation
Changelog💅 Polish
Semantic Diff1 commit · Full page ✏️ Simplify bodies inlined while compiling to JavaScript9af8bb9 · cknitt + Claude · Dec 04, 2026, 17:58 UTC · edited
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;
+ let opt = Primitive_option.some(f(x));
+ if (opt !== undefined) {
+ return opt;
} else {
return 0;
}
}JS modified (a function argument) 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);
}
}Review
|
✅ Compiler benchmarksAllocated wordsIn total: 657,488,730 → 657,493,477 (±0.00%). Generated projects: 629,122,823 → 629,123,605 (±0.00%).
InstructionsIn total: 8,977,171,177 → 8,977,304,619 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,616,044 → 27,616,210 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 9af8bb9 compared with base 38f28fc in this run. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alias-assigned-payload #9527 +/- ##
=======================================================
Coverage 82.68% 82.69%
=======================================================
Files 469 469
Lines 66595 66598 +3
=======================================================
+ Hits 55064 55071 +7
+ Misses 11531 11527 -4
🚀 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-9527 |
49aedef to
33c9f93
Compare
|
@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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 33c9f93aff
ℹ️ 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".
Why:
A call to another module's function that also passes a parameter of
the caller is inlined late, while compiling to JavaScript, after the
alias pass has run. So the inlined body kept what that pass removes
elsewhere: a `Some(x)` argument was bound and unwrapped again, and a
function argument was called instead of inlined. The alias pass now
also runs on such a body before it is compiled.
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) {
let opt = Primitive_option.some(f(x));
if (opt !== undefined) {
return opt;
} else {
return 0;
}
}
JS modified (a function argument):
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);
}
}
Review: Why does the late pass get a fresh `ident_tbl`? The table was
filled by `collect_info` before `simplify_alias 3`, `simplify_lets`,
`sroa` and `simplify_exits` rewrote the program, so at codegen it can
give a function body or a `Some` payload naming a variable those passes
removed or turned into an assigned one: inlining a let-bound local
function from it printed `p + k` with no `k` in scope. The body is now
simplified knowing only the parameters it binds; the caller is still
compiled with the real `meta`.
Review: Which variables count as assigned there? The pass used to take
only the ones `lam` assigns, but at codegen `lam` is just the inlined
body, so a variable of the caller assigned by a call in it looked
immutable and its read moved past that call. The pass now starts from
`meta.assignable` as well. In the other direction, the pass may inline a
further function that assigns a variable of its own, so the variables
the body assigns are collected after the pass, before it is compiled.
Review: What stays? `Option.map` still wraps its result with
`Primitive_option.some`; that needs a mark on the result of the call.
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>
33c9f93 to
9af8bb9
Compare
|
@codex review |
|
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". |
A call to another module's function is inlined in one of two places. If an argument is a parameter of the calling function, inlining waits until the code is compiled to JavaScript. By then the alias pass has already run, so the inlined body kept what that pass removes elsewhere:
Some(x)argument was bound to a variable and unwrapped again withPrimitive_option.valFromOption;The alias pass now also runs on such a body before it is compiled, in
lam_compile.ml. It runs with a fresh table of facts: the one the earlier passes filled describes the caller as it was before the last passes rewrote it, so it names variables that are gone. The fresh table only knows the parameters the inlined body binds. The pass also keeps the caller's assigned variables in its set of assigned variables, which it used to replace with the body's own.Before:
After:
A literal
Some(x)passed without a parameter argument was already read directly, since that call is inlined before the alias pass. The remainingPrimitive_option.someis the result ofOption.map; dropping it needs a mark on the result of the call, which is a separate change.New test cases in
inline_option_unwrap_test: a literalSomenext to a parameter argument, with a payload that can't beundefinedand with one that can. The newinline_late_alias_testruns cases that a version without the fresh table or the assigned variables miscompiled: local functions andSomes of the caller naming removed variables, and reads of assigned variables moved past a call that assigns them.Stacked on #9531.
Follow-up of #9504 (#8733).
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq