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

Stack overflow in vect / promote_typeof #45454

Closed
nystrom opened this issue May 25, 2022 · 2 comments
Closed

Stack overflow in vect / promote_typeof #45454

nystrom opened this issue May 25, 2022 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@nystrom
Copy link

nystrom commented May 25, 2022

vect has a stack overflow when trying to compute the element type of the vector.

julia> abstract type A end
julia> struct B <: A end
julia> struct C <: A end
julia> xs = [B() for i in 1:100000];
julia> ys = [C() for i in 1:100000];
julia> [xs..., ys...]
ERROR: StackOverflowError:
Stacktrace:
 [1] promote_typeof(::B, ::B, ::Vararg{Any}) (repeats 29076 times)
   @ Base ./promotion.jl:330
 [2] vect(::B, ::Vararg{Any})
   @ Base ./array.jl:144

The workaround is to use vcat, but it would be good if the compiler could figure this out given that the two inputs are known to be vectors. At least to avoid the overflow, promote_typeof could be written:

promote_typeof(x) = typeof(x)
promote_typeof(x, xs...) = afoldl((t, x) -> promote_type(t, typeof(x)), typeof(x), xs...)

This occurs on 1.7.2:

Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_DEPOT_PATH = /Users/nystrom/.julia-depots:/Users/nystrom/.julia
  JULIA_NUM_THREADS = 4
  JULIA_PROJECT = /Users/nystrom/rai
  JULIA_EDITOR = code
@gbaraldi
Copy link
Member

I believe the issue is with how we handle massive splats like these

@nsajko
Copy link
Contributor

nsajko commented May 12, 2024

Seems fixed.

@nsajko nsajko closed this as completed May 12, 2024
royess added a commit to royess/QuantumClifford.jl that referenced this issue Jul 31, 2024
… enable syndrome ECC setups for BP

Note that `vect` is replaced with `vcat` to avoid `promote_typeof` stackover flow, as reported also in JuliaLang/julia#45454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants