Skip to content

ghc-9.4.* stack space overflows if optimization is explicitly set to off (with -O0)

Summary

In the GHC user's guide on -Ksize it says that the default is to use 80% of physical memory but that doesn't seem to add up on this machine.

$ vmstat --stats
     65634356 K total memory
...
$ cabal build all --enable-tests --enable-benchmarks
Resolving dependencies...
Build profile: -w ghc-9.4.5 -O1
...
ghc-9.4.5: Stack space overflow: current size 33624 bytes.
ghc-9.4.5: Use `+RTS -Ksize -RTS' to increase it.

I was able to compile this module no problem in ghc-8.10.7 and ghc-9.2.7.

Here's a snippet about -K <size> from the users' guide:

Default: 80% of physical memory

Set the maximum stack size for an individual thread to ⟨size⟩ bytes. If the thread attempts to exceed this limit, it will be sent the StackOverflow exception. The limit can be disabled entirely by specifying a size of zero.

This option is there mainly to stop the program eating up all the available memory in the machine if it gets into an infinite loop.

Environment

Ubuntu 22.04.2 LTS

Edited by Phil de Joux
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information