Skip to content

Commit

Permalink
inference: make BackedgePair struct
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Sep 14, 2022
1 parent 226cf0e commit 0f9eb79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,13 @@ function store_backedges(frame::InferenceResult, edges::Vector{Any})
nothing
end

function store_backedges(caller::MethodInstance, edges::Vector{Any})
for (typ, to) in BackedgeIterator(edges)
if isa(to, MethodInstance)
ccall(:jl_method_instance_add_backedge, Cvoid, (Any, Any, Any), to, typ, caller)
function store_backedges(frame::MethodInstance, edges::Vector{Any})
for (; sig, caller) in BackedgeIterator(edges)
if isa(caller, MethodInstance)
ccall(:jl_method_instance_add_backedge, Cvoid, (Any, Any, Any), caller, sig, frame)
else
typeassert(to, Core.MethodTable)
ccall(:jl_method_table_add_backedge, Cvoid, (Any, Any, Any), to, typ, caller)
typeassert(caller, Core.MethodTable)
ccall(:jl_method_table_add_backedge, Cvoid, (Any, Any, Any), caller, sig, frame)
end
end
end
Expand Down
15 changes: 9 additions & 6 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ is_no_constprop(method::Union{Method,CodeInfo}) = method.constprop == 0x02
Return an iterator over a list of backedges. Iteration returns `(sig, caller)` elements,
which will be one of the following:
- `(nothing, caller::MethodInstance)`: a call made by ordinary inferrable dispatch
- `(invokesig, caller::MethodInstance)`: a call made by `invoke(f, invokesig, args...)`
- `(specsig, mt::MethodTable)`: an abstract call
- `BackedgePair(nothing, caller::MethodInstance)`: a call made by ordinary inferrable dispatch
- `BackedgePair(invokesig, caller::MethodInstance)`: a call made by `invoke(f, invokesig, args...)`
- `BackedgePair(specsig, mt::MethodTable)`: an abstract call
# Examples
Expand All @@ -254,7 +254,7 @@ julia> callyou(2.0)
julia> mi = first(which(callme, (Any,)).specializations)
MethodInstance for callme(::Float64)
julia> @eval Core.Compiler for (sig, caller) in BackedgeIterator(Main.mi.backedges)
julia> @eval Core.Compiler for (; sig, caller) in BackedgeIterator(Main.mi.backedges)
println(sig)
println(caller)
end
Expand All @@ -268,8 +268,11 @@ end

const empty_backedge_iter = BackedgeIterator(Any[])

const MethodInstanceOrTable = Union{MethodInstance, Core.MethodTable}
const BackedgePair = Pair{Union{Type, Nothing, MethodInstanceOrTable}, MethodInstanceOrTable}
struct BackedgePair
sig # ::Union{Nothing,Type}
caller::Union{MethodInstance,Core.MethodTable}
BackedgePair(@nospecialize(sig), caller::Union{MethodInstance,Core.MethodTable}) = new(sig, caller)
end

function iterate(iter::BackedgeIterator, i::Int=1)
backedges = iter.backedges
Expand Down

0 comments on commit 0f9eb79

Please sign in to comment.