Skip to content

Warn when other modules can't inline an @inline function - #9482

Merged
cknitt merged 1 commit into
inline-exports-bodiesfrom
warn-inline-not-stored
Nov 30, 2026
Merged

cknitt merged 1 commit into
inline-exports-bodiesfrom
warn-inline-not-stored

Conversation

@cknitt

@cknitt cknitt commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Adds warning 113, on by default, for an exported @inline function that other modules can't inline. It names the reason:

It's a warning, not an error, since the function is still inlined in its own module. A project can make it an error with --warn-error +113, and one binding can turn it off with @warning("-113").

The warning is reported while the .cmj is built, after type checking, where the warning scopes of a binding are gone. So:

  • the check for fatal warnings now runs after the .cmj is built;
  • the type checker records the warning state of each @inline binding, with its @warning and @warnerror, those on its expression and a @@warning above it, under the binding's identifier (Inline_not_stored). The @inline may be on the binding, on its function, or below a type constraint.

Not covered: functions in nested modules and @inline let rec, which aren't stored for other modules either.

New tests:

  • tests/error_tests/single/fixtures/warning_113_inline_not_stored.res: each reason, a silenced binding and a stored function.
  • tests/build_tests/projects/inline_warning_as_error: --warn-error +113 fails the build.

Two existing tests get the warning where it is correct and intended. inline_static_exit_test.res inlines within its own module only, so it gets an interface that exports nothing. #9475's cross_module_relative_external project, whose exported wrapper calls a relative-path external, makes every warning but 113 an error and checks that 113 is reported.

The benchmarks' build/no-op and build/leaf-edit grow because they build the base's test sources with this PR's compiler. Those sources don't have the interface this PR adds for inline_static_exit_test.res, so that module gets warning 113, and the build system compiles a module with warnings again on every build to report them. A project without new warnings doesn't build more.

Part of stack #9486, after #9479.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Changelog

🚀 New Feature

  • Add warning 113, on by default, for an exported @inline function that other modules can't inline, with the reason: it uses another value of its module, it's async or has a directive, or it calls an external with a relative path. It's still inlined in its own module. Turn it off for one binding with @warning("-113").

Semantic Diff

1 commit · Full page

Warn when other modules can't inline an @inline function

ac21673 · cknitt + Claude · Nov 29, 2026, 09:08 UTC

Why

An exported @inline function stores its body for other modules only when it can: it must be closed, not async, without a directive, and must not call a relative-path external. Otherwise other modules called it, and nothing said so. Warning 113, on by default, now names the reason. It is a warning, not an error, since the function is still inlined in its own module.

