Skip to content

Commit

Permalink
Fix inlining logic for :invoke exprs (JuliaLang#51766)
Browse files Browse the repository at this point in the history
This code path isn't currently used in Base, but is reached in external
abstract interpreters and wasn't correctly handling ConstantCase returns
from `resolve_todo`.
  • Loading branch information
Keno committed Oct 19, 2023
1 parent 8a889ff commit 47d5c02
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,12 @@ function handle_single_case!(todo::Vector{Pair{Int,Any}},
elseif isa(case, InvokeCase)
is_foldable_nothrow(case.effects) && inline_const_if_inlineable!(ir[SSAValue(idx)]) && return nothing
isinvoke && rewrite_invoke_exprargs!(stmt)
stmt.head = :invoke
pushfirst!(stmt.args, case.invoke)
if stmt.head === :invoke
stmt.args[1] = case.invoke
else
stmt.head = :invoke
pushfirst!(stmt.args, case.invoke)
end
ir[SSAValue(idx)][:flag] |= flags_for_effects(case.effects)
elseif case === nothing
# Do, well, nothing
Expand Down Expand Up @@ -1643,13 +1647,11 @@ function handle_finalizer_call!(ir::IRCode, idx::Int, stmt::Expr, info::Finalize
return nothing
end

function handle_invoke_expr!(todo::Vector{Pair{Int,Any}},
function handle_invoke_expr!(todo::Vector{Pair{Int,Any}}, ir::IRCode,
idx::Int, stmt::Expr, @nospecialize(info::CallInfo), flag::UInt32, sig::Signature, state::InliningState)
mi = stmt.args[1]::MethodInstance
case = resolve_todo(mi, sig.argtypes, info, flag, state)
if case !== nothing
push!(todo, idx=>(case::InliningTodo))
end
handle_single_case!(todo, ir, idx, stmt, case, false)
return nothing
end

Expand Down Expand Up @@ -1677,7 +1679,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
# `NativeInterpreter` won't need this, but provide a support for `:invoke` exprs here
# for external `AbstractInterpreter`s that may run the inlining pass multiple times
if isexpr(stmt, :invoke)
handle_invoke_expr!(todo, idx, stmt, info, flag, sig, state)
handle_invoke_expr!(todo, ir, idx, stmt, info, flag, sig, state)
continue
end

Expand Down

0 comments on commit 47d5c02

Please sign in to comment.