From 0f9eb79e228381d1edb48af52d194df4e5ec2b39 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Wed, 14 Sep 2022 00:43:36 +0900 Subject: [PATCH] inference: make `BackedgePair` struct --- base/compiler/typeinfer.jl | 12 ++++++------ base/compiler/utilities.jl | 15 +++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/base/compiler/typeinfer.jl b/base/compiler/typeinfer.jl index c5d19166ad7d0f..6db3c42a6ca54a 100644 --- a/base/compiler/typeinfer.jl +++ b/base/compiler/typeinfer.jl @@ -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 diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl index 071b0b6089b988..88e002a469575d 100644 --- a/base/compiler/utilities.jl +++ b/base/compiler/utilities.jl @@ -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 @@ -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 @@ -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