Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MethodAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ end
methodinstances(mod::Module)
methodinstances(f)

Collect all `MethodInstance`s, optionally restricting them to a particular module or function.
Collect all `MethodInstance`s, optionally restricting them to a particular module, function, method, or methodlist.
"""
function methodinstances(top=())
if isa(top, Module) || isa(top, Function) || isa(top, Type)
if isa(top, Module) || isa(top, Function) || isa(top, Type) || isa(top, Method) || isa(top, Base.MethodList)
top = (top,)
end
mis = Core.MethodInstance[]
Expand Down
12 changes: 12 additions & 0 deletions src/visit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ function _visit(@nospecialize(operation), @nospecialize(f::Callable), visited::I
return nothing
end

function _visit(@nospecialize(operation), ml::Base.MethodList, visited::IdSet{Any}, print::Bool)
ml ∈ visited && return nothing
push!(visited, ml)
print && println("MethodList ", ml)
_visit(operation, ml.mt, visited, print)
for m in ml.ms
_visit(operation, m, visited, print)
end
return nothing
end


function _visit(@nospecialize(operation), mt::MethodTable, visited::IdSet{Any}, print::Bool)
mt ∈ visited && return nothing
push!(visited, mt)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ end
@test mis isa Vector{Core.MethodInstance}
@test mi ∈ mis
@test length(mis) > 1

mi = methodinstance(convert, (Type{String}, String))
mis = methodinstances(methods(convert, (Type{String}, Any)))
@test length(mis) > 10 # in fact, there are many more
@test mi ∈ mis
mis = methodinstances(which(convert, (Type{String}, AbstractString)))
@test length(mis) > 2
@test mi ∉ mis # that's covered by a different Method
end

@testset "Backedges" begin
Expand Down