diff options
author | Zubin Duggal <zubin@cmi.ac.in> | 2020-01-08 16:28:28 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-25 00:44:30 -0400 |
commit | 02133353e712e98bfbbc6ed32305b137bb3654eb (patch) | |
tree | 12909a607dd2910501813fc4d0550913ade367be /compiler/GHC/HsToCore | |
parent | ba205046e4f2ea94b1c978c050b917de4daaf092 (diff) | |
download | haskell-02133353e712e98bfbbc6ed32305b137bb3654eb.tar.gz |
Simplify XRec definition
Change `Located X` usage to `XRec pass X`
This increases the scope of the LPat experiment to almost all of GHC.
Introduce UnXRec and MapXRec classes
Fixes #17587 and #18408
Updates haddock submodule
Co-authored-by: Philipp Krüger <philipp.krueger1@gmail.com>
Diffstat (limited to 'compiler/GHC/HsToCore')
-rw-r--r-- | compiler/GHC/HsToCore/Docs.hs | 40 | ||||
-rw-r--r-- | compiler/GHC/HsToCore/Expr.hs | 1 |
2 files changed, 22 insertions, 19 deletions
diff --git a/compiler/GHC/HsToCore/Docs.hs b/compiler/GHC/HsToCore/Docs.hs index 7066405274..0716fe756a 100644 --- a/compiler/GHC/HsToCore/Docs.hs +++ b/compiler/GHC/HsToCore/Docs.hs @@ -1,5 +1,8 @@ -- | Extract docs from the renamer output so they can be serialized. {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ViewPatterns #-} @@ -112,9 +115,7 @@ user-written. This lets us relate Names (from ClsInsts) to comments (associated with InstDecls and DerivDecls). -} -getMainDeclBinder :: (CollectPass (GhcPass p)) - => HsDecl (GhcPass p) - -> [IdP (GhcPass p)] +getMainDeclBinder :: CollectPass (GhcPass p) => HsDecl (GhcPass p) -> [IdP (GhcPass p)] getMainDeclBinder (TyClD _ d) = [tcdName d] getMainDeclBinder (ValD _ d) = case collectHsBindBinders d of @@ -125,13 +126,14 @@ getMainDeclBinder (ForD _ (ForeignImport _ name _ _)) = [unLoc name] getMainDeclBinder (ForD _ (ForeignExport _ _ _ _)) = [] getMainDeclBinder _ = [] -sigNameNoLoc :: Sig pass -> [IdP pass] -sigNameNoLoc (TypeSig _ ns _) = map unLoc ns -sigNameNoLoc (ClassOpSig _ _ ns _) = map unLoc ns -sigNameNoLoc (PatSynSig _ ns _) = map unLoc ns -sigNameNoLoc (SpecSig _ n _ _) = [unLoc n] -sigNameNoLoc (InlineSig _ n _) = [unLoc n] -sigNameNoLoc (FixSig _ (FixitySig _ ns _)) = map unLoc ns + +sigNameNoLoc :: forall pass. UnXRec pass => Sig pass -> [IdP pass] +sigNameNoLoc (TypeSig _ ns _) = map (unXRec @pass) ns +sigNameNoLoc (ClassOpSig _ _ ns _) = map (unXRec @pass) ns +sigNameNoLoc (PatSynSig _ ns _) = map (unXRec @pass) ns +sigNameNoLoc (SpecSig _ n _ _) = [unXRec @pass n] +sigNameNoLoc (InlineSig _ n _) = [unXRec @pass n] +sigNameNoLoc (FixSig _ (FixitySig _ ns _)) = map (unXRec @pass) ns sigNameNoLoc _ = [] -- Extract the source location where an instance is defined. This is used @@ -302,14 +304,14 @@ ungroup group_ = -- | Collect docs and attach them to the right declarations. -- -- A declaration may have multiple doc strings attached to it. -collectDocs :: [LHsDecl pass] -> [(LHsDecl pass, [HsDocString])] +collectDocs :: forall p. UnXRec p => [LHsDecl p] -> [(LHsDecl p, [HsDocString])] -- ^ This is an example. collectDocs = go [] Nothing where go docs mprev decls = case (decls, mprev) of - ((unLoc->DocD _ (DocCommentNext s)) : ds, Nothing) -> go (s:docs) Nothing ds - ((unLoc->DocD _ (DocCommentNext s)) : ds, Just prev) -> finished prev docs $ go [s] Nothing ds - ((unLoc->DocD _ (DocCommentPrev s)) : ds, mprev) -> go (s:docs) mprev ds + ((unXRec @p -> DocD _ (DocCommentNext s)) : ds, Nothing) -> go (s:docs) Nothing ds + ((unXRec @p -> DocD _ (DocCommentNext s)) : ds, Just prev) -> finished prev docs $ go [s] Nothing ds + ((unXRec @p -> DocD _ (DocCommentPrev s)) : ds, mprev) -> go (s:docs) mprev ds (d : ds, Nothing) -> go docs (Just d) ds (d : ds, Just prev) -> finished prev docs $ go [] (Just d) ds ([] , Nothing) -> [] @@ -318,8 +320,8 @@ collectDocs = go [] Nothing finished decl docs rest = (decl, reverse docs) : rest -- | Filter out declarations that we don't handle in Haddock -filterDecls :: [(LHsDecl a, doc)] -> [(LHsDecl a, doc)] -filterDecls = filter (isHandled . unLoc . fst) +filterDecls :: forall p doc. UnXRec p => [(LHsDecl p, doc)] -> [(LHsDecl p, doc)] +filterDecls = filter (isHandled . unXRec @p . fst) where isHandled (ForD _ (ForeignImport {})) = True isHandled (TyClD {}) = True @@ -333,12 +335,12 @@ filterDecls = filter (isHandled . unLoc . fst) -- | Go through all class declarations and filter their sub-declarations -filterClasses :: [(LHsDecl a, doc)] -> [(LHsDecl a, doc)] -filterClasses = map (first (mapLoc filterClass)) +filterClasses :: forall p doc. (UnXRec p, MapXRec p) => [(LHsDecl p, doc)] -> [(LHsDecl p, doc)] +filterClasses = map (first (mapXRec @p filterClass)) where filterClass (TyClD x c@(ClassDecl {})) = TyClD x $ c { tcdSigs = - filter (liftA2 (||) (isUserSig . unLoc) isMinimalLSig) (tcdSigs c) } + filter (liftA2 (||) (isUserSig . unXRec @p) isMinimalLSig) (tcdSigs c) } filterClass d = d -- | Was this signature given by the user? diff --git a/compiler/GHC/HsToCore/Expr.hs b/compiler/GHC/HsToCore/Expr.hs index 2b959006e0..931527b57a 100644 --- a/compiler/GHC/HsToCore/Expr.hs +++ b/compiler/GHC/HsToCore/Expr.hs @@ -102,6 +102,7 @@ dsIPBinds (IPBinds ev_binds ip_binds) body -- dependency order; hence Rec ; foldrM ds_ip_bind inner ip_binds } where + ds_ip_bind :: LIPBind GhcTc -> CoreExpr -> DsM CoreExpr ds_ip_bind (L _ (IPBind _ ~(Right n) e)) body = do e' <- dsLExpr e return (Let (NonRec n e') body) |