Semantic Diff

#9484 Mark small stdlib functions @inline

1 commit

2bb598f4ac22672954dc3519a02ce6a7a553bc7d..pr-9484

0bb9ef619 · cknitt + Claude · Nov 29, 2026, 08:37 UTC

Mark small stdlib functions @inline

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.

modifiedJS a caller of the stdlib

let reversed = [1, 2, 3]->Array.reduce(list{}, List.add)let last = [1, 2, 3]->Array.last
js
Before
After
let reversed = Stdlib_Array.reduce([1, 2, 3], /* [] */0, Stdlib_List.add);let reversed = [1, 2, 3].reduce(Stdlib_List.add, /* [] */0); let last = Stdlib_Array.last([1, 2, 3]); let a = [1, 2, 3]; let last = a[a.length - 1 | 0];

modifiedJS a Promise.catch handler

js
Before
After
Stdlib_Promise.$$catch(promise, e => { … }); promise.catch(err => { let e = Primitive_exceptions.internalToException(err); …});

modifiedJS the Int constants

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

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