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
In cases like the following code, where a variable defined in the parent scope of a closure is used inside the closure and could potentially be reassigned in the parent scope, it seems to get boxed even if it is never reassigned within the closure itself.
I think the challenge is that lowering needs to prove that no re-assignments occur after closure creation, because if any do, then the closure's captured variable needs to be able to be changed. Ref #15276 (comment)
Functions called with the do syntax typically immediately evaluate and discard the anonymous function, but it might escape — possibly even to a global. There's no way lowering could know this.
julia>functiondemo_box(a)
x =sin(a)
f =identity() do a
a + x
end@showf(1)
x =123123@showf(1)
end
demo_box (generic function with 1 method)
julia>demo_box(1.23)
f(1) =1.9424888019316975f(1) =123124
In cases like the following code, where a variable defined in the parent scope of a closure is used inside the closure and could potentially be reassigned in the parent scope, it seems to get boxed even if it is never reassigned within the closure itself.
This boxing appears completely unnecessary to me. Would it be possible to make a simple change to lowering to fix this issue?
The text was updated successfully, but these errors were encountered: