Skip to content

Commit

Permalink
Fix for many-to-one cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Apr 18, 2023
1 parent 4b86d46 commit d6d2f29
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,21 +746,17 @@ jl_value_t *simple_intersect(jl_value_t *a, jl_value_t *b, int overesi)
if (temp[j] == NULL) continue;
int subs = simple_subtype2(temp[i], temp[j], hasfree || jl_has_free_typevars(temp[j]));
int subab = subs & 1, subba = subs >> 1;
if (subba && !subab) {
stemp[i] = -1;
}
if (subab && !subba) {
stemp[j] = -1;
temp[j] = temp[i];
}
if (subba && !subab) stemp[i] = -1;
if (subab && !subba) stemp[j] = -1;
if (stemp[i] == 0 && subab) stemp[i] = 1;
if (stemp[j] == 0 && subba) stemp[j] = 1;
}
}
int subs[2] = {1, 1}, rs[2] = {1, 1};
for (i = 0; i < nt; i++) {
subs[i >= nta] &= (temp[i] == NULL || stemp[i] == 1);
rs[i >= nta] &= (temp[i] != NULL && stemp[i] == 1);
int isb = i >= nta;
subs[isb] &= (temp[i] == NULL || stemp[i] == 1);
rs[isb] &= (temp[i] != NULL && stemp[i] == 1);
}
// return a(b) if a(b) <: b(a)
if (rs[0]) {
Expand All @@ -776,9 +772,16 @@ jl_value_t *simple_intersect(jl_value_t *a, jl_value_t *b, int overesi)
JL_GC_POP();
return jl_bottom_type;
}
nt = subs[0] ? nta : nt;
count = subs[0] ? nta : ntb;
i = subs[0] ? 0 : nta;
nt = subs[0] ? nta : subs[1] ? nt : nt;
i = subs[0] ? 0 : subs[1] ? nta : 0;
count = nt - i;
if (!subs[0] && !subs[1]) {
// prepare for over estimation
for (j = 0; j < nt; j++) {
if (stemp[j] == -1 || (stemp[j] == 0 && j < nta))
temp[j] = NULL;
}
}
isort_union(&temp[i], count);
temp[nt] = jl_bottom_type;
size_t k;
Expand Down

0 comments on commit d6d2f29

Please sign in to comment.