[Git][ghc/ghc][wip/T24031] Deprecate PrimTyConI
Teo Camarasu (@teo)
gitlab at gitlab.haskell.org
Wed Mar 6 13:31:07 UTC 2024
Teo Camarasu pushed to branch wip/T24031 at Glasgow Haskell Compiler / GHC
Commits:
bf081986 by Teo Camarasu at 2024-03-06T13:30:58+00:00
Deprecate PrimTyConI
- We produce `TyConI` for types where we used to use `PrimTyConI`.
- We add a deprecation warning to `PrimTyConI`
- We add a test case to ensure we can actually reify primitive types.
Resolves #24031
- - - - -
7 changed files:
- compiler/GHC/Tc/Gen/Splice.hs
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- libraries/template-haskell/changelog.md
- testsuite/tests/th/T16293b.hs
- + testsuite/tests/th/T24031.hs
- + testsuite/tests/th/T24031.stderr
- testsuite/tests/th/all.T
Changes:
=====================================
compiler/GHC/Tc/Gen/Splice.hs
=====================================
@@ -2120,15 +2120,6 @@ reifyTyCon tc
| Just cls <- tyConClass_maybe tc
= reifyClass cls
-{- Seems to be just a short cut for the next equation -- omit
- | tc `hasKey` fUNTyConKey -- I'm not quite sure what is happening here
- = return (TH.PrimTyConI (reifyName tc) 2 False)
--}
-
- | isPrimTyCon tc
- = return (TH.PrimTyConI (reifyName tc) (length (tyConVisibleTyVars tc))
- (isUnliftedTypeKind (tyConResKind tc)))
-
| isTypeFamilyTyCon tc
= do { let tvs = tyConTyVars tc
res_kind = tyConResKind tc
=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -2068,6 +2068,7 @@ data Info
Name
Type -- What it is bound to
deriving( Show, Eq, Ord, Data, Generic )
+{-# DEPRECATED PrimTyConI "TyConI is now produced instead." #-}
-- | Obtained from 'reifyModule' in the 'Q' Monad.
data ModuleInfo =
=====================================
libraries/template-haskell/changelog.md
=====================================
@@ -1,5 +1,8 @@
# Changelog for [`template-haskell` package](http://hackage.haskell.org/package/template-haskell)
+## 2.23.0.0
+ * Deprecate `PrimTyConI`. `TyConI` will now be produced to represent primitive types.
+
## 2.22.0.0
* The kind of `Code` was changed from `forall r. (Type -> Type) -> TYPE r -> Type`
=====================================
testsuite/tests/th/T16293b.hs
=====================================
@@ -7,7 +7,8 @@ import GHC.Exts
import Language.Haskell.TH
f :: ()
-f = $(do PrimTyConI _ arity _ <- reify ''Proxy#
+f = $(do TyConI (DataD _ _ targs _ _ _) <- reify ''Proxy#
+ let arity = length targs
unless (arity == 1) $
fail $ "Unexpected arity for Proxy#: " ++ show arity
[| () |])
=====================================
testsuite/tests/th/T24031.hs
=====================================
@@ -0,0 +1,38 @@
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE LinearTypes #-}
+-- | This test shows that we can reify a bunch of wired-in types.
+-- Additionally it acts as a golden test to ensure that we don't accidentally change
+-- our output for these types.
+module T24031 where
+
+import Control.Monad
+import Data.Char
+import GHC.Exts
+import Language.Haskell.TH
+
+f :: ()
+f = $(do let types =
+ [ ''Int#
+ , ''Word#
+ , ''Array#
+ , ''SmallArray#
+ , ''ByteArray#
+ , ''MutableByteArray#
+ , unboxedTupleTypeName 2
+ , unboxedSumTypeName 2
+ , ''(->)
+ , ''[]
+ , tupleTypeName 2
+ ]
+ reified <- mapM reify types
+ let stripInt [] = []
+ stripInt (x:xs)
+ | isDigit x = stripInt xs
+ | otherwise = x:xs
+ -- remove _[0-9]* sequences
+ let stripUniques ('_':xs) = stripUniques $ stripInt xs
+ stripUniques (x:xs)= x:stripUniques xs
+ stripUniques [] = []
+ mapM_ (runIO . putStrLn . stripUniques . show) reified
+ [| () |])
=====================================
testsuite/tests/th/T24031.stderr
=====================================
@@ -0,0 +1,11 @@
+TyConI (DataD [] GHC.Prim.Int# [] Nothing [] [])
+TyConI (DataD [] GHC.Prim.Word# [] Nothing [] [])
+TyConI (DataD [] GHC.Prim.Array# [KindedTV a BndrReq (AppT (ConT GHC.Prim.TYPE) (AppT (PromotedT GHC.Types.BoxedRep) (VarT l)))] Nothing [] [])
+TyConI (DataD [] GHC.Prim.SmallArray# [KindedTV a BndrReq (AppT (ConT GHC.Prim.TYPE) (AppT (PromotedT GHC.Types.BoxedRep) (VarT l)))] Nothing [] [])
+TyConI (DataD [] GHC.Prim.ByteArray# [] Nothing [] [])
+TyConI (DataD [] GHC.Prim.MutableByteArray# [KindedTV a BndrReq StarT] Nothing [] [])
+TyConI (DataD [] GHC.Types.Tuple2# [KindedTV a BndrReq (AppT (ConT GHC.Prim.TYPE) (VarT k0)),KindedTV b BndrReq (AppT (ConT GHC.Prim.TYPE) (VarT k1))] Nothing [NormalC GHC.Types.(#,#) [(Bang NoSourceUnpackedness NoSourceStrictness,VarT a),(Bang NoSourceUnpackedness NoSourceStrictness,VarT b)]] [])
+TyConI (DataD [] GHC.Types.Sum2# [KindedTV a BndrReq (AppT (ConT GHC.Prim.TYPE) (VarT k0)),KindedTV b BndrReq (AppT (ConT GHC.Prim.TYPE) (VarT k1))] Nothing [NormalC GHC.Types.(# | #) [(Bang NoSourceUnpackedness NoSourceStrictness,VarT a)],NormalC GHC.Types.(# | #) [(Bang NoSourceUnpackedness NoSourceStrictness,VarT b)]] [])
+TyConI (TySynD GHC.Types.-> [] (AppT (ConT GHC.Prim.FUN) (PromotedT GHC.Types.Many)))
+TyConI (DataD [] GHC.Types.List [KindedTV a BndrReq StarT] Nothing [NormalC GHC.Types.[] [],InfixC (Bang NoSourceUnpackedness NoSourceStrictness,VarT a) GHC.Types.: (Bang NoSourceUnpackedness NoSourceStrictness,AppT ListT (VarT a))] [])
+TyConI (DataD [] GHC.Tuple.Tuple2 [KindedTV a BndrReq StarT,KindedTV b BndrReq StarT] Nothing [NormalC GHC.Tuple.(,) [(Bang NoSourceUnpackedness NoSourceStrictness,VarT a),(Bang NoSourceUnpackedness NoSourceStrictness,VarT b)]] [])
=====================================
testsuite/tests/th/all.T
=====================================
@@ -604,3 +604,4 @@ test('T24308', normal, compile_and_run, [''])
test('T14032a', normal, compile, [''])
test('T14032e', normal, compile_fail, ['-dsuppress-uniques'])
test('ListTuplePunsTH', [only_ways(['ghci']), extra_files(['ListTuplePunsTH.hs', 'T15843a.hs'])], ghci_script, ['ListTuplePunsTH.script'])
+test('T24031', normal, compile, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf081986c318dd63302ac5f93b9ef591696e7152
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf081986c318dd63302ac5f93b9ef591696e7152
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/20240306/adcd2f68/attachment-0001.html>
More information about the ghc-commits
mailing list