diff options
author | Andrew Martin <andrew.thaddeus@gmail.com> | 2019-05-12 09:23:25 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-06-14 10:48:13 -0400 |
commit | effdd948056923f3bc03688c24d7e0339d6272f5 (patch) | |
tree | 02a3cb68ce1680db89c8440ba8beea808cbf4a11 /libraries/base | |
parent | 3bc6df3223f62a8366e2e4267bac23aa08e6a939 (diff) | |
download | haskell-effdd948056923f3bc03688c24d7e0339d6272f5.tar.gz |
Implement the -XUnliftedNewtypes extension.
GHC Proposal: 0013-unlifted-newtypes.rst
Discussion: https://github.com/ghc-proposals/ghc-proposals/pull/98
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 <rae@richarde.dev>
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/Control/Category.hs | 2 | ||||
-rw-r--r-- | libraries/base/Data/Coerce.hs | 7 | ||||
-rw-r--r-- | libraries/base/Data/Type/Coercion.hs | 1 | ||||
-rw-r--r-- | libraries/base/GHC/Base.hs | 1 | ||||
-rw-r--r-- | libraries/base/changelog.md | 6 |
5 files changed, 13 insertions, 4 deletions
diff --git a/libraries/base/Control/Category.hs b/libraries/base/Control/Category.hs index e8184956f2..96f0c33aed 100644 --- a/libraries/base/Control/Category.hs +++ b/libraries/base/Control/Category.hs @@ -23,7 +23,7 @@ module Control.Category where import qualified GHC.Base (id,(.)) import Data.Type.Coercion import Data.Type.Equality -import GHC.Prim (coerce) +import Data.Coerce (coerce) infixr 9 . infixr 1 >>>, <<< diff --git a/libraries/base/Data/Coerce.hs b/libraries/base/Data/Coerce.hs index 9bd7f9a41a..3785b8a104 100644 --- a/libraries/base/Data/Coerce.hs +++ b/libraries/base/Data/Coerce.hs @@ -1,5 +1,6 @@ {-# LANGUAGE Unsafe #-} {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE MagicHash #-} ----------------------------------------------------------------------------- -- | @@ -21,9 +22,11 @@ module Data.Coerce ( -- * Safe coercions - coerce, Coercible, + coerce, Coercible ) where import GHC.Prim (coerce) import GHC.Types (Coercible) -import GHC.Base () -- for build ordering; see Notes in GHC.Base for more info +-- The import of GHC.Base is for build ordering; see Notes in GHC.Base for +-- more info. +import GHC.Base () diff --git a/libraries/base/Data/Type/Coercion.hs b/libraries/base/Data/Type/Coercion.hs index b757682a62..694bedec01 100644 --- a/libraries/base/Data/Type/Coercion.hs +++ b/libraries/base/Data/Type/Coercion.hs @@ -8,6 +8,7 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE MagicHash #-} ----------------------------------------------------------------------------- -- | diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs index 6fd2ff735b..2649146816 100644 --- a/libraries/base/GHC/Base.hs +++ b/libraries/base/GHC/Base.hs @@ -1156,7 +1156,6 @@ The rules for map work like this. {-# RULES "map/coerce" [1] map coerce = coerce #-} - ---------------------------------------------- -- append ---------------------------------------------- diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index a9f6fcf272..3c12e7c511 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -9,6 +9,12 @@ to detect values `<= maxBound::Word` that were incorrectly encoded using the `NatJ#` constructor. + * The type of `coerce` has been generalized. It is now runtime-representation + polymorphic: + `forall {r :: RuntimeRep} (a :: TYPE r) (b :: TYPE r). Coercible a b => a -> b`. + The type argument `r` is marked as `Inferred` to prevent it from + interfering with visible type application. + ## 4.13.0.0 *TBA* * Bundled with GHC *TBA* |