Semantic Diff

#9344 Evaluate labelled arguments passed out of order in source order

1 commit

a82617064bae3aa9eb1b070b5fc85bb8abfcb422..pr-9344

513572d7f · cknitt + Claude · Nov 19, 2026, 19:17 UTC

Evaluate labelled arguments passed out of order in source order

Why

An application lists its arguments in declared order. A labelled argument passed before arguments declared ahead of it was therefore evaluated after them, against the left-to-right order ReScript keeps elsewhere (#9340, #9154).

An argument is stable when it reads the same wherever it is evaluated: a constant, variable, function, constant constructor or module path. When the arguments that are not stable are out of source order and one of them can have side effects, the callee (unless it is an identifier) and those arguments are bound to temporaries in source order. A stable argument passed early, as in fromArray(~id=module(IntCmp), range(0, 30)), changes nothing.

modifiedJS out-of-order labelled arguments

let f = (x: int, ~extra: int, y: int) => [x, extra, y]let r = f(~extra=b(), a(), c())
js
Before
After
let arg = b();let arg$1 = a();let arg$2 = c();let r = [let r = [ a(), b(), c() arg$1, arg, arg$2];];

Fixes #9340

Review

  • Why bind every argument that is not stable, not only the moved ones? An argument left in place runs after all bound ones, so it would have to come after them in the source as well. Binding all of them is simpler and only happens for out-of-order calls with effects.