Skip to content

Commit e7b8b70

Browse files
committed
Enable AbstractTrees printing of backedges
1 parent 12bcf7c commit e7b8b70

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ uuid = "85b6ec6f-f7df-4429-9514-a64bcd9ee824"
33
authors = ["Tim Holy <tim.holy@gmail.com>"]
44
version = "0.1.0"
55

6+
[deps]
7+
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
8+
69
[compat]
710
julia = "1"
11+
AbstractTrees = "0.3"
812

913
[extras]
1014
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

docs/src/index.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ julia> mis[1].specTypes
8686
Tuple{typeof(findfirst),BitArray{1}}
8787
```
8888

89-
## Getting the backedges for a function
89+
### Getting the backedges for a function
9090

9191
Let's see all the compiled instances of `Base.setdiff` and their immediate callers:
9292

@@ -98,6 +98,49 @@ julia> direct_backedges(setdiff)
9898
MethodInstance for setdiff(::Array{Base.UUID,1}, ::Array{Base.UUID,1}) => MethodInstance for deps_graph(::Pkg.Types.Context, ::Dict{Base.UUID,String}, ::Dict{Base.UUID,Pkg.Types.VersionSpec}, ::Dict{Base.UUID,Pkg.Resolve.Fixed})
9999
```
100100

101+
### Printing backedges as a tree
102+
103+
MethodAnalysis uses [AbstractTrees](https://github.com/JuliaCollections/AbstractTrees.jl) to display the complete set of backedges:
104+
105+
```jldoctest; setup=:(using MethodAnalysis)
106+
julia> mi = instance(findfirst, (BitVector,))
107+
MethodInstance for findfirst(::BitArray{1})
108+
109+
julia> MethodAnalysis.print_tree(mi)
110+
MethodInstance for findfirst(::BitArray{1})
111+
├─ MethodInstance for prune_graph!(::Graph)
112+
│ └─ MethodInstance for #simplify_graph!#111(::Bool, ::typeof(simplify_graph!), ::Graph, ::Set{Int64})
113+
│ └─ MethodInstance for simplify_graph!(::Graph, ::Set{Int64})
114+
│ └─ MethodInstance for simplify_graph!(::Graph)
115+
│ ├─ MethodInstance for trigger_failure!(::Graph, ::Array{Int64,1}, ::Tuple{Int64,Int64})
116+
│ │ ⋮
117+
│ │
118+
│ └─ MethodInstance for resolve_versions!(::Context, ::Array{PackageSpec,1})
119+
│ ⋮
120+
121+
└─ MethodInstance for update_solution!(::SolutionTrace, ::Graph)
122+
└─ MethodInstance for converge!(::Graph, ::Messages, ::SolutionTrace, ::NodePerm, ::MaxSumParams)
123+
├─ MethodInstance for converge!(::Graph, ::Messages, ::SolutionTrace, ::NodePerm, ::MaxSumParams)
124+
│ ├─ MethodInstance for converge!(::Graph, ::Messages, ::SolutionTrace, ::NodePerm, ::MaxSumParams)
125+
│ │ ├─ MethodInstance for converge!(::Graph, ::Messages, ::SolutionTrace, ::NodePerm, ::MaxSumParams)
126+
│ │ │ ⋮
127+
│ │ │
128+
│ │ └─ MethodInstance for maxsum(::Graph)
129+
│ │ ⋮
130+
│ │
131+
│ └─ MethodInstance for maxsum(::Graph)
132+
│ └─ MethodInstance for resolve(::Graph)
133+
│ ⋮
134+
135+
└─ MethodInstance for maxsum(::Graph)
136+
└─ MethodInstance for resolve(::Graph)
137+
├─ MethodInstance for trigger_failure!(::Graph, ::Array{Int64,1}, ::Tuple{Int64,Int64})
138+
│ ⋮
139+
140+
└─ MethodInstance for resolve_versions!(::Context, ::Array{PackageSpec,1})
141+
142+
```
143+
101144
## API reference
102145

103146
### visit

src/MethodAnalysis.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module MethodAnalysis
22

3+
using AbstractTrees
4+
35
using Core: MethodInstance, SimpleVector, MethodTable
46

57
export visit, call_type, instance, worlds
@@ -77,4 +79,6 @@ function instance(f, types)
7779
return inst
7880
end
7981

82+
AbstractTrees.children(mi::MethodInstance) = isdefined(mi, :backedges) ? mi.backedges : []
83+
8084
end # module

0 commit comments

Comments
 (0)