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

tuple_tfunc bug handling of Union containing Type{...} #44705

Closed
aviatesk opened this issue Mar 23, 2022 · 2 comments
Closed

tuple_tfunc bug handling of Union containing Type{...} #44705

aviatesk opened this issue Mar 23, 2022 · 2 comments
Labels
compiler:inference Type inference kind:bug Indicates an unexpected problem or unintended behavior

Comments

@aviatesk
Copy link
Sponsor Member

I guess this issue should be raised before, but I couldn't find an issue that discusses this.
When working on #44512 (in particularity this issue), I found the following isa check doesn't work as I expected:

julia> Type{Int} <: DataType
true

julia> Int isa Type{Int}
true

julia> (Int,) isa Tuple{DataType} # expected
true

julia> (Int,) isa Tuple{Type{Int}} # I expected this to return `true`
false

So in essence Tuple-type whose parameter contains Type-type doesn't seem to follow the covariant rule.

This issue leads to the ERROR: fatal error in type inference (type bound) error in #44512 when we try to union-split Base.indexed_iterate(::Union{Tuple{Nothing, Nothing, Nothing}, Tuple{Any, Union{Type{AbstractContinuousSystem}, Type{AbstractDiscreteSystem}}, Any}}, ...) callsite.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 23, 2022

That is an odd looking signature type, since we should be unable to ever select that part of the union. There do not exist any values which satisfy isa Tuple{Type{Int}}, since Type{Int} is a subtype of DataType, which is the concrete type of this value. In particular, and for Tuples only, we can have subtypes of concrete types (but not concrete subtypes of concrete subtypes), which can lead to some confusion over the dispatch behavior if one is not careful about reflecting this fact in the algorithms.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 23, 2022

incorrect:

julia> Core.Compiler.tuple_tfunc(Any[Union{Type{Int32}, Type{Int64}}])
Tuple{Union{Type{Int32}, Type{Int64}}}

correct:

julia> Core.Compiler.tmerge(Core.Compiler.tuple_tfunc(Any[Type{Int32}]), Core.Compiler.tuple_tfunc(Any[Type{Int64}]))
Tuple{DataType}

@vtjnash vtjnash changed the title Covariance bug of Tuple{Type{...}} tuple_tfunc bug handling of Union containing Type{...} Mar 23, 2022
@vtjnash vtjnash added compiler:inference Type inference kind:bug Indicates an unexpected problem or unintended behavior labels Mar 23, 2022
aviatesk added a commit that referenced this issue Mar 24, 2022
KristofferC pushed a commit that referenced this issue Jul 4, 2022
fix #44705

(cherry picked from commit 4115686)
KristofferC pushed a commit that referenced this issue Jul 4, 2022
fix #44705

(cherry picked from commit 4115686)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants