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

StackOverflow error using tuple types as type parameter #22239

Closed
daanhb opened this issue Jun 6, 2017 · 3 comments
Closed

StackOverflow error using tuple types as type parameter #22239

daanhb opened this issue Jun 6, 2017 · 3 comments
Assignees
Labels
domain:types and dispatch Types, subtyping and method dispatch kind:bug Indicates an unexpected problem or unintended behavior

Comments

@daanhb
Copy link
Contributor

daanhb commented Jun 6, 2017

The following code produces a StackOverflowError on 0.6 RC2:

bar(::Type{Val{Tuple{T,T}}}) where {T} = 1
bar(::Type{Val{Tuple{Int,T}}}) where {T} = 2

Output when running julia foo.jl with the above two lines as contents:

ERROR: LoadError: StackOverflowError:
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:569
 [2] include(::String) at ./sysimg.jl:14
 [3] process_options(::Base.JLOptions) at ./client.jl:305
 [4] _start() at ./client.jl:371
while loading /tmp/foo.jl, in expression starting on line 2

Yet, everything works fine if the order of the two lines is reversed!

  • The problem goes away if you remove the extra complexity of the Val above, i.e. the tuple types have to be type parameters. Maybe that is not a valid thing to do? The above is a MWE, the context was code to convert between nested tuples and flat tuples.
  • The second line matches the first if T=Int, but that is not essential. You can replace the Int with Tuple{T,T} so it never matches the first line, and the problem remains.

Version info:

julia> versioninfo()
Julia Version 0.6.0-rc2.0
Commit 68e911b (2017-05-18 02:31 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
@JeffBezanson JeffBezanson added kind:bug Indicates an unexpected problem or unintended behavior domain:types and dispatch Types, subtyping and method dispatch labels Jun 6, 2017
@JeffBezanson JeffBezanson self-assigned this Jun 6, 2017
JeffBezanson added a commit that referenced this issue Jun 6, 2017
fix #22239, stack overflow in type intersection
tkelman pushed a commit that referenced this issue Jun 17, 2017
@daanhb
Copy link
Contributor Author

daanhb commented Jul 5, 2017

The above example now indeed works on 0.6.0 - thanks! - but unfortunately after more tests the code that led to this issue still produces a similar error. The minimal working example is now more complicated:

bar(::Type{Val{Tuple{Tuple{T},T}}}, ::Val{T}) where {T} = 1
bar(::Type{Val{Tuple{T,Tuple{T}}}}, ::Val{T}) where {T} = 2

I can't reduce this any further without making the problem go away. In particular, the second argument seems important, as well as the nested tuple.

The exact error message is the same StackOverflowError:

ERROR: LoadError: StackOverflowError:
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:569
 [2] include(::String) at ./sysimg.jl:14
 [3] process_options(::Base.JLOptions) at ./client.jl:305
 [4] _start() at ./client.jl:371
while loading /tmp/foo2.jl, in expression starting on line 2

Version info (0.6.0 as released):

julia> versioninfo()
Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)

@daanhb
Copy link
Contributor Author

daanhb commented Jul 5, 2017

Here is another example that is less nested but produces a similar error:

bar(::Type{Tuple{T,Val{T}}}, ::Val{T}) where {T} = 1
bar(::Type{Tuple{Val{T},T}}, ::Val{T}) where {T} = 2

@martinholters
Copy link
Member

julia> typeintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T, Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T)
ERROR: StackOverflowError:
Stacktrace:
 [1] typeintersect(::Any, ::Any) at ./reflection.jl:314

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 kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants