Evaluate labelled arguments passed out of order in source order
Why
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.