Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap y::UnionALL eagerly when x<:y if x isa ∀-var. #49023

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,16 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
// to other left-side variables, so using || here is safe.
return subtype(xub, y, e, param) || subtype(x, ylb, e, param);
}
if (jl_is_unionall(y)) {
jl_varbinding_t *xb = lookup(e, (jl_tvar_t*)x);
if (xb == NULL ? !e->ignore_free : !xb->right) {
// We'd better unwrap `y::UnionAll` eagerly if `x` isa ∀-var.
// This makes sure the following cases work correct:
// 1) `∀T <: Union{∃S, SomeType{P}} where {P}`: `S == Any` ==> `S >: T`
// 2) `∀T <: Union{∀T, SomeType{P}} where {P}`:
return subtype_unionall(x, (jl_unionall_t*)y, e, 1, param);
}
}
return var_lt((jl_tvar_t*)x, y, e, param);
}
if (jl_is_typevar(y))
Expand Down
12 changes: 5 additions & 7 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ struct Z38497{T>:Int} <: Y38497{T} end
@test only(intersection_env(Union{S, Matrix{Int}} where S<:Matrix, Matrix)[2]) isa TypeVar
T46784{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}}, M, Union{AbstractMatrix{B}, AbstractMatrix{<:Vector{<:B}}}}
@testintersect(T46784{T,S} where {T,S}, T46784, !Union{})
@test_broken T46784 <: T46784{T,S} where {T,S}
@test T46784 <: T46784{T,S} where {T,S}

#issue 36185
let S = Tuple{Type{T},Array{Union{T,Missing},N}} where {T,N},
Expand Down Expand Up @@ -2376,12 +2376,10 @@ abstract type P47654{A} end

@testset "known subtype/intersect issue" begin
#issue 45874
# Causes a hang due to jl_critical_error calling back into malloc...
# let S = Pair{Val{P}, AbstractVector{<:Union{P,<:AbstractMatrix{P}}}} where P,
# T = Pair{Val{R}, AbstractVector{<:Union{P,<:AbstractMatrix{P}}}} where {P,R}
# @test_broken S <: T
# @test_broken typeintersect(S,T) === S
# end
let S = Pair{Val{P}, AbstractVector{<:Union{P,<:AbstractMatrix{P}}}} where P,
T = Pair{Val{R}, AbstractVector{<:Union{P,<:AbstractMatrix{P}}}} where {P,R}
@test S <: T
end

#issue 41561
@test_broken typeintersect(Tuple{Vector{VT}, Vector{VT}} where {N1, VT<:AbstractVector{N1}},
Expand Down