Open etiennedeg opened 2 years ago
In case this helps, some variants. (Xref also https://github.com/JuliaLang/julia/issues/45454 recently about stack overflow from a splat.)
julia> let
x = Any[[1] for _ in 1:10^4]
# x[2] = 2 # without this, no problem
vcat(x...)'
end
1×10000 adjoint(::Vector{Int64}) with eltype Int64:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 … 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
julia> let
x = Any[[1] for _ in 1:10^4]
x[2] = 2 # change near the start
vcat(x...)'
end
ERROR: StackOverflowError:
julia> let
x = Any[[1] for _ in 1:10^4]
x[end-2] = 2 # change near the end
vcat(x...)'
end
signal (11): Segmentation fault: 11
in expression starting at REPL[9]:1
gc_read_stack at /Users/me/.julia/dev/julia/src/gc.c:1696 [inlined]
gc_mark_loop at /Users/me/.julia/dev/julia/src/gc.c:2373
This just seems like the old issue of splitting way too big argument lists. Use reduce(vcat, l)
instead.
Dup of https://github.com/JuliaLang/julia/issues/42327, https://github.com/JuliaLang/julia/issues/38364
Until the issue is fixed, perhaps it would be best to find some lower bound of N arguments, where it can be guaranteed to not crash, and then add a check that explicitly errors with an informative error message when a function is called with more than N arguments.
The current situation is both confusing, because it's difficult to understand what happened, and also brittle, because the fact that it sometimes works can cause developers to rely on it working, and then introducing code that will suddenly break in the user's hands. For example, there is no problem here:
julia> f(args...) = sum(args)
f (generic function with 1 method)
julia> f(1:10000...)
50005000
Python limited function to 255 arguments until a few years ago, and I haven't heard about anyone complaining about that. Conversely, if people do begin complaining that Julia suddenly can't handle them splatting 500 elements which they are used to doing, then it's a pretty good sign that Julia's poor handling of lots of arguments is something that is already causing issues.
Note that all of these fail in subtyping with
julia: /data/vtjnash/julia/src/subtype.c:133: statestack_set: Assertion `i >= 0 && i < sizeof(st->stack) * 8' failed.
Context: https://github.com/JuliaGraphs/Graphs.jl/issues/138
MWE:
Edit: smaller reproducer:
original reproducer: Download the file https://pastebin.com/hfv6Jrgv Convert it to LF instead of CRLF if needed.
Result in segmentation fault:
Version info: