# When will a function specialize on types?

**URL:** <https://discourse.julialang.org/t/when-will-a-function-specialize-on-types/9534>\
**Category:** Performance\
**Created:** [March 6, 2018, 12:44pm UTC](https://discourse.julialang.org/t/when-will-a-function-specialize-on-types/9534 "2018-03-06T12:44:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamii](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jamii/32/1373_2.png) [@jamii](https://discourse.julialang.org/u/jamii)\
**Post date:** [March 6, 2018, 12:44pm UTC](https://discourse.julialang.org/t/when-will-a-function-specialize-on-types/9534/1 "2018-03-06T12:44:08Z")

</div>

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
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}

```

---

<div class="post-metadata">

**Author:** ![jamii](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jamii/32/1373_2.png) [@jamii](https://discourse.julialang.org/u/jamii)\
**Post date:** [March 6, 2018, 12:50pm UTC](https://discourse.julialang.org/t/when-will-a-function-specialize-on-types/9534/2 "2018-03-06T12:50:57Z")

</div>

Oh, this appears to be an open doc issue [https://github.com/JuliaLang/julia/issues/23471](https://github.com/JuliaLang/julia/issues/23471), so I assume the answer is no 😃
