Skip to content

Commit

Permalink
Handle Vararg specializations
Browse files Browse the repository at this point in the history
Fixes #44
  • Loading branch information
timholy committed Apr 20, 2023
1 parent 27a263f commit b341bf1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MethodAnalysis"
uuid = "85b6ec6f-f7df-4429-9514-a64bcd9ee824"
authors = ["Tim Holy <[email protected]>"]
version = "0.4.12"
version = "0.4.13"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
7 changes: 4 additions & 3 deletions src/findcallers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ function findcallers(f, argmatch::Union{Function,Nothing}, mis::AbstractVector{C
matches || continue
# Collect the arg types
argtypes = []
for i = (callhead === :iterate ? 4 : 2):length(stmt.args)
a = stmt.args[i]
for iarg = (callhead === :iterate ? 4 : 2):length(stmt.args)
a = stmt.args[iarg]
if isa(a, Core.SSAValue)
push!(argtypes, extract(src.ssavaluetypes[a.id], sparams))
elseif isa(a, Core.SlotNumber)
Expand All @@ -165,7 +165,8 @@ function findcallers(f, argmatch::Union{Function,Nothing}, mis::AbstractVector{C
push!(argtypes, Core.Typeof(getfield(a.mod, a.name)))
elseif isexpr(a, :static_parameter)
a = a::Expr
push!(argtypes, Type{sparams[a.args[1]::Int]})
T = sparams[a.args[1]::Int]
push!(argtypes, Base.isvarargtype(T) ? T : Type{T})
else
push!(argtypes, extract(a, sparams))
end
Expand Down
20 changes: 20 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ if !isdefined(Base, :only)
end
end

# For testing #44 (from Pkg)
struct LikeVersionBound
t::NTuple{3,UInt32}
n::Int
function LikeVersionBound(tin::NTuple{n,Integer}) where n
n <= 3 || throw(ArgumentError("LikeVersionBound: you can only specify major, minor and patch versions"))
n == 0 && return new((0, 0, 0), n)
n == 1 && return new((tin[1], 0, 0), n)
n == 2 && return new((tin[1], tin[2], 0), n)
n == 3 && return new((tin[1], tin[2], tin[3]), n)
error("invalid $n")
end
end

module Outer
module Inner
g(::AbstractString) = 0
Expand Down Expand Up @@ -462,6 +476,12 @@ if isdefined(MethodAnalysis, :findcallers)
callers2 = findcallers(OtherModule.h, nothing, mis)
@test length(callers2) == 1

# issue #44
m = only(methods(LikeVersionBound))
mi = Core.Compiler.specialize_method(m, Tuple{Type{LikeVersionBound}, Tuple{Int, Vararg{Int}}}, Core.svec())
argmatch(typs) = length(typs) >= 2 && typs[2] === AbstractArray
findcallers(convert, argmatch, [mi])

# show
io = IOBuffer()
print(io, cm)
Expand Down

0 comments on commit b341bf1

Please sign in to comment.