diff --git a/base/inference.jl b/base/inference.jl index 42b4d86cc2012..fdba556e21692 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -4471,10 +4471,18 @@ function inlining_pass(e::Expr, sv::InferenceState, stmts, ins) elseif isa(aarg, Tuple) newargs[i-2] = Any[ QuoteNode(x) for x in aarg ] elseif isa(t, DataType) && t.name === Tuple.name && !isvatuple(t) && - effect_free(aarg, sv.src, sv.mod, true) && length(t.parameters) <= sv.params.MAX_TUPLE_SPLAT - # apply(f,t::(x,y)) => f(t[1],t[2]) + length(t.parameters) <= sv.params.MAX_TUPLE_SPLAT + if effect_free(aarg, sv.src, sv.mod, true) + # apply(f,t::(x,y)) => f(t[1],t[2]) + tmpv = aarg + else + # apply(f,t::(x,y)) => tmp=t; f(tmp[1],tmp[2]) + tmpv = newvar!(sv, t) + insert!(stmts, ins, Expr(:(=), tmpv, aarg)) + ins += 1 + end tp = t.parameters - newargs[i-2] = Any[ mk_getfield(aarg,j,tp[j]) for j=1:length(tp) ] + newargs[i-2] = Any[ mk_getfield(tmpv,j,tp[j]) for j=1:length(tp) ] else # not all args expandable return e diff --git a/test/inference.jl b/test/inference.jl index 54621e6c892c8..dfc4bf8d4375e 100644 --- a/test/inference.jl +++ b/test/inference.jl @@ -685,6 +685,21 @@ end aa20704(x) = x(nothing) @test code_typed(aa20704, (typeof(a20704),))[1][1].pure +#issue #21065, elision of _apply when splatted expression is not effect_free +function f21065(x,y) + println("x=$x, y=$y") + return x, y +end +g21065(x,y) = +(f21065(x,y)...) +function test_no_apply(expr::Expr) + return all(test_no_apply, expr.args) +end +function test_no_apply(ref::GlobalRef) + return ref.mod != Core || ref.name !== :_apply +end +test_no_apply(::Any) = true +@test all(test_no_apply, code_typed(g21065, Tuple{Int,Int})[1].first.code) + # issue #20033 # check return_type_tfunc for calls where no method matches bcast_eltype_20033(f, A) = Core.Inference.return_type(f, Tuple{eltype(A)}) @@ -692,4 +707,4 @@ err20033(x::Float64...) = prod(x) @test bcast_eltype_20033(err20033, [1]) === Union{} @test Base.return_types(bcast_eltype_20033, (typeof(err20033), Vector{Int},)) == Any[Type{Union{}}] # return_type on builtins -@test Core.Inference.return_type(tuple, Tuple{Int,Int8,Int}) === Tuple{Int,Int8,Int} +@test Core.Inference.return_type(tuple, Tuple{Int,Int8,Int}) === Tuple{Int,Int8,Int} \ No newline at end of file