[Git][ghc/ghc][wip/kirchner/ast] AST: extract Specificity, ForAllTyFlag and helper functions from GHC.Types.Var

Fabian Kirchner (@kirchner) gitlab at gitlab.haskell.org
Sun Jun 9 10:20:52 UTC 2024



Fabian Kirchner pushed to branch wip/kirchner/ast at Glasgow Haskell Compiler / GHC


Commits:
017c8c31 by Fabian Kirchner at 2024-06-09T12:14:59+02:00
AST: extract Specificity, ForAllTyFlag and helper functions from GHC.Types.Var

Specificity, ForAllTyFlag and its' helper functions are extracted from
GHC.Types.Var and moved into a new module Language.Haskell.Syntax.Specificity.

Note: Eventually (i.e. after Language.Haskell.Syntax.Decls does not depend on
GHC.* anymore) these should be moved into Language.Haskell.Syntax.Decls.
At this point, this would cause cyclic dependencies.

- - - - -


25 changed files:

- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion.hs-boot
- compiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/TyCo/Compare.hs
- compiler/GHC/Core/TyCo/Ppr.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Rep.hs-boot
- compiler/GHC/Core/TyCon.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Type.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Gen/Sig.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
- compiler/GHC/Tc/Types/Evidence.hs
- compiler/GHC/Types/Literal.hs
- compiler/GHC/Types/Var.hs
- compiler/GHC/Types/Var.hs-boot
- compiler/Language/Haskell/Syntax/Decls.hs
- + compiler/Language/Haskell/Syntax/Specificity.hs


Changes:

=====================================
compiler/GHC/Core/Coercion.hs
=====================================
@@ -164,6 +164,8 @@ import GHC.Utils.Misc
 import GHC.Utils.Outputable
 import GHC.Utils.Panic
 
+import Language.Haskell.Syntax.Specificity (coreTyLamForAllTyFlag)
+
 import Control.Monad (foldM, zipWithM)
 import Data.Function ( on )
 import Data.Char( isDigit )


=====================================
compiler/GHC/Core/Coercion.hs-boot
=====================================
@@ -12,6 +12,7 @@ import GHC.Core.Coercion.Axiom
 import GHC.Types.Var
 import GHC.Data.Pair
 import GHC.Utils.Misc
+import Language.Haskell.Syntax.Specificity (ForAllTyFlag)
 
 mkReflCo :: Role -> Type -> Coercion
 mkTyConAppCo :: HasDebugCallStack => Role -> TyCon -> [Coercion] -> Coercion


=====================================
compiler/GHC/Core/Lint.hs
=====================================
@@ -106,6 +106,8 @@ import GHC.Data.Pair
 import GHC.Base (oneShot)
 import GHC.Data.Unboxed
 
