Skip to content

Commit 8574f05

Browse files
authored
Find specializations with Base.specializations (#348)
Also adapts to the new NamedTuple printing
1 parent 09b1d67 commit 8574f05

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

SnoopPrecompile/test/runtests.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@ using SnoopPrecompile
22
using Test
33
using UUIDs
44

5+
56
@testset "SnoopPrecompile.jl" begin
7+
specializations(m::Method) = isdefined(Base, :specializations) ? Base.specializations(m) : m.specializations
8+
69
push!(LOAD_PATH, @__DIR__)
710

811
using SnoopPC_A
912
if VERSION >= v"1.8.0-rc1"
1013
# Check that calls inside :setup are not precompiled
1114
m = which(Tuple{typeof(Base.vect), Vararg{T}} where T)
1215
have_mytype = false
13-
for mi in m.specializations
16+
for mi in specializations(m)
1417
mi === nothing && continue
1518
have_mytype |= Base.unwrap_unionall(mi.specTypes).parameters[2] === SnoopPC_A.MyType
1619
end
1720
have_mytype && @warn "Code in setup block was precompiled"
1821
# Check that calls inside @precompile_calls are precompiled
1922
m = only(methods(SnoopPC_A.call_findfirst))
2023
count = 0
21-
for mi in m.specializations
24+
for mi in specializations(m)
2225
mi === nothing && continue
2326
sig = Base.unwrap_unionall(mi.specTypes)
2427
@test sig.parameters[2] == SnoopPC_A.MyType
@@ -29,7 +32,7 @@ using UUIDs
2932
# Even one that was runtime-dispatched
3033
m = which(Tuple{typeof(findfirst), Base.Fix2{typeof(==), T}, Vector{T}} where T)
3134
count = 0
32-
for mi in m.specializations
35+
for mi in specializations(m)
3336
mi === nothing && continue
3437
sig = Base.unwrap_unionall(mi.specTypes)
3538
if sig.parameters[3] == Vector{SnoopPC_A.MyType}

src/SnoopCompile.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ using OrderedCollections
5757
import YAML # For @snoopl
5858
using Requires
5959

60+
if isdefined(Base, :specializations)
61+
specializations(m::Method) = Base.specializations(m)
62+
else
63+
specializations(m::Method) = m.specializations
64+
end
65+
6066
# Parcel Regex
6167
const anonrex = r"#{1,2}\d+#{1,2}\d+" # detect anonymous functions
62-
const kwrex = r"^#kw##(.*)$|^#([^#]*)##kw$" # detect keyword-supplying functions
68+
const kwrex = r"^#kw##(.*)$|^#([^#]*)##kw$" # detect keyword-supplying functions (prior to Core.kwcall)
6369
const kwbodyrex = r"^##(\w[^#]*)#\d+" # detect keyword body methods
6470
const genrex = r"^##s\d+#\d+$" # detect generators for @generated functions
6571
const innerrex = r"^#[^#]+#\d+" # detect inner functions

src/invalidations.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353

5454
dummy() = nothing
5555
dummy()
56-
const dummyinstance = which(dummy, ()).specializations[1]
56+
const dummyinstance = first(specializations(which(dummy, ())))
5757

5858
mutable struct InstanceNode
5959
mi::MethodInstance

src/parcel_snoopi_deep.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ function Base.summary(io::IO, mtrigs::MethodTriggers)
16321632
hascb = false
16331633
for mi in callers
16341634
tt = Base.unwrap_unionall(mi.specTypes)::DataType
1635-
mlist = Base._methods_by_ftype(tt, -1, typemax(UInt))
1635+
mlist = Base._methods_by_ftype(tt, -1, Base.get_world_counter())
16361636
if length(mlist) < 10
16371637
cts = Base.code_typed_by_type(tt; debuginfo=:source)
16381638
for (ct::CodeInfo, _) in cts

test/snoopi.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ if Base.VERSION >= v"1.6.0-DEV.736"
8484
fb = Base.bodyfunction(m)
8585
mb = methods(fb).ms[1]
8686
@test occursin("#_#", String(mb.name))
87-
mi = mb.specializations[1]
87+
mi = first(SnoopCompile.specializations(mb))
8888
modgens = Dict{Module, Vector{Method}}()
8989
tmp = String[]
9090
SnoopCompile.add_repr!(tmp, modgens, mi; check_eval=true) # no error
@@ -184,7 +184,11 @@ uncompiled(x) = x + 1
184184
@test any(str->occursin("precompile(Tuple{typeof(genkw1)})", str), FK)
185185
@test !any(str->occursin("precompile(Tuple{typeof(genkw2)})", str), FK)
186186
if isdefined(Core, :kwcall)
187-
@test any(str->occursin("Tuple{typeof(Core.kwcall),NamedTuple{(:b,), Tuple{String}},typeof(genkw2)}", str), FK)
187+
if Base.VERSION >= v"1.10.0-DEV.886"
188+
@test any(str->occursin("Tuple{typeof(Core.kwcall),@NamedTuple{b::String},typeof(genkw2)}", str), FK)
189+
else
190+
@test any(str->occursin("Tuple{typeof(Core.kwcall),NamedTuple{(:b,), Tuple{String}},typeof(genkw2)}", str), FK)
191+
end
188192
else
189193
@test any(str->occursin("Tuple{Core.kwftype(typeof(genkw2)),NamedTuple{(:b,),$(SP)Tuple{String}},typeof(genkw2)}", str), FK)
190194
end

test/snoopr.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ end
277277
sig, root = only(tree.mt_backedges)
278278
@test sig.parameters[1] === typeof(PkgC.nbits)
279279
@test sig.parameters[2] === Integer
280-
@test root.mi == only(methods(PkgD.call_nbits)).specializations[1]
280+
@test root.mi == first(SnoopCompile.specializations(only(methods(PkgD.call_nbits))))
281281
end
282282
Pkg.activate(cproj)
283283
elseif Base.VERSION >= v"1.7.0-DEV.254" # julia#39132 (redirect to Pipe)

0 commit comments

Comments
 (0)