Is there any documentation on what type a function will specialize on? My mental model was that it only depended on the types of the arguments, not on the method signature, but I ran into this counter-example:
julia> @noinline f(_::Type{T}) where {T} = T()
f (generic function with 2 methods)
julia> g(_::Type{T}) where {T} = f(T)
g (generic function with 2 methods)
julia> @code_warntype g(Vector{Int64})
Variables:
#self# <optimized out>
_ <optimized out>
Body:
begin
return $(Expr(:invoke, MethodInstance for f(::Type{Array{Int64,1}}), :(Main.f), :($(Expr(:static_parameter, 1)))))
end::Array{Int64,1}
julia> @noinline f2(T::Type) = T()
f2 (generic function with 1 method)
julia> g2(T::Type) = f2(T)
g2 (generic function with 1 method)
julia> @code_warntype g2(Vector{Int64})
Variables:
#self# <optimized out>
T::Type{Array{Int64,1}}
Body:
begin
return $(Expr(:invoke, MethodInstance for f2(::Type{T} where T), :(Main.f2), :(T)))
end::Array{Int64,1}