Skip to content

Commit c18909d

Browse files
authored
Subtype: avoid repeated failing equal_union. (#48410)
skip checked `equal_union` by set `state[i] = 1`
1 parent b84fcc8 commit c18909d

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/subtype.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,19 +1258,6 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
12581258
return ans;
12591259
}
12601260

1261-
static int equal_unions(jl_uniontype_t *x, jl_uniontype_t *y, jl_stenv_t *e)
1262-
{
1263-
jl_value_t *saved=NULL; jl_savedenv_t se;
1264-
JL_GC_PUSH1(&saved);
1265-
save_env(e, &saved, &se);
1266-
int eq = forall_exists_equal(x->a, y->a, e) && forall_exists_equal(x->b, y->b, e);
1267-
if (!eq)
1268-
restore_env(e, saved, &se);
1269-
free_env(&se);
1270-
JL_GC_POP();
1271-
return eq;
1272-
}
1273-
12741261
// `param` means we are currently looking at a parameter of a type constructor
12751262
// (as opposed to being outside any type constructor, or comparing variable bounds).
12761263
// this is used to record the positions where type variables occur for the
@@ -1452,17 +1439,12 @@ static int forall_exists_equal(jl_value_t *x, jl_value_t *y, jl_stenv_t *e)
14521439
(is_definite_length_tuple_type(x) && is_indefinite_length_tuple_type(y)))
14531440
return 0;
14541441

1455-
if (jl_is_uniontype(x) && jl_is_uniontype(y)) {
1456-
// For 2 unions, try a more efficient greedy algorithm that compares the unions
1457-
// componentwise. If it returns `false`, we forget it and proceed with the usual
1458-
// algorithm. If it returns `true` we try returning `true`, but need to come back
1459-
// here to try the usual algorithm if subtyping later fails.
1460-
jl_unionstate_t *state = &e->Runions;
1461-
jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, state);
1442+
if ((jl_is_uniontype(x) && jl_is_uniontype(y))) {
1443+
// For 2 unions, first try a more efficient greedy algorithm that compares the unions
1444+
// componentwise. If failed, `exists_subtype` would memorize that this branch should be skipped.
14621445
if (pick_union_decision(e, 1) == 0) {
1463-
if (equal_unions((jl_uniontype_t*)x, (jl_uniontype_t*)y, e))
1464-
return 1;
1465-
pop_unionstate(state, &oldRunions);
1446+
return forall_exists_equal(((jl_uniontype_t *)x)->a, ((jl_uniontype_t *)y)->a, e) &&
1447+
forall_exists_equal(((jl_uniontype_t *)x)->b, ((jl_uniontype_t *)y)->b, e);
14661448
}
14671449
}
14681450

0 commit comments

Comments
 (0)