From 8efb8be42b7468361f7981e9f621f2902e2f3918 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 13 Jan 2021 03:42:39 -0600 Subject: [PATCH] Handle Core.TypeofVararg in treelist (#118) --- src/backedges.jl | 3 ++- test/runtests.jl | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/backedges.jl b/src/backedges.jl index 5ee82521..afb199c5 100644 --- a/src/backedges.jl +++ b/src/backedges.jl @@ -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 @@ -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)) \ No newline at end of file +treelist(bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}) = treelist(buildframes(bt)) diff --git a/test/runtests.jl b/test/runtests.jl index d1bb4221..70079dca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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()) @@ -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)