JuliaLang / julia

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

StackOverflowError happens for some giant splat calls #47896

Open mzy2240 opened 1 year ago

mzy2240 commented 1 year ago

The stackoverflowerror could be easily reproduced under MacOS. Try the following code:

mapping = Dict("a" => rand(Int64, (1,2000)), "b" => rand(Int64, (1,2000)), "c" => rand(Int64, (1,2000)))
container = Set{Int64}()
push!(container, mapping["a"]...)

Here is my system info

Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.3.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 12 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 12

Running the same code under Windows won't raise the error.

brenhinkeller commented 1 year ago

I'll add the bug label since a stackoverflow here is probably not the optimal failure mode even if we want to have this error.

This is a bit of an edge case though, since generally you do very much do not want to be splatting collections of thousands of things.

W/r/t the use case at hand, since there seems to be no append! method for Set (which would be an idiomatic way to do this if container were an Array instead of a Set), you might consider something along the lines of

container = container ∪ Set(mapping["a"])