GHC 9.12.4 crashes when compiling program (Non-exhaustive patterns in dmd : cont_dmds)
## Summary
GHC 9.12 crashes when compiling a program, but GHC 9.10 or older successfully compile it, as well as GHC 9.14 or later.
## Steps to reproduce
Compile the following program with GHC 9.12.4:
```hs
module Bug (foo) where
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import GHC.Stack (HasCallStack)
foo :: HasCallStack => Int -> Map.Map Int Bool -> StateContT s r IO ()
foo i m = do
t <- pure $ Maybe.fromMaybe (error "no entry") $ Map.lookup i m
_ <- case bar t of
Left err -> error err
Right x -> return x
return ()
bar :: Bool -> Either String String
bar t = if t == t then Left "Left" else Right "Right"
newtype StateContT s r m a
= StateContT { runStateContT :: (a -> s -> m r)
-> s
-> m r
}
instance Functor (StateContT s r m) where
fmap f m = StateContT $ \c -> runStateContT m (\v s -> (c $! f v) s)
instance Applicative (StateContT s r m) where
pure v = seq v $ StateContT $ \c -> c v
mf <*> mv =
StateContT $ \c ->
runStateContT mf (\f -> runStateContT mv (\v s -> (c $! f v) s))
instance Monad (StateContT s r m) where
m >>= n = StateContT $ \c -> runStateContT m (\a -> runStateContT (n a) c)
```
```
$ ghc-9.12.4 Bug.hs -O -fforce-recomp
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
<no location info>: error:
compiler/GHC/Core/Opt/Simplify/Iteration.hs:3942:15-36: Non-exhaustive patterns in dmd : cont_dmds
```
Other versions of GHC successfully compile this program (e.g., `ghc-9.14.1`). Since this appears to be fixed in 9.14, could the commit that fixed this issue be backported to the `ghc-9.12` branch?
## Expected behavior
I would expect the program to compile successfully, as it does with other GHC versions.
## Environment
* GHC version used: 9.12.4
issue