From 226417424b2b578fd3c5424588367cb24e7720eb Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 30 Jul 2020 10:22:48 -0400 Subject: 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. --- compiler/GHC/Rename/Module.hs | 48 ++++++------------------------------------- 1 file changed, 6 insertions(+), 42 deletions(-) (limited to 'compiler/GHC/Rename') diff --git a/compiler/GHC/Rename/Module.hs b/compiler/GHC/Rename/Module.hs index 2bcee1f15f..5e82ebdb7f 100644 --- a/compiler/GHC/Rename/Module.hs +++ b/compiler/GHC/Rename/Module.hs @@ -1856,7 +1856,6 @@ rnDataDefn doc (HsDataDefn { dd_ND = new_or_data, dd_cType = cType where h98_style = case condecls of -- Note [Stupid theta] (L _ (ConDeclGADT {})) : _ -> False - (L _ (XConDecl (ConDeclGADTPrefixPs {}))) : _ -> False _ -> True rn_derivs (L loc ds) @@ -2246,6 +2245,12 @@ rnConDecl decl@(ConDeclGADT { con_names = names ; (new_args, fvs2) <- rnConDeclDetails (unLoc (head new_names)) ctxt args ; (new_res_ty, fvs3) <- rnLHsType ctxt res_ty + -- Ensure that there are no nested `forall`s or contexts, per + -- Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts) + -- in GHC.Hs.Type. + ; addNoNestedForallsContextsErr ctxt + (text "GADT constructor type signature") new_res_ty + ; let all_fvs = fvs1 `plusFV` fvs2 `plusFV` fvs3 ; traceRn "rnConDecl (ConDeclGADT)" @@ -2257,47 +2262,6 @@ rnConDecl decl@(ConDeclGADT { con_names = names , con_forall = forall }, -- Remove when #18311 is fixed all_fvs) } } --- This case is only used for prefix GADT constructors generated by GHC's --- parser, where we do not know the argument types until type operator --- precedence has been resolved. See Note [GADT abstract syntax] in --- GHC.Hs.Decls for the full story. -rnConDecl (XConDecl (ConDeclGADTPrefixPs { con_gp_names = names, con_gp_ty = ty - , con_gp_doc = mb_doc })) - = do { mapM_ (addLocM checkConName) names - ; new_names <- mapM lookupLocatedTopBndrRn names - ; mb_doc' <- rnMbLHsDoc mb_doc - - ; let ctxt = ConDeclCtx new_names - ; (ty', fvs) <- rnHsSigType ctxt TypeLevel ty - ; linearTypes <- xopt LangExt.LinearTypes <$> getDynFlags - - -- Now that operator precedence has been resolved, we can split the - -- GADT type into its individual components below. - ; let HsIB { hsib_ext = implicit_tkvs, hsib_body = body } = ty' - (mb_explicit_tkvs, mb_cxt, tau) = splitLHsGADTPrefixTy body - lhas_forall = L (getLoc body) $ isJust mb_explicit_tkvs - explicit_tkvs = fromMaybe [] mb_explicit_tkvs - (arg_tys, res_ty) = splitHsFunType tau - arg_details | linearTypes = PrefixCon arg_tys - | otherwise = PrefixCon $ map (hsLinear . hsScaledThing) arg_tys - - -- NB: The only possibility here is PrefixCon. RecCon is handled - -- separately, through ConDeclGADT, from the parser onwards. - - -- Ensure that there are no nested `forall`s or contexts, per - -- Note [GADT abstract syntax] (Wrinkle: No nested foralls or contexts) - -- in GHC.Hs.Type. - ; addNoNestedForallsContextsErr ctxt - (text "GADT constructor type signature") res_ty - - ; traceRn "rnConDecl (ConDeclGADTPrefixPs)" - (ppr names $$ ppr implicit_tkvs $$ ppr explicit_tkvs) - ; pure (ConDeclGADT { con_g_ext = implicit_tkvs, con_names = new_names - , con_forall = lhas_forall, con_qvars = explicit_tkvs - , con_mb_cxt = mb_cxt, con_args = arg_details - , con_res_ty = res_ty, con_doc = mb_doc' }, - fvs) } - rnMbContext :: HsDocContext -> Maybe (LHsContext GhcPs) -> RnM (Maybe (LHsContext GhcRn), FreeVars) rnMbContext _ Nothing = return (Nothing, emptyFVs) -- cgit v1.2.1