diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-07-30 10:22:48 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-08-02 16:44:11 -0400 |
commit | 226417424b2b578fd3c5424588367cb24e7720eb (patch) | |
tree | 031e3f130324e1b24ee863bf1aaef471698ce2f7 /compiler/GHC/Parser | |
parent | e30fed6c6de1f881ce313900274294a793e42677 (diff) | |
download | haskell-226417424b2b578fd3c5424588367cb24e7720eb.tar.gz |
Remove ConDeclGADTPrefixPs
This removes the `ConDeclGADTPrefixPs` per the discussion in #18517.
Most of this patch simply removes code, although the code in the
`rnConDecl` case for `ConDeclGADTPrefixPs` had to be moved around a
bit:
* The nested `forall`s check now lives in the `rnConDecl` case for
`ConDeclGADT`.
* The `LinearTypes`-specific code that used to live in the
`rnConDecl` case for `ConDeclGADTPrefixPs` now lives in
`GHC.Parser.PostProcess.mkGadtDecl`, which is now monadic so that
it can check if `-XLinearTypes` is enabled.
Fixes #18157.
Diffstat (limited to 'compiler/GHC/Parser')
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 57 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess/Haddock.hs | 9 |
2 files changed, 32 insertions, 34 deletions
diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 24ceb1f3ea..6fa3d5316b 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -670,34 +670,41 @@ mkConDeclH98 name mb_forall mb_cxt args , con_doc = Nothing } -- | Construct a GADT-style data constructor from the constructor names and --- their type. This will return different AST forms for record syntax --- constructors and prefix constructors, as the latter must be handled --- specially in the renamer. See @Note [GADT abstract syntax]@ in --- "GHC.Hs.Decls" for the full story. +-- their type. Some interesting aspects of this function: +-- +-- * This splits up the constructor type into its quantified type variables (if +-- provided), context (if provided), argument types, and result type, and +-- records whether this is a prefix or record GADT constructor. See +-- Note [GADT abstract syntax] in "GHC.Hs.Decls" for more details. +-- +-- * If -XLinearTypes is not enabled, the function arrows in a prefix GADT +-- constructor are always interpreted as linear. If -XLinearTypes is enabled, +-- we faithfully record whether -> or #-> was used. mkGadtDecl :: [Located RdrName] -> LHsType GhcPs - -> ConDecl GhcPs -mkGadtDecl names ty - | Just (mtvs, mcxt, args, res_ty) <- mb_record_gadt ty - = ConDeclGADT { con_g_ext = noExtField - , con_names = names - , con_forall = L (getLoc ty) $ isJust mtvs - , con_qvars = fromMaybe [] mtvs - , con_mb_cxt = mcxt - , con_args = args - , con_res_ty = res_ty - , con_doc = Nothing } - | otherwise - = XConDecl $ ConDeclGADTPrefixPs { con_gp_names = names - , con_gp_ty = mkLHsSigType ty - , con_gp_doc = Nothing } + -> P (ConDecl GhcPs) +mkGadtDecl names ty = do + linearEnabled <- getBit LinearTypesBit + + let (args, res_ty) + | L _ (HsFunTy _ _w (L loc (HsRecTy _ rf)) res_ty) <- body_ty + = (RecCon (L loc rf), res_ty) + | otherwise + = let (arg_types, res_type) = splitHsFunType body_ty + arg_types' | linearEnabled = arg_types + | otherwise = map (hsLinear . hsScaledThing) arg_types + in (PrefixCon arg_types', res_type) + + pure $ ConDeclGADT { con_g_ext = noExtField + , con_names = names + , con_forall = L (getLoc ty) $ isJust mtvs + , con_qvars = fromMaybe [] mtvs + , con_mb_cxt = mcxt + , con_args = args + , con_res_ty = res_ty + , con_doc = Nothing } where - mb_record_gadt ty - | (mtvs, mcxt, body_ty) <- splitLHsGADTPrefixTy ty - , L _ (HsFunTy _ _w (L loc (HsRecTy _ rf)) res_ty) <- body_ty - = Just (mtvs, mcxt, RecCon (L loc rf), res_ty) - | otherwise - = Nothing + (mtvs, mcxt, body_ty) = splitLHsGadtTy ty setRdrNameSpace :: RdrName -> NameSpace -> RdrName -- ^ This rather gruesome function is used mainly by the parser. diff --git a/compiler/GHC/Parser/PostProcess/Haddock.hs b/compiler/GHC/Parser/PostProcess/Haddock.hs index 8201aeee3c..8c4e061e86 100644 --- a/compiler/GHC/Parser/PostProcess/Haddock.hs +++ b/compiler/GHC/Parser/PostProcess/Haddock.hs @@ -716,15 +716,6 @@ instance HasHaddock (Located (ConDecl GhcPs)) where ConDeclH98 { con_ext, con_name, con_forall, con_ex_tvs, con_mb_cxt, con_doc = con_doc', con_args = RecCon (L l_rec flds') } - XConDecl (ConDeclGADTPrefixPs { con_gp_names, con_gp_ty }) -> do - -- discardHasInnerDocs is ok because we don't need this info for GADTs. - con_gp_doc' <- discardHasInnerDocs $ getConDoc (getLoc (head con_gp_names)) - con_gp_ty' <- addHaddock con_gp_ty - pure $ L l_con_decl $ - XConDecl (ConDeclGADTPrefixPs - { con_gp_names, - con_gp_ty = con_gp_ty', - con_gp_doc = con_gp_doc' }) -- Keep track of documentation comments on the data constructor or any of its -- fields. |