heap overflow panic with 9.2 (but not 9.0 or 9.4)
Summary
We observed a failure when compiling code in the BSC project with GHC 9.2.8, that does not occur when compiling with earlier GHC 9.0.2 or later GHC 9.4.6 and 9.6.2. We have boiled it down to a small two-file example, in case you wanted to investigate -- in case the issue still exists in 9.4+ and is just being masked. The error we see is:
[1 of 2] Compiling Util ( Util.hs, Util.o )
[2 of 2] Compiling GenABin ( GenABin.hs, GenABin.o )
ghc-9.2.8: panic! (the 'impossible' happened)
(GHC version 9.2.8:
heap overflow
Steps to reproduce
Place the following three files in a directory and run make
:
Util.hs (20 lines),
GenABin.hs (365 lines),
Makefile. That will run the following command:
ghc \
-O2 \
-hide-all-packages \
-Wall \
-fno-warn-unused-binds \
-package base \
-package bytestring \
-package containers \
-package text \
+RTS -M4G -A128m -RTS \
GenABin.hs
The file Util.hs
contains two small definitions that are imported by the top file GenABin.hs
. If those definitions are merged into the top file, then it compiles without error. So the separation into two files is necessary. If the numbers of fields of the Flags
datatype is reduced (from 125 to a dozen or so), then it compiles fine; so many fields is necessary (though we haven't experimented with other amounts). Without the RTS flags, I think that GHC starts to use up all the memory and swaps, so the RTS flags may be necessary to get it to fail early.
I can't determine if this is a duplicate of existing issues. For example, #20683.
Expected behavior
If I try with GHC 9.4.6, it compiles without an error:
[1 of 2] Compiling Util ( Util.hs, Util.o )
[2 of 2] Compiling GenABin ( GenABin.hs, GenABin.o )
Environment
I observe these behaviors on both macOS 11.7.8 (x86_64) and Debian 11.7 (x86_64).