summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorRyanGlScott <ryan.gl.scott@gmail.com>2016-01-08 11:46:10 +0100
committerBen Gamari <ben@smart-cactus.org>2016-01-08 12:26:33 +0100
commit0163427761c0e72a3acf09f854b3447f2e553f1b (patch)
tree15e6280c8b8b44c845be010c558223f8c02b7115 /libraries
parent6f2e722973b39b7ef423f6a6b96725395d561836 (diff)
downloadhaskell-0163427761c0e72a3acf09f854b3447f2e553f1b.tar.gz
Fix Template Haskell's handling of infix GADT constructors
This is the second (and hopefully last) fix needed to make TH handle GADTs properly (after D1465). This Diff addresses some issues with infix GADT constructors, specifically: * Before, you could not determine if a GADT constructor was declared infix because TH did not give you the ability to determine if there is a //user-specified// fixity declaration for that constructor. The return type of `reifyFixity` was changed to `Maybe Fixity` so that it yields `Just` the fixity is there is a fixity declaration, and `Nothing` otherwise (indicating it has `defaultFixity`). * `DsMeta`/`Convert` were changed so that infix GADT constructors are turned into `GadtC`, not `InfixC` (which should be reserved for Haskell98 datatype declarations). * Some minor fixes to the TH pretty-printer so that infix GADT constructors will be parenthesized in GADT signatures. Fixes #11345. Test Plan: ./validate Reviewers: goldfire, austin, bgamari, jstolarek Reviewed By: jstolarek Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1744 GHC Trac Issues: #11345
Diffstat (limited to 'libraries')
-rw-r--r--libraries/ghci/GHCi/Message.hs2
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs21
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs11
-rw-r--r--libraries/template-haskell/changelog.md6
4 files changed, 29 insertions, 11 deletions
diff --git a/libraries/ghci/GHCi/Message.hs b/libraries/ghci/GHCi/Message.hs
index 4bc2d25b66..45b19514bc 100644
--- a/libraries/ghci/GHCi/Message.hs
+++ b/libraries/ghci/GHCi/Message.hs
@@ -179,7 +179,7 @@ data Message a where
Report :: Bool -> String -> Message (THResult ())
LookupName :: Bool -> String -> Message (THResult (Maybe TH.Name))
Reify :: TH.Name -> Message (THResult TH.Info)
- ReifyFixity :: TH.Name -> Message (THResult TH.Fixity)
+ ReifyFixity :: TH.Name -> Message (THResult (Maybe TH.Fixity))
ReifyInstances :: TH.Name -> [TH.Type] -> Message (THResult [TH.Dec])
ReifyRoles :: TH.Name -> Message (THResult [TH.Role])
ReifyAnnotations :: TH.AnnLookup -> TypeRep -> Message (THResult [ByteString])
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index 899d27c38f..3f79920a0b 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -66,7 +66,7 @@ instance Ppr Info where
case mb_d of { Nothing -> empty; Just d -> ppr d }]
ppr_sig :: Name -> Type -> Doc
-ppr_sig v ty = ppr v <+> dcolon <+> ppr ty
+ppr_sig v ty = pprName' Applied v <+> dcolon <+> ppr ty
pprFixity :: Name -> Fixity -> Doc
pprFixity _ f | f == defaultFixity = empty
@@ -507,20 +507,24 @@ instance Ppr Con where
<+> pprBangType st2
ppr (ForallC ns ctxt (GadtC c sts ty))
- = commaSep c <+> dcolon <+> pprForall ns ctxt <+> pprGadtRHS sts ty
+ = commaSepApplied c <+> dcolon <+> pprForall ns ctxt
+ <+> pprGadtRHS sts ty
ppr (ForallC ns ctxt (RecGadtC c vsts ty))
- = commaSep c <+> dcolon <+> pprForall ns ctxt
+ = commaSepApplied c <+> dcolon <+> pprForall ns ctxt
<+> pprRecFields vsts ty
ppr (ForallC ns ctxt con)
= pprForall ns ctxt <+> ppr con
ppr (GadtC c sts ty)
- = commaSep c <+> dcolon <+> pprGadtRHS sts ty
+ = commaSepApplied c <+> dcolon <+> pprGadtRHS sts ty
ppr (RecGadtC c vsts ty)
- = commaSep c <+> dcolon <+> pprRecFields vsts ty
+ = commaSepApplied c <+> dcolon <+> pprRecFields vsts ty
+
+commaSepApplied :: [Name] -> Doc
+commaSepApplied = commaSepWith (pprName' Applied)
pprForall :: [TyVarBndr] -> Cxt -> Doc
pprForall ns ctxt
@@ -731,7 +735,12 @@ instance Ppr Loc where
-- Takes a list of printable things and prints them separated by commas followed
-- by space.
commaSep :: Ppr a => [a] -> Doc
-commaSep = sep . punctuate comma . map ppr
+commaSep = commaSepWith ppr
+
+-- Takes a list of things and prints them with the given pretty-printing
+-- function, separated by commas followed by space.
+commaSepWith :: (a -> Doc) -> [a] -> Doc
+commaSepWith pprFun = sep . punctuate comma . map pprFun
-- Takes a list of printable things and prints them separated by semicolons
-- followed by space.
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index f571d6b16f..a3284c53eb 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -67,7 +67,7 @@ class Monad m => Quasi m where
qLookupName :: Bool -> String -> m (Maybe Name)
-- True <=> type namespace, False <=> value namespace
qReify :: Name -> m Info
- qReifyFixity :: Name -> m Fixity
+ qReifyFixity :: Name -> m (Maybe Fixity)
qReifyInstances :: Name -> [Type] -> m [Dec]
-- Is (n tys) an instance?
-- Returns list of matching instance Decs
@@ -355,10 +355,13 @@ and to get information about @D@-the-type, use 'lookupTypeName'.
reify :: Name -> Q Info
reify v = Q (qReify v)
-{- | @reifyFixity nm@ returns the fixity of @nm@. If a fixity value cannot be
-found, 'defaultFixity' is returned.
+{- | @reifyFixity nm@ attempts to find a fixity declaration for @nm@. For
+example, if the function @foo@ has the fixity declaration @infixr 7 foo@, then
+@reifyFixity 'foo@ would return @'Just' ('Fixity' 7 'InfixR')@. If the function
+@bar@ does not have a fixity declaration, then @reifyFixity 'bar@ returns
+'Nothing', so you may assume @bar@ has 'defaultFixity'.
-}
-reifyFixity :: Name -> Q Fixity
+reifyFixity :: Name -> Q (Maybe Fixity)
reifyFixity nm = Q (qReifyFixity nm)
{- | @reifyInstances nm tys@ returns a list of visible instances of @nm tys@. That is,
diff --git a/libraries/template-haskell/changelog.md b/libraries/template-haskell/changelog.md
index 9564e95678..1c0919a8a2 100644
--- a/libraries/template-haskell/changelog.md
+++ b/libraries/template-haskell/changelog.md
@@ -37,6 +37,12 @@
* Add `reifyConStrictness` to query a data constructor's `DecidedStrictness`
values for its fields (#10697)
+ * The `ClassOpI`, `DataConI`, and `VarI` constructors no longer have a
+ `Fixity` field. Instead, all `Fixity` information for a given `Name` is
+ now determined through the `reifyFixity` function, which returns `Just` the
+ fixity if there is an explicit fixity declaration for that `Name`, and
+ `Nothing` otherwise (#10704 and #11345)
+
* TODO: document API changes and important bugfixes