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
modifiedJS a Promise.catch handler
js
modifiedJS the Int constants
// Stdlib_Int.resi, in module Constants@inline(-2147483648)let minValue: int
js
Review
- What was left out? Loops (
zip,partition,filterMap,Option.all*), parsers wrapped intry, async functions, and larger functions such asclamp. Also functions whose inlined code came out worse in the tests: every…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.equalandcompare,NullandNullableequalandcompare, andJsExn.fromException(larger, with no simplification), andIterator.nextandnextValue, which use a module-local helper. Belt is left for its own pass.JsError.panicstays@inline(#9480), since without it the runtime's own JavaScript changes. - How is a wrong
@inlinecaught? 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.