Skip to content

Commit

Permalink
Avoid set var's bounds if offset != 0
Browse files Browse the repository at this point in the history
if `offset != 0`, then these 2 var should have different value, thus it's invalid to set bounds.
  • Loading branch information
N5N3 committed Aug 24, 2022
1 parent 7e58b03 commit 41db5ed
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2165,15 +2165,15 @@ static jl_value_t *set_var_to_const(jl_varbinding_t *bb, jl_value_t *v JL_MAYBE_
offset = -othervar->offset;
assert(!othervar || othervar->offset == -offset);
if (bb->lb == jl_bottom_type && bb->ub == (jl_value_t*)jl_any_type) {
if (jl_is_long(v)) {
if (offset == 0)
bb->lb = bb->ub = v;
else if (jl_is_long(v)) {
size_t iv = jl_unbox_long(v);
v = jl_box_long(iv + offset);
bb->lb = bb->ub = v;
// Here we always return the shorter `Vararg`'s length.
if (offset > 0) return jl_box_long(iv);
}
else
bb->lb = bb->ub = v;
}
else if (jl_is_long(v) && jl_is_long(bb->lb)) {
if (jl_unbox_long(v) + offset != jl_unbox_long(bb->lb))
Expand All @@ -2194,11 +2194,12 @@ static jl_value_t *bound_var_below(jl_tvar_t *tv, jl_varbinding_t *bb, jl_stenv_
return jl_bottom_type;
record_var_occurrence(bb, e, 2);
if (jl_is_long(bb->lb)) {
size_t blb = jl_unbox_long(bb->lb);
if (blb < bb->offset || blb < 0)
return jl_bottom_type;
// Here we always return the shorter `Vararg`'s length.
if (bb->offset <= 0)
return bb->lb;
if (jl_unbox_long(bb->lb) < bb->offset)
return jl_bottom_type;
return jl_box_long(jl_unbox_long(bb->lb) - bb->offset);
}
return (jl_value_t*)tv;
Expand Down Expand Up @@ -3041,14 +3042,14 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
lb = ylb;
else
lb = simple_join(xlb, ylb);
if (yy) {
if (yy && yy->offset == 0) {
yy->lb = lb;
if (!reachable_var(ub, (jl_tvar_t*)y, e))
yy->ub = ub;
assert(yy->ub != y);
assert(yy->lb != y);
}
if (xx && !reachable_var(y, (jl_tvar_t*)x, e)) {
if (xx && xx->offset == 0 && !reachable_var(y, (jl_tvar_t*)x, e)) {
xx->lb = y;
xx->ub = y;
assert(xx->ub != x);
Expand Down

0 comments on commit 41db5ed

Please sign in to comment.