Skip to content

Commit

Permalink
subtype: add a fast-path for Union parameters (JuliaLang#49878)
Browse files Browse the repository at this point in the history
For JuliaLang#49857 performance

The union explosion is caused by the following MWE:
`Type{Vector{Union{....}} <: Type{Array{T}} where {T}`

280f999 only fixes for `Union{......}`
without free `Typevar`. This fast-path makes sure the remaining get fixed.
  • Loading branch information
N5N3 committed May 20, 2023
1 parent 6d70d2a commit 5dafc84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,9 @@ static int local_forall_exists_subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t
{
int16_t oldRmore = e->Runions.more;
int sub;
// fast-path for #49857
if (obviously_in_union(y, x))
return 1;
int kindx = !jl_has_free_typevars(x);
int kindy = !jl_has_free_typevars(y);
if (kindx && kindy)
Expand Down
3 changes: 3 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2547,3 +2547,6 @@ let T = Tuple{Union{Type{T}, Type{S}}, Union{Val{T}, Val{S}}, Union{Val{T}, S}}
@test typeintersect(T, S) == Tuple{Type{A}, Union{Val{A}, Val{S} where S<:Union{Val, A}, Val{x} where x<:Val, Val{x} where x<:Union{Val, A}}, Val{A}} where A<:(Val{S} where S<:Val)
@test typeintersect(S, T) == Tuple{Type{T}, Union{Val{T}, Val{S}}, Val{T}} where {T<:Val, S<:(Union{Val{A}, Val} where A)}
end

#issue #49857
@test !<:(Type{Vector{Union{Base.BitInteger, Base.IEEEFloat, StridedArray, Missing, Nothing, Val{T}}}} where {T}, Type{Array{T}} where {T})

0 comments on commit 5dafc84

Please sign in to comment.