Skip to content

Remove -bs-cross-module-opt - #9480

Merged
cknitt merged 1 commit into
warn-inline-not-storedfrom
remove-cross-module-opt
Nov 30, 2026
Merged

cknitt merged 1 commit into
warn-inline-not-storedfrom
remove-cross-module-opt

Conversation

@cknitt

@cknitt cknitt commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Removes the internal -bs-cross-module-opt and -bs-no-cross-module-opt flags. They were never meant for users, so bsc now rejects them as unknown options. This is PR 7 of the plan in #8733 (proposal 4).

With @inline functions inlined in every module (#9479), the flag only added an internal heuristic: every closed function under size 5, and every closed functor, was inlined into other modules, annotated or not. Now a .cmj stores @inline bodies and the four always-copied constants (true, false, null, undefined), and nothing else.

Only the runtime and Belt set the flag. Without it, the runtime lost three inlinings, which are now @inline: Primitive_option.isNested, Stdlib_JsError.panic, and the Stdlib_TypedArray.Impl functor. With them, the runtime's and Belt's JavaScript is the same as before.

Tests:

The changelog entry is breaking: projects that set the flag no longer get small functions inlined into other modules automatically.

The benchmarks' build/no-op and build/leaf-edit grow because of how they measure, not because of this PR. They compile the base branch's test sources with this PR's compiler. In the base, eight cross-module inlining tests still set -bs-cross-module-opt in @@config; this PR removes those lines. This PR's compiler rejects the flag ("invalid flags for bsc", warning 22), and the build system compiles a module with warnings again on every build, so those eight files are compiled even in a build with nothing to do. Belt's and the runtime's .cmj files shrink (-33%, -19%) because they no longer store the bodies of unannotated small functions; only builds with the flag read those. Their JavaScript doesn't change.

Part of stack #9486, after #9482.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Changelog

💥 Breaking Change

  • Remove the internal -bs-cross-module-opt and -bs-no-cross-module-opt flags: other modules inline exactly the functions marked @inline. With the first flag, small functions and functors used to be inlined into other modules automatically; mark the ones that should be with @inline, and drop the flags from compiler-flags.

🐛 Bug fix

  • Fix inlining another module's function that assigns a local variable, as in let r = ref(x); r := r.contents + 1: the compiler crashed, the generated code assigned an undeclared variable, a value read from the variable before an assignment was read after it instead, or a condition on the variable was decided by the value it started with.

Semantic Diff

1 commit · Full page

Remove -bs-cross-module-opt

7cc0465 · cknitt + Claude · Nov 29, 2026, 09:11 UTC

Why

Since @inline functions are inlined in every module, the flag only added an internal heuristic: with it, every closed function under size 5 and every closed functor was inlined into other modules, annotated or not. Only the runtime and Belt set it, plus a few tests. It was always internal, so it is removed with its -bs-no-cross-module-opt partner: bsc now reports both as unknown options. This is PR 7 of the plan in #8733 (proposal 4).

Representation modified (which bodies a .cmj stores)

mapping · Before: Lam_stats_export.values_of_export, Js_cmj_format.get_result · After: Lam_stats_export.values_of_export

 true, false, null, undefined ↦ always
 @inline function or functor ↦ always
-other closed function under size 5, closed functor ↦ with -bs-cross-module-opt
+anything else ↦ never

JS modified (the runtime, built without the flag)

// Stdlib_Uint8Array.res
include Stdlib_TypedArray.Impl({ … })

js · Before: Stdlib_Uint8Array.mjs without the flag, before @inline on Impl · After: Stdlib_Uint8Array.mjs, as with the flag

-import * as Stdlib_TypedArray from "./Stdlib_TypedArray.mjs";
-
-Stdlib_TypedArray.Impl({});
+let Constants = {};
 …
-/*  Not a pure module */
+/* No side effect */

⚠️ Breaking: bsc rejects -bs-cross-module-opt and -bs-no-cross-module-opt as unknown options; drop them from compiler-flags. Small functions and functors are no longer inlined into other modules automatically; mark the ones that should be with @inline.

Review

  • What did the runtime lose without the flag? Three things, now @inline: Primitive_option.isNested, Stdlib_JsError.panic and the Stdlib_TypedArray.Impl functor. With them, the runtime's and Belt's JavaScript is the same as with the flag. Of the tests, only DocTest changes: JsError.panic is inlined there now.
  • Do the cross-module inlining tests still inline? Yes. Their libraries used the flag; minus3, callNext and the Make functor are now @inline, and their outputs differ only in source locations.
  • What else goes with the flag? Lam_analysis.safe_to_inline, which only the heuristic used, two runtime comments saying the runtime needs the flag, and the flag in the wording of the unreleased changelog entry for Rename the assigned variable when inlining an assignment #9424.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⚠️ Compiler benchmarks

Allocated words

In total: 674,874,144 → 678,705,310 (+0.57%).

Generated projects: 630,660,794 → 630,556,377 (-0.02%).

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

Benchmark Base Head Change
build/no-op 9,347,453 10,893,262 +16.54%
build/leaf-edit 12,080,269 13,626,187 +12.80%
build/shared-edit 87,815,598 88,676,682 +0.98%
packages/@rescript/belt/src/Belt_Map.res (inputs changed) 986,012 981,032 -0.51%
packages/@rescript/belt/src/Belt_Set.res (inputs changed) 861,971 857,736 -0.49%
packages/@rescript/runtime/Stdlib_Generator.res (inputs changed) 200,910 200,017 -0.44%
packages/@rescript/belt/src/Belt_MutableMapString.res (inputs changed) 1,159,197 1,154,468 -0.41%
packages/@rescript/belt/src/Belt_MutableMapInt.res (inputs changed) 1,158,916 1,154,189 -0.41%
packages/@rescript/runtime/Stdlib_Ordering.res (inputs changed) 154,001 153,385 -0.40%
packages/@rescript/runtime/Primitive_module.res (inputs changed) 338,469 337,202 -0.37%
62 more changes
Benchmark Base Head Change
packages/@rescript/belt/src/Belt_Array.res (inputs changed) 2,163,756 2,155,725 -0.37%
packages/@rescript/belt/src/Belt_MutableSetInt.res (inputs changed) 1,668,978 1,662,857 -0.37%
packages/@rescript/belt/src/Belt_MutableSetString.res (inputs changed) 1,670,217 1,664,103 -0.37%
packages/@rescript/runtime/Dom_storage.res (inputs changed) 167,603 166,998 -0.36%
packages/@rescript/belt/src/Belt_MutableMap.res (inputs changed) 1,306,699 1,302,107 -0.35%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res (inputs changed) 211,720 211,041 -0.32%
packages/@rescript/belt/src/Belt_MutableSet.res (inputs changed) 1,906,866 1,900,871 -0.31%
packages/@rescript/runtime/Stdlib_Array.res (inputs changed) 1,284,531 1,280,687 -0.30%
packages/@rescript/belt/src/Belt_Option.res (inputs changed) 390,937 389,772 -0.30%
packages/@rescript/runtime/Stdlib_IterableIterator.res (inputs changed) 179,435 178,912 -0.29%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res (inputs changed) 229,055 228,391 -0.29%
packages/@rescript/runtime/Primitive_array.res (inputs changed) 192,806 192,256 -0.29%
packages/@rescript/runtime/Stdlib_Int.res (inputs changed) 456,149 454,852 -0.28%
packages/@rescript/belt/src/Belt_MutableStack.res (inputs changed) 389,160 388,072 -0.28%
packages/@rescript/belt/src/Belt_SortArray.res (inputs changed) 1,452,650 1,448,739 -0.27%
packages/@rescript/belt/src/Belt_SortArrayString.res (inputs changed) 1,348,646 1,345,170 -0.26%
packages/@rescript/belt/src/Belt_SortArrayInt.res (inputs changed) 1,346,850 1,343,380 -0.26%
packages/@rescript/runtime/Stdlib_Result.res (inputs changed) 1,272,049 1,268,910 -0.25%
packages/@rescript/runtime/Primitive_bool.res (inputs changed) 147,831 147,472 -0.24%
packages/@rescript/belt/src/Belt_MutableQueue.res (inputs changed) 794,116 792,242 -0.24%
packages/@rescript/runtime/Primitive_int.res (inputs changed) 172,595 172,188 -0.24%
packages/@rescript/runtime/Primitive_bigint.res (inputs changed) 178,069 177,662 -0.23%
packages/@rescript/runtime/Stdlib_Nullable.res (inputs changed) 331,242 330,502 -0.22%
packages/@rescript/runtime/Stdlib_Null.res (inputs changed) 333,743 333,003 -0.22%
packages/@rescript/runtime/Primitive_string.res (inputs changed) 160,230 159,885 -0.22%
packages/@rescript/runtime/Stdlib_AsyncIterator.res (inputs changed) 295,758 295,123 -0.21%
packages/@rescript/runtime/Stdlib_IteratorObject.res (inputs changed) 251,232 250,705 -0.21%
packages/@rescript/belt/src/Belt_Result.res (inputs changed) 411,207 410,356 -0.21%
packages/@rescript/runtime/Stdlib_Option.res (inputs changed) 759,061 757,501 -0.21%
packages/@rescript/runtime/Stdlib_Iterator.res (inputs changed) 235,789 235,310 -0.20%
packages/@rescript/runtime/Stdlib_Bool.res (inputs changed) 146,591 146,296 -0.20%
packages/@rescript/runtime/Primitive_hash.res (inputs changed) 965,782 963,858 -0.20%
packages/@rescript/runtime/Stdlib_Pair.res (inputs changed) 165,847 165,531 -0.19%
packages/@rescript/runtime/Primitive_float.res (inputs changed) 147,482 147,214 -0.18%
packages/@rescript/runtime/Stdlib_List.res (inputs changed) 2,695,444 2,690,625 -0.18%
packages/@rescript/runtime/Stdlib_Lazy.res (inputs changed) 222,047 221,656 -0.18%
packages/@rescript/belt/src/Belt_HashMapInt.res (inputs changed) 1,064,116 1,062,330 -0.17%
packages/@rescript/belt/src/Belt_HashMapString.res (inputs changed) 1,064,824 1,063,038 -0.17%
packages/@rescript/runtime/Stdlib_BigInt.res (inputs changed) 207,637 207,297 -0.16%
packages/@rescript/belt/src/Belt_HashSetInt.res (inputs changed) 853,288 851,906 -0.16%
packages/@rescript/belt/src/Belt_HashSetString.res (inputs changed) 853,610 852,228 -0.16%
packages/@rescript/runtime/Stdlib_JsExn.res (inputs changed) 173,900 173,621 -0.16%
packages/@rescript/belt/src/Belt_internalBucketsType.res (inputs changed) 292,448 291,993 -0.16%
packages/@rescript/belt/src/Belt_HashMap.res (inputs changed) 1,203,473 1,201,617 -0.15%
packages/@rescript/belt/src/Belt_internalSetBuckets.res (inputs changed) 703,213 702,145 -0.15%
packages/@rescript/belt/src/Belt_HashSet.res (inputs changed) 981,037 979,577 -0.15%
packages/@rescript/belt/src/Belt_List.res (inputs changed) 3,187,375 3,182,676 -0.15%
packages/@rescript/belt/src/Belt_Id.res (inputs changed) 290,989 290,570 -0.14%
packages/@rescript/belt/src/Belt_Range.res (inputs changed) 289,597 289,195 -0.14%
packages/@rescript/runtime/Primitive_exceptions.res (inputs changed) 201,840 201,574 -0.13%
packages/@rescript/belt/src/Belt_internalBuckets.res (inputs changed) 971,403 970,123 -0.13%
packages/@rescript/runtime/Stdlib_String.res (inputs changed) 504,706 504,065 -0.13%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res (inputs changed) 268,707 268,380 -0.12%
packages/@rescript/runtime/Primitive_list.res (inputs changed) 204,430 204,184 -0.12%
packages/@rescript/belt/src/Belt_internalAVLset.res (inputs changed) 2,885,429 2,882,050 -0.12%
packages/@rescript/belt/src/Belt_internalAVLtree.res (inputs changed) 3,514,124 3,510,171 -0.11%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res (inputs changed) 159,893 159,721 -0.11%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res (inputs changed) 308,062 307,735 -0.11%
packages/@rescript/runtime/Primitive_object.res (inputs changed) 1,158,852 1,157,633 -0.11%
packages/@rescript/runtime/Stdlib_Map.res (inputs changed) 206,088 205,875 -0.10%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res (inputs changed) 320,724 320,397 -0.10%
packages/@rescript/runtime/Stdlib_Set.res (inputs changed) 211,434 211,221 -0.10%

(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions.

Instructions

In total: 9,226,257,585 → 9,225,535,582 (-0.01%).

Benchmark Base Head Change
stress/InlineChain.res 139,435,534 139,185,649 -0.18%
packages/@rescript/belt/src/Belt_List.res (inputs changed) 118,363,111 118,224,909 -0.12%
packages/@rescript/belt/src/Belt_internalAVLtree.res (inputs changed) 136,609,855 136,467,698 -0.10%

(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions.

Output size

In total: 27,366,836 → 27,351,499 (-0.06%).

Benchmark Base Head Change
output/belt/*.cmj (inputs changed) 33,211 22,376 -32.62%
output/runtime/*.cmj (inputs changed) 17,467 14,126 -19.13%
output/tests/*.cmj 99,938 99,491 -0.45%

(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions.

Pull request 7cc0465 compared with base fc9e0cf in this run.

@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-29T09:46:22.806469Z 37c1bfe 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.

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.46%. Comparing base (ac21673) to head (7cc0465).

Files with missing lines Patch % Lines
compiler/backend/js_cmj_format.ml 66.66% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           warn-inline-not-stored    #9480      +/-   ##
==========================================================
- Coverage                   82.47%   82.46%   -0.02%     
==========================================================
  Files                         466      466              
  Lines                       66055    66029      -26     
==========================================================
- Hits                        54481    54448      -33     
- Misses                      11574    11581       +7     
Files with missing lines Coverage Δ
compiler/backend/lam_analysis.ml 70.00% <ø> (+0.40%) ⬆️
compiler/backend/lam_stats_export.ml 92.72% <100.00%> (+0.18%) ⬆️
compiler/driver/rescript_compiler_driver.ml 80.57% <ø> (-0.14%) ⬇️
compiler/typing/js_config.ml 81.81% <ø> (ø)
compiler/backend/js_cmj_format.ml 95.00% <66.66%> (+1.38%) ⬆️

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: b04aa6c13d

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

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 7cc0465

@cknitt
cknitt force-pushed the remove-cross-module-opt branch from b55d092 to a130b27 Compare November 29, 2026 09:26
@cknitt
cknitt removed this pull request from stack #9474 November 29, 2026 09:28
@cknitt
cknitt changed the base branch from inline-exports-bodies to warn-inline-not-stored November 29, 2026 09:28
@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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a130b27513

ℹ️ 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 added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from a130b27 to 37c1bfe Compare November 29, 2026 09:44
@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. 👍

Reviewed commit: 37c1bfe414

ℹ️ 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 remove-cross-module-opt branch from 37c1bfe to fb74e15 Compare November 29, 2026 09:57
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from fb74e15 to c99daf1 Compare November 29, 2026 10:07
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from c99daf1 to e0a8fe0 Compare November 29, 2026 10:35
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from e0a8fe0 to 7fa7e77 Compare November 29, 2026 10:59
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from 7fa7e77 to bda0b78 Compare November 29, 2026 11:17
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from bda0b78 to 3d980c5 Compare November 29, 2026 11:30
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from 3d980c5 to 9be7178 Compare November 29, 2026 11:56
@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:
    Since `@inline` functions are inlined in every module, the flag only
    added an internal heuristic: with it, every closed function under size
    5 and every closed functor was inlined into other modules, annotated or
    not. Only the runtime and Belt set it, plus a few tests. It was always
    internal, so it is removed with its `-bs-no-cross-module-opt` partner:
    bsc now reports both as unknown options.
    This is PR 7 of the plan in #8733 (proposal 4).

Representation modified (which bodies a .cmj stores):
Before (mapping): Lam_stats_export.values_of_export, Js_cmj_format.get_result
    true, false, null, undefined ↦ always
    @inline function or functor ↦ always
    other closed function under size 5, closed functor ↦ with -bs-cross-module-opt
After (mapping): Lam_stats_export.values_of_export
    true, false, null, undefined ↦ always
    @inline function or functor ↦ always
    anything else ↦ never

JS modified (the runtime, built without the flag):
Example:
    // Stdlib_Uint8Array.res
    include Stdlib_TypedArray.Impl({ … })
Before (js): Stdlib_Uint8Array.mjs without the flag, before @inline on Impl
    import * as Stdlib_TypedArray from "./Stdlib_TypedArray.mjs";

    Stdlib_TypedArray.Impl({});
    …
    /*  Not a pure module */
After (js): Stdlib_Uint8Array.mjs, as with the flag
    let Constants = {};
    …
    /* No side effect */

Review: What did the runtime lose without the flag? Three things, now
`@inline`: `Primitive_option.isNested`, `Stdlib_JsError.panic` and the
`Stdlib_TypedArray.Impl` functor. With them, the runtime's and Belt's
JavaScript is the same as with the flag. Of the tests, only DocTest
changes: `JsError.panic` is inlined there now.

Review: Do the cross-module inlining tests still inline? Yes. Their
libraries used the flag; `minus3`, `callNext` and the `Make` functor are
now `@inline`, and their outputs differ only in source locations.

Review: What else goes with the flag? `Lam_analysis.safe_to_inline`,
which only the heuristic used, two runtime comments saying the runtime
needs the flag, and the flag in the wording of the unreleased changelog
entry for #9424.

Breaking: bsc rejects -bs-cross-module-opt and -bs-no-cross-module-opt
as unknown options; drop them from `compiler-flags`. Small functions and
functors are no longer inlined into other modules automatically; mark
the ones that should be with `@inline`.

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 added a commit that referenced this pull request Nov 29, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.

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 remove-cross-module-opt branch from 9be7178 to 7cc0465 Compare November 29, 2026 14:05
@cknitt
cknitt merged commit e33f87d into master Nov 30, 2026
40 of 57 checks passed
@cknitt
cknitt deleted the remove-cross-module-opt branch November 30, 2026 07:53
cknitt added a commit that referenced this pull request Nov 30, 2026
Why:
    Since #9479, other modules inline `@inline` functions, but apart from
    the nine Option helpers, the stdlib marked none, so every call to a
    one-line wrapper such as `Array.reduce` stayed a call through the
    wrapper. 72 functions are now `@inline`, chosen from the exported
    functions whose bodies other modules can store:
    - argument-reordering wrappers around externals: `Array.reduce` and its
      variants, `Array.concatAll`, `Promise.catch`, the iterator and
      generator `next` functions, `Dom_storage`, `Dict.delete`,
      `BigInt.toInt`, `Bool.toString`;
    - combinators that take a callback: `Null`, `Nullable` and `Result`
      `map`, `flatMap`, `mapOr`, `getOr`, `forEach` and the like, `Result`,
      `Pair` and `Date` `equal` and `compare`;
    - the `…Opt` lookups of `Array` and `String`, `Array.last`, `isEmpty`
      of `Array`, `String`, `Map` and `Set`, `List.add`, `head`, `tail`,
      and the `Ordering` helpers.
    `Int.Constants.minValue` and `maxValue` become `@inline` constants in
    `Stdlib_Int.resi`.

JS modified (a caller of the stdlib):
Example:
    let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)
    let last = [1, 2, 3]->Array.last
Before (js):
    let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);

    let last = Stdlib_Array.last([1, 2, 3]);
After (js):
    let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0);

    let a = [1, 2, 3];

    let last = a[a.length - 1 | 0];

