Skip to content

Commit 910c69c

Browse files
committed
better fix for #33337; revert #33353
1 parent b288444 commit 910c69c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/subtype.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ static int subtype_tuple_varargs(struct subtype_tuple_env *env, jl_stenv_t *e, i
977977

978978
static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_t *e, int param)
979979
{
980+
int x_reps = 1;
980981
loop: // while (i <= lx) {
981982
if (env->i >= env->lx)
982983
goto done;
@@ -1045,16 +1046,22 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_
10451046
else if (env->j >= env->ly) {
10461047
return 0;
10471048
}
1049+
int x_same = env->lastx && jl_egal(xi, env->lastx);
10481050
if (env->vy) {
10491051
yi = jl_tparam0(jl_unwrap_unionall(env->vty));
10501052
if (!env->vvx && yi == (jl_value_t*)jl_any_type)
10511053
goto done; // if y ends in `Vararg{Any}` skip checking everything
1052-
// var T in Vararg{T} is diagonal; an abstract type can't be a subtype of it,
1053-
// so avoid exponential blowup when xi is a Union.
1054-
if (jl_is_typevar(yi) && jl_is_uniontype(xi) && !jl_has_free_typevars(xi))
1055-
return 0;
1054+
// keep track of number of consecutive identical types compared to Vararg
1055+
if (x_same)
1056+
x_reps++;
1057+
else
1058+
x_reps = 1;
1059+
}
1060+
if (x_reps > 2) {
1061+
// an identical type on the left doesn't need to be compared to a Vararg
1062+
// element type on the right more than twice.
10561063
}
1057-
if (xi == env->lastx &&
1064+
else if (x_same &&
10581065
((yi == env->lasty && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) ||
10591066
(yi == env->lasty && !env->vx && env->vy && jl_is_concrete_type(xi)))) {
10601067
// fast path for repeated elements

test/subtype.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,3 +1680,5 @@ c32703(::Type{<:Str{C}}, str::Str{C}) where {C<:CSE} = str
16801680
# issue #33337
16811681
@test !issub(Tuple{Type{T}, T} where T<:NTuple{30, Union{Nothing, Ref}},
16821682
Tuple{Type{Tuple{Vararg{V, N} where N}}, Tuple{Vararg{V, N} where N}} where V)
1683+
@test issub(Tuple{Type{Any}, NTuple{4,Union{Int,Nothing}}},
1684+
Tuple{Type{V}, Tuple{Vararg{V, N} where N}} where V)

0 commit comments

Comments
 (0)