Skip to content

Commit f88bc55

Browse files
committed
[NewOptimizer] Fix _apply elision
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.
1 parent c0e6b5b commit f88bc55

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

base/compiler/ssair/inlining2.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,22 @@ function maybe_make_invoke!(ir::IRCode, idx::Int, @nospecialize(etype), atypes::
309309
@nospecialize(atype_unlimited), isinvoke::Bool, isapply::Bool, @nospecialize(invoke_data))
310310
nu = countunionsplit(atypes)
311311
nu > 1 && return # TODO: The old optimizer did union splitting here. Is this the right place?
312-
ex = Expr(:invoke)
313312
linfo = spec_lambda(atype_unlimited, sv, invoke_data)
314-
linfo === nothing && return
313+
if linfo === nothing
314+
# We might not have an linfo, but we can still rewrite the _apply into a regular call
315+
# based on our analysis
316+
if isapply
317+
ex = Expr(:call)
318+
argexprs = ir[SSAValue(idx)].args
319+
argexprs = rewrite_exprargs((node, typ)->insert_node!(ir, idx, typ, node), arg->exprtype(arg, ir, ir.mod),
320+
isinvoke, isapply, argexprs)
321+
ex.typ = etype
322+
ex.args = argexprs
323+
ir[SSAValue(idx)] = ex
324+
end
325+
return
326+
end
327+
ex = Expr(:invoke)
315328
add_backedge!(linfo, sv)
316329
argexprs = ir[SSAValue(idx)].args
317330
argexprs = rewrite_exprargs((node, typ)->insert_node!(ir, idx, typ, node), arg->exprtype(arg, ir, ir.mod),
@@ -466,7 +479,6 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
466479
methsp = methsp::SimpleVector
467480
end
468481

469-
470482
methsig = method.sig
471483
if !(atype <: metharg)
472484
maybe_make_invoke!(ir, idx, stmt.typ, atypes, sv, atype_unlimited, isinvoke, isapply, invoke_data)

0 commit comments

Comments
 (0)