Semantic Diff

#9539 Inline other modules' functions called through a variable

1 commit

fb365099f68acebeb19d4f2b0348a7e11fd4e76a..pr-9539

9d227dff1 · cknitt + Claude · Dec 05, 2026, 10:14 UTC

Inline other modules' functions called through a variable

Why

Since the late inlining went, a call through a variable bound to another module's function, as in let f = M.f or let {f} = module(M), was compiled as a call even when M.f is @inline. The alias pass now remembers which variables are bound to a field of another module and calls that field directly, so the existing case for other modules' functions inlines it. This works for top-level and local bindings alike.

modifiedJS let {f} = module(M) in a function

let orEmpty = (x: option<string>) => {  let {getOr} = module(Option)  x->getOr("")}
js
Before
After
function orEmpty(x) {function orEmpty(x) { return Stdlib_Option.getOr(x, ""); if (x !== undefined) { return x; } else { return ""; }}}

modifiedJS a top-level let f = M.f

let getOr = Option.getOrlet orZero = (x: option<int>) => x->getOr(0)
js
Before
After
function orZero(x) {function orZero(x) { return Stdlib_Option.getOr(x, 0); if (x !== undefined) { return x; } else { return 0; }}}

Review

  • What does inline_through_alias_test cover? The three shapes, let f = M.f, let {f} = module(M) and a local let f = M.f, each with Option functions that inline, and a call whose arguments must still run in order. hello_res.mjs is back to its output on master, where u is neither exported nor used, so only the length call remains.