-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Improve inference of collect
with unstable eltype
#25861
Conversation
Good catch. I wonder whether we could improve inference for |
I had tried renaming all existing promote_typejoin(@nospecialize(a), @nospecialize(b)) = _promote_typejoin(a, b) Curiously, for an example where the generator could return either a |
But more directly to your question: No, I don't think removal of |
83961e6
to
57e7494
Compare
Rebased and reworked this. One interesting problem to inferring julia> foo(::Type{T}) where {T} = Union{Missing, T}
foo (generic function with 1 method)
julia> code_warntype(foo, Tuple{Any})
Variables:
Body:
begin
Core.SSAValue(0) = (Core.apply_type)(Main.Union, Main.Missing, $(Expr(:static_parameter, 1)))::Any
return Core.SSAValue(0)
end::Any I think it should be safe to always infer |
That does sound reasonably safe. It looks like currently apply_type_tfunc just instead returns |
I guess this means "Approved"? |
Ensure that `promote_typejoin(::Any, ::Any)` is at worst inferred as `Type`, since inference of `similar(dest, ::Any)` is very vague as the second parameter could not only be the new element type, but also e.g. new size. Also ensure that `_array_for(::Type, itr, ::HasShape{N})` is inferable as an `Array{T,N}` with the correct `N`.
57e7494
to
5d1480f
Compare
As
promote_typejoin(::Any, ::Any)
is inferred asAny
, inference ofsimilar(dest, promote_typejoin(T, S))
is very vague as the second parameter could not only be the new element type, but also e.g. new size. A simple type-assertion improves the situation.Example:
Before:
After: