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

Subtype: skip more identical check for X::Tuple <: Y::Tuple #48534

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 8 additions & 26 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,17 +968,6 @@ static int check_vararg_length(jl_value_t *v, ssize_t n, jl_stenv_t *e)

static int forall_exists_equal(jl_value_t *x, jl_value_t *y, jl_stenv_t *e);

struct subtype_tuple_env {
jl_datatype_t *xd, *yd;
jl_value_t *lastx, *lasty;
size_t lx, ly;
size_t i, j;
int vx, vy;
jl_value_t *vtx;
jl_value_t *vty;
jl_vararg_kind_t vvx, vvy;
} JL_ROOTED_VALUE_COLLECTION;
N5N3 marked this conversation as resolved.
Show resolved Hide resolved

static int subtype_tuple_varargs(
jl_vararg_t *vtx, jl_vararg_t *vty,
size_t vx, size_t vy,
Expand Down Expand Up @@ -1092,7 +1081,7 @@ static int subtype_tuple_tail(jl_datatype_t *xd, jl_datatype_t *yd, int8_t R, jl
{
size_t lx = jl_nparams(xd);
size_t ly = jl_nparams(yd);
size_t i = 0, j = 0, vx = 0, vy = 0, x_reps = 0;
size_t i = 0, j = 0, vx = 0, vy = 0, x_reps = 1;
jl_value_t *lastx = NULL, *lasty = NULL;
jl_value_t *xi = NULL, *yi = NULL;

Expand Down Expand Up @@ -1142,21 +1131,17 @@ static int subtype_tuple_tail(jl_datatype_t *xd, jl_datatype_t *yd, int8_t R, jl
return !!vx;

xi = vx ? jl_unwrap_vararg(xi) : xi;
int x_same = lastx && jl_egal(xi, lastx);
if (vy) {
yi = jl_unwrap_vararg(yi);
// keep track of number of consecutive identical types compared to Vararg
if (x_same)
x_reps++;
else
x_reps = 1;
}
yi = vy ? jl_unwrap_vararg(yi) : yi;
int x_same = vx > 1 || (lastx && obviously_egal(xi, lastx));
int y_same = vy > 1 || (lasty && obviously_egal(yi, lasty));
// keep track of number of consecutive identical subtyping
x_reps = y_same && x_same ? x_reps + 1 : 1;
if (x_reps > 2) {
// an identical type on the left doesn't need to be compared to a Vararg
// an identical type on the left doesn't need to be compared to the same
// element type on the right more than twice.
}
else if (x_same && e->Runions.depth == 0 &&
((yi == lasty && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) ||
((y_same && !jl_has_free_typevars(xi) && !jl_has_free_typevars(yi)) ||
(yi == lastx && !vx && vy && jl_is_concrete_type(xi)))) {
// fast path for repeated elements
}
Expand Down Expand Up @@ -3073,9 +3058,6 @@ static jl_value_t *intersect_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_sten
(yb && jl_is_long(yb->lb) && ly-1+jl_unbox_long(yb->lb) != len)) {
res = jl_bottom_type;
}
else if (param == 2 && jl_is_unionall(xi) != jl_is_unionall(yi)) {
res = jl_bottom_type;
}
else {
if (xb) set_var_to_const(xb, jl_box_long(len-lx+1), yb);
if (yb) set_var_to_const(yb, jl_box_long(len-ly+1), xb);
Expand Down
3 changes: 3 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,9 @@ end

@test !(Tuple{Any, Any, Any} <: Tuple{Any, Vararg{T}} where T)

# issue #39967
@test (NTuple{27, T} where {S, T<:Union{Array, Array{S}}}) <: Tuple{Array, Array, Vararg{AbstractArray, 25}}

abstract type MyAbstract47877{C}; end
struct MyType47877{A,B} <: MyAbstract47877{A} end
let A = Tuple{Type{T}, T} where T,
Expand Down