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

add a subtyping fast path for tuple of Unions <: Vararg #33353

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_
yi = jl_tparam0(jl_unwrap_unionall(env->vty));
if (!env->vvx && yi == (jl_value_t*)jl_any_type)
goto done; // if y ends in `Vararg{Any}` skip checking everything
// var T in Vararg{T} is diagonal; an abstract type can't be a subtype of it,
// so avoid exponential blowup when xi is a Union.
if (jl_is_typevar(yi) && jl_is_uniontype(xi) && !jl_has_free_typevars(xi))
Copy link
Member

@vtjnash vtjnash Sep 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s also a concrete_min (which does this for obvious-subtype). But we discovered this was false, I thought, because T wasn’t know to be diagonal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok, I can patch that up.

return 0;
}
if (xi == env->lastx &&
((yi == env->lasty && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) ||
Expand Down
4 changes: 4 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1676,3 +1676,7 @@ c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str
@testintersect(Tuple{Pair{Int, DataType}, Any},
Tuple{Pair{A, B} where B<:Type, Int} where A,
Tuple{Pair{Int, DataType}, Int})

# issue #33337
@test !issub(Tuple{Type{T}, T} where T<:NTuple{30, Union{Nothing, Ref}},
Tuple{Type{Tuple{Vararg{V, N} where N}}, Tuple{Vararg{V, N} where N}} where V)