[Git][ghc/ghc][wip/T18521] Make CodeQ and TExpQ levity polymorphic
Ryan Scott
gitlab at gitlab.haskell.org
Mon Aug 3 20:36:49 UTC 2020
Ryan Scott pushed to branch wip/T18521 at Glasgow Haskell Compiler / GHC
Commits:
5a419632 by Ryan Scott at 2020-08-03T16:36:33-04:00
Make CodeQ and TExpQ levity polymorphic
The patch is quite straightforward. The only tricky part is that
`Language.Haskell.TH.Lib.Internal` now must be `Trustworthy` instead
of `Safe` due to the `GHC.Exts` import (in order to import `TYPE`).
Since `CodeQ` has yet to appear in any released version of
`template-haskell`, I didn't bother mentioning the change to `CodeQ`
in the `template-haskell` release notes.
Fixes #18521.
- - - - -
5 changed files:
- libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- libraries/template-haskell/changelog.md
- + testsuite/tests/quotes/T18521.hs
- testsuite/tests/quotes/all.T
Changes:
=====================================
libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
=====================================
@@ -1,4 +1,5 @@
-{-# LANGUAGE Safe #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE Trustworthy #-}
-- |
-- Language.Haskell.TH.Lib.Internal exposes some additional functionality that
@@ -19,19 +20,31 @@ module Language.Haskell.TH.Lib.Internal where
import Language.Haskell.TH.Syntax hiding (Role, InjectivityAnn)
import qualified Language.Haskell.TH.Syntax as TH
import Control.Applicative(liftA, liftA2)
+import qualified Data.Kind as Kind (Type)
import Data.Word( Word8 )
+import GHC.Exts (TYPE)
import Prelude
----------------------------------------------------------
-- * Type synonyms
----------------------------------------------------------
+-- Since GHC 8.8 is currently the minimum boot compiler version that we must
+-- support, we must use inline kind signatures to make TExpQ and CodeQ
+-- levity polymorphic. When we drop support for GHC 8.8, we can instead use
+-- standalone kind signatures, which are provided as comments.
+
+-- | Levity-polymorphic since /template-haskell-2.17.0.0/.
+-- type TExpQ :: TYPE r -> Kind.Type
+type TExpQ (a :: TYPE r) = Q (TExp a)
+
+-- type CodeQ :: TYPE r -> Kind.Type
+type CodeQ = Code Q :: (TYPE r -> Kind.Type)
+
type InfoQ = Q Info
type PatQ = Q Pat
type FieldPatQ = Q FieldPat
type ExpQ = Q Exp
-type TExpQ a = Q (TExp a)
-type CodeQ = Code Q
type DecQ = Q Dec
type DecsQ = Q [Dec]
type Decs = [Dec] -- Defined as it is more convenient to wire-in
=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -341,6 +341,8 @@ newtype TExp (a :: TYPE (r :: RuntimeRep)) = TExp
-- • In the Template Haskell quotation [|| "foo" ||]
-- In the expression: [|| "foo" ||]
-- In the Template Haskell splice $$([|| "foo" ||])
+--
+-- Levity-polymorphic since /template-haskell-2.16.0.0/.
-- | Discard the type annotation and produce a plain Template Haskell
-- expression
=====================================
libraries/template-haskell/changelog.md
=====================================
@@ -32,6 +32,8 @@
* Add support for QualifiedDo. The data constructors `DoE` and `MDoE` got a new
`Maybe ModName` argument to describe the qualifier of do blocks.
+ * The argument to `TExpQ` can now be levity polymorphic.
+
## 2.16.0.0 *TBA*
* Add support for tuple sections. (#15843) The type signatures of `TupE` and
=====================================
testsuite/tests/quotes/T18521.hs
=====================================
@@ -0,0 +1,15 @@
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE TemplateHaskellQuotes #-}
+module T18521 where
+
+import GHC.Exts (Int#)
+import Language.Haskell.TH
+
+a :: Code Q Int#
+a = [|| 42# ||]
+
+b :: CodeQ Int#
+b = a
+
+c :: TExpQ Int#
+c = examineCode a
=====================================
testsuite/tests/quotes/all.T
=====================================
@@ -19,6 +19,7 @@ test('T16384', req_th, compile, [''])
test('T17857', normal, compile, [''])
test('T18103', normal, compile, [''])
test('T18263', normal, compile_fail, [''])
+test('T18521', normal, compile, [''])
test('TH_tf2', normal, compile, ['-v0'])
test('TH_ppr1', normal, compile_and_run, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a41963271906e776f99a866aa134fb99812e999
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a41963271906e776f99a866aa134fb99812e999
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200803/44a01656/attachment-0001.html>
More information about the ghc-commits
mailing list