-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Incorrect env computed for trivial UnionAll over Union #46970
Comments
The first example looks similar to #41096. Deserve to check if this comes from Lines 2155 to 2165 in 9fd4087
where the env change is not restored and merged correctly between 2 intersect_all .
|
I think |
You are right. julia> env = Any[nothing];
julia> a = Union{S, Matrix{Float64}} where S<:AbstractMatrix;
julia> @ccall jl_subtype_env(a::Any, AbstractMatrix::Any, env::Ptr{Any}, 1::Cint)::Cint;
julia> env
1-element Vector{Any}:
Float64 |
In this case, I think it sees that they are |
Exactly, we hit this branch Lines 563 to 566 in e6d9979
where x === y === AbstractMatrix , thus subtype_unionall would not be called for S <: AbstractMatrix Remove this fast-path for y <: Unionall should fix the examples above.
|
I guess that should still be fast, since it will stop when it reaches the inside of the UnionAll, and in the meantime will fill out the env (exactly as we want)? |
I tried to bench this extreme case with the above patch @eval abstract type A{$((Symbol(:T,i) for i in 1:1000)...)} end
B = @eval A{$((:Int for i in 1:1000)...)}
@eval abstract type C{$((Symbol(:T,i) for i in 1:10)...)} end
D = @eval C{$((:Int for i in 1:10)...)}
julia> @btime typeintersect($(Union{S, D} where S<:C), $C)
23.600 μs (212 allocations: 24.31 KiB) # 14.600 μs (117 allocations: 15.25 KiB) on master
julia> @btime typeintersect($Union{S, B} where S<:A, $A)
1.737 s (505503 allocations: 92.04 MiB) # 25.128 ms (1003 allocations: 23.01 MiB) on master But the regression should be rare. I think we can revist it if it does have a pratical usecase |
subtyping forgets to incorporate TypeVar-matched parameters from a Union into the env:
The text was updated successfully, but these errors were encountered: