Opened 10 months ago

Last modified 3 months ago

#15883 patch bug

GHC panic: newtype F rep = F (forall (a :: TYPE rep). a)

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 8.6.2
Keywords: LevityPolymorphism, TypeInType Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash or panic Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4777,
Wiki Page:


{-# Language RankNTypes     #-}
{-# Language KindSignatures #-}
{-# Language PolyKinds      #-}

import GHC.Exts

newtype Foo rep = MkFoo (forall (a :: TYPE rep). a)
$ ~/code/unmodifiedghc/inplace/bin/ghc-stage2 --interactive -ignore-dot-ghci /tmp/U.hs
GHCi, version 8.7.20181029:  :? for help
[1 of 1] Compiling Main             ( /tmp/U.hs, interpreted )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.7.20181029 for x86_64-unknown-linux):
  forall (a :: TYPE rep_a1AA[sk:0]). a :: TYPE rep_a1AA[sk:0]
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
        pprPanic, called at compiler/types/Type.hs:2332:10 in ghc:Type
        isUnliftedType, called at compiler/typecheck/TcTyClsDecls.hs:3055:25 in ghc:TcTyClsDecls

Please report this as a GHC bug:


Change History (7)

comment:1 Changed 10 months ago by Iceland_jack

Relate to #13929? At least similar error

comment:2 Changed 10 months ago by RyanGlScott

Component: CompilerCompiler (Type checker)
Keywords: LevityPolymorphism TypeInType added
Type of failure: None/UnknownCompile-time crash or panic

comment:3 Changed 9 months ago by bgamari

Milestone: 8.6.3

Ticket retargeted after milestone closed

comment:4 Changed 8 months ago by andrewthad

This is fixed (rather accidentally) by the implementation of the UnliftedNewtypes proposal, which is not yet merged.

comment:5 Changed 8 months ago by RyanGlScott

Differential Rev(s): Phab:D4777
Status: newpatch

comment:6 Changed 7 months ago by RyanGlScott

Differential Rev(s): Phab:D4777Phab:D4777,

comment:7 Changed 3 months ago by Marge Bot <ben+marge-bot@…>

In effdd948/ghc:

Implement the -XUnliftedNewtypes extension.

GHC Proposal: 0013-unlifted-newtypes.rst
Issues: #15219, #1311, #13595, #15883
Implementation Details:
  Note [Implementation of UnliftedNewtypes]
  Note [Unifying data family kinds]
  Note [Compulsory newtype unfolding]

This patch introduces the -XUnliftedNewtypes extension. When this
extension is enabled, GHC drops the restriction that the field in
a newtype must be of kind (TYPE 'LiftedRep). This allows types
like Int# and ByteArray# to be used in a newtype. Additionally,
coerce is made levity-polymorphic so that it can be used with
newtypes over unlifted types.

The bulk of the changes are in TcTyClsDecls.hs. With -XUnliftedNewtypes,
getInitialKind is more liberal, introducing a unification variable to
return the kind (TYPE r0) rather than just returning (TYPE 'LiftedRep).
When kind-checking a data constructor with kcConDecl, we attempt to
unify the kind of a newtype with the kind of its field's type. When
typechecking a data declaration with tcTyClDecl, we again perform a
unification. See the implementation note for more on this.

Co-authored-by: Richard Eisenberg <>
Note: See TracTickets for help on using tickets.