Repository navigation
Inline @inline functions in other modules without a flag - #9479
Conversation
Changelog🚀 New Feature
Semantic Diff1 commit · Full page ✏️ Inline
|
|
| Benchmark | Base | Head | Change |
|---|---|---|---|
packages/@rescript/runtime/Stdlib_Option.res (inputs changed) |
755,865 | 758,362 | +0.33% |
packages/@rescript/runtime/Stdlib_Nullable.res (inputs changed) |
330,533 | 331,056 | +0.16% |
packages/@rescript/runtime/Stdlib_Null.res (inputs changed) |
333,034 | 333,557 | +0.16% |
(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,225,758,933 → 9,226,139,623 (±0.00%).
| Benchmark | Base | Head | Change |
|---|---|---|---|
stress/InlineChain.res |
139,165,907 | 139,408,054 | +0.17% |
Output size
In total: 27,307,580 → 27,309,991 (+0.01%).
| Benchmark | Base | Head | Change |
|---|---|---|---|
output/runtime/*.cmj (inputs changed) |
17,059 | 17,467 | +2.39% |
output/tests/*.cmj |
98,026 | 99,310 | +1.31% |
(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 9f3bc63 compared with base 84a2717 in this run.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## closure-try-binder #9479 +/- ##
======================================================
+ Coverage 82.45% 82.46% +0.01%
======================================================
Files 465 465
Lines 65987 66011 +24
======================================================
+ Hits 54408 54439 +31
+ Misses 11579 11572 -7
🚀 New features to boost your workflow:
|
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 972e147bff
ℹ️ 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".
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
972e147 to
3a2f64a
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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>
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>
3a2f64a to
dc9b2a2
Compare
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>
dc9b2a2 to
bf6e379
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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>
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>
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>
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>
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>
Why:
`@inline` on a function inlined its calls only in its own module.
Other modules inlined it only with -bs-cross-module-opt, which also
inlined every small closed function, annotated or not. `@inline` now
means the same in every module: an exported `@inline` function or
functor stores its body in the .cmj, and other modules inline it,
flag or not. The Option helpers that #8689 marked are `@inline`. This
is PR 5 of the plan in #8733 (proposal 3) and replaces the compiler
part of #8689, without the `@inline(crossModule)` payload.
JS modified (another module, without -bs-cross-module-opt):
Example:
// A.res
@inline let g = x => x + 1
let h = x => x * 2
// B.res
let a = A.g(3)
let b = A.h(4)
Before (js): B
let a = A.g(3);
let b = A.h(4);
After (js): B
let b = A.h(4);
let a = 4;
JS modified (an Option helper):
Example:
// tests/belt_tests/src/bs_stack_test.res
while current->Option.isSome { … }
Before (js):
while (Stdlib_Option.isSome(current)) {
After (js):
while (current !== undefined) {
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, closed ↦ with -bs-cross-module-opt
other closed function under size 5, closed functor ↦ with -bs-cross-module-opt
After (mapping): Lam_stats_export.values_of_export, Js_cmj_format.get_result
true, false, null, undefined ↦ always
@inline function or functor, closed, not async, no directive ↦ always
other closed function under size 5, closed functor ↦ with -bs-cross-module-opt
Review: What keeps a body from being stored? It must be closed, since it
is copied without its environment, not async and without a directive, and
it must not call a relative-path external (#9475). A caller that can't
load a module the body names calls the function instead (#9478).
Review: Which functions does this cover? Those defined at the top level
of a module. A function in a nested module (`module M = { @inline let f
= … }`) and an `@inline let rec` are still inlined only in their own
module.
Review: Does the caller rebuild when the body changes? Yes, through the
changed .cmj (#9473); tests/build_tests/projects/inline_function_rebuild
edits a body on the same line, which leaves the .cmi as it is.
Review: Can a JS global be captured by the import of a module whose uses
were all inlined? Not any more. Such a module is still imported when it has
side effects, so `Js_pass_external_shadow` now counts the modules imported
for their side effects as bindings in scope (`Lam_compile_env.side_effect_modules`,
which `populate_required_modules` uses too). Before, it saw only the modules
the generated code still named and printed the global bare, which then read
the import (inline_shadowed_import_test.res). Found by marking every function
in tests/tests `@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>
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>
bf6e379 to
9f3bc63
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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>
@inlineon a function now inlines its calls in other modules too, without-bs-cross-module-opt. This is PR 5 of the plan in #8733 (proposal 3), and replaces the compiler part of #8689 without its@inline(crossModule)payload:@inlinemeans the same in every module.An exported
@inlinefunction or functor stores its body in the.cmjwhen it's closed, not async and has no directive. The earlier PRs in this stack keep it safe:Option.map,flatMap,getOr,mapOr,orElse,filter,forEach,isSomeandisNoneare now@inline, as #8689 marked them. So, for example,current->Option.isSomecompiles tocurrent !== undefined. That changes eight generated test files, all in this way.Benchmarks:
.cmjfiles get larger (tests +1.36%, runtime +2.39%), since they now store the bodies of@inlinefunctions. That's the point of this PR. Allocations are flat (+0.01%).New tests:
tests/tests/src/inline_export.resandinline_export_test.res(from Add opt-in cross-module inlining for Option helpers #8689): the Option helpers and an exported@inlinefunction are inlined, a plain function is called, and fallback arguments are still evaluated eagerly.tests/build_tests/projects/inline_function_rebuild: editing an@inlinebody on the same line, which leaves the.cmias it is, compiles the caller again.An
@inlinefunction containingtry … catchis inlined too, since #9485 below.A module whose uses are all inlined is still imported when it has side effects. A JS global with that module's name was then printed bare and read the import. The external-shadow pass now counts the modules imported for their side effects as bindings in scope, so the global is read through
globalThis. Regression tests:inline_shadowed_import_test.resand an ounit case. Found by an experiment that marked every function intests/tests@inline.Part of stack #9486, after #9485.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D