[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:34:09 UTC 2024
Fabian Kirchner pushed to branch wip/kirchner/ast at Glasgow Haskell Compiler / GHC
Commits:
078ef121 by Fabian Kirchner at 2024-06-09T12:33:37+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.
- - - - -
5 changed files:
- compiler/GHC/Core/TyCo/Rep.hs-boot
- 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/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 Language.Haskell.Syntax.Specificity (ForAllTyFlag)
data Type
data Coercion
=====================================
compiler/GHC/Types/Var.hs
=====================================
@@ -129,6 +129,8 @@ import GHC.Utils.Binary
import GHC.Utils.Outputable
import GHC.Utils.Panic
+import Language.Haskell.Syntax.Specificity
+
import Data.Data
import Control.DeepSeq
@@ -455,57 +457,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, ForAllTyFlag)
-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/078ef12190b00b9001fe18d05b2beff56670afb7
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/078ef12190b00b9001fe18d05b2beff56670afb7
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/ce8137fd/attachment-0001.html>
More information about the ghc-commits
mailing list