summaryrefslogtreecommitdiff
path: root/compiler/GHC/Hs
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2021-02-21 21:16:24 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-01 17:32:12 -0500
commitce85cffc7c3afa55755ae8d1aa027761bf54bed4 (patch)
tree81986b7475f28a20bb80301107f9360a90b1e976 /compiler/GHC/Hs
parent6429943b0a377e076bcfd26c79ceb27cf2f4a9ab (diff)
downloadhaskell-ce85cffc7c3afa55755ae8d1aa027761bf54bed4.tar.gz
Wrap LHsContext in Maybe in the GHC AST
If the context is missing it is captured as Nothing, rather than putting a noLoc in the ParsedSource. Updates haddock submodule
Diffstat (limited to 'compiler/GHC/Hs')
-rw-r--r--compiler/GHC/Hs/Decls.hs18
-rw-r--r--compiler/GHC/Hs/Type.hs52
2 files changed, 32 insertions, 38 deletions
diff --git a/compiler/GHC/Hs/Decls.hs b/compiler/GHC/Hs/Decls.hs
index 6633cf657f..cfafa76733 100644
--- a/compiler/GHC/Hs/Decls.hs
+++ b/compiler/GHC/Hs/Decls.hs
@@ -381,7 +381,7 @@ instance (OutputableBndrId p) => Outputable (TyClDecl (GhcPass p)) where
ppr (SynDecl { tcdLName = ltycon, tcdTyVars = tyvars, tcdFixity = fixity
, tcdRhs = rhs })
= hang (text "type" <+>
- pp_vanilla_decl_head ltycon tyvars fixity noLHsContext <+> equals)
+ pp_vanilla_decl_head ltycon tyvars fixity Nothing <+> equals)
4 (ppr rhs)
ppr (DataDecl { tcdLName = ltycon, tcdTyVars = tyvars, tcdFixity = fixity
@@ -424,7 +424,7 @@ pp_vanilla_decl_head :: (OutputableBndrId p)
=> Located (IdP (GhcPass p))
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
- -> LHsContext (GhcPass p)
+ -> Maybe (LHsContext (GhcPass p))
-> SDoc
pp_vanilla_decl_head thing (HsQTvs { hsq_explicit = tyvars }) fixity context
= hsep [pprLHsContext context, pp_tyvars tyvars]
@@ -512,7 +512,7 @@ pprFamilyDecl top_level (FamilyDecl { fdInfo = info, fdLName = ltycon
, fdResultSig = L _ result
, fdInjectivityAnn = mb_inj })
= vcat [ pprFlavour info <+> pp_top_level <+>
- pp_vanilla_decl_head ltycon tyvars fixity noLHsContext <+>
+ pp_vanilla_decl_head ltycon tyvars fixity Nothing <+>
pp_kind <+> pp_inj <+> pp_where
, nest 2 $ pp_eqns ]
where
@@ -607,7 +607,7 @@ hsConDeclTheta Nothing = []
hsConDeclTheta (Just (L _ theta)) = theta
pp_data_defn :: (OutputableBndrId p)
- => (LHsContext (GhcPass p) -> SDoc) -- Printing the header
+ => (Maybe (LHsContext (GhcPass p)) -> SDoc) -- Printing the header
-> HsDataDefn (GhcPass p)
-> SDoc
pp_data_defn pp_hdr (HsDataDefn { dd_ND = new_or_data, dd_ctxt = context
@@ -661,7 +661,7 @@ pprConDecl (ConDeclH98 { con_name = L _ con
, con_args = args
, con_doc = doc })
= sep [ ppr_mbDoc doc
- , pprHsForAll (mkHsForAllInvisTele ex_tvs) cxt
+ , pprHsForAll (mkHsForAllInvisTele ex_tvs) mcxt
, ppr_details args ]
where
-- In ppr_details: let's not print the multiplicities (they are always 1, by
@@ -673,19 +673,17 @@ pprConDecl (ConDeclH98 { con_name = L _ con
: map (pprHsType . unLoc . hsScaledThing) tys)
ppr_details (RecCon fields) = pprPrefixOcc con
<+> pprConDeclFields (unLoc fields)
- cxt = fromMaybe noLHsContext mcxt
pprConDecl (ConDeclGADT { con_names = cons, con_bndrs = L _ outer_bndrs
, con_mb_cxt = mcxt, con_g_args = args
, con_res_ty = res_ty, con_doc = doc })
= ppr_mbDoc doc <+> ppr_con_names cons <+> dcolon
- <+> (sep [pprHsOuterSigTyVarBndrs outer_bndrs <+> pprLHsContext cxt,
+ <+> (sep [pprHsOuterSigTyVarBndrs outer_bndrs <+> pprLHsContext mcxt,
ppr_arrow_chain (get_args args ++ [ppr res_ty]) ])
where
get_args (PrefixConGADT args) = map ppr args
get_args (RecConGADT fields) = [pprConDeclFields (unLoc fields)]
- cxt = fromMaybe noLHsContext mcxt
ppr_arrow_chain (a:as) = sep (a : map (arrow <+>) as)
ppr_arrow_chain [] = empty
@@ -740,7 +738,7 @@ ppr_fam_inst_eqn (FamEqn { feqn_tycon = L _ tycon
, feqn_pats = pats
, feqn_fixity = fixity
, feqn_rhs = rhs })
- = pprHsFamInstLHS tycon bndrs pats fixity noLHsContext <+> equals <+> ppr rhs
+ = pprHsFamInstLHS tycon bndrs pats fixity Nothing <+> equals <+> ppr rhs
instance OutputableBndrId p
=> Outputable (DataFamInstDecl (GhcPass p)) where
@@ -770,7 +768,7 @@ pprHsFamInstLHS :: (OutputableBndrId p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
- -> LHsContext (GhcPass p)
+ -> Maybe (LHsContext (GhcPass p))
-> SDoc
pprHsFamInstLHS thing bndrs typats fixity mb_ctxt
= hsep [ pprHsOuterFamEqnTyVarBndrs bndrs
diff --git a/compiler/GHC/Hs/Type.hs b/compiler/GHC/Hs/Type.hs
index d5560411e4..0e67a4a94e 100644
--- a/compiler/GHC/Hs/Type.hs
+++ b/compiler/GHC/Hs/Type.hs
@@ -1,10 +1,8 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
-{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
@@ -35,7 +33,7 @@ module GHC.Hs.Type (
HsPatSigType(..), HsPSRn(..),
HsSigType(..), LHsSigType, LHsSigWcType, LHsWcType,
HsTupleSort(..),
- HsContext, LHsContext, noLHsContext,
+ HsContext, LHsContext, fromMaybeContext,
HsTyLit(..),
HsIPName(..), hsIPNameFS,
HsArg(..), numVisibleArgs,
@@ -140,13 +138,8 @@ getBangStrictness _ = (HsSrcBang NoSourceText NoSrcUnpack NoSrcStrict)
************************************************************************
-}
-noLHsContext :: LHsContext (GhcPass p)
--- Use this when there is no context in the original program
--- It would really be more kosher to use a Maybe, to distinguish
--- class () => C a where ...
--- from
--- class C a where ...
-noLHsContext = noLoc []
+fromMaybeContext :: Maybe (LHsContext (GhcPass p)) -> HsContext (GhcPass p)
+fromMaybeContext mctxt = unLoc $ fromMaybe (noLoc []) mctxt
type instance XHsForAllVis (GhcPass _) = NoExtField
type instance XHsForAllInvis (GhcPass _) = NoExtField
@@ -514,9 +507,9 @@ lhsTypeArgSrcSpan arg = case arg of
splitLHsPatSynTy ::
LHsSigType (GhcPass p)
-> ( [LHsTyVarBndr Specificity (NoGhcTc (GhcPass p))] -- universals
- , LHsContext (GhcPass p) -- required constraints
+ , Maybe (LHsContext (GhcPass p)) -- required constraints
, [LHsTyVarBndr Specificity (GhcPass p)] -- existentials
- , LHsContext (GhcPass p) -- provided constraints
+ , Maybe (LHsContext (GhcPass p)) -- provided constraints
, LHsType (GhcPass p)) -- body type
splitLHsPatSynTy ty = (univs, reqs, exis, provs, ty4)
where
@@ -550,7 +543,8 @@ splitLHsPatSynTy ty = (univs, reqs, exis, provs, ty4)
-- generally possible to take the returned types and reconstruct the original
-- type (parentheses and all) from them.
splitLHsSigmaTyInvis :: LHsType (GhcPass p)
- -> ([LHsTyVarBndr Specificity (GhcPass p)], LHsContext (GhcPass p), LHsType (GhcPass p))
+ -> ([LHsTyVarBndr Specificity (GhcPass p)]
+ , Maybe (LHsContext (GhcPass p)), LHsType (GhcPass p))
splitLHsSigmaTyInvis ty
| (tvs, ty1) <- splitLHsForAllTyInvis ty
, (ctxt, ty2) <- splitLHsQualTy ty1
@@ -629,10 +623,11 @@ splitLHsForAllTyInvis_KP lty@(L _ ty) =
-- such as @(context => <...>)@. The downside to this is that it is not
-- generally possible to take the returned types and reconstruct the original
-- type (parentheses and all) from them.
-splitLHsQualTy :: LHsType (GhcPass pass) -> (LHsContext (GhcPass pass), LHsType (GhcPass pass))
+splitLHsQualTy :: LHsType (GhcPass pass)
+ -> (Maybe (LHsContext (GhcPass pass)), LHsType (GhcPass pass))
splitLHsQualTy ty
| (mb_ctxt, body) <- splitLHsQualTy_KP (ignoreParens ty)
- = (fromMaybe noLHsContext mb_ctxt, body)
+ = (mb_ctxt, body)
-- | Decompose a type of the form @context => body@ into its constituent parts.
--
@@ -640,7 +635,7 @@ splitLHsQualTy ty
-- parentheses, hence the suffix @_KP@ (short for \"Keep Parentheses\").
splitLHsQualTy_KP :: LHsType (GhcPass pass) -> (Maybe (LHsContext (GhcPass pass)), LHsType (GhcPass pass))
splitLHsQualTy_KP (L _ (HsQualTy { hst_ctxt = ctxt, hst_body = body }))
- = (Just ctxt, body)
+ = (ctxt, body)
splitLHsQualTy_KP body = (Nothing, body)
-- | Decompose a type class instance type (of the form
@@ -657,12 +652,11 @@ splitLHsQualTy_KP body = (Nothing, body)
-- See @Note [No nested foralls or contexts in instance types]@
-- for why this is important.
splitLHsInstDeclTy :: LHsSigType GhcRn
- -> ([Name], LHsContext GhcRn, LHsType GhcRn)
+ -> ([Name], Maybe (LHsContext GhcRn), LHsType GhcRn)
splitLHsInstDeclTy (L _ (HsSig{sig_bndrs = outer_bndrs, sig_body = inst_ty})) =
- (hsOuterTyVarNames outer_bndrs, ctxt, body_ty)
+ (hsOuterTyVarNames outer_bndrs, mb_cxt, body_ty)
where
(mb_cxt, body_ty) = splitLHsQualTy_KP inst_ty
- ctxt = fromMaybe noLHsContext mb_cxt
-- | Decompose a type class instance type (of the form
-- @forall <tvs>. context => instance_head@) into the @instance_head@.
@@ -897,13 +891,13 @@ pprHsOuterSigTyVarBndrs :: OutputableBndrId p
=> HsOuterSigTyVarBndrs (GhcPass p) -> SDoc
pprHsOuterSigTyVarBndrs (HsOuterImplicit{}) = empty
pprHsOuterSigTyVarBndrs (HsOuterExplicit{hso_bndrs = bndrs}) =
- pprHsForAll (mkHsForAllInvisTele bndrs) noLHsContext
+ pprHsForAll (mkHsForAllInvisTele bndrs) Nothing
-- | Prints a forall; When passed an empty list, prints @forall .@/@forall ->@
-- only when @-dppr-debug@ is enabled.
pprHsForAll :: forall p. OutputableBndrId p
=> HsForAllTelescope (GhcPass p)
- -> LHsContext (GhcPass p) -> SDoc
+ -> Maybe (LHsContext (GhcPass p)) -> SDoc
pprHsForAll tele cxt
= pp_tele tele <+> pprLHsContext cxt
where
@@ -919,15 +913,17 @@ pprHsForAll tele cxt
| otherwise = forAllLit <+> interppSP qtvs <> separator
pprLHsContext :: (OutputableBndrId p)
- => LHsContext (GhcPass p) -> SDoc
-pprLHsContext lctxt
+ => Maybe (LHsContext (GhcPass p)) -> SDoc
+pprLHsContext Nothing = empty
+pprLHsContext (Just lctxt)
| null (unLoc lctxt) = empty
- | otherwise = pprLHsContextAlways lctxt
+ | otherwise = pprLHsContextAlways (Just lctxt)
-- For use in a HsQualTy, which always gets printed if it exists.
pprLHsContextAlways :: (OutputableBndrId p)
- => LHsContext (GhcPass p) -> SDoc
-pprLHsContextAlways (L _ ctxt)
+ => Maybe (LHsContext (GhcPass p)) -> SDoc
+pprLHsContextAlways Nothing = parens empty <+> darrow
+pprLHsContextAlways (Just (L _ ctxt))
= case ctxt of
[] -> parens empty <+> darrow
[L _ ty] -> ppr_mono_ty ty <+> darrow
@@ -967,7 +963,7 @@ ppr_mono_lty ty = ppr_mono_ty (unLoc ty)
ppr_mono_ty :: (OutputableBndrId p) => HsType (GhcPass p) -> SDoc
ppr_mono_ty (HsForAllTy { hst_tele = tele, hst_body = ty })
- = sep [pprHsForAll tele noLHsContext, ppr_mono_lty ty]
+ = sep [pprHsForAll tele Nothing, ppr_mono_lty ty]
ppr_mono_ty (HsQualTy { hst_ctxt = ctxt, hst_body = ty })
= sep [pprLHsContextAlways ctxt, ppr_mono_lty ty]
@@ -1113,7 +1109,7 @@ lhsTypeHasLeadingPromotionQuote ty
go (HsForAllTy{}) = False
go (HsQualTy{ hst_ctxt = ctxt, hst_body = body})
- | L _ (c:_) <- ctxt = goL c
+ | Just (L _ (c:_)) <- ctxt = goL c
| otherwise = goL body
go (HsBangTy{}) = False
go (HsRecTy{}) = False