Skip to content

Commit 2117018

Browse files
committed
Subtype: avoid repeated failing equal_union. (JuliaLang#48410)
skip checked `equal_union` by set `state[i] = 1`
1 parent 1107361 commit 2117018

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
@@ -1189,19 +1189,6 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
11891189
return ans;
11901190
}
11911191

1192-
static int equal_unions(jl_uniontype_t *x, jl_uniontype_t *y, jl_stenv_t *e)
1193-
{
1194-
jl_value_t *saved=NULL; jl_savedenv_t se;
1195-
JL_GC_PUSH1(&saved);
1196-
save_env(e, &saved, &se);
1197-
int eq = forall_exists_equal(x->a, y->a, e) && forall_exists_equal(x->b, y->b, e);
1198-
if (!eq)
1199-
restore_env(e, saved, &se);
1200-
free_env(&se);
1201-
JL_GC_POP();
1202-
return eq;
1203-
}
1204-
12051192
// `param` means we are currently looking at a parameter of a type constructor
12061193
// (as opposed to being outside any type constructor, or comparing variable bounds).
12071194
// this is used to record the positions where type variables occur for the
@@ -1383,17 +1370,12 @@ static int forall_exists_equal(jl_value_t *x, jl_value_t *y, jl_stenv_t *e)
13831370
(is_definite_length_tuple_type(x) && is_indefinite_length_tuple_type(y)))
13841371
return 0;
13851372

1386-
if (jl_is_uniontype(x) && jl_is_uniontype(y)) {
1387-
// For 2 unions, try a more efficient greedy algorithm that compares the unions
1388-
// componentwise. If it returns `false`, we forget it and proceed with the usual
1389-
// algorithm. If it returns `true` we try returning `true`, but need to come back
1390-
// here to try the usual algorithm if subtyping later fails.
1391-
jl_unionstate_t *state = &e->Runions;
1392-
jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, state);
1373+
if ((jl_is_uniontype(x) && jl_is_uniontype(y))) {
1374+
// For 2 unions, first try a more efficient greedy algorithm that compares the unions
1375+
// componentwise. If failed, `exists_subtype` would memorize that this branch should be skipped.
13931376
if (pick_union_decision(e, 1) == 0) {
1394-
if (equal_unions((jl_uniontype_t*)x, (jl_uniontype_t*)y, e))
1395-
return 1;
1396-
pop_unionstate(state, &oldRunions);
1377+
return forall_exists_equal(((jl_uniontype_t *)x)->a, ((jl_uniontype_t *)y)->a, e) &&
1378+
forall_exists_equal(((jl_uniontype_t *)x)->b, ((jl_uniontype_t *)y)->b, e);
13971379
}
13981380
}
13991381

0 commit comments

Comments
 (0)