Skip to content

Commit ffdbce2

Browse files
committed
make GC happy.
1 parent a3c09f4 commit ffdbce2

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

src/subtype.c

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,9 +2818,9 @@ static jl_value_t *omit_bad_union(jl_value_t *u, jl_tvar_t *t)
28182818
// Caller might not have rooted `res`
28192819
static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbinding_t *vb, jl_unionall_t *u, jl_stenv_t *e)
28202820
{
2821-
jl_value_t *varval = NULL, *nivar = NULL;
2822-
jl_tvar_t *newvar = vb->var;
2823-
JL_GC_PUSH3(&res, &newvar, &nivar);
2821+
jl_value_t *varval = NULL, *ilb = NULL, *iub = NULL, *nivar = NULL;
2822+
jl_tvar_t *newvar = vb->var, *ivar = NULL;
2823+
JL_GC_PUSH6(&res, &newvar, &ivar, &nivar, &ilb, &iub);
28242824
// try to reduce var to a single value
28252825
if (jl_is_long(vb->ub) && jl_is_typevar(vb->lb)) {
28262826
varval = vb->ub;
@@ -2914,71 +2914,74 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind
29142914
jl_ivarbinding_t *pwrap = NULL;
29152915
for (jl_ivarbinding_t *btemp = allvars, *pbtemp = NULL; btemp != NULL; btemp = btemp->next) {
29162916
int bdepth0 = btemp->root->depth0;
2917-
if (jl_has_typevar(*btemp->lb, vb->var)) {
2918-
assert(btemp->root->var == *btemp->var || bdepth0 == vb->depth0);
2919-
if (vb->lb == (jl_value_t*)*btemp->var) {
2917+
ivar = *btemp->var;
2918+
ilb = *btemp->lb;
2919+
iub = *btemp->ub;
2920+
if (jl_has_typevar(ilb, vb->var)) {
2921+
assert(btemp->root->var == ivar || bdepth0 == vb->depth0);
2922+
if (vb->lb == (jl_value_t*)ivar) {
29202923
JL_GC_POP();
29212924
JL_GC_POP();
29222925
return jl_bottom_type;
29232926
}
29242927
if (varval) {
29252928
JL_TRY {
2926-
*btemp->lb = jl_substitute_var(*btemp->lb, vb->var, varval);
2929+
*btemp->lb = jl_substitute_var(ilb, vb->var, varval);
29272930
}
29282931
JL_CATCH {
29292932
res = jl_bottom_type;
29302933
}
29312934
}
2932-
else if (*btemp->lb == (jl_value_t*)vb->var) {
2935+
else if (ilb == (jl_value_t*)vb->var) {
29332936
*btemp->lb = vb->lb;
29342937
}
2935-
else if (bdepth0 == vb->depth0 && !jl_has_typevar(vb->lb, *btemp->var) && !jl_has_typevar(vb->ub, *btemp->var)) {
2938+
else if (bdepth0 == vb->depth0 && !jl_has_typevar(vb->lb, ivar) && !jl_has_typevar(vb->ub, ivar)) {
29362939
// if our variable is T, and some outer variable has constraint S = Ref{T},
29372940
// move the `where T` outside `where S` instead of putting it here. issue #21243.
29382941
if (newvar != vb->var)
2939-
*btemp->lb = jl_substitute_var(*btemp->lb, vb->var, (jl_value_t*)newvar);
2942+
*btemp->lb = jl_substitute_var(ilb, vb->var, (jl_value_t*)newvar);
29402943
if (!wrapped) pwrap = pbtemp;
29412944
wrapped = 1;
29422945
}
29432946
else {
2944-
*btemp->lb = jl_new_struct(jl_unionall_type, vb->var, *btemp->lb);
2947+
*btemp->lb = jl_new_struct(jl_unionall_type, vb->var, ilb);
29452948
}
2946-
assert((jl_value_t*)*btemp->var != *btemp->lb);
2949+
assert((jl_value_t*)ivar != *btemp->lb);
29472950
}
2948-
if (jl_has_typevar(*btemp->ub, vb->var)) {
2949-
assert(btemp->root->var == *btemp->var || bdepth0 == vb->depth0);
2950-
if (vb->ub == (jl_value_t*)*btemp->var) {
2951-
*btemp->ub = omit_bad_union(*btemp->ub, vb->var);
2952-
if (*btemp->ub == jl_bottom_type && btemp->ub != btemp->lb) {
2951+
if (jl_has_typevar(iub, vb->var)) {
2952+
assert(btemp->root->var == ivar || bdepth0 == vb->depth0);
2953+
if (vb->ub == (jl_value_t*)ivar) {
2954+
*btemp->ub = omit_bad_union(iub, vb->var);
2955+
if (*btemp->ub == jl_bottom_type && *btemp->ub != *btemp->lb) {
29532956
JL_GC_POP();
29542957
JL_GC_POP();
29552958
return jl_bottom_type;
29562959
}
29572960
}
29582961
if (varval) {
29592962
JL_TRY {
2960-
*btemp->ub = jl_substitute_var(*btemp->ub, vb->var, varval);
2963+
*btemp->ub = jl_substitute_var(iub, vb->var, varval);
29612964
}
29622965
JL_CATCH {
29632966
res = jl_bottom_type;
29642967
}
29652968
}
2966-
else if (*btemp->ub == (jl_value_t*)vb->var) {
2969+
else if (iub == (jl_value_t*)vb->var) {
29672970
// TODO: this loses some constraints, such as in this test, where we replace T4<:S3 (e.g. T4==S3 since T4 only appears covariantly once) with T4<:Any
29682971
// a = Tuple{Float64,T3,T4} where T4 where T3
29692972
// b = Tuple{S2,Tuple{S3},S3} where S2 where S3
29702973
// Tuple{Float64, T3, T4} where {S3, T3<:Tuple{S3}, T4<:S3}
29712974
*btemp->ub = vb->ub;
29722975
}
2973-
else if (bdepth0 == vb->depth0 && !jl_has_typevar(vb->lb, *btemp->var) && !jl_has_typevar(vb->ub, *btemp->var)) {
2976+
else if (bdepth0 == vb->depth0 && !jl_has_typevar(vb->lb, ivar) && !jl_has_typevar(vb->ub, ivar)) {
29742977
if (newvar != vb->var)
2975-
*btemp->ub = jl_substitute_var(*btemp->ub, vb->var, (jl_value_t*)newvar);
2978+
*btemp->ub = jl_substitute_var(iub, vb->var, (jl_value_t*)newvar);
29762979
if (!wrapped) pwrap = pbtemp;
29772980
wrapped = 1;
29782981
}
29792982
else
2980-
*btemp->ub = jl_new_struct(jl_unionall_type, vb->var, *btemp->ub);
2981-
assert((jl_value_t*)*btemp->var != *btemp->ub);
2983+
*btemp->ub = jl_new_struct(jl_unionall_type, vb->var, iub);
2984+
assert((jl_value_t*)ivar != *btemp->ub);
29822985
}
29832986
pbtemp = btemp;
29842987
}
@@ -3033,18 +3036,21 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind
30333036

30343037
// Freeze the innervars' lb/ub and perform substitution if needed.
30353038
for (jl_ivarbinding_t *btemp1 = allvars; btemp1 != NULL; btemp1 = btemp1->next) {
3036-
jl_tvar_t *ivar = *btemp1->var;
3039+
ivar = *btemp1->var;
3040+
ilb = *btemp1->lb;
3041+
iub = *btemp1->ub;
30373042
int isinnervar = btemp1->root->var != ivar;
3038-
if (isinnervar && ((ivar->lb != *btemp1->lb) ||
3039-
(ivar->ub != *btemp1->ub))) {
3040-
nivar = (jl_value_t *)jl_new_typevar(ivar->name, *btemp1->lb, *btemp1->ub);
3043+
if (isinnervar && (ivar->lb != ilb || ivar->ub != iub)) {
3044+
nivar = (jl_value_t *)jl_new_typevar(ivar->name, ilb, iub);
30413045
if (jl_has_typevar(res, ivar))
30423046
res = jl_substitute_var(res, ivar, nivar);
30433047
for (jl_ivarbinding_t *btemp2 = btemp1->next; btemp2 != NULL; btemp2 = btemp2->next) {
3044-
if (jl_has_typevar(*btemp2->lb, ivar))
3045-
*btemp2->lb = jl_substitute_var(*btemp2->lb, ivar, nivar);
3046-
if (jl_has_typevar(*btemp2->ub, ivar))
3047-
*btemp2->ub = jl_substitute_var(*btemp2->ub, ivar, nivar);
3048+
ilb = *btemp2->lb;
3049+
iub = *btemp2->ub;
3050+
if (jl_has_typevar(ilb, ivar))
3051+
*btemp2->lb = jl_substitute_var(ilb, ivar, nivar);
3052+
if (jl_has_typevar(iub, ivar))
3053+
*btemp2->ub = jl_substitute_var(iub, ivar, nivar);
30483054
}
30493055
*btemp1->var = (jl_tvar_t *)nivar;
30503056
}

0 commit comments

Comments
 (0)