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

StackOverflowError in type intersection / inference #44395

Closed
goerch opened this issue Mar 1, 2022 · 1 comment
Closed

StackOverflowError in type intersection / inference #44395

goerch opened this issue Mar 1, 2022 · 1 comment
Labels
domain:types and dispatch Types, subtyping and method dispatch

Comments

@goerch
Copy link

goerch commented Mar 1, 2022

Reported on discourse:

using Graphs

abstract type MyAbstract end

struct Composite{T <: MyAbstract,R <: MyAbstract} <: MyAbstract
    a::T
    av::Vector{Union{T,R}}
end

struct Leaf <: MyAbstract
    b
end
Leaf() = Leaf(1)

Composite{T,R}() where {T<:MyAbstract,R<:MyAbstract} = Composite{T,R}(T(),Vector{Union{T,R}}([T()]))

randcomp1(firsttype::Type) = Composite{firsttype, Composite}()

randcomp1(Leaf)

crashes 1.7.2 with

Internal error: encountered unexpected error in runtime:
StackOverflowError()
intersect at /cygdrive/c/buildbot/worker/package_win64/build/src\subtype.c:2960

and seems to work on nightly.

@vtjnash vtjnash changed the title StackOverflowError in type inference [release-1.7] StackOverflowError in type inference Mar 1, 2022
@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 1, 2022

semi-MWE fails on all (recent) Julia versions, so something merely avoided reaching this case in inference for 1.8+:

julia> using StaticArrays
julia> abstract type MyAbstract end
julia> typeintersect(
  Tuple{typeof(Base.convert), Type{Array{Union{T, R}, 1}}, StaticArrays.SizedArray{S, Union{T, R}, 1, 1, Array{Union{T, R}, 1}}} where R<:Main.MyAbstract where T<:Main.MyAbstract where S,
  Tuple{typeof(Base.convert), Type{T}, T} where T<:(Array{Union{T, R}, 1} where R<:Main.MyAbstract where T<:Main.MyAbstract)
)

@vtjnash vtjnash changed the title [release-1.7] StackOverflowError in type inference StackOverflowError in type intersection / inference Mar 1, 2022
@vtjnash vtjnash added the domain:types and dispatch Types, subtyping and method dispatch label Mar 1, 2022
N5N3 added a commit to N5N3/julia that referenced this issue Jan 11, 2023
They might be recreated in `finish_unionall`, (thus `lookup` returns false.)
But their bounds might still live in the current env.

close JuliaLang#44395.
(JuliaLang#44395 could also be fixed by the fast path added in JuliaLang#48221.
This commit would skip more `intersect_var` under circular constraint.)
@N5N3 N5N3 closed this as completed in 3933f90 Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

2 participants