JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.78k stars 5.49k forks source link

egal results in unions from type intersection #49267

Closed vtjnash closed 1 year ago

vtjnash commented 1 year ago

This isn't ideal, since it makes work much harder for inference:

julia> using Phylo, Phylo.SimpleTraits

julia> typeintersect(Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, N}}}, T, N, N} where {RT, N, T<:(AbstractTree{OneTree, RT, NL, N, B} where {NL, N<:Phylo.AbstractNode{RT, NL}, B<:Phylo.AbstractBranch{RT, NL}})},
              Tuple{typeof(branchroute), Type{SimpleTraits.Not{Phylo.API.MatchNodeType{T, Missing}}} where T<:LinkTree, LinkTree, Missing, Missing}).body.var.ub.a
LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}

julia> typeintersect(Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, N}}}, T, N, N} where {RT, N, T<:(AbstractTree{OneTree, RT, NL, N, B} where {NL, N<:Phylo.AbstractNode{RT, NL}, B<:Phylo.AbstractBranch{RT, NL}})},
              Tuple{typeof(branchroute), Type{SimpleTraits.Not{Phylo.API.MatchNodeType{T, Missing}}} where T<:LinkTree, LinkTree, Missing, Missing}).body.var.ub.b
Union{LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}, LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}}

julia> typeintersect(Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, N}}}, T, N, N} where {RT, N, T<:(AbstractTree{OneTree, RT, NL, N, B} where {NL, N<:Phylo.AbstractNode{RT, NL}, B<:Phylo.AbstractBranch{RT, NL}})},
              Tuple{typeof(branchroute), Type{SimpleTraits.Not{Phylo.API.MatchNodeType{T, Missing}}} where T<:LinkTree, LinkTree, Missing, Missing}).body.var.ub.b.a
LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}

julia> typeintersect(Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, N}}}, T, N, N} where {RT, N, T<:(AbstractTree{OneTree, RT, NL, N, B} where {NL, N<:Phylo.AbstractNode{RT, NL}, B<:Phylo.AbstractBranch{RT, NL}})},
              Tuple{typeof(branchroute), Type{SimpleTraits.Not{Phylo.API.MatchNodeType{T, Missing}}} where T<:LinkTree, LinkTree, Missing, Missing}).body.var.ub.b.b
LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}
resulting in
Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, Missing}}}, T, Missing, Missing} where {RT, T<:Union{LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}, LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}, LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}}}

instead of the equivalent
Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, Missing}}}, T, Missing, Missing} where {RT, T<:(LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})})}
vtjnash commented 1 year ago

result now seems acceptable

julia> typeintersect(Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, N}}}, T, N, N} where {RT, N, T<:(AbstractTree{OneTree, RT, NL, N, B} where {NL, N<:Phylo.AbstractNode{RT, NL}, B<:Phylo.AbstractBranch{RT, NL}})},
              Tuple{typeof(branchroute), Type{SimpleTraits.Not{Phylo.API.MatchNodeType{T, Missing}}} where T<:LinkTree, LinkTree, Missing, Missing})
Tuple{typeof(branchroute), Type{Not{Phylo.API.MatchNodeType{T, Missing}}}, LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})}, Missing, Missing} where {RT, T<:(LinkTree{RT, NL, N, B} where {NL, N<:(LinkNode{RT, NL, Data, B} where {Data, B<:Phylo.AbstractBranch{RT, NL}}), B<:(LinkBranch{RT, NL})})}