Skip to content

Commit

Permalink
Merge pull request JuliaLang#22349 from JuliaLang/jb/fix22347
Browse files Browse the repository at this point in the history
fix JuliaLang#22347, `_apply` optimization dropping argument expressions
  • Loading branch information
JeffBezanson committed Jun 15, 2017
2 parents 52069d7 + b064a1a commit b49cb07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4857,7 +4857,8 @@ function inlining_pass(e::Expr, sv::InferenceState, stmts, ins)
if isa(aarg,Expr) && (is_known_call(aarg, tuple, sv.src, sv.mod) || is_known_call(aarg, svec, sv.src, sv.mod))
# apply(f,tuple(x,y,...)) => f(x,y,...)
newargs[i-2] = aarg.args[2:end]
elseif isa(argt,Const) && (isa(argt.val, Tuple) || isa(argt.val, SimpleVector))
elseif isa(argt,Const) && (isa(argt.val, Tuple) || isa(argt.val, SimpleVector)) &&
effect_free(aarg, sv.src, sv.mod, true)
newargs[i-2] = Any[ QuoteNode(x) for x in argt.val ]
elseif isa(aarg, Tuple) || (isa(aarg, QuoteNode) && (isa(aarg.value, Tuple) || isa(aarg.value, SimpleVector)))
if isa(aarg, QuoteNode)
Expand Down
11 changes: 11 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,17 @@ end
@test isdefined_tfunc(Tuple{Any,Vararg{Any}}, Const(2)) === Bool
@test isdefined_tfunc(Tuple{Any,Vararg{Any}}, Const(3)) === Bool

@noinline map3_22347(f, t::Tuple{}) = ()
@noinline map3_22347(f, t::Tuple) = (f(t[1]), map3_22347(f, Base.tail(t))...)
# issue #22347
let niter = 0
map3_22347((1, 2, 3, 4)) do y
niter += 1
nothing
end
@test niter == 4
end

# demonstrate that inference must converge
# while doing constant propagation
Base.@pure plus1(x) = x + 1
Expand Down

0 comments on commit b49cb07

Please sign in to comment.