JS modified (a Promise.catch handler):
Before (js):
    Stdlib_Promise.$$catch(promise, e => { … });
After (js):
    promise.catch(err => {
      let e = Primitive_exceptions.internalToException(err);
      …
    });

Review: What was left out? Loops (`zip`, `partition`, `filterMap`,
`Option.all*`), parsers wrapped in `try`, async functions, and larger
functions such as `clamp`. Also functions whose inlined code came out
worse in the tests: every `…OrThrow` (a `throw` block at each call, without
a source position), `Lazy.make` and `isEvaluated` (the runtime's lazy
representation in every caller), `JsError.throwWithMessage` (its throw
site lost its source position), `Option.equal` and `compare`, `Null` and
`Nullable` `equal` and `compare`, and `JsExn.fromException` (larger, with
no simplification), and `Iterator.next` and `nextValue`, which use a
module-local helper. Belt is left for its own pass. `JsError.panic` stays
`@inline` (#9480), since without it the runtime's own JavaScript changes.

JS modified (the Int constants):
Example:
    // Stdlib_Int.resi, in module Constants
    @inline(-2147483648)
    let minValue: int
Before (js): Stdlib_Int.mjs
    let Constants = {
      minValue: -2147483648,
      maxValue: 2147483647
    };
After (js): Stdlib_Int.mjs; other modules inline the constants
    let Constants = {};

Review: How is a wrong `@inline` caught? Warning 113: the runtime builds
with warnings as errors, so a function other modules cannot inline fails
the build. The runtime's and Belt's own JavaScript is unchanged.

Breaking: JavaScript that reads `Int.Constants.minValue` or `maxValue`
from the runtime's `Stdlib_Int` module gets `undefined`; ReScript code
inlines them.


Claude-Session: https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D

Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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