+import Language.Haskell.Syntax.Specificity (coreTyLamForAllTyFlag)
+
 {-
 Note [Core Lint guarantee]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~


=====================================
compiler/GHC/Core/Opt/Arity.hs
=====================================
@@ -87,6 +87,8 @@ import GHC.Utils.Outputable
 import GHC.Utils.Panic
 import GHC.Utils.Misc
 
+import Language.Haskell.Syntax.Specificity (coreTyLamForAllTyFlag)
+
 import Data.Maybe( isJust )
 
 {-


=====================================
compiler/GHC/Core/TyCo/Compare.hs
=====================================
@@ -42,6 +42,8 @@ import GHC.Base (reallyUnsafePtrEquality#)
 
 import qualified Data.Semigroup as S
 
+import Language.Haskell.Syntax.Specificity (isInvisibleForAllTyFlag)
+
 {- GHC.Core.TyCo.Compare overview
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 This module implements type equality and comparison


=====================================
compiler/GHC/Core/TyCo/Ppr.hs
=====================================
@@ -53,6 +53,8 @@ import GHC.Utils.Panic
 import GHC.Types.Basic ( PprPrec(..), topPrec, sigPrec, opPrec
                        , funPrec, appPrec, maybeParen )
 
+import Language.Haskell.Syntax.Specificity (Specificity(..))
+
 {-
 %************************************************************************
 %*                                                                      *


=====================================
compiler/GHC/Core/TyCo/Rep.hs
=====================================
@@ -96,6 +96,8 @@ import qualified Data.Data as Data hiding ( TyCon )
 import Data.IORef ( IORef )   -- for CoercionHole
 import Control.DeepSeq
 
+import Language.Haskell.Syntax.Specificity (ForAllTyFlag(..), coreTyLamForAllTyFlag)
+
 {- **********************************************************************
 *                                                                       *
                         Type


=====================================
compiler/GHC/Core/TyCo/Rep.hs-boot
=====================================
@@ -3,8 +3,9 @@ module GHC.Core.TyCo.Rep where
 
 import GHC.Utils.Outputable ( Outputable )
 import Data.Data  ( Data )
-import {-# SOURCE #-} GHC.Types.Var( Var, VarBndr, ForAllTyFlag, FunTyFlag )
+import {-# SOURCE #-} GHC.Types.Var( Var, VarBndr, FunTyFlag )
 import {-# SOURCE #-} GHC.Core.TyCon ( TyCon )
+import {-# SOURCE #-} Language.Haskell.Syntax.Specificity ( ForAllTyFlag )
 
 data Type
 data Coercion


=====================================
compiler/GHC/Core/TyCon.hs
=====================================
@@ -183,6 +183,7 @@ import GHC.Types.Unique.Set
 import GHC.Unit.Module
 
 import Language.Haskell.Syntax.Basic (FieldLabelString(..))
+import Language.Haskell.Syntax.Specificity (ForAllTyFlag(..), Specificity(..), isVisibleForAllTyFlag)
 
 import qualified Data.Data as Data
 


=====================================
compiler/GHC/Core/Type.hs
=====================================
@@ -291,6 +291,8 @@ import GHC.Data.FastString
 
 import GHC.Data.Maybe   ( orElse, isJust, firstJust )
 
+import Language.Haskell.Syntax.Specificity (Specificity(..), isInvisibleForAllTyFlag, isVisibleForAllTyFlag)
+
 -- $type_classification
 -- #type_classification#
 --


=====================================
compiler/GHC/Core/Utils.hs
=====================================
@@ -109,6 +109,8 @@ import GHC.Utils.Outputable
 import GHC.Utils.Panic
 import GHC.Utils.Misc
 
+import Language.Haskell.Syntax.Specificity (coreTyLamForAllTyFlag)
+
 import Data.ByteString     ( ByteString )
 import Data.Function       ( on )
 import Data.List           ( sort, sortBy, partition, zipWith4, mapAccumL )


=====================================
compiler/GHC/HsToCore/Quote.hs
=====================================
@@ -90,6 +90,7 @@ import Data.Kind (Constraint)
 import qualified GHC.LanguageExtensions as LangExt
 
 import Language.Haskell.Syntax.Basic (FieldLabelString(..))
+import Language.Haskell.Syntax.Specificity (Specificity(..))
 
 import Data.ByteString ( unpack )
 import Control.Monad


=====================================
compiler/GHC/Iface/Type.hs
=====================================
@@ -100,6 +100,8 @@ import Control.Arrow (first)
 import Control.DeepSeq
 import Control.Monad ((<$!>))
 
+import Language.Haskell.Syntax.Specificity (ForAllTyFlag(..), Specificity, isInvisibleForAllTyFlag, isVisibleForAllTyFlag, coreTyLamForAllTyFlag)
+
 {-
 ************************************************************************
 *                                                                      *


=====================================
compiler/GHC/Tc/Errors/Types.hs
=====================================
@@ -189,7 +189,7 @@ import GHC.Types.Name.Reader
 import GHC.Types.SourceFile (HsBootOrSig(..))
 import GHC.Types.SrcLoc
 import GHC.Types.TyThing (TyThing)
-import GHC.Types.Var (Id, TyCoVar, TyVar, TcTyVar, CoVar, Specificity)
+import GHC.Types.Var (Id, TyCoVar, TyVar, TcTyVar, CoVar)
 import GHC.Types.Var.Env (TidyEnv)
 import GHC.Types.Var.Set (TyVarSet, VarSet)
 import GHC.Unit.Types (Module)
@@ -214,6 +214,7 @@ import GHC.Data.Pair
 import GHC.Exception.Type (SomeException)
 
 import Language.Haskell.Syntax.Basic (FieldLabelString(..))
+import Language.Haskell.Syntax.Specificity (Specificity)
 
 import qualified Data.List.NonEmpty as NE
 import           Data.Typeable (Typeable)


=====================================
compiler/GHC/Tc/Gen/App.hs
=====================================
@@ -62,6 +62,8 @@ import GHC.Utils.Outputable as Outputable
 import GHC.Utils.Panic
 import qualified GHC.LanguageExtensions as LangExt
 
+import Language.Haskell.Syntax.Specificity (isInferredForAllTyFlag)
+
 import Control.Monad
 import Data.Function
 


=====================================
compiler/GHC/Tc/Gen/Bind.hs
=====================================
@@ -96,6 +96,8 @@ import GHC.Data.Maybe
 import Control.Monad
 import Data.Foldable (find)
 
+import Language.Haskell.Syntax.Specificity (Specificity(..))
+
 {-
 ************************************************************************
 *                                                                      *


=====================================
compiler/GHC/Tc/Gen/Pat.hs
=====================================
@@ -75,6 +75,7 @@ import qualified Data.List.NonEmpty as NE
 
 import GHC.Data.List.SetOps ( getNth )
 import Language.Haskell.Syntax.Basic (FieldLabelString(..))
+import Language.Haskell.Syntax.Specificity (isSpecifiedForAllTyFlag)
 
 import Data.List( partition )
 import Data.Maybe (isJust)


=====================================
compiler/GHC/Tc/Gen/Sig.hs
=====================================
@@ -51,7 +51,7 @@ import GHC.Core.Type ( mkTyVarBinders )
 import GHC.Core.Multiplicity
 import GHC.Core.TyCo.Rep( mkNakedFunTy )
 
-import GHC.Types.Var ( TyVar, Specificity(..), tyVarKind, binderVars, invisArgTypeLike )
+import GHC.Types.Var ( TyVar, tyVarKind, binderVars, invisArgTypeLike )
 import GHC.Types.Id  ( Id, idName, idType, setInlinePragma
                      , mkLocalId, realIdUnfolding )
 import GHC.Types.Basic
@@ -72,6 +72,8 @@ import Data.Maybe( mapMaybe )
 import qualified Data.List.NonEmpty as NE
 import Control.Monad( unless )
 
+import Language.Haskell.Syntax.Specificity (Specificity(..))
+
 
 {- -------------------------------------------------------------
           Note [Overview of type signatures]


=====================================
compiler/GHC/Tc/TyCl/PatSyn.hs
=====================================
@@ -69,6 +69,8 @@ import Control.Monad ( zipWithM )
 import Data.List( partition, mapAccumL )
 import Data.List.NonEmpty (NonEmpty, nonEmpty)
 
+import Language.Haskell.Syntax.Specificity (Specificity(..))
+
 {-
 ************************************************************************
 *                                                                      *


=====================================
compiler/GHC/Tc/Types/Evidence.hs
=====================================
@@ -85,6 +85,8 @@ import Data.IORef( IORef )
 import GHC.Types.Unique.Set
 import GHC.Core.Multiplicity
 
+import Language.Haskell.Syntax.Specificity (coreTyLamForAllTyFlag)
+
 import qualified Data.Semigroup as S
 
 {-


=====================================
compiler/GHC/Types/Literal.hs
=====================================
@@ -87,6 +87,8 @@ import Data.Data ( Data )
 import GHC.Exts( isTrue#, dataToTag#, (<#) )
 import Numeric ( fromRat )
 
+import Language.Haskell.Syntax.Specificity (ForAllTyFlag(..))
+
 {-
 ************************************************************************
 *                                                                      *


=====================================
compiler/GHC/Types/Var.hs
=====================================
@@ -65,13 +65,6 @@ module GHC.Types.Var (
         isGlobalId, isExportedId,
         mustHaveLocalBinding,
 
-        -- * ForAllTyFlags
-        ForAllTyFlag(Invisible,Required,Specified,Inferred),
-        Specificity(..),
-        isVisibleForAllTyFlag, isInvisibleForAllTyFlag, isInferredForAllTyFlag,
-        isSpecifiedForAllTyFlag,
-        coreTyLamForAllTyFlag,
-
         -- * FunTyFlag
         FunTyFlag(..), isVisibleFunArg, isInvisibleFunArg, isFUNArg,
         mkFunTyFlag, visArg, invisArg,
@@ -129,6 +122,8 @@ import GHC.Utils.Binary
 import GHC.Utils.Outputable
 import GHC.Utils.Panic
 
+import Language.Haskell.Syntax.Specificity (ForAllTyFlag(..), Specificity(..), isInvisibleForAllTyFlag, isVisibleForAllTyFlag)
+
 import Data.Data
 import Control.DeepSeq
 
@@ -455,57 +450,6 @@ updateVarTypeM upd var
 *                                                                      *
 ********************************************************************* -}
 
--- | ForAllTyFlag
---
--- Is something required to appear in source Haskell ('Required'),
--- permitted by request ('Specified') (visible type application), or
--- prohibited entirely from appearing in source Haskell ('Inferred')?
--- See Note [VarBndrs, ForAllTyBinders, TyConBinders, and visibility] in "GHC.Core.TyCo.Rep"
-data ForAllTyFlag = Invisible !Specificity
-                  | Required
-  deriving (Eq, Ord, Data)
-  -- (<) on ForAllTyFlag means "is less visible than"
-
--- | Whether an 'Invisible' argument may appear in source Haskell.
-data Specificity = InferredSpec
-                   -- ^ the argument may not appear in source Haskell, it is
-                   -- only inferred.
-                 | SpecifiedSpec
-                   -- ^ the argument may appear in source Haskell, but isn't
-                   -- required.
-  deriving (Eq, Ord, Data)
-
-pattern Inferred, Specified :: ForAllTyFlag
-pattern Inferred  = Invisible InferredSpec
-pattern Specified = Invisible SpecifiedSpec
-
-{-# COMPLETE Required, Specified, Inferred #-}
-
--- | Does this 'ForAllTyFlag' classify an argument that is written in Haskell?
-isVisibleForAllTyFlag :: ForAllTyFlag -> Bool
-isVisibleForAllTyFlag af = not (isInvisibleForAllTyFlag af)
-
--- | Does this 'ForAllTyFlag' classify an argument that is not written in Haskell?
-isInvisibleForAllTyFlag :: ForAllTyFlag -> Bool
-isInvisibleForAllTyFlag (Invisible {}) = True
-isInvisibleForAllTyFlag Required       = False
-
-isInferredForAllTyFlag :: ForAllTyFlag -> Bool
--- More restrictive than isInvisibleForAllTyFlag
-isInferredForAllTyFlag (Invisible InferredSpec) = True
-isInferredForAllTyFlag _                        = False
-
-isSpecifiedForAllTyFlag :: ForAllTyFlag -> Bool
--- More restrictive than isInvisibleForAllTyFlag
-isSpecifiedForAllTyFlag (Invisible SpecifiedSpec) = True
-isSpecifiedForAllTyFlag _                         = False
-
-coreTyLamForAllTyFlag :: ForAllTyFlag
--- ^ The ForAllTyFlag on a (Lam a e) term, where `a` is a type variable.
--- If you want other ForAllTyFlag, use a cast.
--- See Note [Required foralls in Core] in GHC.Core.TyCo.Rep
-coreTyLamForAllTyFlag = Specified
-
 instance Outputable ForAllTyFlag where
   ppr Required  = text "[req]"
   ppr Specified = text "[spec]"


=====================================
compiler/GHC/Types/Var.hs-boot
=====================================
@@ -2,13 +2,12 @@
 module GHC.Types.Var where
 
 import {-# SOURCE #-} GHC.Types.Name
+import Language.Haskell.Syntax.Specificity (Specificity)
 
-data ForAllTyFlag
 data FunTyFlag
 data Var
 instance NamedThing Var
 data VarBndr var argf
-data Specificity
 type TyVar = Var
 type Id    = Var
 type TyCoVar = Id


=====================================
compiler/Language/Haskell/Syntax/Decls.hs
=====================================
@@ -98,13 +98,13 @@ import Language.Haskell.Syntax.Binds
 import Language.Haskell.Syntax.Extension
 import Language.Haskell.Syntax.Type
 import Language.Haskell.Syntax.Basic (Role)
+import Language.Haskell.Syntax.Specificity (Specificity)
 
 import GHC.Types.Basic (TopLevelFlag, OverlapMode, RuleName, Activation
                        ,TyConFlavour(..), TypeOrData(..))
 import GHC.Types.ForeignCall (CType, CCallConv, Safety, Header, CLabelString, CCallTarget, CExportSpec)
 import GHC.Types.Fixity (LexicalFixity)
 
-import GHC.Core.Type (Specificity)
 import GHC.Unit.Module.Warnings (WarningTxt)
 import GHC.Utils.Panic.Plain ( assert )
 


=====================================
compiler/Language/Haskell/Syntax/Specificity.hs
=====================================
@@ -0,0 +1,68 @@
+{-# LANGUAGE MultiWayIf, PatternSynonyms #-}
+
+-- TODO Everthing in this module should be moved to
+-- Language.Haskell.Syntax.Decls
+
+module Language.Haskell.Syntax.Specificity (
+        -- * ForAllTyFlags
+        ForAllTyFlag(Invisible,Required,Specified,Inferred),
+        Specificity(..),
+        isVisibleForAllTyFlag, isInvisibleForAllTyFlag, isInferredForAllTyFlag,
+        isSpecifiedForAllTyFlag,
+        coreTyLamForAllTyFlag,
+        ) where
+
+import Prelude
+
+import Data.Data
+
+-- | ForAllTyFlag
+--
+-- Is something required to appear in source Haskell ('Required'),
+-- permitted by request ('Specified') (visible type application), or
+-- prohibited entirely from appearing in source Haskell ('Inferred')?
+-- See Note [VarBndrs, ForAllTyBinders, TyConBinders, and visibility] in "GHC.Core.TyCo.Rep"
+data ForAllTyFlag = Invisible !Specificity
+                  | Required
+  deriving (Eq, Ord, Data)
+  -- (<) on ForAllTyFlag means "is less visible than"
+
+-- | Whether an 'Invisible' argument may appear in source Haskell.
+data Specificity = InferredSpec
+                   -- ^ the argument may not appear in source Haskell, it is
+                   -- only inferred.
+                 | SpecifiedSpec
+                   -- ^ the argument may appear in source Haskell, but isn't
+                   -- required.
+  deriving (Eq, Ord, Data)
+
+pattern Inferred, Specified :: ForAllTyFlag
+pattern Inferred  = Invisible InferredSpec
+pattern Specified = Invisible SpecifiedSpec
+
+{-# COMPLETE Required, Specified, Inferred #-}
+
+-- | Does this 'ForAllTyFlag' classify an argument that is written in Haskell?
+isVisibleForAllTyFlag :: ForAllTyFlag -> Bool
+isVisibleForAllTyFlag af = not (isInvisibleForAllTyFlag af)
+
+-- | Does this 'ForAllTyFlag' classify an argument that is not written in Haskell?
+isInvisibleForAllTyFlag :: ForAllTyFlag -> Bool
+isInvisibleForAllTyFlag (Invisible {}) = True
+isInvisibleForAllTyFlag Required       = False
+
+isInferredForAllTyFlag :: ForAllTyFlag -> Bool
+-- More restrictive than isInvisibleForAllTyFlag
+isInferredForAllTyFlag (Invisible InferredSpec) = True
+isInferredForAllTyFlag _                        = False
+
+isSpecifiedForAllTyFlag :: ForAllTyFlag -> Bool
+-- More restrictive than isInvisibleForAllTyFlag
+isSpecifiedForAllTyFlag (Invisible SpecifiedSpec) = True
+isSpecifiedForAllTyFlag _                         = False
+
+coreTyLamForAllTyFlag :: ForAllTyFlag
+-- ^ The ForAllTyFlag on a (Lam a e) term, where `a` is a type variable.
+-- If you want other ForAllTyFlag, use a cast.
+-- See Note [Required foralls in Core] in GHC.Core.TyCo.Rep
+coreTyLamForAllTyFlag = Specified



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/017c8c319cd599a199006904de5694f00cc6896b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/017c8c319cd599a199006904de5694f00cc6896b
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/62fc9448/attachment-0001.html>


More information about the ghc-commits mailing list