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

Vararg affecting constant propagation #55042

Open
MilesCranmer opened this issue Jul 5, 2024 · 2 comments
Open

Vararg affecting constant propagation #55042

MilesCranmer opened this issue Jul 5, 2024 · 2 comments
Labels
performance Must go faster

Comments

@MilesCranmer
Copy link
Sponsor Member

MilesCranmer commented Jul 5, 2024

It seems like constant propagation is affected by a vararg, even if typed to ::Vararg{Any,N} which I would expect to force specialization via this page of the docs.

call1(f::F, x, y) where {F} = f(x, y)
call2(f::F, x, y...) where {F} = f(x, y...)
call3(f::F, x, y::Vararg{Any,N}) where {F,N} = f(x, y...)

g1(a) = call1(isa, a, Int) ? a : 0
g2(a) = call2(isa, a, Int) ? a : 0
g3(a) = call3(isa, a, Int) ? a : 0

Constant propagation only happens through call1, but call2 and call3 block it:

julia> Base.return_types(g1, (Any,))
1-element Vector{Any}:
 Int64

julia> Base.return_types(g2, (Any,))
1-element Vector{Any}:
 Any

julia> Base.return_types(g3, (Any,))
1-element Vector{Any}:
 Any
@oscardssmith oscardssmith added the performance Must go faster label Jul 5, 2024
@nsajko
Copy link
Contributor

nsajko commented Jul 5, 2024

The effect inference seems fine. I guess this is just the usual limitation of #29368:

julia> typeof((Int,))
Tuple{DataType}

julia> typeof((Int,)) <: Tuple{Type{Int}}
false

@MilesCranmer
Copy link
Sponsor Member Author

I guess im also surprised it doesn’t inline it

(Is there any general way to force specialisation for a Vararg which includes types? There is this but it seems to only work if all the Vararg is types)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

No branches or pull requests

3 participants