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
function inner(; kw=nothing)
println("in inner()")
end
function get_inner()
println("in get_inner()")
inner
end
function test1()
f = get_inner()
f(kw=1)
end
function test2()
get_inner()(kw=1)
end
function test3()
get_inner()(; :kw => 1)
end
println("test1:")
test1()
println("test2:")
test2()
println("test3:")
test3()
In each of the test functions I would expect get_inner() to be only called once. Yet the output I get is
test1:
in get_inner()
in inner()
test2:
in get_inner()
in get_inner()
in inner()
test3:
in get_inner()
in get_inner()
in get_inner()
in inner()
AFAIU, the expression yielding the function to be called would need to be evaluated once with the result being stored in an SSAValue instead of evaluating it twice.
Lower e.g. `get_inner()(kw=1)` to
```
SSAValue(n) = get_inner()
((Core.kwfunc)(SSAValue(n)))((Base.vector_any)(:kw, 1), SSAValue(n))
```
instead of
```
((Core.kwfunc)(get_inner()))((Base.vector_any)(:kw, 1), get_inner())`
```
as the latter would call `get_inner` twice.
Fixes#21518.
Lower e.g. `get_inner()(kw=1)` to
```
SSAValue(n) = get_inner()
((Core.kwfunc)(SSAValue(n)))((Base.vector_any)(:kw, 1), SSAValue(n))
```
instead of
```
((Core.kwfunc)(get_inner()))((Base.vector_any)(:kw, 1), get_inner())
```
as the latter would call `get_inner` twice.
Fixes#21518.
* Only evaluate `fexpr` in `fexpr(kw=...)` once
Lower e.g. `get_inner()(kw=1)` to
```
SSAValue(n) = get_inner()
((Core.kwfunc)(SSAValue(n)))((Base.vector_any)(:kw, 1), SSAValue(n))
```
instead of
```
((Core.kwfunc)(get_inner()))((Base.vector_any)(:kw, 1), get_inner())
```
as the latter would call `get_inner` twice.
Fixes#21518.
Consider the following code:
In each of the
test
functions I would expectget_inner()
to be only called once. Yet the output I get isIs it some peculiarity of Julia syntax, or a bug?
versioninfo()
output:The text was updated successfully, but these errors were encountered: