[Git][ghc/ghc][wip/aforemny/ast] 4 commits: AST: remove `GHC.Types.SourceText` from `Language.Haskell.Syntax.Binds`

Alexander Foremny (@aforemny) gitlab at gitlab.haskell.org
Sun Jun 9 16:45:47 UTC 2024



Alexander Foremny pushed to branch wip/aforemny/ast at Glasgow Haskell Compiler / GHC


Commits:
f2ec2f73 by Alexander Foremny at 2024-06-09T10:52:57+02:00
AST: remove `GHC.Types.SourceText` from `Language.Haskell.Syntax.Binds`

The `SCCFunSig` tracks the optional cost centre name as a
`GHC.Types.SourceText.StringLiteral`. Since we want to keep it in the
AST, we introduce an extension field `XSCCFunSigCC`.

We have NOT merged it into the existing extension field `XSCCFunSig`.

- - - - -
f3216652 by Alexander Foremny at 2024-06-09T10:56:01+02:00
AST: remove `GHC.Types.SourceText.StringLiteral` from `Language.Haskell.Syntax.Expr`

The `HsPragSCC` tracks the set cost centre SCC pragma as a
`GHC.Types.SourceText.StringLiteral`. Since we want to keep it in the
AST, we introduce an extension field `XSCCCC`.

We have NOT merged it into the existing extension field `XSCC`.

- - - - -
eb734893 by Alexander Foremny at 2024-06-09T11:34:09+02:00
AST: remove `GHC.Types.SourceText.StringLiteral` from `Language.Haskell.Syntax.Decls`

This commit does not really remove it, but argues that it will likely be
moved out when `WithHsDocIdentifiers` is moved out.

- - - - -
9565c263 by Alexander Foremny at 2024-06-09T12:01:21+02:00
AST: remove `GHC.Types.SourceText.SourceText` from `Language.Haskell.Syntax.Decls`

Introduces an extension field each for the constructors of `WarningTxt`
to abstract over `SourceText`.

- - - - -


7 changed files:

- compiler/GHC/Hs/Binds.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Unit/Module/Warnings.hs
- compiler/Language/Haskell/Syntax/Binds.hs
- compiler/Language/Haskell/Syntax/Decls.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/Language/Haskell/Syntax/Extension.hs


Changes:

=====================================
compiler/GHC/Hs/Binds.hs
=====================================
@@ -714,6 +714,7 @@ type instance XSpecSig          (GhcPass p) = [AddEpAnn]
 type instance XSpecInstSig      (GhcPass p) = ([AddEpAnn], SourceText)
 type instance XMinimalSig       (GhcPass p) = ([AddEpAnn], SourceText)
 type instance XSCCFunSig        (GhcPass p) = ([AddEpAnn], SourceText)
+type instance XSCCFunSigCC      (GhcPass p) = StringLiteral
 type instance XCompleteMatchSig (GhcPass p) = ([AddEpAnn], SourceText)
     -- SourceText: Note [Pragma source text] in "GHC.Types.SourceText"
 type instance XXSig             GhcPs = DataConCantHappen


=====================================
compiler/GHC/Hs/Expr.hs
=====================================
@@ -429,6 +429,7 @@ instance NoAnn AnnsIf where
 -- ---------------------------------------------------------------------
 
 type instance XSCC           (GhcPass _) = (AnnPragma, SourceText)
+type instance XSCCCC         (GhcPass _) = StringLiteral
 type instance XXPragE        (GhcPass _) = DataConCantHappen
 
 type instance XCDotFieldOcc (GhcPass _) = AnnFieldLabel


=====================================
compiler/GHC/Unit/Module/Warnings.hs
=====================================
@@ -62,7 +62,7 @@ import GHC.Utils.Outputable
 import GHC.Unicode
 
 import Language.Haskell.Syntax.Extension
-import Language.Haskell.Syntax.Decls (WarningTxt(..), InWarningCategory(..), XInWarningCategoryIn(), WarningCategory(..))
+import Language.Haskell.Syntax.Decls (WarningTxt(..), XWarningTxt, XDeprecatedTxt, InWarningCategory(..), XInWarningCategory, XInWarningCategoryIn(), WarningCategory(..))
 
 import Data.List (isPrefixOf)
 
@@ -73,6 +73,8 @@ fromWarningCategory
   => WarningCategory -> InWarningCategory (GhcPass pass)
 fromWarningCategory wc = InWarningCategory noAnn NoSourceText (noLocA wc)
 
+type instance XInWarningCategory (GhcPass p) = SourceText
+
 mkWarningCategory :: FastString -> WarningCategory
 mkWarningCategory = WarningCategory
 
@@ -190,6 +192,9 @@ instance Outputable (WarningTxt (GhcPass p)) where
           NoSourceText   -> pp_ws ds
           SourceText src -> ftext src <+> pp_ws ds <+> text "#-}"
 
+type instance XWarningTxt (GhcPass p) = SourceText
+type instance XDeprecatedTxt (GhcPass p) = SourceText
+
 pp_ws :: [LocatedE (WithHsDocIdentifiers StringLiteral pass)] -> SDoc
 pp_ws [l] = ppr $ unLoc l
 pp_ws ws
@@ -248,6 +253,9 @@ type ExportWarnNames pass = [(Name, WarningTxt pass)]
 
 deriving instance
   ( Eq (IdP (GhcPass p)),
+    Eq (XWarningTxt (GhcPass p)),
+    Eq (XDeprecatedTxt (GhcPass p)),
+    Eq (XInWarningCategory (GhcPass p)),
     Eq (XInWarningCategoryIn (GhcPass p))
   ) => Eq (Warnings (GhcPass p))
 


=====================================
compiler/Language/Haskell/Syntax/Binds.hs
=====================================
@@ -37,7 +37,6 @@ import GHC.Data.Bag (Bag)
 import GHC.Types.Basic (InlinePragma)
 
 import GHC.Data.BooleanFormula (LBooleanFormula)
-import GHC.Types.SourceText (StringLiteral)
 
 import Data.Void
 import Data.Bool
@@ -478,7 +477,7 @@ data Sig pass
 
   | SCCFunSig  (XSCCFunSig pass)
                (LIdP pass)    -- Function name
-               (Maybe (XRec pass StringLiteral))
+               (Maybe (XRec pass (XSCCFunSigCC pass))) -- cost centre name
        -- | A complete match pragma
        --
        -- > {-# COMPLETE C, D [:: T] #-}


=====================================
compiler/Language/Haskell/Syntax/Decls.hs
=====================================
@@ -87,8 +87,8 @@ module Language.Haskell.Syntax.Decls (
   -- * Grouping
   HsGroup(..), hsGroupInstDecls,
   -- * Warnings
-  WarningTxt(..), InWarningCategory(..), WarningCategory(..),
-  XInWarningCategoryIn,
+  WarningTxt(..), XWarningTxt, XDeprecatedTxt, InWarningCategory(..),
+  XInWarningCategory, WarningCategory(..), XInWarningCategoryIn,
     ) where
 
 -- friends:
@@ -110,7 +110,8 @@ import GHC.Core.Type (Specificity)
 import GHC.Utils.Panic.Plain ( assert )
 
 import GHC.Hs.Doc (LHsDoc, WithHsDocIdentifiers) -- ROMES:TODO Discuss in #21592 whether this is parsed AST or base AST
-import GHC.Types.SourceText (StringLiteral, SourceText)
+-- TODO(ghc-import): `StringLiteral` is only used in `WithHsDocIdentifiers`, which presumably get moved out themselves.
+import GHC.Types.SourceText (StringLiteral)
 
 import Control.Monad
 import Data.Data        hiding (TyCon, Fixity, Infix)
@@ -1800,15 +1801,21 @@ data WarningTxt pass
       (Maybe (XRec pass (InWarningCategory pass)))
         -- ^ Warning category attached to this WARNING pragma, if any;
         -- see Note [Warning categories]
-      SourceText
+      (XWarningTxt pass)
       [XRec pass (WithHsDocIdentifiers StringLiteral pass)]
    | DeprecatedTxt
-      SourceText
+      (XDeprecatedTxt pass)
       [XRec pass (WithHsDocIdentifiers StringLiteral pass)]
   deriving (Generic)
 
+type family XWarningTxt p
+
+type family XDeprecatedTxt p
+
 deriving instance
-  ( Eq (XRec pass (InWarningCategory pass)),
+  ( Eq (XWarningTxt pass),
+    Eq (XDeprecatedTxt pass),
+    Eq (XRec pass (InWarningCategory pass)),
     Eq (XRec pass (WithHsDocIdentifiers StringLiteral pass))
   ) => Eq (WarningTxt pass)
 
@@ -1861,15 +1868,17 @@ the possibility of them being infinite.
 data InWarningCategory pass
   = InWarningCategory
     { iwc_in :: !(XInWarningCategoryIn pass),
-      iwc_st :: !SourceText,
+      iwc_st :: !(XInWarningCategory pass),
       iwc_wc :: (XRec pass WarningCategory)
     }
 
+type family XInWarningCategory p
 
 type family XInWarningCategoryIn p
 
 deriving instance
   (
+    Eq (XInWarningCategory pass),
     Eq (XInWarningCategoryIn pass),
     Eq (XRec pass WarningCategory)
   )
@@ -1879,6 +1888,7 @@ deriving instance Typeable (InWarningCategory pass)
 
 deriving instance
   ( Data pass,
+    Data (XInWarningCategory pass),
     Data (XInWarningCategoryIn pass),
     Data (XRec pass WarningCategory)
   )


=====================================
compiler/Language/Haskell/Syntax/Expr.hs
=====================================
@@ -32,7 +32,7 @@ import Language.Haskell.Syntax.Binds
 
 -- others:
 import GHC.Types.Fixity (LexicalFixity(Infix), Fixity)
-import GHC.Types.SourceText (StringLiteral, SourceText)
+import GHC.Types.SourceText (SourceText)
 
 import GHC.Data.FastString (FastString)
 
@@ -598,7 +598,7 @@ data DotFieldOcc p
 -- | A pragma, written as {-# ... #-}, that may appear within an expression.
 data HsPragE p
   = HsPragSCC   (XSCC p)
-                StringLiteral         -- "set cost centre" SCC pragma
+                (XSCCCC p)            -- "set cost centre" SCC pragma
 
   -- | - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen',
   --       'GHC.Parser.Annotation.AnnOpen' @'{-\# GENERATED'@,


=====================================
compiler/Language/Haskell/Syntax/Extension.hs
=====================================
@@ -214,6 +214,7 @@ type family XSpecSig          x
 type family XSpecInstSig      x
 type family XMinimalSig       x
 type family XSCCFunSig        x
+type family XSCCFunSigCC      x
 type family XCompleteMatchSig x
 type family XXSig             x
 
@@ -458,6 +459,7 @@ type family XXDotFieldOcc  x
 -- -------------------------------------
 -- HsPragE type families
 type family XSCC            x
+type family XSCCCC          x
 type family XXPragE         x
 
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/523dd6642535c234d0bfd40fe80c679db281779b...9565c2630e20a1b5d0ea57d26a6550a9c96c0fba

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/523dd6642535c234d0bfd40fe80c679db281779b...9565c2630e20a1b5d0ea57d26a6550a9c96c0fba
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240609/ee1eb592/attachment-0001.html>


More information about the ghc-commits mailing list