Ghci does not terminate cleanly after Stack Overflow Error
In certain cases, after a Stack Overflow occurs, Ghci threads are not correctly cleaned up, letting them linger with 100% CPU usage.
Steps to reproduce
data X a = X instance Show a => Show (X a) where x = show (X :: X Int)
> ghci Err.hs +RTS -M2G -K100M -RTS -e "x" Err.hs:2:10-29: warning: [-Wmissing-methods] • No explicit implementation for either ‘showsPrec’ or ‘show’ • In the instance declaration for ‘Show (X a)’ | 2 | instance Show a => Show (X a) where | ^^^^^^^^^^^^^^^^^^^^ <interactive>: stack overflow
However, this computation does not terminate and you can verify in
htop that there is at least one
ghc thread with 100% CPU usage.
Note, that you can get the desired behaviour, if you omit the typeclass constraint on
a in the Instance declaration. (Assume file
data X a = X instance Show (X a) where x = show (X :: X Int)
Now the invocation
ghci Ok.hs +RTS -M2G -K100M -RTS -e "x" terminates with a
Stack Overflow correctly.
Moreover, reducing the amount of stack (e.g. to
-K1M) also solves the issue.
Eventually terminate with a
What do you expect the reproducer described above to do?
It will not terminate and also not react on ctrl+c or other signals. You have to send sigkill to it.
- GHC version used: 8.8.4
- Operating System: NixOS
- System Architecture: x86_64