JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.43k stars 5.45k forks source link

Specialize kw body method arguments if the argument is specialized in the main method #37797

Open timholy opened 3 years ago

timholy commented 3 years ago

I've seen a few cases where the main method specializes on an argument but then the kw body method does not. Example (with >700 backedges):

julia> mi = miexp[end-3].first   # from MethodAnalysis/demos/abstract.jl
MethodInstance for #sprint#371(::Nothing, ::Int64, ::typeof(sprint), ::Function, ::Vector{SubString{String}}, ::Vararg{Any, N} where N)

julia> ascend(mi)
Choose a call for analysis (q to quit):
     #sprint#371(::Nothing, ::Int64, ::typeof(sprint), ::Function, ::Vector{SubString{String}}, ::Vararg{Any, N} where N)
 >     sprint(::typeof(join), ::Vector{SubString{String}}, ::String)
         join(::Vector{SubString{String}}, ::String)
           normpath(::String)
             abspath(::String)
               include(::Module, ::String)
...

Neither the ::Function nor varargs is specialized in the body method, but both are in sprint itself.

DilumAluthge commented 3 years ago

Maybe related (vaguely) to https://github.com/JuliaLang/julia/issues/35045 ?