Turning on optimisations produces SEGFAULT or Impossible case alternative
I believe I've found a bug that makes GHC generate the "Impossible case alternative" run-time crash with optimisations turned on (
-O), which does not happen in ghci or without optimisations (
for a reproduction with GHC 7.10 and 7.8.
What seems to happen here is that when
fun2 is inlined, the simplifier (or whatever component) decides that some
case (I haven't figured out yet which one) is impossible; you can clearly see how it gets fixed in the Core when adding a
NOINLINE fun2 and compiling with
-ddump-simpl. I believe this difference in inlining is also why
-O makes a difference vs
What certainly surprised me is that when replacing
(do p <- earlyExit <* error "bad" return p)
(earlyExit <* error "bad")
the error goes away as well.
Note that I'm using some TemplateHaskell around that block; I'm wondering whether that somehow leads to an unfortunate interaction with the simpilifier.
First thing I'd appreciate is somebody to tell me: Is this a real bug or something GHC allows itself to do? Since for most other run-time errors, GHC asks me to report a bug, but it doesn't do so for
Impossible case alternative.
I would have liked to make a smaller reproduction (currently it needs 2 files and aeson as an external depencency), but if I shrink it any further the error goes away. So for now I hope that a 150 line repro in 2 files will do.
We have reproduced this on Linux and Mac, but I'm quite confident that it's platform-independent.
I'm setting the milestone for this to 8.0.1 because this is a problem that makes some real-world trouble for us, feel free to change back if that's inappropriate.