Commit b3b564fb authored by Ryan Scott's avatar Ryan Scott

Merge types and kinds in DsMeta

Types and kinds are now the same in GHC... well, except in the code
that involves Template Haskell, where types and kinds are given separate
treatment. This aims to unify that treatment in the `DsMeta` module.

The gist of this patch is replacing all uses of `repLKind` with `repLTy`.
This is isn't quite as simple as one might imagine, since `repLTy` returns a
`Core (Q Type)` (a monadic expression), whereas `repLKind` returns a
`Core Kind` (a pure expression). This causes many awkward impedance mismatches.

One option would be to change every combinator in `Language.Haskell.TH.Lib` to
take `KindQ` as an argument instead of `Kind`. But this would be a breaking
change of colossal proportions.

Instead, this patch takes a somewhat different approach. This migrates the
existing `Language.Haskell.TH.Lib` module to
`Language.Haskell.TH.Lib.Internal`, and changes all `Kind`-related combinators
in `Language.Haskell.TH.Lib.Internal` to live in `Q`. The new
`Language.Haskell.TH.Lib` module then re-exports most of
`Language.Haskell.TH.Lib.Internal` with the exception of the `Kind`-related
combinators, for which it redefines them to be their current definitions (which
don't live in `Q`). This allows us to retain backwards compatibility with
previous `template-haskell` releases, but more importantly, it allows GHC to
make as many changes to the `Internal` code as it wants for its purposes
without fear of disrupting the public API.

This solves half of #11785 (the other half being `TcSplice`).

Test Plan: ./validate

Reviewers: goldfire, austin, bgamari

Reviewed By: goldfire

Subscribers: rwbarton, thomie

GHC Trac Issues: #11785

Differential Revision:
parent d6186496
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -6,6 +6,14 @@
* Add support for overloaded labels. Introduces `labelE :: String -> ExpQ`.
* Add `KindQ`, `TyVarBndrQ`, and `FamilyResultSigQ` aliases to
* Add `Language.Haskell.TH.Lib.Internal` module, which exposes some
additional functionality that is used internally in GHC's integration
with Template Haskell. This is not a part of the public API, and as
such, there are no API guarantees for this module from version to version.
## *TBA*
* Bundled with GHC *TBA*
......@@ -45,6 +45,8 @@ Library
......@@ -5,7 +5,7 @@ TH_localname.hs:3:11: error:
t0)’ from being solved.
Relevant bindings include
y :: t0 (bound at TH_localname.hs:3:6)
x :: t0 -> Language.Haskell.TH.Lib.ExpQ
x :: t0 -> Language.Haskell.TH.Lib.Internal.ExpQ
(bound at TH_localname.hs:3:1)
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
......@@ -5,5 +5,5 @@ import Data.Kind (Type)
import Language.Haskell.TH (stringE, pprint)
foo :: IO ()
foo = $([d| data Foo :: forall a. a -> Type where MkFoo :: Foo Int |]
>>= \d -> stringE (pprint d))
foo = putStrLn $([d| data Foo :: forall a. a -> Type where MkFoo :: Foo Int |]
>>= \d -> stringE (pprint d))
T13642.hs:8:9: error:
Exotic form of kind not (yet) handled by Template Haskell
forall a. a -> Type
......@@ -2,7 +2,7 @@
T7276.hs:6:8: error:
• Couldn't match type ‘[Language.Haskell.TH.Syntax.Dec]’
with ‘Language.Haskell.TH.Syntax.Exp’
Expected type: Language.Haskell.TH.Lib.ExpQ
Actual type: Language.Haskell.TH.Lib.DecsQ
Expected type: Language.Haskell.TH.Lib.Internal.ExpQ
Actual type: Language.Haskell.TH.Lib.Internal.DecsQ
• In the expression: [d| y = 3 |]
In the untyped splice: $([d| y = 3 |])
......@@ -386,7 +386,7 @@ test('T13473', normal, multimod_compile_and_run,
['T13473.hs', '-v0 ' + config.ghc_th_way_flags])
test('T13587', expect_broken(13587), compile_and_run, ['-v0'])
test('T13618', normal, compile_and_run, ['-v0'])
test('T13642', normal, compile_fail, ['-v0'])
test('T13642', normal, compile, ['-v0'])
test('T13781', normal, compile, ['-v0'])
test('T13782', normal, compile, [''])
test('T13837', normal, compile_fail, ['-v0 -dsuppress-uniques'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment