Skip to content

Commit a1738ae

Browse files
authored
Remove duplicates from parcel (fixes #70) (#72)
1 parent f5f065e commit a1738ae

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/parcel_snoopi.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function handle_kwbody(topmod::Module, m::Method, paramrepr, tt, fstr="fbody")
194194
end
195195

196196
function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=Vector{Pair{String, String}}(), blacklist=String[])
197-
pc = Dict{Symbol, Vector{String}}() # output
197+
pc = Dict{Symbol, Set{String}}() # output
198198
modgens = Dict{Module, Vector{Method}}() # methods with generators in a module
199199
mods = OrderedSet{Module}() # module of each parameter for a given method
200200
for (t, mi) in reverse(tinf)
@@ -216,7 +216,7 @@ function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=
216216
# If we haven't yet started the list for this module, initialize
217217
topmodname = nameof(topmod)
218218
if !haskey(pc, topmodname)
219-
pc[topmodname] = String[]
219+
pc[topmodname] = Set{String}()
220220
# For testing our precompile directives, we might need to have lookup available
221221
if VERSION >= v"1.4.0-DEV.215" && topmod !== Core && !isdefined(topmod, :__bodyfunction__)
222222
Core.eval(topmod, lookup_kwbody_ex)
@@ -298,7 +298,7 @@ function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=
298298
add_if_evals!(pc[topmodname], topmod, reprcontext(topmod, p), paramrepr, tt)
299299
end
300300
end
301-
return pc
301+
return Dict(mod=>collect(lines) for (mod, lines) in pc)
302302
end
303303

304304
"""
@@ -312,7 +312,7 @@ pcI = ["good","bad","hi","bye","no"]
312312
SnoopCompile.blacklist_remover!(pcI, blacklist)
313313
```
314314
"""
315-
function blacklist_remover!(pcI, blacklist)
315+
function blacklist_remover!(pcI::AbstractVector, blacklist)
316316
idx = Int[]
317317
for (iLine, line) in enumerate(pcI)
318318
if any(occursin.(blacklist, line))
@@ -322,3 +322,14 @@ function blacklist_remover!(pcI, blacklist)
322322
deleteat!(pcI, idx)
323323
return pcI
324324
end
325+
326+
function blacklist_remover!(pcI::AbstractSet, blacklist)
327+
# We can't just use `setdiff!` because this is a substring search
328+
todelete = Set{eltype(pcI)}()
329+
for line in pcI
330+
if any(occursin.(blacklist, line))
331+
push!(todelete, line)
332+
end
333+
end
334+
return setdiff!(pcI, todelete)
335+
end

test/snoopi.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,17 @@ end
202202
dct = Docs.meta(SnoopCompile)
203203
@test haskey(dct, Docs.Binding(SnoopCompile, Symbol("@snoopi")))
204204
end
205+
206+
@testset "Duplicates (#70)" begin
207+
tinf = @snoopi begin
208+
function eval_local_function(i)
209+
@eval generated() = $i
210+
return Base.invokelatest(generated)
211+
end
212+
eval_local_function(1)
213+
eval_local_function(2)
214+
eval_local_function(3)
215+
end
216+
pc = SnoopCompile.parcel(tinf)
217+
@test count(isequal("precompile(Tuple{typeof(generated)})"), pc[:Main]) == 1
218+
end

0 commit comments

Comments
 (0)