Vladislav Zavialov pushed to branch wip/int-index/curried-ctxts at Glasgow Haskell Compiler / GHC
Commits:
-
bb2c9f35
by Vladislav Zavialov at 2026-10-14T20:05:35+02:00
20 changed files:
- changelog.d/allow-gadt-prefix-con-parens
- + changelog.d/gadt-curried-contexts-27424
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Type.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Parser/PostProcess/Haddock.hs
- compiler/GHC/Rename/Module.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/ThToHs.hs
- compiler/Language/Haskell/Syntax/Decls.hs
- compiler/Language/Haskell/Syntax/Type.hs
- docs/users_guide/exts/gadt_syntax.rst
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hoogle.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/GhcUtils.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs
Changes:
| ... | ... | @@ -6,7 +6,7 @@ mrs: !16321 |
| 6 | 6 | |
| 7 | 7 | description:
|
| 8 | 8 | Parenthesized types are now accepted in prefix GADT constructor declarations,
|
| 9 | - even when they contain explicit ``forall`` quantifiers. For example:
|
|
| 9 | + even when they contain explicit ``forall`` quantifiers. For example::
|
|
| 10 | 10 | |
| 11 | 11 | data T where
|
| 12 | 12 | MkT :: (forall a. a -> b -> T)
|
| 1 | +section: language
|
|
| 2 | +synopsis: Allow multiple consecutive contexts in prefix GADT constructor declarations (GHC Proposal `#402 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0402-gadt-syntax.rst>`_ "Stable GADT constructor syntax")
|
|
| 3 | +issues: #27424
|
|
| 4 | +mrs: !16819
|
|
| 5 | + |
|
| 6 | +description: {
|
|
| 7 | + Prefix GADT constructor declarations now accept multiple consecutive contexts,
|
|
| 8 | + equivalent to a single conjoined context. For example::
|
|
| 9 | + |
|
| 10 | + data G a where
|
|
| 11 | + MkCurried :: C a => (D a, E a) => G a
|
|
| 12 | + MkConjoined :: (C a, D a, E a) => G a
|
|
| 13 | + |
|
| 14 | + Record-style GADT constructor declarations continue to accept at most one context.
|
|
| 15 | +} |
| ... | ... | @@ -886,9 +886,8 @@ getRecConArgs_maybe (ConDeclGADT{con_g_args = args}) = case args of |
| 886 | 886 | PrefixConGADT{} -> Nothing
|
| 887 | 887 | RecConGADT _ flds -> Just flds
|
| 888 | 888 | |
| 889 | -hsConDeclTheta :: Maybe (LHsContext (GhcPass p)) -> [LHsType (GhcPass p)]
|
|
| 890 | -hsConDeclTheta Nothing = []
|
|
| 891 | -hsConDeclTheta (Just (L _ (HsContext _ theta))) = theta
|
|
| 889 | +hsConDeclTheta :: Foldable t => t (LHsContext (GhcPass p)) -> [LHsType (GhcPass p)]
|
|
| 890 | +hsConDeclTheta = concatMap (hsc_ctxt . unLoc)
|
|
| 892 | 891 | |
| 893 | 892 | ppDataDefnHeader
|
| 894 | 893 | :: (OutputableBndrId p)
|
| ... | ... | @@ -971,11 +970,11 @@ pprConDecl (ConDeclH98 { con_name = L _ con |
| 971 | 970 | pprConDecl (ConDeclGADT { con_names = cons
|
| 972 | 971 | , con_outer_bndrs = L _ outer_bndrs
|
| 973 | 972 | , con_inner_bndrs = inner_bndrs
|
| 974 | - , con_mb_cxt = mcxt, con_g_args = args
|
|
| 973 | + , con_cxts = cxts, con_g_args = args
|
|
| 975 | 974 | , con_res_ty = res_ty, con_modifiers = mods, con_doc = doc })
|
| 976 | 975 | = pprMaybeWithDoc doc $ pprLHsModifiers mods <+> ppr_con_names (toList cons) <+> dcolon
|
| 977 | 976 | <+> sep [ppr_outer_bndrs, ppr_inner_bndrs (
|
| 978 | - sep [ pprLHsContext mcxt,
|
|
| 977 | + sep [ pprLHsContext cxts,
|
|
| 979 | 978 | sep (ppr_args args ++ [ppr res_ty])])]
|
| 980 | 979 | where
|
| 981 | 980 | ppr_args (PrefixConGADT _ args) = map (pprHsConDeclFieldWith (\arr tyDoc -> tyDoc <+> pprHsModifiedFunArr arr)) args
|
| ... | ... | @@ -126,6 +126,7 @@ import GHC.Utils.Misc (count) |
| 126 | 126 | |
| 127 | 127 | import Data.Maybe
|
| 128 | 128 | import Data.Data (Data)
|
| 129 | +import Data.Foldable ( toList )
|
|
| 129 | 130 | |
| 130 | 131 | import qualified Data.Semigroup as S
|
| 131 | 132 | import GHC.Data.Bag
|
| ... | ... | @@ -896,7 +897,7 @@ splitLHsSigmaTyInvis ty |
| 896 | 897 | = (tvs, ctxt, ty2)
|
| 897 | 898 | |
| 898 | 899 | -- | Decompose a GADT type into its constituent parts.
|
| 899 | --- Returns @(outer_bndrs, inner_bndrs, mb_ctxt, body)@, where:
|
|
| 900 | +-- Returns @(outer_bndrs, inner_bndrs, ctxts, body)@, where:
|
|
| 900 | 901 | --
|
| 901 | 902 | -- * @outer_bndrs@ are 'HsOuterExplicit' if the type has explicit, outermost
|
| 902 | 903 | -- type variable binders. Otherwise, they are 'HsOuterImplicit'.
|
| ... | ... | @@ -904,10 +905,9 @@ splitLHsSigmaTyInvis ty |
| 904 | 905 | -- * @inner_bndrs@ are the remaining @forall@ telescopes, interleaved with the
|
| 905 | 906 | -- parentheses that enclose them.
|
| 906 | 907 | --
|
| 907 | --- * @mb_ctxt@ is @Just@ the context, if it is provided.
|
|
| 908 | --- Otherwise, it is @Nothing@.
|
|
| 908 | +-- * @ctxts@ are the contexts adjacent to the @forall@s, if any.
|
|
| 909 | 909 | --
|
| 910 | --- * @body@ is the body of the type after the optional @forall@s and context.
|
|
| 910 | +-- * @body@ is the body of the type after the optional @forall@s and contexts.
|
|
| 911 | 911 | --
|
| 912 | 912 | -- This function does look through parentheses, but it does not discard them:
|
| 913 | 913 | -- they are syntactically significant, so they are recorded in @inner_bndrs@.
|
| ... | ... | @@ -915,16 +915,22 @@ splitLHsSigmaTyInvis ty |
| 915 | 915 | -- in "GHC.Hs.Decls" for why this is important.
|
| 916 | 916 | splitLHsGadtTy ::
|
| 917 | 917 | LHsSigType GhcPs
|
| 918 | - -> (HsOuterSigTyVarBndrs GhcPs, [LHsGadtTelescope GhcPs], Maybe (LHsContext GhcPs), LHsType GhcPs)
|
|
| 918 | + -> (HsOuterSigTyVarBndrs GhcPs, [LHsGadtTelescope GhcPs], [LHsContext GhcPs], LHsType GhcPs)
|
|
| 919 | 919 | splitLHsGadtTy (L _ sig_ty)
|
| 920 | 920 | | (outer_bndrs, sigma_ty) <- split_outer_bndrs sig_ty
|
| 921 | 921 | , (inner_bndrs, phi_ty) <- split_inner_bndrs sigma_ty
|
| 922 | - , (mb_ctxt, rho_ty) <- splitLHsQualTy_KP phi_ty
|
|
| 923 | - = if is_gadt_rec_ty rho_ty && not (null inner_bndrs)
|
|
| 924 | - -- Bad! Record GADTs are not allowed to have inner_bndrs,
|
|
| 925 | - -- undo the split to get a proper error message later
|
|
| 926 | - then (outer_bndrs, [], Nothing, sigma_ty)
|
|
| 927 | - else (outer_bndrs, inner_bndrs, mb_ctxt, rho_ty)
|
|
| 922 | + , (outer_theta, phi_ty') <- splitLHsQualTy_KP phi_ty
|
|
| 923 | + , (inner_theta, rho_ty) <- split_ctxts phi_ty'
|
|
| 924 | + = case rho_ty of
|
|
| 925 | + -- Record GADTs are not allowed to have multiple foralls or contexts.
|
|
| 926 | + -- Detect and undo the split to get a proper error message later.
|
|
| 927 | + L _ (HsFunTy _ _ (L _ (XHsType HsRecTy{})) _)
|
|
| 928 | + | not (null inner_bndrs) -> (outer_bndrs, [], [], sigma_ty)
|
|
| 929 | + | not (null inner_theta) -> (outer_bndrs, inner_bndrs, toList outer_theta, phi_ty')
|
|
| 930 | + -- All good: either a prefix GADT con, or a record GADT con with at most
|
|
| 931 | + -- one forall and at most one context.
|
|
| 932 | + _ -> let theta_tys = toList outer_theta ++ inner_theta
|
|
| 933 | + in (outer_bndrs, inner_bndrs, theta_tys, rho_ty)
|
|
| 928 | 934 | where
|
| 929 | 935 | split_outer_bndrs :: HsSigType GhcPs -> (HsOuterSigTyVarBndrs GhcPs, LHsType GhcPs)
|
| 930 | 936 | split_outer_bndrs (HsSig{sig_bndrs = outer_bndrs, sig_body = body_ty}) =
|
| ... | ... | @@ -941,9 +947,10 @@ splitLHsGadtTy (L _ sig_ty) |
| 941 | 947 | in (L l (HsGadtPar toks) : args, t)
|
| 942 | 948 | split_inner_bndrs t = ([], t)
|
| 943 | 949 | |
| 944 | - -- type of form {fld :: ty, ...} -> ResTy
|
|
| 945 | - is_gadt_rec_ty (L _ (HsFunTy _ _ (L _ (XHsType HsRecTy{})) _)) = True
|
|
| 946 | - is_gadt_rec_ty _ = False
|
|
| 950 | + split_ctxts :: LHsType GhcPs -> ([LHsContext GhcPs], LHsType GhcPs)
|
|
| 951 | + split_ctxts (L _ HsQualTy { hst_ctxt = ctxt, hst_body = body })
|
|
| 952 | + = let { ~(ctxts, t) = split_ctxts body } in (ctxt : ctxts, t)
|
|
| 953 | + split_ctxts t = ([], t)
|
|
| 947 | 954 | |
| 948 | 955 | -- | Decompose a type of the form @forall <tvs>. body@ into its constituent
|
| 949 | 956 | -- parts. Only splits type variable binders that
|
| ... | ... | @@ -1426,10 +1433,9 @@ pprHsForAllTelescope tele = |
| 1426 | 1433 | -- be updated to match.
|
| 1427 | 1434 | | otherwise = forAllLit <+> interppSP qtvs <> separator
|
| 1428 | 1435 | |
| 1429 | -pprLHsContext :: (OutputableBndrId p)
|
|
| 1430 | - => Maybe (LHsContext (GhcPass p)) -> SDoc
|
|
| 1431 | -pprLHsContext Nothing = empty
|
|
| 1432 | -pprLHsContext (Just lctxt) = pprLHsContextAlways lctxt
|
|
| 1436 | +pprLHsContext :: (Foldable t, OutputableBndrId p)
|
|
| 1437 | + => t (LHsContext (GhcPass p)) -> SDoc
|
|
| 1438 | +pprLHsContext = sep . map pprLHsContextAlways . toList
|
|
| 1433 | 1439 | |
| 1434 | 1440 | -- For use in a HsQualTy, which always gets printed if it exists.
|
| 1435 | 1441 | pprLHsContextAlways :: (OutputableBndrId p)
|
| ... | ... | @@ -888,7 +888,7 @@ repC (L _ (ConDeclH98 { con_name = con |
| 888 | 888 | , con_args = args }))
|
| 889 | 889 | = addHsTyVarBinds FreshNamesOnly con_tvs $ \ ex_bndrs ->
|
| 890 | 890 | do { c' <- repH98DataCon con args
|
| 891 | - ; ctxt' <- repMbContext mcxt
|
|
| 891 | + ; ctxt' <- repContexts mcxt
|
|
| 892 | 892 | ; if not is_existential && isNothing mcxt
|
| 893 | 893 | then return c'
|
| 894 | 894 | else rep2 forallCOcc ([unC ex_bndrs, unC ctxt', unC c'])
|
| ... | ... | @@ -897,7 +897,7 @@ repC (L _ (ConDeclH98 { con_name = con |
| 897 | 897 | repC (L l (ConDeclGADT { con_names = cons
|
| 898 | 898 | , con_outer_bndrs = L _ outer_bndrs
|
| 899 | 899 | , con_inner_bndrs = inner_bndrs
|
| 900 | - , con_mb_cxt = mcxt
|
|
| 900 | + , con_cxts = cxts
|
|
| 901 | 901 | , con_g_args = args
|
| 902 | 902 | , con_res_ty = res_ty }))
|
| 903 | 903 | | no_explicit_forall, no_context
|
| ... | ... | @@ -908,9 +908,9 @@ repC (L l (ConDeclGADT { con_names = cons |
| 908 | 908 | |
| 909 | 909 | | Just invis_inner_bndrs <- m_invis_inner_bndrs
|
| 910 | 910 | = addHsOuterSigTyVarBinds outer_bndrs $ \ outer_bndrs' ->
|
| 911 | - -- the context is attached to the innermost ForallC
|
|
| 911 | + -- the contexts are flattened and attached to the innermost ForallC
|
|
| 912 | 912 | let loop last_bndrs' [] = do
|
| 913 | - ctxt' <- repMbContext mcxt
|
|
| 913 | + ctxt' <- repContexts cxts
|
|
| 914 | 914 | c' <- repGadtDataCons cons args res_ty
|
| 915 | 915 | rep2 forallCOcc ([unC last_bndrs', unC ctxt', unC c'])
|
| 916 | 916 | loop last_bndrs' (bndrs : bndrs_s) =
|
| ... | ... | @@ -927,7 +927,7 @@ repC (L l (ConDeclGADT { con_names = cons |
| 927 | 927 | inner_teles = gadtArgTelescopes inner_bndrs
|
| 928 | 928 | |
| 929 | 929 | no_explicit_forall = nullOuterExplicit outer_bndrs && null inner_teles
|
| 930 | - no_context = isNothing mcxt
|
|
| 930 | + no_context = null cxts
|
|
| 931 | 931 | |
| 932 | 932 | m_invis_inner_bndrs :: Maybe [[LHsTyVarBndr Specificity GhcRn]]
|
| 933 | 933 | m_invis_inner_bndrs = traverse get_invis_bndrs inner_teles
|
| ... | ... | @@ -936,9 +936,9 @@ repC (L l (ConDeclGADT { con_names = cons |
| 936 | 936 | get_invis_bndrs HsForAllVis{} = Nothing
|
| 937 | 937 | get_invis_bndrs HsForAllInvis { hsf_invis_bndrs = tvbs } = Just tvbs
|
| 938 | 938 | |
| 939 | -repMbContext :: Maybe (LHsContext GhcRn) -> MetaM (Core (M TH.Cxt))
|
|
| 940 | -repMbContext Nothing = repContext emptyContext
|
|
| 941 | -repMbContext (Just (L _ cxt)) = repContext cxt
|
|
| 939 | +-- | Flatten several contexts into a single 'TH.Cxt'.
|
|
| 940 | +repContexts :: Foldable t => t (LHsContext GhcRn) -> MetaM (Core (M TH.Cxt))
|
|
| 941 | +repContexts cxts = repContext $ HsContext noAnn (hsConDeclTheta cxts)
|
|
| 942 | 942 | |
| 943 | 943 | repSrcUnpackedness :: SrcUnpackedness -> MetaM (Core (M TH.SourceUnpackedness))
|
| 944 | 944 | repSrcUnpackedness SrcUnpack = rep2 sourceUnpackOcc []
|
| ... | ... | @@ -1761,7 +1761,7 @@ instance ToHie (LocatedA (ConDecl GhcRn)) where |
| 1761 | 1761 | ConDeclGADT { con_names = names
|
| 1762 | 1762 | , con_outer_bndrs = L outer_bndrs_loc outer_bndrs
|
| 1763 | 1763 | , con_inner_bndrs = inner_bndrs
|
| 1764 | - , con_mb_cxt = ctx
|
|
| 1764 | + , con_cxts = cxts
|
|
| 1765 | 1765 | , con_g_args = args
|
| 1766 | 1766 | , con_res_ty = typ
|
| 1767 | 1767 | , con_doc = doc} ->
|
| ... | ... | @@ -1770,14 +1770,14 @@ instance ToHie (LocatedA (ConDecl GhcRn)) where |
| 1770 | 1770 | map (C $ TyVarBind (mkScope outer_bndrs_loc) (ResolvedScopes [sigmaScope]))
|
| 1771 | 1771 | imp_vars
|
| 1772 | 1772 | , toHie $ tvScopes (ResolvedScopes [phiScope]) NoScope exp_bndrs
|
| 1773 | - , toHie ctx
|
|
| 1773 | + , toHie cxts
|
|
| 1774 | 1774 | , toHie args
|
| 1775 | 1775 | , toHie typ
|
| 1776 | 1776 | , toHie doc
|
| 1777 | 1777 | ]
|
| 1778 | 1778 | where
|
| 1779 | 1779 | rhsScope = combineScopes argsScope tyScope
|
| 1780 | - ctxScope = maybe NoScope mkScope ctx
|
|
| 1780 | + ctxScope = foldr combineScopes NoScope (map mkScope cxts)
|
|
| 1781 | 1781 | argsScope = case args of
|
| 1782 | 1782 | PrefixConGADT _ xs -> scaled_args_scope xs
|
| 1783 | 1783 | RecConGADT _ x -> mkScope x
|
| ... | ... | @@ -833,13 +833,13 @@ mkGadtDecl loc mods names dcol ty = do |
| 833 | 833 | , con_names = names
|
| 834 | 834 | , con_outer_bndrs = L outer_bndrs_loc outer_bndrs
|
| 835 | 835 | , con_inner_bndrs = inner_bndrs
|
| 836 | - , con_mb_cxt = mcxt
|
|
| 836 | + , con_cxts = cxts
|
|
| 837 | 837 | , con_g_args = args
|
| 838 | 838 | , con_res_ty = res_ty
|
| 839 | 839 | , con_modifiers = mods
|
| 840 | 840 | , con_doc = Nothing }
|
| 841 | 841 | where
|
| 842 | - (outer_bndrs, inner_bndrs, mcxt, body_ty) = splitLHsGadtTy ty
|
|
| 842 | + (outer_bndrs, inner_bndrs, cxts, body_ty) = splitLHsGadtTy ty
|
|
| 843 | 843 | outer_bndrs_loc = case outer_bndrs of
|
| 844 | 844 | HsOuterImplicit{} -> getLoc ty
|
| 845 | 845 | HsOuterExplicit an _ -> EpAnn (entry an) noAnn emptyComments
|
| ... | ... | @@ -694,7 +694,7 @@ instance HasHaddock (LocatedA (ConDecl GhcPs)) where |
| 694 | 694 | extendHdkA (locA l_con_decl) $
|
| 695 | 695 | case con_decl of
|
| 696 | 696 | ConDeclGADT { con_g_ext, con_names, con_outer_bndrs, con_inner_bndrs
|
| 697 | - , con_mb_cxt, con_g_args, con_res_ty, con_modifiers } -> do
|
|
| 697 | + , con_cxts, con_g_args, con_res_ty, con_modifiers } -> do
|
|
| 698 | 698 | con_doc' <- getConDoc (getLocA (NE.head con_names))
|
| 699 | 699 | con_g_args' <-
|
| 700 | 700 | case con_g_args of
|
| ... | ... | @@ -705,7 +705,7 @@ instance HasHaddock (LocatedA (ConDecl GhcPs)) where |
| 705 | 705 | con_res_ty' <- addHaddock con_res_ty
|
| 706 | 706 | pure $ L l_con_decl $
|
| 707 | 707 | ConDeclGADT { con_g_ext, con_names,
|
| 708 | - con_outer_bndrs, con_inner_bndrs, con_mb_cxt, con_modifiers,
|
|
| 708 | + con_outer_bndrs, con_inner_bndrs, con_cxts, con_modifiers,
|
|
| 709 | 709 | con_doc = lexLHsDocString <$> con_doc',
|
| 710 | 710 | con_g_args = con_g_args',
|
| 711 | 711 | con_res_ty = con_res_ty' }
|
| ... | ... | @@ -28,7 +28,8 @@ import GHC.Rename.HsType |
| 28 | 28 | import GHC.Rename.Bind
|
| 29 | 29 | import GHC.Rename.Doc
|
| 30 | 30 | import GHC.Rename.Env
|
| 31 | -import GHC.Rename.Utils ( mapFvRn, bindLocalNames
|
|
| 31 | +import GHC.Rename.Utils ( mapFvRn, mapMaybeFvRn
|
|
| 32 | + , bindLocalNames
|
|
| 32 | 33 | , checkDupRdrNames, bindLocalNamesFV
|
| 33 | 34 | , warnUnusedTypePatterns
|
| 34 | 35 | , noNestedForallsContextsErr
|
| ... | ... | @@ -2615,7 +2616,7 @@ rnConDecl decl@(ConDeclH98 { con_name = name, con_ex_tvs = ex_tvs |
| 2615 | 2616 | ; let ctxt = ConDeclCtx [new_name]
|
| 2616 | 2617 | ; bindLHsTyVarBndrs ctxt WarnUnusedForalls
|
| 2617 | 2618 | Nothing ex_tvs $ \ new_ex_tvs ->
|
| 2618 | - do { (new_context, fvs1) <- rnMbContext ctxt mcxt
|
|
| 2619 | + do { (new_context, fvs1) <- mapMaybeFvRn (rnContext ctxt) mcxt
|
|
| 2619 | 2620 | ; (new_args, fvs2) <- rnConDeclH98Details (unLoc new_name) ctxt args
|
| 2620 | 2621 | ; (mods', mods_fvs) <- rnModifiersContextAndWarn ctxt mods
|
| 2621 | 2622 | ; let all_fvs = fvs1 `plusFN` fvs2 `plusFN` mods_fvs
|
| ... | ... | @@ -2635,7 +2636,7 @@ rnConDecl decl@(ConDeclH98 { con_name = name, con_ex_tvs = ex_tvs |
| 2635 | 2636 | rnConDecl (ConDeclGADT { con_names = names
|
| 2636 | 2637 | , con_outer_bndrs = L outer_bndrs_loc outer_bndrs
|
| 2637 | 2638 | , con_inner_bndrs = inner_bndrs
|
| 2638 | - , con_mb_cxt = mcxt
|
|
| 2639 | + , con_cxts = cxts
|
|
| 2639 | 2640 | , con_g_args = args
|
| 2640 | 2641 | , con_res_ty = res_ty
|
| 2641 | 2642 | , con_modifiers = mods
|
| ... | ... | @@ -2651,7 +2652,7 @@ rnConDecl (ConDeclGADT { con_names = names |
| 2651 | 2652 | implicit_bndrs =
|
| 2652 | 2653 | extractHsOuterTvBndrs outer_bndrs $
|
| 2653 | 2654 | extractHsGadtTelescopes inner_bndrs $
|
| 2654 | - extractHsTysRdrTyVars (hsConDeclTheta mcxt) $
|
|
| 2655 | + extractHsTysRdrTyVars (hsConDeclTheta cxts) $
|
|
| 2655 | 2656 | extractConDeclGADTDetailsTyVars args $
|
| 2656 | 2657 | extractHsTysRdrTyVars [res_ty] []
|
| 2657 | 2658 | |
| ... | ... | @@ -2659,7 +2660,7 @@ rnConDecl (ConDeclGADT { con_names = names |
| 2659 | 2660 | |
| 2660 | 2661 | ; bindHsOuterTyVarBndrs ctxt Nothing implicit_bndrs outer_bndrs $ \outer_bndrs' ->
|
| 2661 | 2662 | bindHsGadtTelescopes ctxt inner_bndrs $ \inner_bndrs' ->
|
| 2662 | - do { (new_cxt, fvs1) <- rnMbContext ctxt mcxt
|
|
| 2663 | + do { (new_cxts, fvs1) <- mapFvRn (rnContext ctxt) cxts
|
|
| 2663 | 2664 | ; (new_args, fvs2) <- rnConDeclGADTDetails (unLoc (head new_names)) ctxt args
|
| 2664 | 2665 | ; (new_res_ty, fvs3) <- rnLHsType ctxt res_ty
|
| 2665 | 2666 | ; (mods', mods_fvs) <- rnModifiersContextAndWarn ctxt mods
|
| ... | ... | @@ -2678,17 +2679,11 @@ rnConDecl (ConDeclGADT { con_names = names |
| 2678 | 2679 | ; return (ConDeclGADT { con_g_ext = noExtField, con_names = new_names
|
| 2679 | 2680 | , con_outer_bndrs = L outer_bndrs_loc outer_bndrs'
|
| 2680 | 2681 | , con_inner_bndrs = inner_bndrs'
|
| 2681 | - , con_mb_cxt = new_cxt
|
|
| 2682 | + , con_cxts = new_cxts
|
|
| 2682 | 2683 | , con_g_args = new_args, con_res_ty = new_res_ty
|
| 2683 | 2684 | , con_doc = new_mb_doc, con_modifiers = mods' },
|
| 2684 | 2685 | all_fvs) } }
|
| 2685 | 2686 | |
| 2686 | -rnMbContext :: HsDocContext -> Maybe (LHsContext GhcPs)
|
|
| 2687 | - -> RnM (Maybe (LHsContext GhcRn), FreeNames)
|
|
| 2688 | -rnMbContext _ Nothing = return (Nothing, emptyFNs)
|
|
| 2689 | -rnMbContext doc cxt = do { (ctx',fvs) <- rnMaybeContext doc cxt
|
|
| 2690 | - ; return (ctx',fvs) }
|
|
| 2691 | - |
|
| 2692 | 2687 | rnConDeclH98Details ::
|
| 2693 | 2688 | Name
|
| 2694 | 2689 | -> HsDocContext
|
| ... | ... | @@ -2144,9 +2144,8 @@ checkExpKind _rn_ty ty ki (Infer cell) = do |
| 2144 | 2144 | |
| 2145 | 2145 | ---------------------------
|
| 2146 | 2146 | |
| 2147 | -tcHsContext :: Maybe (LHsContext GhcRn) -> TcM [PredType]
|
|
| 2148 | -tcHsContext Nothing = return []
|
|
| 2149 | -tcHsContext (Just cxt) = tc_hs_context typeLevelMode cxt
|
|
| 2147 | +tcHsContext :: Foldable t => t (LHsContext GhcRn) -> TcM [PredType]
|
|
| 2148 | +tcHsContext = foldMapM (tc_hs_context typeLevelMode)
|
|
| 2150 | 2149 | |
| 2151 | 2150 | tcLHsPredType :: LHsType GhcRn -> TcM PredType
|
| 2152 | 2151 | tcLHsPredType pred = tc_lhs_pred typeLevelMode pred
|
| ... | ... | @@ -2263,14 +2263,14 @@ kcConDecl new_or_data _tc_res_kind |
| 2263 | 2263 | (ConDeclGADT { con_names = names
|
| 2264 | 2264 | , con_outer_bndrs = L _ outer_bndrs
|
| 2265 | 2265 | , con_inner_bndrs = inner_bndrs
|
| 2266 | - , con_mb_cxt = cxt
|
|
| 2266 | + , con_cxts = cxts
|
|
| 2267 | 2267 | , con_g_args = args
|
| 2268 | 2268 | , con_res_ty = res_ty })
|
| 2269 | 2269 | = -- See Note [kcConDecls: kind-checking data type decls]
|
| 2270 | 2270 | addErrCtxt (DataConDefCtxt names) $
|
| 2271 | 2271 | -- Not sure this is right, should just extend rather than skolemise but no test
|
| 2272 | 2272 | bind_con_tvbs outer_bndrs inner_bndrs $
|
| 2273 | - do { _ <- tcHsContext cxt
|
|
| 2273 | + do { _ <- tcHsContext cxts
|
|
| 2274 | 2274 | ; traceTc "kcConDecl:GADT {" (ppr names $$ ppr res_ty)
|
| 2275 | 2275 | ; con_res_kind <- newOpenTypeKind
|
| 2276 | 2276 | ; _ <- tcCheckLHsTypeInContext res_ty (TheKind con_res_kind)
|
| ... | ... | @@ -4175,7 +4175,7 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map |
| 4175 | 4175 | (ConDeclGADT { con_names = names
|
| 4176 | 4176 | , con_outer_bndrs = L _ outer_bndrs
|
| 4177 | 4177 | , con_inner_bndrs = inner_bndrs
|
| 4178 | - , con_mb_cxt = cxt, con_g_args = hs_args
|
|
| 4178 | + , con_cxts = cxts, con_g_args = hs_args
|
|
| 4179 | 4179 | , con_res_ty = hs_res_ty })
|
| 4180 | 4180 | = addErrCtxt (DataConDefCtxt names) $
|
| 4181 | 4181 | do { traceTc "tcConDecl 1 gadt" (ppr names)
|
| ... | ... | @@ -4184,7 +4184,7 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map |
| 4184 | 4184 | ; (tclvl, wanted, (tvbs, (ctxt, arg_tys, res_ty, field_lbls, stricts)))
|
| 4185 | 4185 | <- pushLevelAndSolveEqualitiesX "tcConDecl:GADT" $
|
| 4186 | 4186 | tcGadtConTyVarBndrs skol_info outer_bndrs inner_bndrs $
|
| 4187 | - do { ctxt <- tcHsContext cxt
|
|
| 4187 | + do { ctxt <- tcHsContext cxts
|
|
| 4188 | 4188 | ; (res_ty, res_kind) <- tcInferLHsTypeKind hs_res_ty
|
| 4189 | 4189 | -- See Note [GADT return kinds]
|
| 4190 | 4190 |
| ... | ... | @@ -59,7 +59,7 @@ import Data.Bifunctor (first) |
| 59 | 59 | import Data.Foldable (for_)
|
| 60 | 60 | import Data.List.NonEmpty( NonEmpty (..), nonEmpty )
|
| 61 | 61 | import qualified Data.List.NonEmpty as NE
|
| 62 | -import Data.Maybe( catMaybes, isNothing )
|
|
| 62 | +import Data.Maybe( catMaybes, maybeToList, isNothing )
|
|
| 63 | 63 | import Data.Word (Word64)
|
| 64 | 64 | import GHC.Boot.TH.Syntax as TH
|
| 65 | 65 | import Foreign.ForeignPtr
|
| ... | ... | @@ -718,16 +718,23 @@ cvtConstr parent_con do_con_name (ForallC tvs ctxt con) |
| 718 | 718 | add_cxt (L loc (HsContext _ cxt1)) (Just (L _ (HsContext _ cxt2)))
|
| 719 | 719 | = Just (L loc (HsContext noAnn (cxt1 ++ cxt2)))
|
| 720 | 720 | |
| 721 | - -- Nested foralls end up flattened (see tests/th/GadtConSigs_th_dump1.stderr)
|
|
| 721 | + prepend_cxt :: LHsContext GhcPs -> [LHsContext GhcPs] -> [LHsContext GhcPs]
|
|
| 722 | + prepend_cxt lcxt = map_mb_head (add_cxt lcxt)
|
|
| 723 | + where
|
|
| 724 | + map_mb_head :: (Maybe a -> Maybe a) -> [a] -> [a]
|
|
| 725 | + map_mb_head f [] = maybeToList (f Nothing)
|
|
| 726 | + map_mb_head f (x:xs) = maybeToList (f (Just x)) ++ xs
|
|
| 727 | + |
|
| 728 | + -- Nested foralls and contexts end up flattened (see tests/th/GadtConSigs_th_dump1.stderr)
|
|
| 722 | 729 | -- but it doesn't seem to matter.
|
| 723 | 730 | add_forall :: [LHsTyVarBndr Hs.Specificity GhcPs] -> LHsContext GhcPs
|
| 724 | 731 | -> ConDecl GhcPs -> ConDecl GhcPs
|
| 725 | 732 | add_forall tvs' cxt' con@(ConDeclGADT { con_outer_bndrs = L l outer_bndrs
|
| 726 | 733 | , con_inner_bndrs = inner_bndrs
|
| 727 | - , con_mb_cxt = cxt })
|
|
| 734 | + , con_cxts = cxts })
|
|
| 728 | 735 | = con { con_outer_bndrs = L l outer_bndrs'
|
| 729 | 736 | , con_inner_bndrs = inner_bndrs
|
| 730 | - , con_mb_cxt = add_cxt cxt' cxt }
|
|
| 737 | + , con_cxts = prepend_cxt cxt' cxts }
|
|
| 731 | 738 | where
|
| 732 | 739 | outer_bndrs'
|
| 733 | 740 | | null all_tvs = mkHsOuterImplicit
|
| ... | ... | @@ -770,7 +777,7 @@ mk_gadt_decl names args res_ty |
| 770 | 777 | , con_names = names
|
| 771 | 778 | , con_outer_bndrs = outer_bndrs
|
| 772 | 779 | , con_inner_bndrs = []
|
| 773 | - , con_mb_cxt = Nothing
|
|
| 780 | + , con_cxts = []
|
|
| 774 | 781 | , con_g_args = args
|
| 775 | 782 | , con_res_ty = res_ty
|
| 776 | 783 | , con_modifiers = []
|
| ... | ... | @@ -964,7 +964,7 @@ data ConDecl pass |
| 964 | 964 | , con_inner_bndrs :: [LHsGadtTelescope pass]
|
| 965 | 965 | -- ^ The forall telescopes other than the outermost invisible forall,
|
| 966 | 966 | -- interleaved with the parentheses that enclose them.
|
| 967 | - , con_mb_cxt :: Maybe (LHsContext pass) -- ^ User-written context (if any)
|
|
| 967 | + , con_cxts :: [LHsContext pass] -- ^ User-written contexts
|
|
| 968 | 968 | , con_g_args :: HsConDeclGADTDetails pass -- ^ Arguments; never infix
|
| 969 | 969 | , con_res_ty :: LHsType pass -- ^ Result type
|
| 970 | 970 | |
| ... | ... | @@ -994,7 +994,7 @@ data ConDecl pass |
| 994 | 994 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 995 | 995 | The types of both forms of GADT constructors are very structured, as they
|
| 996 | 996 | must consist of the quantified type variables (if provided), followed by the
|
| 997 | -context (if provided), followed by the argument types (if provided), followed
|
|
| 997 | +contexts (if provided), followed by the argument types (if provided), followed
|
|
| 998 | 998 | by the result type. (See "Wrinkle: No nested foralls or contexts" below for
|
| 999 | 999 | more discussion on the restrictions imposed here.) As a result, instead of
|
| 1000 | 1000 | storing the type of a GADT constructor as a single LHsType, we split it up
|
| ... | ... | @@ -1069,6 +1069,8 @@ the GADT type, in precisely that order. For instance: |
| 1069 | 1069 | MkT2 :: forall a. Eq a => forall b. a -> b -> T
|
| 1070 | 1070 | -- Rejected, `forall b` is nested
|
| 1071 | 1071 | MkT3 :: forall a b. Eq a => Eq b => a -> b -> T
|
| 1072 | + -- OK, `Eq a` and `Eq b` are consecutive
|
|
| 1073 | + MkT3' :: forall a b. Eq a => a -> Eq b => b -> T
|
|
| 1072 | 1074 | -- Rejected, `Eq b` is nested
|
| 1073 | 1075 | MkT4 :: Int -> forall a. a -> T
|
| 1074 | 1076 | -- Rejected, `forall a` is nested
|
| ... | ... | @@ -1084,10 +1086,11 @@ User's Guide. GHC enforces that GADT constructors do not have nested `forall`s |
| 1084 | 1086 | or contexts in a single place:
|
| 1085 | 1087 | |
| 1086 | 1088 | GHC, in the process of splitting apart a GADT's type,
|
| 1087 | - extracts out the leading `forall`s and context (if they are provided). To
|
|
| 1088 | - accomplish this splitting, the parser uses the GHC.Hs.Type.splitLHsGadtTy
|
|
| 1089 | - function, which records the parentheses that surround the leading `forall`s
|
|
| 1090 | - in con_inner_bndrs (as these parentheses are syntactically significant).
|
|
| 1089 | + extracts out the leading `forall`s and the adjacent contexts (if they are
|
|
| 1090 | + provided). To accomplish this splitting, the parser uses the
|
|
| 1091 | + GHC.Hs.Type.splitLHsGadtTy function, which records the parentheses that
|
|
| 1092 | + surround the leading `forall`s in con_inner_bndrs (as these parentheses are
|
|
| 1093 | + syntactically significant), and the contexts in con_cxts.
|
|
| 1091 | 1094 | If the body returned by splitLHsGadtTy still contains any `forall`s or
|
| 1092 | 1095 | contexts, then they must be nested, so they will be rejected.
|
| 1093 | 1096 |
| ... | ... | @@ -416,7 +416,7 @@ data HsGadtTelescope pass |
| 416 | 416 | = HsGadtForAll !(XGadtForAll pass) (HsForAllTelescope pass)
|
| 417 | 417 | | HsGadtPar !(XGadtPar pass)
|
| 418 | 418 | -- ^ `HsGadtPar` is only usefull for pretty-printing/exact-printing for recovering
|
| 419 | - -- parenthisis interleaved with foralls.
|
|
| 419 | + -- parentheses interleaved with foralls.
|
|
| 420 | 420 | --
|
| 421 | 421 | -- This approach differs from `HsPar`, which wraps the inner expression as if
|
| 422 | 422 | -- surrounding it with parentheses. We can ditch the `HsPar` approach because
|
| ... | ... | @@ -124,7 +124,7 @@ grammar is subject to change in the future. |
| 124 | 124 | |
| 125 | 125 | .. code-block:: none
|
| 126 | 126 | |
| 127 | - gadt_con ::= conids '::' foralls opt_ctxt gadt_body
|
|
| 127 | + gadt_con ::= conids '::' foralls ctxts gadt_body
|
|
| 128 | 128 | |
| 129 | 129 | conids ::= conid
|
| 130 | 130 | | conid ',' conids
|
| ... | ... | @@ -145,9 +145,9 @@ grammar is subject to change in the future. |
| 145 | 145 | | '{' tyvar '}'
|
| 146 | 146 | | '{' tyvar '::' ctype '}'
|
| 147 | 147 | |
| 148 | - opt_ctxt ::= <empty>
|
|
| 149 | - | btype '=>'
|
|
| 150 | - | '(' ctxt ')' '=>'
|
|
| 148 | + ctxts ::= <empty>
|
|
| 149 | + | btype '=>'
|
|
| 150 | + | '(' ctxt ')' '=>'
|
|
| 151 | 151 | |
| 152 | 152 | ctxt ::= ctype
|
| 153 | 153 | | ctype ',' ctxt
|
| ... | ... | @@ -194,15 +194,29 @@ syntactically allowed. Some further various observations about this grammar: |
| 194 | 194 | |
| 195 | 195 | - GADT constructor types are currently not permitted to have arbitrarily nested
|
| 196 | 196 | ``forall``\ s or ``=>``\ s. (e.g., something like ``MkT :: Int -> forall a. a -> T``
|
| 197 | - would be rejected.) As a result, ``gadt_sig`` puts all of its quantification
|
|
| 198 | - and constraints up front with ``foralls`` and ``opt_context``. Note that
|
|
| 197 | + would be rejected.) As a result, ``gadt_con`` puts all of its quantification
|
|
| 198 | + and constraints up front with ``foralls`` and ``ctxts``. Note that
|
|
| 199 | 199 | higher-rank ``forall``\ s and ``=>``\ s are only permitted if they do not appear
|
| 200 | 200 | directly to the right of a function arrow in a `prefix_gadt_body`. (e.g.,
|
| 201 | 201 | something like ``MkS :: Int -> (forall a. a) -> S`` is allowed, since
|
| 202 | 202 | parentheses separate the ``forall`` from the ``->``.)
|
| 203 | 203 | |
| 204 | +- A prefix GADT constructor may be given several consecutive contexts, as
|
|
| 205 | + indicated by `ctxts`. Curried contexts are equivalent to a single conjoined
|
|
| 206 | + context, so the following constructors have interchangeable types: ::
|
|
| 207 | + |
|
| 208 | + data G a where
|
|
| 209 | + MkCurried :: C a => D a => E a => G a
|
|
| 210 | + MkConjoined :: (C a, D a, E a) => G a
|
|
| 211 | + MkMixedL :: (C a, D a) => E a => G a
|
|
| 212 | + MkMixedR :: C a => (D a, E a) => G a
|
|
| 213 | + |
|
| 214 | + Note that, per the grammar above, the contexts must be consecutive: it is
|
|
| 215 | + currently not possible to interleave contexts with foralls or function arrows.
|
|
| 216 | + This restriction will be lifted in a future release of GHC.
|
|
| 217 | + |
|
| 204 | 218 | - GADT constructors permit outermost parentheses that surround the ``foralls``
|
| 205 | - or ``opt_ctxt``, as well as interleaved parentheses between multiple
|
|
| 219 | + or ``ctxts``, as well as interleaved parentheses between multiple
|
|
| 206 | 220 | ``foralls``. For example, ``MkU :: (forall a. a -> U)`` is accepted, as is
|
| 207 | 221 | ``MkW :: forall a. (forall b. a -> b -> W)``.
|
| 208 | 222 |
| ... | ... | @@ -432,7 +432,7 @@ https://gitlab.haskell.org/ghc/ghc/-/merge_requests/16644, using |
| 432 | 432 | |
| 433 | 433 | data InnerBindings
|
| 434 | 434 | = InnerMore (LHsGadtTelescope GhcPs) InnerBindings
|
| 435 | - | InnerDone (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs)
|
|
| 435 | + | InnerDone ([LHsContext GhcPs], HsConDeclGADTDetails GhcPs, LHsType GhcPs)
|
|
| 436 | 436 | |
| 437 | 437 | The key part of the ExactPrint instance for this is
|
| 438 | 438 | |
| ... | ... | @@ -4146,6 +4146,14 @@ instance ExactPrint (HsType GhcPs) where |
| 4146 | 4146 | (ann', mt') <- exactBang (ann, mt) str
|
| 4147 | 4147 | ty' <- markAnnotated ty
|
| 4148 | 4148 | return (XHsType (HsBangTy ann' (HsSrcBang mt' up str) ty'))
|
| 4149 | + -- mkGadtDecl sometimes leaves HsRecTy intact instead of converting
|
|
| 4150 | + -- it to RecConGADT, counting on the renamer to reject it later on.
|
|
| 4151 | + -- Exact printing must cope with it.
|
|
| 4152 | + exact (XHsType (HsRecTy (o,c) flds)) = do
|
|
| 4153 | + o' <- markEpToken o
|
|
| 4154 | + flds' <- markAnnotated flds
|
|
| 4155 | + c' <- markEpToken c
|
|
| 4156 | + return (XHsType (HsRecTy (o',c') flds'))
|
|
| 4149 | 4157 | exact (HsExplicitListTy (sq,o,c) prom tys) = do
|
| 4150 | 4158 | sq' <- if (isPromoted prom)
|
| 4151 | 4159 | then markEpToken sq
|
| ... | ... | @@ -4462,7 +4470,7 @@ instance ExactPrint (ConDecl GhcPs) where |
| 4462 | 4470 | , con_names = cons
|
| 4463 | 4471 | , con_outer_bndrs = outer_bndrs
|
| 4464 | 4472 | , con_inner_bndrs = inner_bndrs
|
| 4465 | - , con_mb_cxt = mcxt, con_g_args = args
|
|
| 4473 | + , con_cxts = cxts, con_g_args = args
|
|
| 4466 | 4474 | , con_modifiers = mods
|
| 4467 | 4475 | , con_res_ty = res_ty, con_doc = doc }) = do
|
| 4468 | 4476 | mods' <- mapM markAnnotated mods
|
| ... | ... | @@ -4475,15 +4483,15 @@ instance ExactPrint (ConDecl GhcPs) where |
| 4475 | 4483 | L _ (HsOuterImplicit _) -> return outer_bndrs
|
| 4476 | 4484 | _ -> markAnnotated outer_bndrs
|
| 4477 | 4485 | |
| 4478 | - let ib = toInnerBindings inner_bndrs (mcxt, args, res_ty)
|
|
| 4486 | + let ib = toInnerBindings inner_bndrs (cxts, args, res_ty)
|
|
| 4479 | 4487 | ib' <- markAnnotated ib
|
| 4480 | - let (inner_bndrs', (mcxt', args', res_ty')) = fromInnerBindings ib'
|
|
| 4488 | + let (inner_bndrs', (cxts', args', res_ty')) = fromInnerBindings ib'
|
|
| 4481 | 4489 | |
| 4482 | 4490 | return (ConDeclGADT { con_g_ext = AnnConDeclGADT [] [] dcol'
|
| 4483 | 4491 | , con_names = cons'
|
| 4484 | 4492 | , con_outer_bndrs = outer_bndrs'
|
| 4485 | 4493 | , con_inner_bndrs = inner_bndrs'
|
| 4486 | - , con_mb_cxt = mcxt', con_g_args = args'
|
|
| 4494 | + , con_cxts = cxts', con_g_args = args'
|
|
| 4487 | 4495 | , con_modifiers = mods'
|
| 4488 | 4496 | , con_res_ty = res_ty', con_doc = doc })
|
| 4489 | 4497 | |
| ... | ... | @@ -4491,14 +4499,14 @@ instance ExactPrint (ConDecl GhcPs) where |
| 4491 | 4499 | |
| 4492 | 4500 | data InnerBindings
|
| 4493 | 4501 | = InnerMore (LHsGadtTelescope GhcPs) InnerBindings
|
| 4494 | - | InnerDone (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs)
|
|
| 4502 | + | InnerDone ([LHsContext GhcPs], HsConDeclGADTDetails GhcPs, LHsType GhcPs)
|
|
| 4495 | 4503 | |
| 4496 | 4504 | toInnerBindings :: [LHsGadtTelescope GhcPs]
|
| 4497 | - -> (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs) -> InnerBindings
|
|
| 4505 | + -> ([LHsContext GhcPs], HsConDeclGADTDetails GhcPs, LHsType GhcPs) -> InnerBindings
|
|
| 4498 | 4506 | toInnerBindings [] inner = InnerDone inner
|
| 4499 | 4507 | toInnerBindings (b:bs) inner = InnerMore b (toInnerBindings bs inner)
|
| 4500 | 4508 | |
| 4501 | -fromInnerBindings :: InnerBindings -> ([LHsGadtTelescope GhcPs], (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs))
|
|
| 4509 | +fromInnerBindings :: InnerBindings -> ([LHsGadtTelescope GhcPs], ([LHsContext GhcPs], HsConDeclGADTDetails GhcPs, LHsType GhcPs))
|
|
| 4502 | 4510 | fromInnerBindings = go []
|
| 4503 | 4511 | where
|
| 4504 | 4512 | go acc (InnerMore b n) = go (b:acc) n
|
| ... | ... | @@ -4520,8 +4528,8 @@ instance ExactPrint InnerBindings where |
| 4520 | 4528 | xs' <- markAnnotated xs
|
| 4521 | 4529 | rp' <- markEpToken rp
|
| 4522 | 4530 | return (InnerMore (L l (HsGadtPar (lp',rp'))) xs')
|
| 4523 | - exact (InnerDone (mcxt, args, res_ty)) = do
|
|
| 4524 | - mcxt' <- markAnnotated mcxt
|
|
| 4531 | + exact (InnerDone (cxts, args, res_ty)) = do
|
|
| 4532 | + cxts' <- mapM markAnnotated cxts
|
|
| 4525 | 4533 | args' <-
|
| 4526 | 4534 | case args of
|
| 4527 | 4535 | (PrefixConGADT x args0) -> do
|
| ... | ... | @@ -4534,7 +4542,7 @@ instance ExactPrint InnerBindings where |
| 4534 | 4542 | rarr' <- markEpUniToken rarr
|
| 4535 | 4543 | return (RecConGADT (oc',cc',rarr') fields')
|
| 4536 | 4544 | res_ty' <- markAnnotated res_ty
|
| 4537 | - return (InnerDone (mcxt', args', res_ty'))
|
|
| 4545 | + return (InnerDone (cxts', args', res_ty'))
|
|
| 4538 | 4546 | |
| 4539 | 4547 | -- ---------------------------------------------------------------------
|
| 4540 | 4548 |
| ... | ... | @@ -340,7 +340,7 @@ ppCtor |
| 340 | 340 | { con_names = names
|
| 341 | 341 | , con_outer_bndrs = L _ outer_bndrs
|
| 342 | 342 | , con_inner_bndrs = inner_bndrs
|
| 343 | - , con_mb_cxt = mcxt
|
|
| 343 | + , con_cxts = cxts
|
|
| 344 | 344 | , con_g_args = args
|
| 345 | 345 | , con_res_ty = res_ty
|
| 346 | 346 | }
|
| ... | ... | @@ -352,9 +352,7 @@ ppCtor |
| 352 | 352 | con_sig_ty = HsSig noExtField outer_bndrs $
|
| 353 | 353 | mkGadtArgTys inner_bndrs phi_ty
|
| 354 | 354 | where
|
| 355 | - phi_ty = case mcxt of
|
|
| 356 | - Just theta -> mkQualTy theta tau_ty
|
|
| 357 | - Nothing -> tau_ty
|
|
| 355 | + phi_ty = foldr mkQualTy tau_ty cxts
|
|
| 358 | 356 | tau_ty = foldr mkFunTy res_ty $
|
| 359 | 357 | case args of
|
| 360 | 358 | PrefixConGADT _ pos_args -> map cdf_type pos_args
|
| ... | ... | @@ -29,7 +29,7 @@ module Haddock.Convert |
| 29 | 29 | |
| 30 | 30 | import Control.DeepSeq (force)
|
| 31 | 31 | import Data.Either (lefts, partitionEithers, rights)
|
| 32 | -import Data.Maybe (catMaybes, mapMaybe)
|
|
| 32 | +import Data.Maybe (catMaybes, mapMaybe, maybeToList)
|
|
| 33 | 33 | import GHC.Builtin.KnownKeys
|
| 34 | 34 | ( boxedRepDataConKey
|
| 35 | 35 | , eqTyConKey
|
| ... | ... | @@ -625,7 +625,7 @@ synifyDataCon use_gadt_syntax dc = |
| 625 | 625 | , con_names = pure name
|
| 626 | 626 | , con_outer_bndrs = noLocA outer_bndrs
|
| 627 | 627 | , con_inner_bndrs = inner_bndrs
|
| 628 | - , con_mb_cxt = ctx
|
|
| 628 | + , con_cxts = maybeToList ctx
|
|
| 629 | 629 | , con_g_args = hat
|
| 630 | 630 | , con_res_ty = synifyType WithinType emptyVarSet res_ty
|
| 631 | 631 | , con_modifiers = []
|
| ... | ... | @@ -220,7 +220,7 @@ getGADTConType |
| 220 | 220 | ( ConDeclGADT
|
| 221 | 221 | { con_outer_bndrs = outer_bndrs
|
| 222 | 222 | , con_inner_bndrs = inner_bndrs
|
| 223 | - , con_mb_cxt = mcxt
|
|
| 223 | + , con_cxts = cxts
|
|
| 224 | 224 | , con_g_args = args
|
| 225 | 225 | , con_res_ty = res_ty
|
| 226 | 226 | }
|
| ... | ... | @@ -234,9 +234,7 @@ getGADTConType |
| 234 | 234 | )
|
| 235 | 235 | where
|
| 236 | 236 | phi_ty :: LHsType DocNameI
|
| 237 | - phi_ty = case mcxt of
|
|
| 238 | - Nothing -> tau_ty
|
|
| 239 | - Just theta -> mkQualTy theta tau_ty
|
|
| 237 | + phi_ty = foldr mkQualTy tau_ty cxts
|
|
| 240 | 238 | |
| 241 | 239 | tau_ty :: LHsType DocNameI
|
| 242 | 240 | tau_ty = case args of
|
| ... | ... | @@ -758,7 +758,7 @@ renameCon |
| 758 | 758 | { con_names = lnames
|
| 759 | 759 | , con_outer_bndrs = outer_bndrs
|
| 760 | 760 | , con_inner_bndrs = inner_bndrs
|
| 761 | - , con_mb_cxt = lcontext
|
|
| 761 | + , con_cxts = lcontexts
|
|
| 762 | 762 | , con_g_args = details
|
| 763 | 763 | , con_res_ty = res_ty
|
| 764 | 764 | , con_modifiers = mods
|
| ... | ... | @@ -767,7 +767,7 @@ renameCon |
| 767 | 767 | lnames' <- mapM renameNameL lnames
|
| 768 | 768 | outer_bndrs' <- mapM renameOuterTyVarBndrs outer_bndrs
|
| 769 | 769 | inner_bndrs' <- mapM renameHsGadtTelescope inner_bndrs
|
| 770 | - lcontext' <- traverse renameLContext lcontext
|
|
| 770 | + lcontexts' <- traverse renameLContext lcontexts
|
|
| 771 | 771 | details' <- renameGADTDetails details
|
| 772 | 772 | res_ty' <- renameLType res_ty
|
| 773 | 773 | mods' <- renameModifiers mods
|
| ... | ... | @@ -778,7 +778,7 @@ renameCon |
| 778 | 778 | , con_names = lnames'
|
| 779 | 779 | , con_outer_bndrs = outer_bndrs'
|
| 780 | 780 | , con_inner_bndrs = inner_bndrs'
|
| 781 | - , con_mb_cxt = lcontext'
|
|
| 781 | + , con_cxts = lcontexts'
|
|
| 782 | 782 | , con_g_args = details'
|
| 783 | 783 | , con_res_ty = res_ty'
|
| 784 | 784 | , con_modifiers = mods'
|