[Git][ghc/ghc][wip/T26217] 2 commits: ghc-internal: Move Data instance for TH.Syntax to Data.Data

Teo Camarasu pushed to branch wip/T26217 at Glasgow Haskell Compiler / GHC
Commits:
fc20efb3 by Teo Camarasu at 2025-08-17T22:53:32+01:00
ghc-internal: Move Data instance for TH.Syntax to Data.Data
This means that Data.Data no longer blocks building TH.Syntax, which
allows greater parallelism in our builds.
Previously TH.Syntax was a bottleneck when compiling ghc-internal. Now
it is less of a bottle-neck and is also slightly quicker to
compile (since it no longer contains these instances) at the cost of
making Data.Data slightly more expensive to compile.
TH.Lift which depends on TH.Syntax can also compile quicker and no
longer blocks ghc-internal finishing to compile.
Resolves #26217
- - - - -
63b5b30d by Teo Camarasu at 2025-08-17T22:53:32+01:00
compiler: delete unused names in Builtins.Names.TH
returnQ and bindQ are no longer used in the compiler.
There was also a very old comment that referred to them that I have modernized
- - - - -
4 changed files:
- compiler/GHC/Builtin/Names/TH.hs
- compiler/GHC/HsToCore/Quote.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Data.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs
Changes:
=====================================
compiler/GHC/Builtin/Names/TH.hs
=====================================
@@ -30,7 +30,7 @@ templateHaskellNames :: [Name]
-- Should stay in sync with the import list of GHC.HsToCore.Quote
templateHaskellNames = [
- returnQName, bindQName, sequenceQName, newNameName, liftName, liftTypedName,
+ sequenceQName, newNameName, liftName, liftTypedName,
mkNameName, mkNameG_vName, mkNameG_dName, mkNameG_tcName, mkNameG_fldName,
mkNameLName,
mkNameSName, mkNameQName,
@@ -240,12 +240,10 @@ overlapTyConName = thTc (fsLit "Overlap") overlapTyConKey
modNameTyConName = thTc (fsLit "ModName") modNameTyConKey
quasiQuoterTyConName = mk_known_key_name tcName qqLib (fsLit "QuasiQuoter") quasiQuoterTyConKey
-returnQName, bindQName, sequenceQName, newNameName, liftName,
+sequenceQName, newNameName, liftName,
mkNameName, mkNameG_vName, mkNameG_fldName, mkNameG_dName, mkNameG_tcName,
mkNameLName, mkNameSName, liftStringName, unTypeName, unTypeCodeName,
unsafeCodeCoerceName, liftTypedName, mkModNameName, mkNameQName :: Name
-returnQName = thFun (fsLit "returnQ") returnQIdKey
-bindQName = thFun (fsLit "bindQ") bindQIdKey
sequenceQName = thMonadFun (fsLit "sequenceQ") sequenceQIdKey
newNameName = thMonadFun (fsLit "newName") newNameIdKey
mkNameName = thFun (fsLit "mkName") mkNameIdKey
@@ -812,12 +810,10 @@ dataNamespaceSpecifierDataConKey = mkPreludeDataConUnique 215
-- IdUniques available: 200-499
-- If you want to change this, make sure you check in GHC.Builtin.Names
-returnQIdKey, bindQIdKey, sequenceQIdKey, liftIdKey, newNameIdKey,
+sequenceQIdKey, liftIdKey, newNameIdKey,
mkNameIdKey, mkNameG_vIdKey, mkNameG_fldIdKey, mkNameG_dIdKey, mkNameG_tcIdKey,
mkNameLIdKey, mkNameSIdKey, unTypeIdKey, unTypeCodeIdKey,
unsafeCodeCoerceIdKey, liftTypedIdKey, mkModNameIdKey, mkNameQIdKey :: Unique
-returnQIdKey = mkPreludeMiscIdUnique 200
-bindQIdKey = mkPreludeMiscIdUnique 201
sequenceQIdKey = mkPreludeMiscIdUnique 202
liftIdKey = mkPreludeMiscIdUnique 203
newNameIdKey = mkPreludeMiscIdUnique 204
=====================================
compiler/GHC/HsToCore/Quote.hs
=====================================
@@ -245,14 +245,14 @@ first generate a polymorphic definition and then just apply the wrapper at the e
[| \x -> x |]
====>
- gensym (unpackString "x"#) `bindQ` \ x1::String ->
- lam (pvar x1) (var x1)
+ newName (unpackString "x"#) >>= \ x1::Name ->
+ lamE (varP x1) (varE x1)
[| \x -> $(f [| x |]) |]
====>
- gensym (unpackString "x"#) `bindQ` \ x1::String ->
- lam (pvar x1) (f (var x1))
+ newName (unpackString "x"#) >>= \ x1::Name ->
+ lamE (varP x1) (f (varE x1))
-}
=====================================
libraries/ghc-internal/src/GHC/Internal/Data/Data.hs
=====================================
@@ -143,6 +143,7 @@ import GHC.Internal.Arr -- So we can give Data instance for Array
import qualified GHC.Internal.Generics as Generics (Fixity(..))
import GHC.Internal.Generics hiding (Fixity(..))
-- So we can give Data instance for U1, V1, ...
+import qualified GHC.Internal.TH.Syntax as TH
------------------------------------------------------------------------------
--
@@ -1353,3 +1354,63 @@ deriving instance Data DecidedStrictness
-- | @since base-4.12.0.0
deriving instance Data a => Data (Down a)
+
+----------------------------------------------------------------------------
+-- Data instances for GHC.Internal.TH.Syntax
+
+deriving instance Data TH.AnnLookup
+deriving instance Data TH.AnnTarget
+deriving instance Data TH.Bang
+deriving instance Data TH.BndrVis
+deriving instance Data TH.Body
+deriving instance Data TH.Bytes
+deriving instance Data TH.Callconv
+deriving instance Data TH.Clause
+deriving instance Data TH.Con
+deriving instance Data TH.Dec
+deriving instance Data TH.DecidedStrictness
+deriving instance Data TH.DerivClause
+deriving instance Data TH.DerivStrategy
+deriving instance Data TH.DocLoc
+deriving instance Data TH.Exp
+deriving instance Data TH.FamilyResultSig
+deriving instance Data TH.Fixity
+deriving instance Data TH.FixityDirection
+deriving instance Data TH.Foreign
+deriving instance Data TH.FunDep
+deriving instance Data TH.Guard
+deriving instance Data TH.Info
+deriving instance Data TH.InjectivityAnn
+deriving instance Data TH.Inline
+deriving instance Data TH.Lit
+deriving instance Data TH.Loc
+deriving instance Data TH.Match
+deriving instance Data TH.ModName
+deriving instance Data TH.Module
+deriving instance Data TH.ModuleInfo
+deriving instance Data TH.Name
+deriving instance Data TH.NameFlavour
+deriving instance Data TH.NameSpace
+deriving instance Data TH.NamespaceSpecifier
+deriving instance Data TH.OccName
+deriving instance Data TH.Overlap
+deriving instance Data TH.Pat
+deriving instance Data TH.PatSynArgs
+deriving instance Data TH.PatSynDir
+deriving instance Data TH.Phases
+deriving instance Data TH.PkgName
+deriving instance Data TH.Pragma
+deriving instance Data TH.Range
+deriving instance Data TH.Role
+deriving instance Data TH.RuleBndr
+deriving instance Data TH.RuleMatch
+deriving instance Data TH.Safety
+deriving instance Data TH.SourceStrictness
+deriving instance Data TH.SourceUnpackedness
+deriving instance Data TH.Specificity
+deriving instance Data TH.Stmt
+deriving instance Data TH.TyLit
+deriving instance Data TH.TySynEqn
+deriving instance Data TH.Type
+deriving instance Data TH.TypeFamilyHead
+deriving instance Data flag => Data (TH.TyVarBndr flag)
=====================================
libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs
=====================================
@@ -1,14 +1,16 @@
{-# OPTIONS_HADDOCK not-home #-} -- we want users to import Language.Haskell.TH.Syntax instead
-{-# LANGUAGE CPP, DeriveDataTypeable,
- DeriveGeneric, FlexibleInstances, DefaultSignatures,
- RankNTypes, RoleAnnotations, ScopedTypeVariables,
- MagicHash, KindSignatures, PolyKinds, TypeApplications, DataKinds,
- GADTs, UnboxedTuples, UnboxedSums, TypeOperators,
- Trustworthy, DeriveFunctor, DeriveTraversable,
- BangPatterns, RecordWildCards, ImplicitParams #-}
-
-{-# LANGUAGE TemplateHaskellQuotes #-}
-{-# LANGUAGE StandaloneKindSignatures #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE DeriveTraversable #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE RoleAnnotations #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE Safe #-}
+{-# LANGUAGE UnboxedTuples #-}
-- | This module is used internally in GHC's integration with Template Haskell
-- and defines the abstract syntax of Template Haskell.
@@ -26,7 +28,6 @@ module GHC.Internal.TH.Syntax
#ifdef BOOTSTRAP_TH
import Prelude
-import Data.Data hiding (Fixity(..))
import System.IO.Unsafe ( unsafePerformIO )
import Data.Char ( isAlpha, isAlphaNum, isUpper )
import Data.List.NonEmpty ( NonEmpty(..) )
@@ -38,7 +39,6 @@ import GHC.Ptr ( Ptr, plusPtr )
import GHC.Generics ( Generic )
#else
import GHC.Internal.Base hiding (NonEmpty(..),Type, Module, sequence)
-import GHC.Internal.Data.Data hiding (Fixity(..))
import GHC.Internal.Data.NonEmpty (NonEmpty(..))
import GHC.Internal.Data.Traversable
import GHC.Internal.Word
@@ -72,19 +72,19 @@ manyName = mkNameG DataName "ghc-internal" "GHC.Internal.Types" "Many"
-- | The name of a module.
newtype ModName = ModName String -- Module name
- deriving (Show,Eq,Ord,Data,Generic)
+ deriving (Show,Eq,Ord,Generic)
-- | The name of a package.
newtype PkgName = PkgName String -- package name
- deriving (Show,Eq,Ord,Data,Generic)
+ deriving (Show,Eq,Ord,Generic)
-- | Obtained from 'reifyModule' and 'Language.Haskell.TH.Lib.thisModule'.
data Module = Module PkgName ModName -- package qualified module name
- deriving (Show,Eq,Ord,Data,Generic)
+ deriving (Show,Eq,Ord,Generic)
-- | An "Occurence Name".
newtype OccName = OccName String
- deriving (Show,Eq,Ord,Data,Generic)
+ deriving (Show,Eq,Ord,Generic)
-- | Smart constructor for 'ModName'
mkModName :: String -> ModName
@@ -200,7 +200,7 @@ Names constructed using @newName@ and @mkName@ may be used in bindings
(such as @let x = ...@ or @\x -> ...@), but names constructed using
@lookupValueName@, @lookupTypeName@, @'f@, @''T@ may not.
-}
-data Name = Name OccName NameFlavour deriving (Data, Eq, Generic)
+data Name = Name OccName NameFlavour deriving (Eq, Generic)
instance Ord Name where
-- check if unique is different before looking at strings
@@ -216,7 +216,7 @@ data NameFlavour
-- An original name (occurrences only, not binders)
-- Need the namespace too to be sure which
-- thing we are naming
- deriving ( Data, Eq, Ord, Show, Generic )
+ deriving ( Eq, Ord, Show, Generic )
data NameSpace = VarName -- ^ Variables
| DataName -- ^ Data constructors
@@ -230,7 +230,7 @@ data NameSpace = VarName -- ^ Variables
-- of the datatype (regardless of whether this constructor has this field).
-- - For a field of a pattern synonym, this is the name of the pattern synonym.
}
- deriving( Eq, Ord, Show, Data, Generic )
+ deriving( Eq, Ord, Show, Generic )
-- | @Uniq@ is used by GHC to distinguish names from each other.
type Uniq = Integer
@@ -532,7 +532,7 @@ data Loc
, loc_module :: String
, loc_start :: CharPos
, loc_end :: CharPos }
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
type CharPos = (Int, Int) -- ^ Line and character position
@@ -615,13 +615,13 @@ data Info
| TyVarI -- Scoped type variable
Name
Type -- What it is bound to
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
-- | Obtained from 'reifyModule' in the 'Q' Monad.
data ModuleInfo =
-- | Contains the import list of the module.
ModuleInfo [Module]
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
{- |
In 'ClassOpI' and 'DataConI', name of the parent class or type
@@ -659,11 +659,11 @@ type InstanceDec = Dec
-- | Fixity, as specified in a @infix[lr] n@ declaration.
data Fixity = Fixity Int FixityDirection
- deriving( Eq, Ord, Show, Data, Generic )
+ deriving( Eq, Ord, Show, Generic )
-- | The associativity of an operator, as in an @infix@ declaration.
data FixityDirection = InfixL | InfixR | InfixN
- deriving( Eq, Ord, Show, Data, Generic )
+ deriving( Eq, Ord, Show, Generic )
-- | Highest allowed operator precedence for 'Fixity' constructor (answer: 9)
maxPrecedence :: Int
@@ -696,7 +696,7 @@ data Lit = CharL Char -- ^ @\'c\'@
| StringPrimL [Word8] -- ^ @"string"#@. A primitive C-style string, type 'Addr#'
| BytesPrimL Bytes -- ^ Some raw bytes, type 'Addr#':
| CharPrimL Char -- ^ @\'c\'#@
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
-- We could add Int, Float, Double etc, as we do in HsLit,
-- but that could complicate the
@@ -718,7 +718,7 @@ data Bytes = Bytes
-- , bytesInitialized :: Bool -- ^ False: only use `bytesSize` to allocate
-- -- an uninitialized region
}
- deriving (Data,Generic)
+ deriving (Generic)
-- We can't derive Show instance for Bytes because we don't want to show the
-- pointer value but the actual bytes (similarly to what ByteString does). See
@@ -785,14 +785,14 @@ data Pat
| TypeP Type -- ^ @{ type p }@
| InvisP Type -- ^ @{ @p }@
| OrP (NonEmpty Pat) -- ^ @{ p1; p2 }@
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
-- | A (field name, pattern) pair. See 'RecP'.
type FieldPat = (Name,Pat)
-- | A @case@-alternative
data Match = Match Pat Body [Dec] -- ^ @case e of { pat -> body where decs }@
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
-- | A clause consists of patterns, guards, a body expression, and a list of
-- declarations under a @where@. Clauses are seen in equations for function
@@ -800,7 +800,7 @@ data Match = Match Pat Body [Dec] -- ^ @case e of { pat -> body where decs }@
-- etc.
data Clause = Clause [Pat] Body [Dec]
-- ^ @f { p1 p2 = body where decs }@
- deriving( Show, Eq, Ord, Data, Generic )
+ deriving( Show, Eq, Ord, Generic )
-- | A Haskell expression.
data Exp
@@ -895,7 +895,7 @@ data Exp
| ForallE [TyVarBndr Specificity] Exp -- ^ @forall \
participants (1)
-
Teo Camarasu (@teo)