Skip to content

Commit

Permalink
Also merge var with unchanged bounds. (#46757)
Browse files Browse the repository at this point in the history
* Also merge var with unchanged bounds.
The current `env` might not be valid if the var's bounds get fixed by another Unions decision.
* Replace `v->var->lb` with `simple_meet`
* Remove the unneeded NUll check.

Co-Authored-By: Jameson Nash <[email protected]>
(cherry picked from commit 6557542)
  • Loading branch information
N5N3 authored and KristofferC committed Sep 16, 2022
1 parent ab67e93 commit 7955e8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -3176,18 +3176,15 @@ static int merge_env(jl_stenv_t *e, jl_value_t **root, jl_savedenv_t *se, int co
}
int n = 0;
jl_varbinding_t *v = e->vars;
jl_value_t *ub = NULL, *vub = NULL;
JL_GC_PUSH2(&ub, &vub);
jl_value_t *b1 = NULL, *b2 = NULL;
JL_GC_PUSH2(&b1, &b2);
while (v != NULL) {
if (v->ub != v->var->ub || v->lb != v->var->lb) {
jl_value_t *lb = jl_svecref(*root, n);
if (v->lb != lb)
jl_svecset(*root, n, lb ? jl_bottom_type : v->lb);
ub = jl_svecref(*root, n+1);
vub = v->ub;
if (vub != ub)
jl_svecset(*root, n+1, ub ? simple_join(ub, vub) : vub);
}
b1 = jl_svecref(*root, n);
b2 = v->lb;
jl_svecset(*root, n, simple_meet(b1, b2));
b1 = jl_svecref(*root, n+1);
b2 = v->ub;
jl_svecset(*root, n+1, simple_join(b1, b2));
n = n + 3;
v = v->prev;
}
Expand Down
11 changes: 11 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2020,3 +2020,14 @@ end
#issue #43082
struct X43082{A, I, B<:Union{Ref{I},I}}; end
@testintersect(Tuple{X43082{T}, Int} where T, Tuple{X43082{Int}, Any}, Tuple{X43082{Int}, Int})

#issue #46735
T46735{B<:Real} = Pair{<:Union{B, Val{<:B}}, <:Union{AbstractMatrix{B}, AbstractMatrix{Vector{B}}}}
@testintersect(T46735{B} where {B}, T46735, !Union{})
@testintersect(T46735{B} where {B<:Integer}, T46735, !Union{})
S46735{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}},M,<:(Union{AbstractMatrix{B}, AbstractMatrix{<:Vector{<:B}}})}
@testintersect(S46735{B} where {B}, S46735, !Union{})
@testintersect(S46735{B, M} where {B, M}, S46735, !Union{})
A46735{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}},M,Union{AbstractMatrix{B}, AbstractMatrix{<:Vector{<:B}}}}
@testintersect(A46735{B} where {B}, A46735, !Union{})
@testintersect(A46735{B, M} where {B, M}, A46735, !Union{})

0 comments on commit 7955e8a

Please sign in to comment.