JuliaLang / julia

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

StackOverflowError while unzipping array of tuples #35950

Open deepaksuresh opened 4 years ago

deepaksuresh commented 4 years ago

Consider the following snippet

array1 = rand(2000)
array2 = rand(2000)

arrays_zipped = collect(zip(array1, array2))

arrays_zipped is an array of tuples, where first and second element of each tuple comes array1 and array2 respectively.

In order to unzip arrays_zipped i.e. to get back array1 and array2 out of arrays_zipped collect(zip(arrays_zipped...))

This throws the following error and exits the Julia session

Internal error: encountered unexpected error in runtime:
StackOverflowError()
malloc_s at /Users/julia/buildbot/worker/package_macos64/build/src/support/dtypes.h:355 [inlined]
subtype_in_env_existential at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2164
intersect_var at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2200
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:0
intersect_invariant at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2742
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:3002
intersect_tuple at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2642 [inlined]
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2958
intersect_unionall_ at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2491
intersect_unionall at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2539
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:0
intersect_all at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:3047
jl_type_intersection_env_s at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:3241
jl_typemap_intersection_node_visitor at /Users/julia/buildbot/worker/package_macos64/build/src/typemap.c:484
jl_typemap_intersection_visitor at /Users/julia/buildbot/worker/package_macos64/build/src/typemap.c:572
ml_matches at /Users/julia/buildbot/worker/package_macos64/build/src/gf.c:2723
jl_matching_methods at /Users/julia/buildbot/worker/package_macos64/build/src/gf.c:1811
_methods_by_ftype at ./reflection.jl:841 [inlined]
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:50
abstract_call_known at ./compiler/abstractinterpretation.jl:873
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_call at ./compiler/abstractinterpretation.jl:880
abstract_eval at ./compiler/abstractinterpretation.jl:974
typeinf_local at ./compiler/abstractinterpretation.jl:1227
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1283
typeinf at ./compiler/typeinfer.jl:12
typeinf_edge at ./compiler/typeinfer.jl:488
abstract_call_method at ./compiler/abstractinterpretation.jl:404
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:101
abstract_call_known at ./compiler/abstractinterpretation.jl:873
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_call at ./compiler/abstractinterpretation.jl:880
abstract_eval at ./compiler/abstractinterpretation.jl:974
typeinf_local at ./compiler/abstractinterpretation.jl:1227
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1283
typeinf at ./compiler/typeinfer.jl:12
typeinf_edge at ./compiler/typeinfer.jl:488
abstract_call_method at ./compiler/abstractinterpretation.jl:404
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:101
abstract_call_known at ./compiler/abstractinterpretation.jl:873
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_call at ./compiler/abstractinterpretation.jl:880
abstract_eval at ./compiler/abstractinterpretation.jl:974
typeinf_local at ./compiler/abstractinterpretation.jl:1227
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1283
typeinf at ./compiler/typeinfer.jl:12
typeinf_edge at ./compiler/typeinfer.jl:488
abstract_call_method at ./compiler/abstractinterpretation.jl:404
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:101
abstract_call_known at ./compiler/abstractinterpretation.jl:873
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_call at ./compiler/abstractinterpretation.jl:880
abstract_eval at ./compiler/abstractinterpretation.jl:974
typeinf_local at ./compiler/abstractinterpretation.jl:1227
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1283
typeinf at ./compiler/typeinfer.jl:12
typeinf_edge at ./compiler/typeinfer.jl:488
julia> versioninfo()
Julia Version 1.4.0
Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, broadwell)
JeffBezanson commented 4 years ago

More or less a duplicate of #35269. Splatting very long argument lists should never be done. We could use some sort of better error or checks here but I'm not sure exactly what. In the mean time please avoid this.

grahamas commented 4 years ago

Is there a correct way to accomplish this zipping, then? I just think of separate list comprehensions, or for efficiency, preallocating arrays and then looping over the array of tuples.

(I just spent a while trying to figure out what was going on, so +1 to catching this without an infinitely long stack overflow error)