Repository navigation
Mark small stdlib functions @inline - #9484
Conversation
Changelog💥 Breaking Change
🚀 New Feature
Semantic Diff1 commit · Full page Mark small stdlib functions
|
|
@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. |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
✅ Compiler benchmarksAllocated wordsIn total: 674,782,686 → 674,904,325 (+0.02%). Generated projects: 630,567,513 → 630,567,667 (±0.00%).
12 more changes
(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. InstructionsIn total: 9,225,173,451 → 9,225,173,451 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,359,384 → 27,368,415 (+0.03%).
(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 0bb9ef6 compared with base f607fbe in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
744d3c4 to
e30a9a1
Compare
e30a9a1 to
884cef8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## inline-const-diagnostics #9484 +/- ##
============================================================
+ Coverage 82.46% 82.47% +0.01%
============================================================
Files 466 466
Lines 66070 66070
============================================================
+ Hits 54486 54493 +7
+ Misses 11584 11577 -7 🚀 New features to boost your workflow:
|
884cef8 to
301f4a6
Compare
885f727 to
2d43271
Compare
308c984 to
a768261
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>
a768261 to
0bb9ef6
Compare
Marks 72 small stdlib functions
@inline, so calls to them compile to the code they run. They were chosen from the exported functions whose bodies other modules can store:Array.reduceand its variants,Array.concatAll,Promise.catch, the iterator and generatornextfunctions,Dom_storage,Dict.delete,BigInt.toInt,Bool.toString;Null,NullableandResultmap,flatMap,mapOr,getOr,forEachand the like, andResult,PairandDateequalandcompare;…Optlookups ofArrayandString,Array.last,isEmptyofArray,String,MapandSet,List.add,headandtail, and theOrderinghelpers.For example,
[1, 2, 3]->Array.reduce(list{}, List.add)now compiles to[1, 2, 3].reduce(Stdlib_List.add, /* [] */0). APromise.catchhandler is passed straight topromise.catch.Left out:
zip,partition,filterMap,Option.all*), parsers wrapped intry, async functions, and larger functions such asclamp;…OrThrow(athrowblock at each call, without a source position);Lazy.makeandisEvaluated(the runtime's lazy representation in every caller);JsError.throwWithMessage(its throw site lost its source position);Option,NullandNullableequalandcompare, andJsExn.fromException(larger, with nothing simplified);Iterator.nextandnextValue, which use a module-local helper.Belt is left for its own pass.
Int.Constants.minValueandmaxValuebecome@inlineconstants inStdlib_Int.resi. JavaScript that reads them from the runtime's module getsundefined, so that has abreakingchangelog entry.A wrong
@inlinefails the build: the runtime builds with warnings as errors, and warning 113 (#9482) reports functions other modules can't inline. The runtime's and Belt's own JavaScript is unchanged, apart fromStdlib_Int. Intests/tests, 20 generated files change, by about as many lines added as removed.This takes over the stdlib part of #8689. Part of stack #9486, at the top.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gJwNt3jmNq5d8xKA9D