Discrepancies of Errors caused by `collect(Base.OneTo(N))`

I discover this (using Version 1.11.5 (2025-04-14) )

julia> collect(Base.OneTo(2^59))
ERROR: OutOfMemoryError()
Stacktrace:
 [1] GenericMemory
   @ .\boot.jl:516 [inlined]
 [2] Array
   @ .\boot.jl:578 [inlined]
 [3] Array
   @ .\range.jl:1372 [inlined]
 [4] Array
   @ .\boot.jl:605 [inlined]
 [5] collect(r::Base.OneTo{Int64})
   @ Base .\range.jl:1380
 [6] top-level scope
   @ REPL[2]:1

julia> collect(Base.OneTo(2^60))
ERROR: ArgumentError: invalid GenericMemory size: too large for system address width
Stacktrace:
 [1] GenericMemory
   @ .\boot.jl:516 [inlined]
 [2] Array
   @ .\boot.jl:578 [inlined]
 [3] Array
   @ .\range.jl:1372 [inlined]
 [4] Array
   @ .\boot.jl:605 [inlined]
 [5] collect(r::Base.OneTo{Int64})
   @ Base .\range.jl:1380
 [6] top-level scope
   @ REPL[3]:1

julia> collect(Base.OneTo(2^61))

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks. 
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffa6b1bb350 -- jl_gc_pool_alloc_inner at C:/workdir/src\gc.c:1329
in expression starting at none:0
jl_gc_pool_alloc_inner at C:/workdir/src\gc.c:1329
jl_gc_alloc_ at C:/workdir/src\julia_internal.h:523 [inlined]
_new_array at C:/workdir/src\array.c:71 [inlined]
new_array at C:/workdir/src\array.c:93 [inlined]
ijl_alloc_array_1d at C:/workdir/src\array.c:156
decode_backtrace at C:/workdir/src\stackwalk.c:307
ijl_get_excstack at C:/workdir/src\stackwalk.c:368
#current_exceptions#97 at .\error.jl:151
current_exceptions at .\error.jl:150 [inlined]
current_exceptions at .\error.jl:150 [inlined]
eval_user_input at C:\workdir\usr\share\julia\stdlib\v1.11\REPL\src\REPL.jl:272
repl_backend_loop at C:\workdir\usr\share\julia\stdlib\v1.11\REPL\src\REPL.jl:368
#start_repl_backend#59 at C:\workdir\usr\share\julia\stdlib\v1.11\REPL\src\REPL.jl:343
start_repl_backend at C:\workdir\usr\share\julia\stdlib\v1.11\REPL\src\REPL.jl:340
#run_repl#76 at C:\workdir\usr\share\julia\stdlib\v1.11\REPL\src\REPL.jl:500
run_repl at C:\workdir\usr\share\julia\stdlib\v1.11\REPL\src\REPL.jl:486
jfptr_run_repl_10381.1 at K:\julia-1.11.5\share\julia\compiled\v1.11\REPL\u0gqU_hz07T.dll (unknown line)
#1150 at .\client.jl:446
jfptr_YY.1150_15121.1 at K:\julia-1.11.5\share\julia\compiled\v1.11\REPL\u0gqU_hz07T.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:2157 [inlined]
jl_f__call_latest at C:/workdir/src\builtins.c:875
#invokelatest#2 at .\essentials.jl:1055 [inlined]
invokelatest at .\essentials.jl:1052 [inlined]
run_main_repl at .\client.jl:430
repl_main at .\client.jl:567 [inlined]
_start at .\client.jl:541
jfptr__start_75200.1 at K:\julia-1.11.5\lib\julia\sys.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:2157 [inlined]
true_main at C:/workdir/src\jlapi.c:900
jl_repl_entrypoint at C:/workdir/src\jlapi.c:1059
mainCRTStartup at C:/workdir/cli\loader_exe.c:58
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 3165221 (Pool: 3162026; Big: 3195); GC: 5
4 Likes

Some somewhat similar strangeness:

julia> Vector{Int64}(undef, 2^59)  # Would expect the same as for collect(1:2^59). Yep
ERROR: OutOfMemoryError()
Stacktrace:
 [1] GenericMemory
   @ .\boot.jl:516 [inlined]
 [2] Vector{Int64}(::UndefInitializer, m::Int64)
   @ Core .\boot.jl:578
 [3] top-level scope
   @ REPL[1]:1

julia> Vector{Int64}(undef, 2^60)  # Yep
ERROR: ArgumentError: invalid GenericMemory size: too large for system address width
Stacktrace:
 [1] GenericMemory
   @ .\boot.jl:516 [inlined]
 [2] Vector{Int64}(::UndefInitializer, m::Int64)
   @ Core .\boot.jl:578
 [3] top-level scope
   @ REPL[2]:1

julia> Vector{Int64}(undef, 2^61)  # Wait, what? Same for 2^62
2305843009213693952-element Vector{Int64}:
                   0
     140717662892034
       2487682399264
       2487682399248
 2305843009213693952
     140717671215762
       2487682399280
     140717705664512
                   0
       2487682399368
                   0
       2486995996824
                   0
                   ⋮
                   0
       2487682399208
                   1
       2487682399200
                   2
       2487682399336
       2487682399200
       2487682399184
                   1
     140717662892226
 2305843009213693952
       2487682399264

julia> Vector{Int64}(undef, 2^63)  # Note: 2^63 < 0. Not exactly "too large" (same for any negative length, e.g. -1)
ERROR: ArgumentError: invalid GenericMemory size: too large for system address width
Stacktrace:
 [1] GenericMemory
   @ .\boot.jl:516 [inlined]
 [2] Vector{Int64}(::UndefInitializer, m::Int64)
   @ Core .\boot.jl:578
 [3] top-level scope
   @ REPL[5]:1

julia> Vector{Int64}(undef, 2^64)  # (This is expected as 2^64 == 0 for (U)Int64)
Int64[]
3 Likes