Diagnostic added (exported @inline function that isn't stored)

let rec helper = x => x > 10 ? x : helper(x + 1)
@inline let usesHelper = x => helper(x) + 1
@inline let asyncOne = async x => x

diagnostic

-none
+Warning number 113
+
+This @inline function is inlined only in this module, not in modules that use it: it uses helper, a value of this module.
+
+Warning number 113
+
+This @inline function is inlined only in this module, not in modules that use it: it is async.

Review

  • The warning is reported while the .cmj is built, after type checking. Do -warn-error +113, @warning("-113") and @warnerror("+113") still apply? Yes. The check for fatal warnings now runs after the .cmj is built, and the type checker records the warning state of each @inline value binding, whose @inline may be on the binding or on its function (let f = {@inline x => …}), and of each @inline module binding, whose @inline may be below a module type constraint. Other bindings aren't recorded, which keeps the cost away from the many bindings without @inline. The state holds the binding's @warning and @warnerror, those on its expression and a @@warning above it, under the binding's identifier (Inline_not_stored). Warning 113 is reported in that state, so a silenced value in a nested module doesn't silence another of the same name.
  • Does it fire for functions an interface hides? No. Only exported values are considered, so an @inline helper the .resi leaves out is inlined in its module without a warning. Functions in nested modules and @inline let rec are not covered either.

@cknitt
cknitt changed the base branch from master to inline-exports-bodies November 29, 2026 09:27
@cknitt
cknitt added this pull request to stack #9486 November 29, 2026 09:29
@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 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-11-29T11:58:18.638570Z 747d0b2 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.

@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: c715ba1751

ℹ️ 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 thread compiler/typing/typemod.ml Resolved
Comment thread compiler/typing/inline_not_stored.ml Resolved
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⚠️ Compiler benchmarks

Allocated words

In total: 674,700,608 → 676,864,204 (+0.32%).

Generated projects: 630,451,576 → 630,658,894 (+0.03%).

⚠️ Regression: 2 benchmarks allocate more than 1% more.

Benchmark Base Head Change
build/no-op 9,345,290 10,222,715 +9.39%
build/leaf-edit 12,078,029 12,955,517 +7.27%
build/shared-edit 87,812,795 88,045,730 +0.27%
build/Namespace/clean 84,736,757 84,880,848 +0.17%
packages/@rescript/runtime/Primitive_list.resi 92,021 92,171 +0.16%
packages/@rescript/runtime/Primitive_float_extern.res 93,881 94,031 +0.16%
packages/@rescript/runtime/Stdlib_Blob.res 94,098 94,248 +0.16%
packages/@rescript/runtime/Stdlib_File.res 95,907 96,057 +0.16%
packages/@rescript/runtime/Primitive_promise.res 97,257 97,407 +0.15%
packages/@rescript/runtime/Primitive_int_extern.res 98,110 98,260 +0.15%
43 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Iterable.resi 98,227 98,377 +0.15%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi 98,376 98,526 +0.15%
packages/@rescript/runtime/Primitive_string_extern.res 98,418 98,568 +0.15%
packages/@rescript/runtime/Stdlib_Iterable.res 99,138 99,288 +0.15%
packages/@rescript/runtime/Stdlib_AsyncIterable.res 99,209 99,359 +0.15%
packages/@rescript/runtime/Obj.res 99,358 99,508 +0.15%
packages/@rescript/runtime/RescriptTools.res 104,773 104,931 +0.15%
packages/@rescript/runtime/Primitive_exceptions.resi 100,449 100,599 +0.15%
packages/@rescript/runtime/Primitive_hash.resi 102,866 103,016 +0.15%
packages/@rescript/runtime/Primitive_dict.res 102,910 103,060 +0.15%
packages/@rescript/runtime/Primitive_module.resi 103,308 103,458 +0.15%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,192 106,342 +0.14%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res 107,734 107,884 +0.14%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 110,990 111,140 +0.14%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,282 112,432 +0.13%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res 112,334 112,484 +0.13%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res 115,668 115,822 +0.13%
packages/@rescript/runtime/Primitive_array_extern.res 114,418 114,568 +0.13%
packages/@rescript/runtime/Primitive_object_extern.res 114,929 115,079 +0.13%
packages/@rescript/runtime/Stdlib_Bool.resi 116,502 116,652 +0.13%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 116,797 116,947 +0.13%
packages/@rescript/runtime/Primitive_object.resi 117,223 117,373 +0.13%
packages/@rescript/runtime/Dom_storage2.res 120,383 120,533 +0.12%
packages/@rescript/runtime/Jsx.res 121,938 122,088 +0.12%
packages/@rescript/runtime/Primitive_option.resi 122,313 122,463 +0.12%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,399 122,549 +0.12%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,370 123,520 +0.12%
packages/@rescript/belt/src/Belt.res 188,641 188,863 +0.12%
packages/@rescript/runtime/Stdlib_Global.res 142,018 142,176 +0.11%
packages/@rescript/runtime/Stdlib_Bool.res 146,429 146,591 +0.11%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,702 135,852 +0.11%
packages/@rescript/runtime/Stdlib_Ordering.res 153,831 154,001 +0.11%
packages/@rescript/runtime/Stdlib_Type.resi 135,854 136,004 +0.11%
packages/@rescript/runtime/Primitive_float.res 147,320 147,482 +0.11%
packages/@rescript/runtime/Primitive_bool.res 147,669 147,831 +0.11%
packages/@rescript/runtime/Stdlib_Intl.res 174,368 174,558 +0.11%
build/Namespace/edit 7,934,460 7,942,816 +0.11%
packages/@rescript/runtime/Stdlib_Temporal_Now.res 143,694 143,844 +0.10%
packages/@rescript/runtime/Primitive_string.res 160,064 160,230 +0.10%
packages/@rescript/runtime/Stdlib_JsExn.res 173,722 173,900 +0.10%
packages/@rescript/runtime/Stdlib_Symbol.res 146,723 146,873 +0.10%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,075 149,225 +0.10%
packages/@rescript/belt/src/Belt_Int.resi 149,340 149,490 +0.10%

Instructions

In total: 9,226,120,339 → 9,226,238,564 (±0.00%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,271,384 21,247,304 -0.11%

Output size

In total: 27,367,799 → 27,369,129 (±0.00%).

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

Pull request ac21673 compared with base e4d3187 in this run.

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.47%. Comparing base (9f3bc63) to head (ac21673).

Files with missing lines Patch % Lines
compiler/backend/lam_stats_export.ml 90.62% 3 Missing ⚠️
compiler/typing/inline_not_stored.ml 93.75% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           inline-exports-bodies    #9482   +/-   ##
======================================================
  Coverage                  82.46%   82.47%           
======================================================
  Files                        465      466    +1     
  Lines                      66011    66055   +44     
======================================================
+ Hits                       54439    54481   +42     
- Misses                     11572    11574    +2     
Files with missing lines Coverage Δ
compiler/backend/lam_compile_main.ml 94.67% <100.00%> (ø)
compiler/typing/typemod.ml 77.69% <100.00%> (+0.34%) ⬆️
compiler/typing/warnings.ml 76.32% <100.00%> (+0.19%) ⬆️
compiler/typing/inline_not_stored.ml 93.75% <93.75%> (ø)
compiler/backend/lam_stats_export.ml 92.53% <90.62%> (-1.91%) ⬇️

... and 2 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 Nov 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: ac21673

@cknitt
cknitt force-pushed the warn-inline-not-stored branch from c715ba1 to 241f209 Compare November 29, 2026 09:57
@cknitt
cknitt force-pushed the warn-inline-not-stored branch from 241f209 to 136d8b7 Compare November 29, 2026 10:07
@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 136d8b71ef

ℹ️ 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 thread compiler/typing/typemod.ml Resolved
@cknitt
cknitt force-pushed the warn-inline-not-stored branch from 136d8b7 to 87c2e43 Compare November 29, 2026 10:35
@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 87c2e4311c

ℹ️ 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 thread compiler/typing/inline_not_stored.ml Resolved
@cknitt
cknitt force-pushed the warn-inline-not-stored branch from 87c2e43 to 7c6a5eb Compare November 29, 2026 10:59
@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 7c6a5eb54a

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

@cknitt
cknitt force-pushed the warn-inline-not-stored branch 2 times, most recently from bbace4e to 4c21005 Compare November 29, 2026 11:30
@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 4c210053d4

ℹ️ 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 thread compiler/typing/typemod.ml Resolved
@cknitt
cknitt force-pushed the warn-inline-not-stored branch from 4c21005 to 747d0b2 Compare November 29, 2026 11:56
@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 747d0b2a28

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

@cknitt
cknitt marked this pull request as ready for review November 29, 2026 12:08
@cknitt
cknitt requested a review from cristianoc November 29, 2026 12:12
Why:
    An exported `@inline` function stores its body for other modules
    only when it can: it must be closed, not async, without a directive,
    and must not call a relative-path external. Otherwise other modules
    called it, and nothing said so. Warning 113, on by default, now names
    the reason. It is a warning, not an error, since the function is still
    inlined in its own module.

Diagnostic added (exported @inline function that isn't stored):
Example:
    let rec helper = x => x > 10 ? x : helper(x + 1)
    @inline let usesHelper = x => helper(x) + 1
    @inline let asyncOne = async x => x
Before (diagnostic): none
After (diagnostic):
    Warning number 113

    This @inline function is inlined only in this module, not in modules that use it: it uses helper, a value of this module.

    Warning number 113

    This @inline function is inlined only in this module, not in modules that use it: it is async.

Review: The warning is reported while the .cmj is built, after type
checking. Do `-warn-error +113`, `@warning("-113")` and
`@warnerror("+113")` still apply? Yes. The check for fatal warnings now
runs after the .cmj is built, and the type checker records the warning
state of each `@inline` value binding, whose `@inline` may be on the
binding or on its function (`let f = {@inline x => …}`), and of each
`@inline` module binding, whose `@inline` may be below a module type
constraint. Other bindings aren't recorded, which keeps the cost away from
the many bindings without `@inline`. The state
holds the binding's `@warning` and `@warnerror`, those on its expression and
a `@@warning` above it, under the binding's identifier
(`Inline_not_stored`). Warning 113 is reported in that state, so a silenced
value in a nested module doesn't silence another of the same name.

Review: Does it fire for functions an interface hides? No. Only exported
values are considered, so an `@inline` helper the `.resi` leaves out is
inlined in its module without a warning. Functions in nested modules and
`@inline let rec` are not covered either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the warn-inline-not-stored branch from 747d0b2 to ac21673 Compare November 29, 2026 14:05
@cknitt
cknitt merged commit a255d0f into master Nov 30, 2026
49 of 69 checks passed
@cknitt
cknitt deleted the warn-inline-not-stored branch November 30, 2026 07:53
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.

2 participants