diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2019-12-02 23:10:33 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-12-05 16:07:49 -0500 |
commit | 3354c68ec6c90bbccc0f361aa7973eeb75ea229c (patch) | |
tree | b9c5e2f9627b25b6d7bdf745b281b6771b8d5990 /compiler/iface | |
parent | c4ca29c796fa86ad9d5cd4dfa1a5cdd4e0565fb0 (diff) | |
download | haskell-3354c68ec6c90bbccc0f361aa7973eeb75ea229c.tar.gz |
Pretty-printing of the * kind
Before this patch, GHC always printed the * kind unparenthesized.
This led to two issues:
1. Sometimes GHC printed invalid or incorrect code.
For example, GHC would print: type F @* x = x
when it meant to print: type F @(*) x = x
In the former case, instead of a kind application we were getting a
type operator (@*).
2. Sometimes GHC printed kinds that were correct but hard to read.
Should Either * Int be read as Either (*) Int
or as (*) Either Int ?
This depends on whether -XStarIsType is enabled, but it would be
easier if we didn't have to check for the flag when reading the code.
We can solve both problems by assigning (*) a different precedence. Note
that Haskell98 kinds are not affected:
((* -> *) -> *) -> * does NOT become (((*) -> (*)) -> (*)) -> (*)
The parentheses are added when (*) is used in a function argument
position:
F * * * becomes F (*) (*) (*)
F A * B becomes F A (*) B
Proxy * becomes Proxy (*)
a * -> * becomes a (*) -> *
Diffstat (limited to 'compiler/iface')
-rw-r--r-- | compiler/iface/IfaceType.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/iface/IfaceType.hs b/compiler/iface/IfaceType.hs index db3157f39b..d649be701b 100644 --- a/compiler/iface/IfaceType.hs +++ b/compiler/iface/IfaceType.hs @@ -1315,7 +1315,7 @@ pprTyTcApp' ctxt_prec tc tys dflags style | tc `ifaceTyConHasKey` tYPETyConKey , IA_Arg (IfaceTyConApp rep IA_Nil) Required IA_Nil <- tys , rep `ifaceTyConHasKey` liftedRepDataConKey - = kindType + = ppr_kind_type ctxt_prec | otherwise = getPprDebug $ \dbg -> @@ -1332,6 +1332,14 @@ pprTyTcApp' ctxt_prec tc tys dflags style info = ifaceTyConInfo tc tys_wo_kinds = appArgsIfaceTypesArgFlags $ stripInvisArgs dflags tys +ppr_kind_type :: PprPrec -> SDoc +ppr_kind_type ctxt_prec = + sdocWithDynFlags $ \dflags -> + if useStarIsType dflags + then maybeParen ctxt_prec starPrec $ + unicodeSyntax (char '★') (char '*') + else text "Type" + -- | Pretty-print a type-level equality. -- Returns (Just doc) if the argument is a /saturated/ application -- of eqTyCon (~) @@ -1440,7 +1448,7 @@ ppr_iface_tc_app pp _ tc [ty] ppr_iface_tc_app pp ctxt_prec tc tys | tc `ifaceTyConHasKey` liftedTypeKindTyConKey - = kindType + = ppr_kind_type ctxt_prec | not (isSymOcc (nameOccName (ifaceTyConName tc))) = pprIfacePrefixApp ctxt_prec (ppr tc) (map (pp appPrec) tys) |