Skip to content

Add opt-in cross-module inlining for Option helpers - #8689

Open
cknitt wants to merge 6 commits into
masterfrom
codex/cross-module-inline
Open

cknitt wants to merge 6 commits into
masterfrom
codex/cross-module-inline

Conversation

@cknitt

@cknitt cknitt commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Add @inline(crossModule) to opt individual functions into cross-module inlining, and use it for selected Option helpers.

Inlining copies a function’s body into its callers. If that body changes but its type does not, the caller must still be rebuilt; checking only the .cmi type signature would leave the old body in the generated JavaScript.

The compiler stores exported inline bodies in the existing .cmj file, alongside other JavaScript compilation metadata. Rewatch now compares the digest already stored in that file’s header before and after compiling a module. If it changes, Rewatch rebuilds dependents. This keeps implementation details out of .cmi and requires no new artifact. A .cmj change unrelated to inlining may also cause a dependent rebuild.

Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.71%. Comparing base (ece8b14) to head (24646c5).

Files with missing lines Patch % Lines
compiler/ml/translattribute.ml 66.66% 3 Missing ⚠️
compiler/core/lam_stats_export.ml 66.66% 2 Missing ⚠️
compiler/ml/printlambda.ml 0.00% 2 Missing ⚠️
compiler/core/lam_analysis.ml 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8689      +/-   ##
==========================================
+ Coverage   78.67%   78.71%   +0.03%     
==========================================
  Files         476      476              
  Lines       64402    64413      +11     
==========================================
+ Hits        50670    50704      +34     
+ Misses      13732    13709      -23     
Files with missing lines Coverage Δ
compiler/core/js_cmj_format.ml 92.72% <100.00%> (+0.13%) ⬆️
compiler/ml/lambda.ml 64.89% <ø> (ø)
compiler/core/lam_analysis.ml 65.92% <0.00%> (-0.75%) ⬇️
compiler/core/lam_stats_export.ml 88.23% <66.66%> (-2.88%) ⬇️
compiler/ml/printlambda.ml 9.33% <0.00%> (-0.08%) ⬇️
compiler/ml/translattribute.ml 78.78% <66.66%> (+0.66%) ⬆️

... and 7 files with indirect coverage changes

🚀 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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8689

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 24646c5

@github-actions

Copy link
Copy Markdown

Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt marked this pull request as ready for review September 28, 2026 10:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24646c5cb8

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

Comment on lines +68 to +71
else if not (Lam_closure.is_closed lambda) then
Location.raise_errorf ~loc
"@inline(crossModule) requires a function without captured local \
values"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat catch binders as local during inline validation

For an exported @inline(crossModule) function containing a try ... catch whose handler inspects the exception, this check incorrectly rejects the function as capturing a local value. Lam_closure.is_closed delegates to free_variables, but its Ltrywith branch ignores _exn instead of adding that binder to the local set (compiler/core/lam_closure.ml:118-120), so ordinary references to the caught exception are reported as free. Register the catch binder during closure traversal or use validation that handles all Lambda binders.

AGENTS.md reference: AGENTS.md:L51-L54

Useful? React with 👍 / 👎.

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