-
-
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
error in type inference, causes either a crash or silently wrong results depending on Julia version #57429
Comments
On 1.10, this reduced to const a = Tuple{Vararg{Nothing,d}} where d
struct b{d, a{d} <: e <: a}
global function c(::Type{b{d}}) where d
e = a{d}
new{d,e}()
end
end
c(f) = c(b{f})
h = b{d,e} where {d, e<:Tuple{Nothing}}
r(::b{t}) where t = t
function ae(an, ao::h)
if an isa h
an == a ? a : r(ao)
end
end
ai(::aj, c) where aj = z
function ap(::aj, l) where aj
an = ao = signbit(l) ? nothing : c(l)
m = ae(an, ao)
ai(aj, m)
end
function (::Type{aj})(l) where aj
ap(aj, l)
end
h(1) but the function (::Type{aj})(l) where aj
ap(aj, l)
end signature is a bit fishy so not sure it is a 100% proper reduction. On 1.10 and 1.11 this gives
|
Reduces more to this type intersect error (verified on master and v1.10), depending on the order of the typeintersect arguments to it: julia> const a = Tuple{Vararg{Nothing,d}} where d
NTuple{d, Nothing} where d
julia> struct b{d, a{d} <: e <: a} end
julia> const h = b{d,e} where {d, e<:Tuple{Nothing}}
julia> typeintersect(b{t, e} where Tuple{Vararg{Nothing, t}}<:e<:(Tuple{Vararg{Nothing, d}} where d) where t, h)
b{1, Tuple{Nothing}}
julia> typeintersect(h, b{t, e} where Tuple{Vararg{Nothing, t}}<:e<:(Tuple{Vararg{Nothing, d}} where d) where t)
Union{} |
Also confirmed this is not a new regression (last seen correct in v1.2), just an unwise way to write code in any version (the julia type system is not especially well-suited to proving arbitrary properties) |
Some other inaccurate julia> struct NonnegativeStrict{N, NTuple{N, Nothing} <: Tup <: NTuple{N, Nothing}} end
julia> const Positive = NonnegativeStrict{N, Tup} where {N, NTuple{N, Nothing} <: Tup <: Tuple{Nothing, Vararg{Nothing}}}
Positive{N} where N (alias for NonnegativeStrict{N, Tup} where {N, NTuple{N, Nothing}<:Tup<:Tuple{Nothing, Vararg{Nothing}}})
julia> typeintersect(NonnegativeStrict, Positive) # buggy, see counterexample below
Union{}
julia> typeintersect(Positive, NonnegativeStrict) # same
Union{}
julia> counterexample = NonnegativeStrict{1, Tuple{Nothing}}
NonnegativeStrict{1, Tuple{Nothing}}
julia> counterexample <: NonnegativeStrict
true
julia> counterexample <: Positive
true |
fix JuliaLang#41561 fix JuliaLang#57429 Typevars are all existential (in the sense of variable lb/ub) during intersection.
fix JuliaLang#57429 JuliaLang#41561 Typevars are all existential (in the sense of variable lb/ub) during intersection. This fix is somehow costly as we have to perform 3 times check to prove a false result. But a single existential <: seems too dangerous as it cause many circular env in the past.
fix JuliaLang#57429 JuliaLang#41561 Typevars are all existential (in the sense of variable lb/ub) during intersection. This fix is somehow costly as we have to perform 3 times check to prove a false result. But a single existential <: seems too dangerous as it cause many circular env in the past.
fix JuliaLang#57429 JuliaLang#41561 Typevars are all existential (in the sense of variable lb/ub) during intersection. This fix is somehow costly as we have to perform 3 times check to prove a false result. But a single existential <: seems too dangerous as it cause many circular env in the past.
The bug:
For all Julia versions the correct behavior is obtained with
--compile=min
.Reproducer:
The text was updated successfully, but these errors were encountered: