Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
ocamlopt, ocaml, ocamlc, Stack Overflow on large hardcoded arrays. #4405
Original bug ID: 4405
If a .ml file contains an array that is of large size, ocamlopt(.opt).exe, ocaml.exe and ocamlc.(opt).exe all crash with a Stack Overflow exception. It happens if the array has 274 896 elements, but not if it has 60 000 elements. If I split the array in smaller parts and then I call Array.concat to merge them into the original array, the resulting program will work correctly.
In the attachment, crash.ml has a single 274 896 arrays and will crash all the aforementioned programs, whereas no-crash.ml has splitted the array in five parts and doesn't crash (and, FWIW, can Array.iter and Array.get without trouble).
Windows X86, OCaml 3.10.0 / MinGW.
Comment author: @xavierleroy
The compilers use stack space proportional to the size of the array expression. So, yes, you can get stack overflow conditions at compile-time. With the "non-opt" compilers ocamlc, ocamlopt, you can easily increase the stack space available to the compiler: set the OCAMLRUNPARAM environment variable to e.g.