Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential for better type inference with Vararg #37316

Closed
simeonschaub opened this issue Sep 1, 2020 · 5 comments
Closed

potential for better type inference with Vararg #37316

simeonschaub opened this issue Sep 1, 2020 · 5 comments
Labels
compiler:inference Type inference

Comments

@simeonschaub
Copy link
Member

Since for example Vararg{Any,Int} throws an error during construction, would it be possible to take advantage of the fact that the N parameter in a Vararg is always an Int in type inference? It would be nice if the following inferred more precisely:

julia> f(::NTuple{N}) where {N} = N
f (generic function with 1 method)

julia> code_warntype(f, Tuple{Tuple})
Variables
  #self#::Core.Compiler.Const(f, false)
  #unused#::Tuple{Vararg{T,N}} where T where N

Body::Any
1return $(Expr(:static_parameter, 1))

Sorry if there is an issue about this already, but I couldn't find one.

@JeffBezanson
Copy link
Sponsor Member

Yes, it looks like we should add this.

@ranocha
Copy link
Member

ranocha commented Jan 13, 2021

Closes ... #37316

It looks like this should have been closed by #38136?

@simeonschaub
Copy link
Member Author

Looks like we still don't infer this on nightly:

julia> f(::NTuple{N}) where {N} = N
f (generic function with 1 method)

julia> code_warntype(f, Tuple{Tuple})
Variables
  #self#::Core.Const(f)
  #unused#::Tuple{Vararg{T, N}} where T where N

Body::Any
1return $(Expr(:static_parameter, 1))

@simeonschaub
Copy link
Member Author

Ah, but it does infer now if the Tuple has a concrete eltype:

julia> f(::NTuple{N}) where {N} = N
f (generic function with 1 method)

julia> code_warntype(f, Tuple{Tuple{Vararg{Int}}})
Variables
  #self#::Core.Const(f)
  #unused#::Tuple{Vararg{Int64}}

Body::Int64
1return $(Expr(:static_parameter, 1))

@aviatesk
Copy link
Sponsor Member

Fixed by #51449.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

4 participants