@@ -11,7 +11,7 @@ CodeTracking can be thought of as an extension of InteractiveUtils, and pairs we
1111module CodeTracking
1212
1313using Base: PkgId
14- using Core: LineInfoNode
14+ using Core: LineInfoNode, MethodTable
1515using Base. Meta: isexpr
1616using UUIDs
1717using InteractiveUtils
@@ -29,12 +29,12 @@ include("utils.jl")
2929
3030# These values get populated by Revise
3131
32- # `method_info[sig]` is either:
32+ # `method_info[mt => sig]` is either:
3333# - `missing`, to indicate that the method cannot be located
3434# - a list of `(lnn,ex)` pairs. In almost all cases there will be just one of these,
3535# but "mistakes" in moving methods from one file to another can result in more than
3636# definition. The last pair in the list is the currently-active definition.
37- const method_info = IdDict{Type,Union{Missing,Vector{Tuple{LineNumberNode,Expr}}}}()
37+ const method_info = IdDict{Pair{ <: Union{Nothing, MethodTable} , <: Type } ,Union{Missing,Vector{Tuple{LineNumberNode,Expr}}}}()
3838
3939const _pkgfiles = Dict {PkgId,PkgFiles} ()
4040
@@ -58,6 +58,9 @@ const expressions_callback = Ref{Any}(nothing)
5858const juliabase = joinpath (" julia" , " base" )
5959const juliastdlib = joinpath (" julia" , " stdlib" , " v$(VERSION . major) .$(VERSION . minor) " )
6060
61+ method_table (method:: Method ) = isdefined (method, :external_mt ) ? method. external_mt:: MethodTable : nothing
62+ method_info_key (method:: Method ) = method_table (method) => method. sig
63+
6164# ## Public API
6265
6366"""
@@ -70,13 +73,13 @@ the method declaration, otherwise it is the first line of the method's body.
7073function whereis (method:: Method )
7174 file, line = String (method. file), method. line
7275 startswith (file, " REPL[" ) && return file, line
73- lin = get (method_info, method. sig , nothing )
76+ lin = get (method_info, method_info_key ( method) , nothing )
7477 if lin === nothing
7578 f = method_lookup_callback[]
7679 if f != = nothing
7780 try
7881 Base. invokelatest (f, method)
79- lin = get (method_info, method. sig , nothing )
82+ lin = get (method_info, method_info_key ( method) , nothing )
8083 catch
8184 end
8285 end
@@ -298,13 +301,13 @@ See also [`code_expr`](@ref).
298301"""
299302function definition (:: Type{Expr} , method:: Method )
300303 file = String (method. file)
301- def = startswith (file, " REPL[" ) ? nothing : get (method_info, method. sig , nothing )
304+ def = startswith (file, " REPL[" ) ? nothing : get (method_info, method_info_key ( method) , nothing )
302305 if def === nothing
303306 f = method_lookup_callback[]
304307 if f != = nothing
305308 try
306309 Base. invokelatest (f, method)
307- def = get (method_info, method. sig , nothing )
310+ def = get (method_info, method_info_key ( method) , nothing )
308311 catch
309312 end
310313 end
0 commit comments