Skip to content

Commit c282224

Browse files
authored
Merge pull request #21080 from JuliaLang/mh/backport_21069
[release-0.5] Backport of #21069
2 parents 9844192 + e9fc37a commit c282224

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

base/inference.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,10 +3053,17 @@ function inlining_pass(e::Expr, sv, linfo)
30533053
elseif isa(aarg, Tuple)
30543054
newargs[i-2] = Any[ QuoteNode(x) for x in aarg ]
30553055
elseif isa(t, DataType) && t.name === Tuple.name && !isvatuple(t) &&
3056-
effect_free(aarg, linfo, true) && length(t.parameters) <= MAX_TUPLE_SPLAT
3057-
# apply(f,t::(x,y)) => f(t[1],t[2])
3056+
length(t.parameters) <= MAX_TUPLE_SPLAT
3057+
if effect_free(aarg, linfo, true)
3058+
# apply(f,t::(x,y)) => f(t[1],t[2])
3059+
tmpv = aarg
3060+
else
3061+
# apply(f,t::(x,y)) => tmp=t; f(tmp[1],tmp[2])
3062+
tmpv = newvar!(sv, t)
3063+
push!(stmts, Expr(:(=), tmpv, aarg))
3064+
end
30583065
tp = t.parameters
3059-
newargs[i-2] = Any[ mk_getfield(aarg,j,tp[j]) for j=1:length(tp) ]
3066+
newargs[i-2] = Any[ mk_getfield(tmpv,j,tp[j]) for j=1:length(tp) ]
30603067
else
30613068
# not all args expandable
30623069
return (e,stmts)

test/inference.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,18 @@ test_fast_le(a, b) = @fastmath a <= b
376376
@inferred test_fast_ne(1.0, 1.0)
377377
@inferred test_fast_lt(1.0, 1.0)
378378
@inferred test_fast_le(1.0, 1.0)
379+
380+
#issue #21065, elision of _apply when splatted expression is not effect_free
381+
function f21065(x,y)
382+
println("x=$x, y=$y")
383+
return x, y
384+
end
385+
g21065(x,y) = +(f21065(x,y)...)
386+
function test_no_apply(expr::Expr)
387+
return all(test_no_apply, expr.args)
388+
end
389+
function test_no_apply(ref::GlobalRef)
390+
return ref.mod != Core || ref.name !== :_apply
391+
end
392+
test_no_apply(::Any) = true
393+
@test all(test_no_apply, Base.uncompressed_ast(code_typed(g21065, Tuple{Int,Int})[1]))

0 commit comments

Comments
 (0)