Skip to content

Commit

Permalink
Merge pull request #48534 from N5N3/Test2
Browse files Browse the repository at this point in the history
Subtype: skip more identical check for `X::Tuple <: Y::Tuple`
(cherry picked from commit e3dfcc3)
  • Loading branch information
N5N3 authored and KristofferC committed Apr 13, 2023
1 parent be1c71d commit eb764cc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
12 changes: 1 addition & 11 deletions src/clangsa/GCChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,6 @@ class GCChecker
}
return f(TD->getName());
}
static bool isValueCollection(QualType QT) {
if (QT->isPointerType() || QT->isArrayType())
return isValueCollection(
clang::QualType(QT->getPointeeOrArrayElementType(), 0));
const TagDecl *TD = QT->getUnqualifiedDesugaredType()->getAsTagDecl();
if (!TD)
return false;
return declHasAnnotation(TD, "julia_rooted_value_collection");
}
template <typename callback>
static SymbolRef walkToRoot(callback f, const ProgramStateRef &State,
const MemRegion *Region);
Expand Down Expand Up @@ -710,8 +701,7 @@ bool GCChecker::isFDAnnotatedNotSafepoint(const clang::FunctionDecl *FD) {
#endif

bool GCChecker::isGCTrackedType(QualType QT) {
return isValueCollection(QT) ||
isJuliaType(
return isJuliaType(
[](StringRef Name) {
if (Name.endswith_lower("jl_value_t") ||
Name.endswith_lower("jl_svec_t") ||
Expand Down
34 changes: 8 additions & 26 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,17 +905,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;

static int subtype_tuple_varargs(
jl_vararg_t *vtx, jl_vararg_t *vty,
size_t vx, size_t vy,
Expand Down Expand Up @@ -1029,7 +1018,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 @@ -1079,21 +1068,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 @@ -2940,9 +2925,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
2 changes: 0 additions & 2 deletions src/support/analyzer_annotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define JL_ALWAYS_LEAFTYPE JL_GLOBALLY_ROOTED
#define JL_ROOTS_TEMPORARILY __attribute__((annotate("julia_temporarily_roots")))
#define JL_REQUIRE_ROOTED_SLOT __attribute__((annotate("julia_require_rooted_slot")))
#define JL_ROOTED_VALUE_COLLECTION __attribute__((annotate("julia_rooted_value_collection")))
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -42,7 +41,6 @@ extern "C" {
#define JL_ALWAYS_LEAFTYPE
#define JL_ROOTS_TEMPORARILY
#define JL_REQUIRE_ROOTED_SLOT
#define JL_ROOTED_VALUE_COLLECTION
#define JL_GC_PROMISE_ROOTED(x) (void)(x)
#define jl_may_leak(x) (void)(x)

Expand Down
3 changes: 3 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,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}}

let a = (isodd(i) ? Pair{Char, String} : Pair{String, String} for i in 1:2000)
@test Tuple{Type{Pair{Union{Char, String}, String}}, a...} <: Tuple{Type{Pair{K, V}}, Vararg{Pair{A, B} where B where A}} where V where K
end
Expand Down

0 comments on commit eb764cc

Please sign in to comment.