[GHC] #11172: Turning on optimisations produces Impossible case alternative

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Runtime crash Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 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 (`-O0`). Please see https://github.com/fpco/impossible-case-alternative-repro 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 `-O0`. What certainly surprised me is that when replacing {{{ (do p <- earlyExit <* error "bad" return p) }}} with {{{ (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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton):
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`.
It is a GHC bug. Are you sure you have seen GHC ask you to report a bug when running a program compiled by GHC (other than GHC itself)? I don't think that ever happens. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Are you sure you have seen GHC ask you to report a bug when running a
#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Replying to [comment:1 rwbarton]: program compiled by GHC (other than GHC itself)? I don't think that ever happens. I think you are right, I got confused it with ghci (where I both compiled and ran something, as in #1130). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I'd like to reproduce, but I get this (with the current HEAD). Any suggestions, anyone? {{{ bash$ cabal install --with-ghc=/home/simonpj/5builds/HEAD-4/inplace/bin /ghc-stage2 Resolving dependencies... cabal: Could not resolve dependencies: trying: impossible-case-alternative-repro-0.0 (user goal) trying: base-4.9.0.0/installed-4.9... (dependency of impossible-case-alternative-repro-0.0) trying: either-4.4.1 (dependency of impossible-case-alternative-repro-0.0) trying: semigroupoids-5.0.0.4 (dependency of either-4.4.1) trying: semigroupoids-5.0.0.4:+tagged trying: semigroupoids-5.0.0.4:+comonad trying: comonad-4.2.7.2 (dependency of semigroupoids-5.0.0.4:+comonad) trying: comonad-4.2.7.2:+distributive trying: comonad-4.2.7.2:+contravariant trying: contravariant-1.3.3 (dependency of comonad-4.2.7.2:+contravariant) trying: void-0.7.1 (dependency of contravariant-1.3.3) next goal: hashable (dependency of void-0.7.1) rejecting: hashable-1.2.3.3, 1.2.3.2 (conflict: base==4.9.0.0/installed-4.9..., hashable => base>=4.0 && <4.9) rejecting: hashable-1.2.3.1, 1.2.3.0, 1.2.2.0, 1.2.1.0, 1.2.0.10, 1.2.0.9, 1.2.0.8, 1.2.0.7, 1.2.0.6, 1.2.0.5, 1.2.0.4, 1.2.0.3, 1.2.0.2, 1.2.0.1, 1.2.0.0, 1.1.2.5, 1.1.2.4, 1.1.2.3 (conflict: base==4.9.0.0/installed-4.9..., hashable => base>=4.0 && <4.8) rejecting: hashable-1.1.2.2, 1.1.2.1, 1.1.2.0, 1.1.1.0, 1.1.0.0 (conflict: base => ghc-prim==0.5.0.0/installed-0.5..., hashable => ghc-prim<0.3) rejecting: hashable-1.0.1.1, 1.0.1.0, 1.0.0 (conflict: void => hashable>=1.1) Dependency tree exhaustively searched. }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Simon, for reproducing with GHC 8 HEAD it seems a little more effort is needed, but it seems to work for me this way: * From my repro, use the `ghc-8-head` branch instead (https://github.com/fpco/impossible-case-alternative- repro/tree/ghc-8-head); use `cabal install --with-ghc=...` as you did, it will now break at compiling `aeson` because that's not yet GHC 8 ready; ignore that issue * Use my custom `aeson` version from https://github.com/nh2/aeson/tree/ghc-8-head-workaround, which should compile with `cabal install --with-ghc=...` Then you should be able to `ghc --make` with GHC head. Please let me know if it works! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I fell at the first fence. I downloaded your custom `aeson`, cd'd into its directory. Then {{{ bash$ cabal install --with-ghc=/home/simonpj/5builds/HEAD-4/inplace/bin /ghc-stage2 Resolving dependencies... cabal: Could not resolve dependencies: trying: aeson-0.10.0.0 (user goal) trying: base-4.9.0.0/installed-4.9... (dependency of aeson-0.10.0.0) next goal: vector (dependency of aeson-0.10.0.0) rejecting: vector-0.11.0.0 (conflict: base==4.9.0.0/installed-4.9..., vector => base>=4.3 && <4.9) trying: vector-0.10.12.3 next goal: primitive (dependency of vector-0.10.12.3) rejecting: primitive-0.6.1.0, 0.5.4.0 (conflict: base==4.9.0.0/installed-4.9..., primitive => base>=4.3 && <4.9) rejecting: primitive-0.5.3.0, 0.5.2.1 (conflict: base==4.9.0.0/installed-4.9..., primitive => base>=4.3 && <4.8) rejecting: primitive-0.5.1.0 (conflict: base==4.9.0.0/installed-4.9..., primitive => base>=4 && <4.8) rejecting: primitive-0.5.0.1 (conflict: base==4.9.0.0/installed-4.9..., primitive => base>=4 && <4.7) rejecting: primitive-0.5, 0.4.1, 0.4.0.1, 0.4, 0.3.1, 0.3, 0.2.1, 0.2, 0.1 (conflict: vector => primitive>=0.5.0.1 && <0.7) rejecting: primitive-0.6 (conflict: base==4.9.0.0/installed-4.9..., primitive => base>=4.3 && <4.9) Dependency tree exhaustively searched. simonpj@cam-05-unx:~/tmp/aeson-ghc-8-head-workaround$ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Ah, you'd have to use `cabal` with `--allow-newer`, both for the first invocation in my repro until cabal fails installing aeson, and then for the invocation and for aeson as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): I just learned from our application that this bug can also lead to `segmentation fault` instead of `Impossible case alternative`. Consequently I'm very eager to contribute anything necessary to find a solution ;) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): I got this far using HEAD: {{{ Preprocessing library free-4.12.1... [ 1 of 16] Compiling Control.Monad.Free.TH ( src/Control/Monad/Free/TH.hs, dist/build/Control/Monad/Free/TH.o ) src/Control/Monad/Free/TH.hs:235:5: error: • The constructor ‘DataConI’ should have 3 arguments, but has been given 4 • In the pattern: DataConI _ _ tname _ In a case alternative: DataConI _ _ tname _ -> genFree typeSig (Just [cname]) tname In a stmt of a 'do' block: case info of { DataConI _ _ tname _ -> genFree typeSig (Just [cname]) tname _ -> fail "makeFreeCon expects a data constructor" } Failed to install free-4.12.1 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Here is a workaround: use `-fno-cse`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Are you sure you have seen GHC ask you to report a bug when running a
#11172: Turning on optimisations produces Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): (Small digression:) Replying to [comment:1 rwbarton]: program compiled by GHC (other than GHC itself)? I don't think that ever happens. @rwbarton: Actually, I did find such a case, I have one right here: A yesod webserver that when compiled without `-threaded`, and Ctrl-C'd, throws the following error: {{{ src/main/Main Development ^CMain: internal error: removeFromQueues: 22294 (GHC version 7.10.2 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): I managed to reproduce the `segmentation fault` now! See branch `segfault`, https://github.com/fpco/impossible-case- alternative-repro/tree/segfault (Note that that branch is only for GHC <= 7.10, I'd have to make the same adjustments as for the other repro to make it work on GHC 8 HEAD, if that is desired.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Hmm, I'm afraid I'm having some trouble reproducing this on 7.10.2, {{{ $ ghc --make -O -Wall Main.hs -fforce-recomp && ./Main [1 of 2] Compiling Module ( Module.hs, Module.o ) Module.hs:34:1: Warning: The import of ‘Control.Applicative’ is redundant except perhaps to import instances from ‘Control.Applicative’ To import instances alone, use: import Control.Applicative() [2 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:7:1: Warning: The import of ‘Control.Applicative’ is redundant except perhaps to import instances from ‘Control.Applicative’ To import instances alone, use: import Control.Applicative() Linking Main ... Main: Impossible case alternative [1826 ben@ben-laptop impossible-case-alternative-repro(master)] $ ghc -V The Glorious Glasgow Haskell Compilation System, version 7.10.2 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Replying to [comment:8 thomie]:
I got this far using HEAD:
{{{ Preprocessing library free-4.12.1... }}}
@thomie: On the branch `ghc-8-head` branch it shouldn't try to install `free` (at least it's not in my `ghc-pkg list`). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Replying to [comment:12 bgamari]:
Hmm, I'm afraid I'm having some trouble reproducing this on 7.10.2, {{{ Module.hs:34:1: Warning: The import of ‘Control.Applicative’ is redundant }}}
@bgamari: I think you are on the `master` branch - for reproducing the segfault you need to go on the `segfault` branch of my repo, and on that one the `Control.Applicative` import is on a different line than in your warning: https://github.com/fpco/impossible-case-alternative- repro/blob/segfault/Module.hs#L44 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * priority: normal => highest Comment: We should really try to get to this for 8.0.1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * owner: => bgamari Comment: Ben will try to reproduce on 8.0 or HEAD. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Alright, I am able to reproduce this on `master`, {{{ $ git clone git://github.com/bgamari/impossible-case-alternative-repro repro $ cd repro $ git checkout segfault $ git clone git://github.com/bos/aeson $ cabal install aeson $ ghc -O Main.hs $ ./Main "before eval" Segmentation fault $ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): The issue here is clearly, {{{#!hs Main.main5 :: (Either () GHC.Prim.Any, Module.JSONState Mytype) -> Either String (Either () Float, Module.JSONState ()) Main.main5 = \ (a31_XcHt :: (Either () GHC.Prim.Any, Module.JSONState Mytype)) -> case a31_XcHt of _ [Occ=Dead] { (a26_XdKv, s'_XdKx) -> case a26_XdKv of _ [Occ=Dead] { Left e1_adOn -> case s'_XdKx of _ [Occ=Dead] { Module.JSONState ds1_XcmP ns'_XagP ds2_XcmS -> Data.Either.Right @ String @ (Either () Float, Module.JSONState ()) (Data.Either.Left @ () @ Float e1_adOn, Module.JSONState @ () (GHC.Types.[] @ String) ns'_XagP GHC.Tuple.()) }; Right x_XdQJ -> case Main.main6 of wild2_00 { } -- uh oh } } }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): This appears rather early during simplification. Namely after, {{{ SimplMode {Phase = 2 [main], inline, rules, eta-expand, case-of-case} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): I should note that, distressingly enough, this testcase passes both STG linting and Core linting. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Ben says that with with GHC 7.10 you should just be able to do {{{ $ git clone git://github.com/bgamari/impossible-case-alternative-repro repro $ cd repro $ git checkout master $ cabal install --with- ghc=/home/simonpj/5builds/ghc-7.10-branch/inplace/bin/ghc-stage2 }}} and get the "impossible case alternative" error message. Simpler because 7.10 can work with older packages. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative
-------------------------------------+-------------------------------------
Reporter: nh2 | Owner: bgamari
Type: bug | Status: new
Priority: highest | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Runtime crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by bgamari):
It appears that this,
{{{#!hs
(\ (a48_aeBK :: (Either () Int, Module.JSONState Double)) ->
case a48_aeBK of _ [Occ=Dead] { (a1_aeN0, s'_aeN1) ->
case a1_aeN0 of _ [Occ=Dead] {
Left l_aeDR ->
ks_XeD2 (Data.Either.Left @ () @ Int l_aeDR,
s'_aeN1);
Right r_aeDU ->
ks_XeD2 (Data.Either.Right @ () @ Int r_aeDU,
s'_aeN1)
}
})
}}}
is getting simplified to,
{{{#!hs
(\ (a48_aeBK :: (Either () Int, Module.JSONState Double)) ->
case a48_aeBK
of _ [Occ=Dead, Dmd=], s'_aeN1 [Dmd=])
->
case a1_aeN0 of _ [Occ=Dead, Dmd=

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by jscholl): * Attachment "SmallExample.hs" added. Small example triggering the bug -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jscholl): I tried to break down the input data and arrieved at the following program triggering this bug. I derived it by taking the core before the bad transformation and simplified it. It still fails with an impossible case alternative when compiled with optimizations, but works without themIt is a lot smaller than the original code, so hopefully this helps in tracking down this bug. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:23 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): jscholl: nice work. {{{ $ ghc-head SmallExample.hs -fforce-recomp -O [1 of 1] Compiling Main ( SmallExample.hs, SmallExample.o ) Linking SmallExample ... $ ./SmallExample SmallExample: Impossible case alternative }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:24 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): jscholl: very very helpful, thank you. With your nice small case I nailed the bug in 15 mins. Patch coming. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:25 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative
-------------------------------------+-------------------------------------
Reporter: nh2 | Owner: bgamari
Type: bug | Status: new
Priority: highest | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Runtime crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative
-------------------------------------+-------------------------------------
Reporter: nh2 | Owner: bgamari
Type: bug | Status: new
Priority: highest | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Runtime crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): OK thanks to jscholl the bug is fixed. But I am still eager to know why this could give a **seg-fault**. An "impossible alternative" message perhaps; but a seg-fault is more worrying. Ben describes how to elicit the seg-fault in comment:17. (NB: you need the `segfault` branch of his repo.) jscholl: if you could repeat your amazing work on this variant, to make a much smaller seg-faulting test case, that would be amazing. (Of course it is always possible that there are two bugs, and I have only fixed one; another reason to investigate the seg-fault variant.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:28 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by jscholl): * Attachment "Segfault.tar.gz" added. Smaller example triggering the segfault. Does not typecheck with 8.0-rc1... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jscholl): Ok, I think the segfault boils down to: Somewhere something expects to only recieve a {{{Right}}} constructor and then gets passed a {{{Left}}}. Hence the pointer is tagged with a 1 but should be tagged with a 2, we add 6 to access the contents and read the wrong memory. I think this could be related to the previous bug (only that this time the simplifier removes the impossible case alternative, so we do not enter an exception but this segfault in the case). To test this I first tried to run the example with ghc-8.0-rc1, but somehow it does not typecheck... I just get {{{ [1 of 2] Compiling Module ( Module.hs, Module.o ) Module.hs:28:38: error: • Couldn't match kind ‘GHC.Prim.Any’ with ‘*’ When matching the kind of ‘Either [Char]’ • In the third argument of ‘runParser’, namely ‘onError’ In the expression: runParser (m v) [] onError Right In an equation for ‘parseEither’: parseEither m v = runParser (m v) [] onError Right where onError _ = Left "Error in " }}} ghc-7.10.3 works fine, though. So maybe this is another regression? I just though the fix would work best with a current ghc. Anyway, here's the code. It's not as short as last time, sadly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:29 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jscholl): I tried the fix with ghc-7.10.3 and the segfault vanished. If I compare the core it is almost identical, the only difference is that the fixed version generates a {{{Left}}} and a {{{Right}}} branch in Main.main3 while without the fix the {{{Left}}} branch is missing. So I think the segfault is really just another instance of the bug in the simplifier. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:30 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): So it works with 7.10.3 and 8.0 rc1. So in which version does it seg- fault? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:31 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jscholl): It only works when I manually include the important bits of 514bac2/ghc, otherwise it seg-faults. So the only working version right now should be HEAD as the fix dos not seem to be included any other branch yet. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:32 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I think I misunderstood. I think you are saying that it segfaults with an un-modified 7.10.3. That's fine; I can investigate. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:33 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Simon's fix has been merged to `ghc-8.0` as fc5f85768c297c51a2366aa8af8afa33a85dd19c. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:34 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Thanks. So we are now convinced that there is only one bug. I wish that Core Lint checked for this; so I've opened #11475 to ask for help with that. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:35 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:36 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11172: Turning on optimisations produces SEGFAULT or Impossible case alternative -------------------------------------+------------------------------------- Reporter: nh2 | Owner: bgamari Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Excellent, thank you Simon for the fix! Also thanks to bgamari for the updated reproduction and jscholl for the further minimised test case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11172#comment:37 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC