Skip to content

Commit 39d37dd

Browse files
committed
Add a local save point in subtype hot path.
A quick fix for #48582.
1 parent 578c432 commit 39d37dd

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/subtype.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,11 +1439,25 @@ static int may_contain_union_decision(jl_value_t *x, jl_stenv_t *e, jl_typeenv_t
14391439
may_contain_union_decision(xb ? xb->ub : ((jl_tvar_t *)x)->ub, e, &newlog);
14401440
}
14411441

1442+
static int local_forall_subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param) {
1443+
int sub;
1444+
while (1) {
1445+
e->Lunions.more = 0;
1446+
e->Lunions.depth = 0;
1447+
sub = subtype(x, y, e, param);
1448+
if (!sub || !next_union_state(e, 0))
1449+
break;
1450+
}
1451+
return sub;
1452+
}
1453+
14421454
static int local_forall_exists_subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param, int limit_slow)
14431455
{
14441456
int16_t oldRmore = e->Runions.more;
14451457
int sub;
1446-
if (may_contain_union_decision(y, e, NULL) && pick_union_decision(e, 1) == 0) {
1458+
if (!may_contain_union_decision(y, e, NULL))
1459+
sub = local_forall_subtype(x, y, e, param);
1460+
else if (pick_union_decision(e, 1) == 0) {
14471461
jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, &e->Runions);
14481462
e->Lunions.used = e->Runions.used = 0;
14491463
e->Lunions.depth = e->Runions.depth = 0;
@@ -1460,14 +1474,20 @@ static int local_forall_exists_subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t
14601474
}
14611475
else {
14621476
// slow path
1463-
e->Lunions.used = 0;
1477+
int oldRmore = e->Runions.more;
1478+
jl_value_t *saved = NULL; jl_savedenv_t se;
1479+
JL_GC_PUSH1(&saved);
1480+
save_env(e, &saved, &se);
14641481
while (1) {
1465-
e->Lunions.more = 0;
1466-
e->Lunions.depth = 0;
1467-
sub = subtype(x, y, e, param);
1468-
if (!sub || !next_union_state(e, 0))
1482+
sub = local_forall_subtype(x, y, e, param);
1483+
if (sub || e->Runions.more == oldRmore)
14691484
break;
1485+
next_union_state(e, 1);
1486+
restore_env(e, saved, &se); // also restore depth here.
1487+
e->Runions.more = oldRmore;
14701488
}
1489+
free_env(&se);
1490+
JL_GC_POP();
14711491
}
14721492
return sub;
14731493
}

0 commit comments

Comments
 (0)