Skip to content

better fix for #33337; revert #33353 #33440

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

Merged
merged 1 commit into from
Oct 2, 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
17 changes: 12 additions & 5 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ static int subtype_tuple_varargs(struct subtype_tuple_env *env, jl_stenv_t *e, i

static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_t *e, int param)
{
int x_reps = 1;
loop: // while (i <= lx) {
if (env->i >= env->lx)
goto done;
Expand Down Expand Up @@ -1045,16 +1046,22 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_
else if (env->j >= env->ly) {
return 0;
}
int x_same = env->lastx && jl_egal(xi, env->lastx);
if (env->vy) {
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))
return 0;
// keep track of number of consecutive identical types compared to Vararg
if (x_same)
x_reps++;
else
x_reps = 1;
}
if (x_reps > 2) {
// an identical type on the left doesn't need to be compared to a Vararg
// element type on the right more than twice.
}
if (xi == env->lastx &&
else if (x_same &&
((yi == env->lasty && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) ||
(yi == env->lasty && !env->vx && env->vy && jl_is_concrete_type(xi)))) {
// fast path for repeated elements
Expand Down
2 changes: 2 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1680,3 +1680,5 @@ c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str
# 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)
@test issub(Tuple{Type{Any}, NTuple{4,Union{Int,Nothing}}},
Tuple{Type{V}, Tuple{Vararg{V, N} where N}} where V)