Opened 6 years ago
Closed 6 years ago
#7729 closed bug (fixed)
GHC panics. Invalid core
Reported by: | Khudyakov | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 7.6.3 |
Component: | Compiler | Version: | 7.6.2 |
Keywords: | Cc: | ekmett@… | |
Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
Type of failure: | None/Unknown | Test Case: | indexed_types/should_fail/T7729,T7729a |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Rev(s): | ||
Wiki Page: |
Description
Following code snippet triggers panic:
{-# LANGUAGE FlexibleContexts, TypeFamilies #-} module Monad where class Monad m => PrimMonad m where type PrimState m class MonadTrans t where lift :: Monad m => m a -> t m a class (PrimMonad (BasePrimMonad m), Monad m) => MonadPrim m where type BasePrimMonad m :: * -> * liftPrim :: BasePrimMonad m a -> m a newtype Rand m a = Rand { runRand :: Maybe (m ()) -> m a } instance (Monad m) => Monad (Rand m) where return = Rand . const . return (Rand rnd) >>= f = Rand $ \g -> (\x -> runRand (f x) g) =<< rnd g instance MonadTrans Rand where lift = Rand . const instance MonadPrim m => MonadPrim (Rand m) where type BasePrimMonad (Rand m) = BasePrimMonad m liftPrim = liftPrim . lift
GHC 7.6.2 panics
$ ghc-7.6.2 -c Monad.hs ghc: panic! (the 'impossible' happened) (GHC version 7.6.2 for x86_64-unknown-linux): cgLookupPanic (probably invalid Core; try -dcore-lint) $dMonadTrans{v ahe} [lid] static binds for: local binds for: main:Monad.lift{v ra} [gid[ClassOp]] main:Monad.liftPrim{v rc} [gid[ClassOp]] main:Monad.$p1PrimMonad{v rgv} [gid[ClassOp]] main:Monad.$p1MonadPrim{v rgA} [gid[ClassOp]] main:Monad.$p2MonadPrim{v rgB} [gid[ClassOp]] Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
whereas 7.4.2 reports type error
$ ghc-7.4.2 -c Monad.hs Monad.hs:28:14: Occurs check: cannot construct the infinite type: m0 = t0 m0 Expected type: BasePrimMonad (Rand m) a -> Rand m a Actual type: m0 a -> Rand m a In the expression: liftPrim . lift In an equation for `liftPrim': liftPrim = liftPrim . lift
Change History (6)
comment:1 Changed 6 years ago by
difficulty: | → Unknown |
---|
comment:2 Changed 6 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Test Case: | → indexed_types/should_fail/T7729,T7729a |
comment:3 Changed 6 years ago by
Cc: | ekmett@… added |
---|
Had a user bitten by this one today:
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-} module Test where import Control.Lens newtype A a = A a deriving (Show) asA :: Iso' a (A a) asA = iso A $ \(A x) -> x f :: (Ord a, Eq a) => a -> [(a,b)] -> Maybe b f _ _ = Nothing ‗‗ type instance Index (A a) = a instance (Gettable f, Ord a) => Contains f (A a) where contains = containsLookup (\k m -> f k (m ^. from asA)) thing :: A a thing = view asA [] main = print $ thing ^. from asA
It causes
$ ghc --make Test.hs [1 of 1] Compiling A ( Test.hs, Test.o ) ghc: panic! (the 'impossible' happened) (GHC version 7.6.2 for x86_64-unknown-linux): cgLookupPanic (probably invalid Core; try -dcore-lint) $dMonadReader{v a2W4} [lid] static binds for: local binds for: Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
on 7.4.1 I get
localhost:wl-pprint-terminfo ekmett$ ghci ~/Cube.hs GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. /Users/ekmett/Cube.hs:17:14: Occurs check: cannot construct the infinite type: a3 = [(a3, a2)] Expected type: Index (A a) -> p Bool (f Bool) -> A a -> f (A a) Actual type: a3 -> p Bool (f Bool) -> A a -> f (A a) In the return type of a call of `containsLookup' In the expression: containsLookup (\ k m -> f k (m ^. from asA))
This http://hpaste.org/raw/83760 contains the result of -dcore-lint
.
comment:4 Changed 6 years ago by
Milestone: | → 7.6.3 |
---|---|
Resolution: | wontfix |
Status: | closed → new |
Haev you checked whether it's fixed in HEAD, as this ticket claims? Currently it's a bit of a guess that it's the same bug, isn't it?
It's bad that 7.6 fails here. I hate the idea of the main extant compiler being broken; very un-keen on tracking it down given that the benefit will be for a matter of months only. Well, I suppose the next HP is likely to use 7.6.
It's a balance with how painful it is. Keep saying if it is!
I think I'll re-open anyway.
Simon
comment:5 Changed 6 years ago by
For the record, I confirm that ekmett's program and the original ticket concerns exactly the same bug, fixed in HEAD. Both programs can be reduced to http://hpaste.org/88612, which crashes 7.6 and gives occurs check in 7.7. I don't think this bug is worth hunting and releasing another 7.6.x - I would close it.
comment:6 Changed 6 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
OK, thanks for checking!
Simon
Interesting. With HEAD we get
If you change the offending line to
then we get a different erro rmessage
Although these errors look different, they are acutally pretty similar.
GHC 7.6.2 fails to reject the program, but gives a Lint error if you use
-docore-lint
. I don't propose to try to fix this... too obscure. I'll add a regression test thought. Thank you for the example.Simon