Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Core.TypeofVararg in treelist #118

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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