Skip to content

Inline other modules' functions only in the alias pass - #9537

Open
cknitt wants to merge 1 commit into
inline-no-assigned-bodyfrom
no-late-inline
Open

cknitt wants to merge 1 commit into
inline-no-assigned-bodyfrom
no-late-inline

Conversation

@cknitt

@cknitt cknitt commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

With the PR below, the alias pass inlines calls with parameter arguments, so late inlining while compiling to JavaScript only gets calls through an alias, such as add from let {add} = module(List). The late copy skipped every Lambda pass and was inlined into code whose local refs were already assigned variables, which is where the recent inlining bugs lived.

This removes late inlining: compile_external_field_apply always compiles a call. It no longer looks up the other module's .cmj there either: only the late path needed the stored body. Calls through an alias are compiled as calls until a later PR in the stack lets the alias pass see through them. In the runtime, Belt and the tests, that affects only two calls in hello_res.res.

compiler/backend/README.md gets a section on the Lambda pipeline: the pass order, why simplify_alias runs three times with fresh facts, why sroa runs last, and the single cross-module inlining phase.

New tests in inline_late_alias_test cover the cases that broke when a late body was simplified. The alias pass inlines all of them now.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Inline functions of other modules in one phase, the alias pass, and no longer again while compiling to JavaScript. A call through an alias, such as add from let {add} = module(List), is now compiled as a call.

Semantic Diff

1 commit · Full page

Inline other modules' functions only in the alias pass

de87d9a · cknitt + Claude · Dec 05, 2026, 10:00 UTC

Why

A call to another module's @inline function could be inlined in two places: early by the alias pass, and late while compiling to JavaScript. The late copy skipped every Lambda pass, so it kept what those passes remove, and it was inlined into a function whose refs were already assigned variables. Since the alias pass now inlines calls with parameters as arguments, the late path only gets calls through an alias, such as add from let {add} = module(List). These are now compiled as calls, until the alias pass learns to see through them. The call no longer looks up the other module's .cmj: the late path needed its stored body, and the name it returned is the field name the call already has. The backend guide gets a section on the Lambda pipeline, with its single cross-module inlining phase.

JS modified (a call through an alias)

let {length: l, add} = module(List)
let r = list{}->add(l(list{1, 2, 3}))

js

-let r_0 = Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}});
-
-let r = {hd: r_0, tl: /* [] */0};
+let r = Stdlib_List.add(/* [] */0, Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}));

Review

  • What do the new tests cover? inline_late_alias_test has the cases that broke when a late body was simplified: functions reading a let-bound global, a known tuple or an assigned ref, Somes of known values, and refs of the caller assigned by a callback. The alias pass inlines all of them now.

@cknitt

cknitt commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 865aca6fd3

ℹ️ 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".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T10:51:37.106267Z 76c6173 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 656,848,808 → 656,798,232 (-0.01%).

Generated projects: 628,532,363 → 628,525,017 (±0.00%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 8,976,278,320 → 8,976,466,622 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 27,604,158 → 27,603,798 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request de87d9a compared with base 3b52031 in this run.

@pkg-pr-new

pkg-pr-new Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9537

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9537

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9537

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9537

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9537

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9537

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9537

commit: de87d9a

@cknitt

cknitt commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 76c61739fb

ℹ️ 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 `@inline` function could be inlined in
    two places: early by the alias pass, and late while compiling to
    JavaScript. The late copy skipped every Lambda pass, so it kept what
    those passes remove, and it was inlined into a function whose refs
    were already assigned variables. Since the alias pass now inlines
    calls with parameters as arguments, the late path only gets calls
    through an alias, such as `add` from `let {add} = module(List)`.
    These are now compiled as calls, until the alias pass learns to see
    through them. The call no longer looks up the other
    module's `.cmj`: the late path needed its stored body, and the name it
    returned is the field name the call already has. The backend guide gets a section on the Lambda
    pipeline, with its single cross-module inlining phase.

JS modified (a call through an alias):
Example:
    let {length: l, add} = module(List)
    let r = list{}->add(l(list{1, 2, 3}))
Before (js):
    let r_0 = Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}});

    let r = {hd: r_0, tl: /* [] */0};
After (js):
    let r = Stdlib_List.add(/* [] */0, Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}));

Review: What do the new tests cover? `inline_late_alias_test` has the
cases that broke when a late body was simplified: functions reading a
let-bound global, a known tuple or an assigned ref, `Some`s of known
values, and refs of the caller assigned by a callback. The alias pass
inlines all of them now.

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>
@codecov

codecov Bot commented Dec 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.65%. Comparing base (97f2861) to head (de87d9a).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           inline-no-assigned-body    #9537      +/-   ##
===========================================================
- Coverage                    82.65%   82.65%   -0.01%     
===========================================================
  Files                          469      469              
  Lines                        66587    66577      -10     
===========================================================
- Hits                         55038    55028      -10     
  Misses                       11549    11549              
Files with missing lines Coverage Δ
compiler/backend/lam_compile.ml 92.21% <100.00%> (-0.09%) ⬇️
compiler/backend/lam_pass_remove_alias.ml 92.85% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cknitt
cknitt marked this pull request as ready for review December 5, 2026 13:11
@cknitt
cknitt requested a review from cristianoc December 5, 2026 13:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant