Skip to content

Commit

Permalink
[NewOptimizer] Fix _apply elision
Browse files Browse the repository at this point in the history
The old optimizer had an extra loop outside the inlining pass that would
turn _apply's in to regular calls. When I wrote the new inliner we discussed
that this wasn't actually necessary because we could just keep track of
this information in the inliner (as we do for invoke). However, that of
course also means that if we can't turn something into an :invoke, we
should still at least turn it into a regular call. Do that.
  • Loading branch information
Keno committed Apr 17, 2018
1 parent c0e6b5b commit 84298cb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions base/compiler/ssair/inlining2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,22 @@ function maybe_make_invoke!(ir::IRCode, idx::Int, @nospecialize(etype), atypes::
@nospecialize(atype_unlimited), isinvoke::Bool, isapply::Bool, @nospecialize(invoke_data))
nu = countunionsplit(atypes)
nu > 1 && return # TODO: The old optimizer did union splitting here. Is this the right place?
ex = Expr(:invoke)
linfo = spec_lambda(atype_unlimited, sv, invoke_data)
linfo === nothing && return
add_backedge!(linfo, sv)
if linfo === nothing
if !isapply || isinvoke
return
end
# We might not have an linfo, but we can still rewrite the _apply into a regular call
# based on our analysis
ex = Expr(:call)
else
ex = Expr(:invoke)
add_backedge!(linfo, sv)
end
argexprs = ir[SSAValue(idx)].args
argexprs = rewrite_exprargs((node, typ)->insert_node!(ir, idx, typ, node), arg->exprtype(arg, ir, ir.mod),
isinvoke, isapply, argexprs)
pushfirst!(argexprs, linfo)
linfo !== nothing && pushfirst!(argexprs, linfo)
ex.typ = etype
ex.args = argexprs
ir[SSAValue(idx)] = ex
Expand Down Expand Up @@ -466,7 +474,6 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
methsp = methsp::SimpleVector
end


methsig = method.sig
if !(atype <: metharg)
maybe_make_invoke!(ir, idx, stmt.typ, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data)
Expand Down

0 comments on commit 84298cb

Please sign in to comment.