diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2021-05-04 20:09:31 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2022-04-02 07:11:30 -0400 |
commit | ff8d81265090dc89e067a08028d9c598f72529ab (patch) | |
tree | 1e3393647bd970d9fa515529cadcce35aceff16b /compiler/GHC/Hs/Decls.hs | |
parent | d85c7dcb7c457efc23b20ac8f4e4ae88bae5b050 (diff) | |
download | haskell-wip/T18389-task-zero.tar.gz |
Introduce and use ConGadtSigBody (preparatory refactor for #18389)wip/T18389-task-zero
This patch removes the `con_g_args :: HsConDeclGADTDetails pass` and
`con_res_ty :: LHsType pass` fields of `ConDeclGADT` in favor of a unified
`con_body :: ConGadtSigBody pass` field. There are two major differences
between `HsConDeclGADTDetails` and `ConGadtSigBody`:
1. `HsConDeclGADTDetails` only contains the argument type, while
`ConGadtSigBody` contains both the argument and result types.
2. The `PrefixConGADT` constructor of `ConGadtSigBody` now uses a new
`PrefixConGadtSigBody` data type. `PrefixConGadtSigBody` closely mirrors the
structure of `HsType`, but with minor, data constructor–specific tweaks.
This will become vital in a future patch which implements nested `forall`s
and contexts in prefix GADT constructor types (see #18389).
Besides the refactoring in the GHC API (and some minor changes in
GHC AST–related test cases) this does not introduce any user-visible
changes in behavior.
Diffstat (limited to 'compiler/GHC/Hs/Decls.hs')
-rw-r--r-- | compiler/GHC/Hs/Decls.hs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/compiler/GHC/Hs/Decls.hs b/compiler/GHC/Hs/Decls.hs index 568783bdb5..a61b6f1514 100644 --- a/compiler/GHC/Hs/Decls.hs +++ b/compiler/GHC/Hs/Decls.hs @@ -76,7 +76,9 @@ module GHC.Hs.Decls ( CImportSpec(..), -- ** Data-constructor declarations ConDecl(..), LConDecl, - HsConDeclH98Details, HsConDeclGADTDetails(..), hsConDeclTheta, + HsConDeclH98Details, + ConGadtSigBody(..), PrefixConGadtSigBody(..), + anonPrefixConGadtSigArgs, prefixConGadtSigRes, hsConDeclTheta, getConNames, getRecConArgs_maybe, -- ** Document comments DocDecl(..), LDocDecl, docDeclDoc, @@ -624,9 +626,9 @@ getRecConArgs_maybe (ConDeclH98{con_args = args}) = case args of PrefixCon{} -> Nothing RecCon flds -> Just flds InfixCon{} -> Nothing -getRecConArgs_maybe (ConDeclGADT{con_g_args = args}) = case args of - PrefixConGADT{} -> Nothing - RecConGADT flds _ -> Just flds +getRecConArgs_maybe (ConDeclGADT{con_body = body}) = case body of + PrefixConGADT{} -> Nothing + RecConGADT flds _ _ -> Just flds hsConDeclTheta :: Maybe (LHsContext (GhcPass p)) -> [LHsType (GhcPass p)] hsConDeclTheta Nothing = [] @@ -701,14 +703,20 @@ pprConDecl (ConDeclH98 { con_name = L _ con <+> pprConDeclFields (unLoc fields) 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 }) + , con_mb_cxt = mcxt, con_body = body, con_doc = doc }) = pprMaybeWithDoc doc $ ppr_con_names cons <+> dcolon <+> (sep [pprHsOuterSigTyVarBndrs outer_bndrs <+> pprLHsContext mcxt, - sep (ppr_args args ++ [ppr res_ty]) ]) + ppr_body body ]) where - ppr_args (PrefixConGADT args) = map (\(HsScaled arr t) -> ppr t <+> ppr_arr arr) args - ppr_args (RecConGADT fields _) = [pprConDeclFields (unLoc fields) <+> arrow] + ppr_body (PrefixConGADT args) = ppr_prefix_body args + ppr_body (RecConGADT fields _ res_ty) = + sep [ pprConDeclFields (unLoc fields) + , arrow <+> ppr res_ty ] + + ppr_prefix_body (PCGSRes res_ty) = ppr res_ty + ppr_prefix_body (PCGSAnonArg (HsScaled arr arg) body') = + sep [ ppr arg + , ppr_arr arr <+> ppr_prefix_body body' ] -- Display linear arrows as unrestricted with -XNoLinearTypes -- (cf. dataConDisplayType in Note [Displaying linear fields] in GHC.Core.DataCon) |