From 6c8f47e64a1272cbb5df68c9dd7d7ae91fd9ed8b Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 15 Jan 2020 14:46:49 -0500 Subject: [PATCH 1/2] `func_specializations` include types in MethodTable backedges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This now returns `(:MethodTable, Type{...})` for the backedges of a function: ```julia julia> LookingGlass.func_backedges(foo) Dict{Tuple,Array{Any,1}} with 2 entries: (foo(x) in Main at none:1, Tuple{typeof(foo),Int64}) => Any[] (:MethodTable, Tuple{typeof(foo),Int64,Int64}) => Any[MethodInstance for static_hasmethod(::typeof(fo… ``` --- src/LookingGlass.jl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/LookingGlass.jl b/src/LookingGlass.jl index d70df2b..641bb15 100644 --- a/src/LookingGlass.jl +++ b/src/LookingGlass.jl @@ -13,6 +13,7 @@ example: There are also other non-reflection-focused utilities, such as `@quot`. """ module LookingGlass +import Base.Iterators """ @quot 2 + 3 @@ -95,12 +96,22 @@ Dict{Any,Array{Any,1}} with 2 entries: Backedges on a function's MethodTable means changes to _any methods_ (including adding a method) will trigger recompilation of the target function. """ -func_backedges(f) = - Dict( - :MethodTable => try methods(f).mt.backedges catch ; [] end, - (k => try s.func.backedges catch ; [] end - for (k,s) in func_specializations(f))... +function func_backedges(f) + out = Dict{Tuple, Vector{Any}}( + # Method backedges + k => try s.func.backedges catch ; [] end + for (k,s) in func_specializations(f) ) + # MethodTable backedges + for (typ, method) in + # MethodTable edges are pairs of (type, method_instance) (but stored as a flat array) + try Tuple.(Iterators.partition(methods(f).mt.backedges, 2)) catch ; [] end + methods = get!(out, (:MethodTable, typ), []) + push!(methods, method) + end + out +end + # --------------------------------------------------------------------------- From f2becd053d36289948e5ba168ab43ac1cde67814 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 15 Jan 2020 14:50:19 -0500 Subject: [PATCH 2/2] Stronger type on func_specializations out dict --- src/LookingGlass.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LookingGlass.jl b/src/LookingGlass.jl index 641bb15..675eee3 100644 --- a/src/LookingGlass.jl +++ b/src/LookingGlass.jl @@ -97,7 +97,7 @@ Backedges on a function's MethodTable means changes to _any methods_ (including a method) will trigger recompilation of the target function. """ function func_backedges(f) - out = Dict{Tuple, Vector{Any}}( + out = Dict{Tuple{Any,Type}, Vector{Any}}( # Method backedges k => try s.func.backedges catch ; [] end for (k,s) in func_specializations(f)