Skip to content

Commit

Permalink
Handle Core.TypeofVararg in treelist (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Jan 13, 2021
1 parent 0b5b862 commit 8efb8be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/backedges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function stripType(@nospecialize(typ))
elseif isa(typ, TypeVar) || isa(typ, Union)
return typ
end
Base.isvarargtype(typ) && return typ
return typ <: Type && length(typ.parameters) == 1 ? typ.parameters[1] : typ
end
nonconcrete_red(@nospecialize(typ)) = isconcretetype(stripType(typ)) ? :nothing : :red
Expand Down Expand Up @@ -147,4 +148,4 @@ else
treelist!(strs, mis, ::IO, ::Nothing, ::AbstractString, ::Base.IdSet) = nothing
end

treelist(bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}) = treelist(buildframes(bt))
treelist(bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}) = treelist(buildframes(bt))
29 changes: 29 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ using InteractiveUtils
using Test
using StaticArrays

function firstassigned(specializations::Core.SimpleVector)
# the methodinstance may not be first (annoying)
for i = 1:length(specializations)
if isassigned(specializations, i)
return specializations[i]
end
end
return nothing
end
function firstassigned(specializations)
mis = []
Base.visit(specializations) do mi
isempty(mis) && push!(mis, mi)
end
return mis[1]
end

function process(@nospecialize(f), @nospecialize(TT); optimize=true)
mi = Cthulhu.first_method_instance(f, TT)
(ci, rt, slottypes) = Cthulhu.do_typeinf_slottypes(mi, optimize, Cthulhu.current_params())
Expand Down Expand Up @@ -237,6 +254,18 @@ else
@test strs == ["fbackedge1()", " fbackedge2(::Float64)"]
end

# issue #114
unspecva(@nospecialize(i::Int...)) = 1
@test unspecva(1, 2) == 1
mi = firstassigned(first(methods(unspecva)).specializations)
if isdefined(REPL.TerminalMenus, :ConfiguredMenu)
root = Cthulhu.treelist(mi)
@test occursin("Vararg", root.data.callstr)
else
strs, mis = Cthulhu.treelist(mi)
@test occursin("Vararg", strs[1])
end

# treelist for stacktraces
fst1(x) = backtrace()
@inline fst2(x) = fst1(x)
Expand Down

0 comments on commit 8efb8be

Please sign in to comment.