Skip to content

Commit

Permalink
typeintersect: more fastpath to skip intersect under circular env (#5…
Browse files Browse the repository at this point in the history
…6304)

fix #56040

(cherry picked from commit 53ffe56)
  • Loading branch information
N5N3 authored and KristofferC committed Oct 30, 2024
1 parent b23811e commit 028858f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2392,8 +2392,10 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,
return y;
if (y == (jl_value_t*)jl_any_type && !jl_is_typevar(x))
return x;
// band-aid for #46736
if (obviously_egal(x, y))
// band-aid for #46736 #56040
if (obviously_in_union(x, y))
return y;
if (obviously_in_union(y, x))
return x;

jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, &e->Runions);
Expand All @@ -2407,6 +2409,9 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,

static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t *e, int8_t R, int param)
{
// band-aid for #56040
if (!jl_is_uniontype(x) && obviously_in_union((jl_value_t *)u, x))
return x;
if (param == 2 || (!jl_has_free_typevars(x) && !jl_has_free_typevars((jl_value_t*)u))) {
jl_value_t *a=NULL, *b=NULL;
JL_GC_PUSH2(&a, &b);
Expand Down
9 changes: 9 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2641,3 +2641,12 @@ let S = Tuple{Val, Val{T}} where {T}, R = Tuple{Val{Val{T}}, Val{T}} where {T},
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NamedTuple{(:a),B}}}, S{NTuple{2,Int}}, R{NTuple{2,Int}})
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NamedTuple{B,Tuple{Int,Int}}}}, S{(:a,:a)}, R{(:a,:a)})
end

#issue 56040
let S = Dict{V,V} where {V},
T = Dict{Ref{Union{Set{A2}, Set{A3}, A3}}, Ref{Union{Set{A3}, Set{A2}, Set{A1}, Set{A4}, A4}}} where {A1, A2<:Set{A1}, A3<:Union{Set{A1}, Set{A2}}, A4<:Union{Set{A2}, Set{A1}, Set{A3}}},
A = Dict{Ref{Set{Union{}}}, Ref{Set{Union{}}}}
@testintersect(S, T, !Union{})
@test A <: typeintersect(S, T)
@test A <: typeintersect(T, S)
end

0 comments on commit 028858f

Please sign in to comment.