Skip to content

Commit

Permalink
Segregate loctrigs by callee
Browse files Browse the repository at this point in the history
Sometimes multiple inference triggers occur on the same
source-code line, and it's better to keep them separated by callee.
  • Loading branch information
timholy committed Jan 20, 2021
1 parent 4e0ac3c commit d289a0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/parcel_snoopi_deep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -997,13 +997,17 @@ julia> accumulate_by_source(itrigs)
```
"""
function accumulate_by_source(itrigs::AbstractVector{InferenceTrigger})
cs = Dict{Location,Vector{InferenceTrigger}}()
cs = IdDict{Tuple{Location,Any},Vector{InferenceTrigger}}()
for itrig in itrigs
# Identify a trigger by both its location and what it calls, since some lines can have multiple callees
loc = Location(itrig)
itrigs_loc = get!(Vector{InferenceTrigger}, cs, loc)
callee = MethodInstance(itrig.node)
ft = Base.unwrap_unionall(callee.specTypes).parameters[1]
f = ft <: Type ? ft.parameters[1] : ft.instance
itrigs_loc = get!(Vector{InferenceTrigger}, cs, (loc, f))
push!(itrigs_loc, itrig)
end
return sort([LocationTrigger(loc, itrigs_loc) for (loc, itrigs_loc) in cs]; by=loctrig->length(loctrig.itrigs))
return sort([LocationTrigger(loc, itrigs_loc) for ((loc, _), itrigs_loc) in cs]; by=loctrig->length(loctrig.itrigs))
end

function linetable_match(linetable::Vector{Core.LineInfoNode}, sffile::String, sffunc::String, sfline::Int)
Expand Down
11 changes: 11 additions & 0 deletions test/snoopi_deep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ fdouble(x) = 2x
show(io, loctrigs)
@test any(str->occursin("4 callees from 2 callers", str), split(String(take!(io)), '\n'))

# Multiple callees on the same line
fline(x) = 2*x[]
gline(x) = x[]
fg(x) = fline(gline(x[]))
cc = Ref{Any}(Ref{Base.RefValue}(Ref(3)))
tinf = @snoopi_deep fg(cc)
itrigs = inference_triggers(tinf)
loctrigs = accumulate_by_source(itrigs)
@test length(loctrigs) == 2
loctrigs[1].loc == loctrigs[2].loc

# Higher order function attribution
@noinline function mymap!(f, dst, src)
for i in eachindex(dst, src)
Expand Down

0 comments on commit d289a0b

Please sign in to comment.