Skip to content

@code_warntype with non-specialized type arguments shows the wrong specialization #23749

Closed

Description

I was informed in #23471 that functions that accept ::Type (vs. ::Type{T} where T) do not specialize on that argument. However, @code_warntype shows a specialized function body (on 0.6):

julia> foo(t::Type) = t
foo (generic function with 1 method)

julia> @code_warntype foo(Int)
Variables:
  #self#::#foo
  t::Type{Int64}

Body:
  begin 
      return t::Type{Int64}
  end::Type{Int64}

This is confirmed by looking at the specializations:

julia> foo(Int)   # run it normally
Int64

julia> Base.visit(println, methods(foo).ms[1].specializations)
MethodInstance for foo(::Type{T} where T)    # specialization triggered by foo(Int)
MethodInstance for foo(::Type{Int64})        # specialization triggered by @code_warntype

I'm guessing that the correct outcome is this:

julia> code_warntype(foo, (Type{T} where T,))
Variables:
  #self#::#foo
  t::Type{T} where T

Body:
  begin 
      return t::Type{T} where T
  end::Type{T} where T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions