You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An inlined function reads an external callee before it evaluates the argument #9334
A function whose body is the call of an external is inlined so that JavaScript reads the external function before the argument runs. ReScript evaluates the argument first.
%%raw(`globalThis.hook=x=> x +1`)
@valexternalhook: int=>int="hook"letinstall: unit=>int=%raw(`() => {globalThis.hook=x=> x +100return1}`)letcallHook=x=>hook(x)
typeobjleto: obj=%raw(`{run:x=> x +1}`)
@sendexternalrun: (obj, int) =>int="run"letreplaceRun: unit=>int=%raw(`() => {o.run=x=> x +100return1}`)letcallRun= (o, x) =>o->run(x)
Console.log(callHook(install()))
Console.log(callRun(o, replaceRun()))
This prints 2 and 2. The wrappers called without inlining print 101 and 101, because install() and replaceRun() run before the wrapper reads hook and o.run.
The rewrite is the fast path of beta reduction, Lam_beta_reduce_util.simple_beta_reduce. It takes the callee of an Lapply as evaluated before the arguments, but not the function or method that a Pjs_call reads. #9296 fixes the same order for let x = e; f(x) and leaves this case out: binding the argument here changes the output of every inlined wrapper around an external whose argument has side effects.
Activity