error "I’m still alive?"`.
#1600: Optimisation: CPR the results of IO -------------------------------------+------------------------------------- Reporter: simonmar | Owner: nomeata Type: task | Status: new Priority: lowest | Milestone: 7.6.2 Component: Compiler | Version: 6.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Runtime | Difficulty: Moderate (less performance bug | than a day) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by nomeata): * owner: => nomeata Comment: Interesting corner case: With nested CPR enabled, `GHC.TopHandler` in base fails to compile with: {{{ ghc-stage1: panic! (the 'impossible' happened) (GHC version 7.7.20131203 for x86_64-unknown-linux): mkWWcpr: non-algebraic or open body type a{tv a28d} [tv] but CPR type tm1() }}} The problem is this code: {{{ #!haskell case {__pkg_ccall_GC base shutdownHaskellAndExit GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.State# GHC.Prim.RealWorld -> (# GHC.Prim.State# GHC.Prim.RealWorld #)}_d2VI 255 ds_d2VF eta_XG of _ [Occ=Dead, Dmd=<L,A>] { (# ds_d2VG [OS=OneShot] #) -> (# ds_d2VG, GHC.Tuple.() #) }}} stemming from {{{ #!haskell foreign import ccall "shutdownHaskellAndSignal" shutdownHaskellAndSignal :: CInt -> CInt -> IO () }}} which then is `unsafeCoerce#`’ed to `a`, with note explanation {{{ -- we have to use unsafeCoerce# to get the 'IO a' result type, since the -- compiler doesn't let us declare that as the result type of a foreign export. }}} There are a few ways to attack this issue: 1. We allow `a` in the return type of a foreign export (but maybe overkill to do that just for this code). 2. We try to forget CPR information when things pass through `unsafeCoerce#` (but that is just a {{{`cast`}}} in Core, and may be hard to detect reliably. Maybe every coercion that has a `UnivCo representational` inside?) 3. We re-write that code in base, e.g. instead of `unsafeCoerce` use `... 4. We simply turn the `panic` into a warning. I guess 2. makes most sense, because we don’t want other instances of `unsafeCoerce#` to cause this error either. For now I’ll do 4, to not get stuck compiling base. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/1600#comment:25> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler