Opened 3 years ago

Closed 3 years ago

#12709 closed bug (fixed)

GHC panic

Reported by: Iceland_jack Owned by:
Priority: normal Milestone: 8.2.1
Component: Compiler Version: 8.0.1
Keywords: LevityPolymorphism Cc: nfrisby
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_fail/T12709
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I get

$ ./ghc-stage2 -ignore-dot-ghci --interactive /tmp/tEZm.hs
GHCi, version 8.1.20160930: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /tmp/tEZm.hs, interpreted )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.1.20160930 for x86_64-unknown-linux):
        kindPrimRep.go
  rep_a13E
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1076:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1080:37 in ghc:Outputable
        pprPanic, called at compiler/simplStg/RepType.hs:369:9 in ghc:RepType
        kindPrimRep, called at compiler/simplStg/RepType.hs:337:18 in ghc:RepType
        typePrimRep, called at compiler/ghci/ByteCodeGen.hs:1541:15 in ghc:ByteCodeGen

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

> 

running

{-# Language MagicHash, PolyKinds, ViewPatterns, TypeInType, RebindableSyntax, NoImplicitPrelude #-}

import GHC.Types
import Prelude hiding (Num (..))
import qualified Prelude as P
import GHC.Prim

data BoxUnbox = BUB Int Int#

class Num (a :: TYPE rep) where
  (+) :: a -> a -> a

  fromInteger :: Integer -> a

instance Num Int where
  (+) = (P.+)
  fromInteger = P.fromInteger

instance Num Int# where
  (+) = (+#)
  fromInteger (fromInteger -> I# n) = n

a :: BoxUnbox
a = let u :: Num (a :: TYPE rep) => a
        u = 1 + 2 + 3 + 4
     in
        BUB u u

Change History (7)

comment:1 Changed 3 years ago by Iceland_jack

Btw this works,

data BoxUnbox = BUB Int Int#

a :: (forall rep (a :: TYPE rep). Num a => a) -> BoxUnbox
a u = BUB u u

as does this

b :: BoxUnbox
b = do
  let u :: forall rep (a :: TYPE rep). Num a => a
      u = 24
  BUB u u

and it looks like it fails on more complicated numerical equations

--   × × × FAILS × × ×
a_applied :: BoxUnbox
a_applied = a (1 + 2 + 3)

--   × × × FAILS × × ×
b' :: BoxUnbox
b' = do
  let u :: forall rep (a :: TYPE rep). Num a => a
      u = 1 + 2 + 3
  BUB u u

comment:2 Changed 3 years ago by nfrisby

I don't know if it's exactly the same as this ticket, but I get a similar panic from the following minimization.

{-# Language TypeFamilies, TypeInType #-}

import Data.Kind (Type)

data U = U

type family A (k :: Type) :: Type where
  A U = Type

type family B (ty :: k) :: A k

bad :: B 'U -> U
bad _ = U

That gives the following panic when loaded in GHCi.

ghc.exe: panic! (the 'impossible' happened)
  (GHC version 8.0.1 for x86_64-unknown-mingw32):
        kindPrimRep.go U

It does not panic when compiling with GHC.

comment:3 Changed 3 years ago by nfrisby

Cc: nfrisby added

comment:4 Changed 3 years ago by simonpj

Keywords: LevityPolymorphism added

We should rejec

a :: BoxUnbox
a = let u :: Num (a :: TYPE rep) => a
        u = 1 + 2 + 3 + 4

because application 1 + blah has a levity-polymorphic argument. See the paper.

comment:5 Changed 3 years ago by Richard Eisenberg <rae@…>

In dca44adb/ghc:

Fix #12709 by not building bad applications

In an effort to report multiple levity polymorphism errors all at
once, the desugarer does not fail when encountering bad levity
polymorphism. But we must be careful not to build the bad applications,
lest they try to satisfy the let/app invariant and call
isUnliftedType on a levity polymorphic type. This protects calls
to mkCoreAppDs appropriately.

test case: typecheck/should_fail/T12709

comment:6 Changed 3 years ago by goldfire

Milestone: 8.2.1
Status: newmerge
Test Case: typecheck/should_fail/T12709

Please merge for 8.2.

comment:7 Changed 3 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.