Commit 0e9f6def authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot

Split GHC.Driver.Types

I was working on making DynFlags stateless (#17957), especially by
storing loaded plugins into HscEnv instead of DynFlags. It turned out to
be complicated because HscEnv is in GHC.Driver.Types but LoadedPlugin
isn't: it is in GHC.Driver.Plugins which depends on GHC.Driver.Types. I
didn't feel like introducing yet another hs-boot file to break the loop.

Additionally I remember that while we introduced the module hierarchy
(#13009) we talked about splitting GHC.Driver.Types because it contained
various unrelated types and functions, but we never executed. I didn't
feel like making GHC.Driver.Types bigger with more unrelated Plugins
related types, so finally I bit the bullet and split GHC.Driver.Types.

As a consequence this patch moves a lot of things. I've tried to put
them into appropriate modules but nothing is set in stone.

Several other things moved to avoid loops.

* Removed Binary instances from GHC.Utils.Binary for random compiler
  things
* Moved Typeable Binary instances into GHC.Utils.Binary.Typeable: they
  import a lot of things that users of GHC.Utils.Binary don't want to
  depend on.
* put everything related to Units/Modules under GHC.Unit:
  GHC.Unit.Finder, GHC.Unit.Module.{ModGuts,ModIface,Deps,etc.}
* Created several modules under GHC.Types: GHC.Types.Fixity, SourceText,
  etc.
* Split GHC.Utils.Error (into GHC.Types.Error)
* Finally removed GHC.Driver.Types

Note that this patch doesn't put loaded plugins into HscEnv. It's left
for another patch.

Bump haddock submodule
parent 795908dc
......@@ -264,6 +264,7 @@ module GHC (
-- * Exceptions
GhcException(..), showGhcException,
GhcApiError(..),
-- * Token stream manipulations
Token,
......@@ -294,14 +295,14 @@ module GHC (
import GHC.Prelude hiding (init)
import GHC.ByteCode.Types
import GHC.Runtime.Eval
import GHC.Runtime.Eval.Types
import GHC.Runtime.Interpreter
import GHC.Runtime.Interpreter.Types
import GHCi.RemoteTypes
import GHC.Platform
import GHC.Platform.Ways
import GHC.Core.Ppr.TyThing ( pprFamInst )
import GHC.Driver.Phases ( Phase(..), isHaskellSrcFilename
, isSourceFilename, startPhase )
import GHC.Driver.Env
import GHC.Driver.CmdLine
import GHC.Driver.Session hiding (WarnReason(..))
import GHC.Driver.Backend
import GHC.Driver.Config
import GHC.Driver.Main
......@@ -309,19 +310,49 @@ import GHC.Driver.Make
import GHC.Driver.Hooks
import GHC.Driver.Pipeline ( compileOne' )
import GHC.Driver.Monad
import GHC.Tc.Utils.Monad ( finalSafeMode, fixSafeInstances, initIfaceTcRn )
import GHC.Driver.Ppr
import GHC.ByteCode.Types
import GHC.Runtime.Eval
import GHC.Runtime.Eval.Types
import GHC.Runtime.Interpreter
import GHC.Runtime.Interpreter.Types
import GHC.Runtime.Context
import GHCi.RemoteTypes
import qualified GHC.Parser as Parser
import GHC.Parser.Lexer
import GHC.Parser.Annotation
import GHC.Parser.Errors.Ppr
import GHC.Iface.Load ( loadSysInterface )
import GHC.Hs
import GHC.Builtin.Types.Prim ( alphaTyVars )
import GHC.Iface.Tidy
import GHC.Data.Bag ( listToBag )
import GHC.Data.StringBuffer
import GHC.Data.FastString
import qualified GHC.LanguageExtensions as LangExt
import GHC.Tc.Utils.Monad ( finalSafeMode, fixSafeInstances, initIfaceTcRn )
import GHC.Tc.Types
import GHC.Tc.Utils.TcType
import GHC.Tc.Module
import GHC.Tc.Utils.Instantiate
import GHC.Tc.Instance.Family
import GHC.SysTools.FileCleanup
import GHC.SysTools
import GHC.SysTools.BaseDir
import GHC.Utils.Error
import GHC.Utils.Monad
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Core.Predicate
import GHC.Unit
import GHC.Unit.State
import GHC.Types.Name.Set
import GHC.Types.Name.Reader
import GHC.Hs
import GHC.Core.Type hiding( typeKind )
import GHC.Tc.Utils.TcType
import GHC.Types.Id
import GHC.Builtin.Types.Prim ( alphaTyVars )
import GHC.Core.TyCon
import GHC.Core.TyCo.Ppr ( pprForAll )
import GHC.Core.Class
......@@ -329,42 +360,37 @@ import GHC.Core.DataCon
import GHC.Core.FVs ( orphNamesOfFamInst )
import GHC.Core.FamInstEnv ( FamInst, famInstEnvElts )
import GHC.Core.InstEnv
import GHC.Core
import GHC.Types.Id
import GHC.Types.Name hiding ( varName )
import GHC.Types.Avail
import GHC.Types.SrcLoc
import GHC.Core
import GHC.Iface.Tidy
import GHC.Driver.Phases ( Phase(..), isHaskellSrcFilename
, isSourceFilename, startPhase )
import GHC.Driver.Finder
import GHC.Driver.Types
import GHC.Driver.CmdLine
import GHC.Driver.Session hiding (WarnReason(..))
import GHC.Platform.Ways
import GHC.Driver.Ppr
import GHC.SysTools
import GHC.SysTools.BaseDir
import GHC.Types.TyThing.Ppr ( pprFamInst )
import GHC.Types.Annotations
import GHC.Utils.Panic
import GHC.Platform
import GHC.Data.Bag ( listToBag )
import GHC.Utils.Error
import GHC.Utils.Monad
import GHC.Utils.Misc
import GHC.Data.StringBuffer
import GHC.Utils.Outputable
import GHC.Types.Name.Set
import GHC.Types.Name.Reader
import GHC.Types.SourceError
import GHC.Types.SafeHaskell
import GHC.Types.Fixity
import GHC.Types.Target
import GHC.Types.Basic
import GHC.Data.FastString
import qualified GHC.Parser as Parser
import GHC.Parser.Lexer
import GHC.Parser.Annotation
import GHC.Parser.Errors.Ppr
import qualified GHC.LanguageExtensions as LangExt
import GHC.Types.TyThing
import GHC.Types.Name.Env
import GHC.Tc.Module
import GHC.Tc.Utils.Instantiate
import GHC.Tc.Instance.Family
import GHC.SysTools.FileCleanup
import GHC.Types.Name.Ppr
import GHC.Types.TypeEnv
import GHC.Types.SourceFile
import GHC.Unit
import GHC.Unit.External
import GHC.Unit.State
import GHC.Unit.Finder
import GHC.Unit.Module.ModIface
import GHC.Unit.Module.ModGuts
import GHC.Unit.Module.ModDetails
import GHC.Unit.Module.ModSummary
import GHC.Unit.Module.Graph
import GHC.Unit.Home.ModInfo
import Data.Foldable
import qualified Data.Map.Strict as Map
......@@ -1507,7 +1533,7 @@ getModuleSourceAndFlags mod = do
-- | Return module source as token stream, including comments.
--
-- The module must be in the module graph and its source must be available.
-- Throws a 'GHC.Driver.Types.SourceError' on parse error.
-- Throws a 'GHC.Driver.Env.SourceError' on parse error.
getTokenStream :: GhcMonad m => Module -> m [Located Token]
getTokenStream mod = do
(sourceFile, source, dflags) <- getModuleSourceAndFlags mod
......@@ -1842,3 +1868,15 @@ interpretPackageEnv dflags = do
"Package environment "
++ show env
++ " (specified in GHC_ENVIRONMENT) not found"
-- | An error thrown if the GHC API is used in an incorrect fashion.
newtype GhcApiError = GhcApiError String
instance Show GhcApiError where
show (GhcApiError msg) = msg
instance Exception GhcApiError
mkApiErr :: DynFlags -> SDoc -> GhcApiError
mkApiErr dflags msg = GhcApiError (showSDoc dflags msg)
......@@ -39,10 +39,11 @@ import GHC.Builtin.Names ( gHC_PRIMOPWRAPPERS )
import GHC.Core.TyCon ( TyCon, isPrimTyCon, PrimRep(..) )
import GHC.Core.Type
import GHC.Types.RepType ( tyConPrimRep1 )
import GHC.Types.Basic ( Arity, Fixity(..), FixityDirection(..), Boxity(..),
SourceText(..) )
import GHC.Types.Basic ( Arity, Boxity(..) )
import GHC.Types.Fixity ( Fixity(..), FixityDirection(..) )
import GHC.Types.SrcLoc ( wiredInSrcSpan )
import GHC.Types.ForeignCall ( CLabelString )
import GHC.Types.SourceText ( SourceText(..) )
import GHC.Types.Unique ( Unique)
import GHC.Builtin.Uniques (mkPrimOpIdUnique, mkPrimOpWrapperUnique )
import GHC.Unit.Types ( Unit )
......
......@@ -164,13 +164,15 @@ import GHC.Builtin.Uniques
-- others:
import GHC.Core.Coercion.Axiom
import GHC.Types.Id
import GHC.Types.TyThing
import GHC.Types.SourceText
import GHC.Types.Var (VarBndr (Bndr))
import GHC.Settings.Constants ( mAX_TUPLE_SIZE, mAX_CTUPLE_SIZE, mAX_SUM_SIZE )
import GHC.Unit.Module ( Module )
import GHC.Core.Type
import GHC.Types.RepType
import GHC.Core.DataCon
import {-# SOURCE #-} GHC.Core.ConLike
import GHC.Core.ConLike
import GHC.Core.TyCon
import GHC.Core.Class ( Class, mkClass )
import GHC.Types.Name.Reader
......
......@@ -115,6 +115,7 @@ import {-# SOURCE #-} GHC.Builtin.Types
import GHC.Types.Var ( TyVar, mkTyVar )
import GHC.Types.Name
import {-# SOURCE #-} GHC.Types.TyThing
import GHC.Core.TyCon
import GHC.Types.SrcLoc
import GHC.Types.Unique
......@@ -199,14 +200,14 @@ mkPrimTc :: FastString -> Unique -> TyCon -> Name
mkPrimTc fs unique tycon
= mkWiredInName gHC_PRIM (mkTcOccFS fs)
unique
(ATyCon tycon) -- Relevant TyCon
(mkATyCon tycon) -- Relevant TyCon
UserSyntax
mkBuiltInPrimTc :: FastString -> Unique -> TyCon -> Name
mkBuiltInPrimTc fs unique tycon
= mkWiredInName gHC_PRIM (mkTcOccFS fs)
unique
(ATyCon tycon) -- Relevant TyCon
(mkATyCon tycon) -- Relevant TyCon
BuiltInSyntax
......@@ -547,7 +548,7 @@ mkPrimTyConName = mkPrimTcName BuiltInSyntax
mkPrimTcName :: BuiltInSyntax -> FastString -> Unique -> TyCon -> Name
mkPrimTcName built_in_syntax occ key tycon
= mkWiredInName gHC_PRIM (mkTcOccFS occ) key (ATyCon tycon) built_in_syntax
= mkWiredInName gHC_PRIM (mkTcOccFS occ) key (mkATyCon tycon) built_in_syntax
-----------------------------
-- | Given a RuntimeRep, applies TYPE to it.
......
......@@ -50,31 +50,34 @@ module GHC.Builtin.Utils (
import GHC.Prelude
import GHC.Builtin.Uniques
import GHC.Types.Unique ( isValidKnownKeyUnique )
import GHC.Core.ConLike ( ConLike(..) )
import GHC.Builtin.PrimOps
import GHC.Builtin.Types
import GHC.Builtin.Types.Literals ( typeNatTyCons )
import GHC.Builtin.Types.Prim
import GHC.Builtin.Names.TH ( templateHaskellNames )
import GHC.Builtin.Names
import GHC.Core.ConLike ( ConLike(..) )
import GHC.Core.Opt.ConstantFold
import GHC.Types.Avail
import GHC.Builtin.PrimOps
import GHC.Core.DataCon
import GHC.Core.Class
import GHC.Core.TyCon
import GHC.Types.Avail
import GHC.Types.Basic
import GHC.Types.Id
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Id.Make
import GHC.Utils.Outputable
import GHC.Builtin.Types.Prim
import GHC.Builtin.Types
import GHC.Driver.Types
import GHC.Core.Class
import GHC.Core.TyCon
import GHC.Types.Unique.FM
import GHC.Types.TyThing
import GHC.Types.Unique ( isValidKnownKeyUnique )
import GHC.Utils.Outputable
import GHC.Utils.Misc as Utils
import GHC.Utils.Panic
import GHC.Builtin.Types.Literals ( typeNatTyCons )
import GHC.Hs.Doc
import GHC.Unit.Module.ModIface (IfaceExport)
import Control.Applicative ((<|>))
import Data.List ( intercalate , find )
......
......@@ -19,27 +19,30 @@ module GHC.ByteCode.Asm (
import GHC.Prelude
import GHC.Driver.Env
import GHC.Driver.Session
import GHC.ByteCode.Instr
import GHC.ByteCode.InfoTable
import GHC.ByteCode.Types
import GHCi.RemoteTypes
import GHC.Runtime.Interpreter
import GHC.Runtime.Heap.Layout
import GHC.Driver.Types
import GHC.Types.Name
import GHC.Types.Name.Set
import GHC.Types.Literal
import GHC.Types.Unique
import GHC.Types.Unique.DSet
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Utils.Misc
import GHC.Core.TyCon
import GHC.Data.FastString
import GHC.StgToCmm.Layout ( ArgRep(..) )
import GHC.Runtime.Heap.Layout
import GHC.Driver.Session
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Platform
import GHC.Utils.Misc
import GHC.Types.Unique
import GHC.Types.Unique.DSet
-- From iserv
import SizedSeq
......
......@@ -12,21 +12,26 @@ module GHC.ByteCode.InfoTable ( mkITbls ) where
import GHC.Prelude
import GHC.Driver.Session
import GHC.Driver.Env
import GHC.Platform
import GHC.Platform.Profile
import GHC.ByteCode.Types
import GHC.Runtime.Interpreter
import GHC.Driver.Session
import GHC.Driver.Types
import GHC.Types.Name ( Name, getName )
import GHC.Types.Name.Env
import GHC.Types.RepType
import GHC.Core.DataCon ( DataCon, dataConRepArgTys, dataConIdentity )
import GHC.Core.TyCon ( TyCon, tyConFamilySize, isDataTyCon, tyConDataCons )
import GHC.Core.Multiplicity ( scaledThing )
import GHC.Types.RepType
import GHC.StgToCmm.Layout ( mkVirtConstrSizes )
import GHC.StgToCmm.Closure ( tagForCon, NonVoid (..) )
import GHC.Utils.Misc
import GHC.Utils.Panic
......
......@@ -19,24 +19,29 @@ module GHC.ByteCode.Linker (
import GHC.Prelude
import GHC.Driver.Env
import GHC.Runtime.Interpreter
import GHC.ByteCode.Types
import GHCi.RemoteTypes
import GHCi.ResolvedBCO
import GHCi.BreakArray
import SizedSeq
import GHC.Runtime.Interpreter
import GHC.ByteCode.Types
import GHC.Driver.Types
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Builtin.PrimOps
import GHC.Unit.Types
import GHC.Unit.Module.Name
import GHC.Data.FastString
import GHC.Utils.Panic
import GHC.Utils.Outputable
import GHC.Utils.Misc
import GHC.Types.Name
import GHC.Types.Name.Env
-- Standard libraries
import Data.Array.Unboxed
import Foreign.Ptr
......
......@@ -24,7 +24,7 @@ import GHC.Types.Unique.Supply
import GHC.Driver.Session
import GHC.Driver.Backend
import GHC.Utils.Error
import GHC.Driver.Types
import GHC.Driver.Env
import Control.Monad
import GHC.Utils.Outputable
import GHC.Platform
......
......@@ -968,7 +968,7 @@ data Tickish id =
{ breakpointId :: !Int
, breakpointFVs :: [id] -- ^ the order of this list is important:
-- it matches the order of the lists in the
-- appropriate entry in 'GHC.Driver.Types.ModBreaks'.
-- appropriate entry in 'GHC.ByteCode.Types.ModBreaks'.
--
-- Careful about substitution! See
-- Note [substTickish] in "GHC.Core.Subst".
......
......@@ -385,7 +385,7 @@ giving rise to the FamInstBranch.
Note [Implicit axioms]
~~~~~~~~~~~~~~~~~~~~~~
See also Note [Implicit TyThings] in GHC.Driver.Types
See also Note [Implicit TyThings] in GHC.Types.TyThing
* A CoAxiom arising from data/type family instances is not "implicit".
That is, it has its own IfaceAxiom declaration in an interface file
......
module GHC.Core.ConLike where
import {-# SOURCE #-} GHC.Core.DataCon (DataCon)
import {-# SOURCE #-} GHC.Core.PatSyn (PatSyn)
import GHC.Types.Name ( Name )
data ConLike = RealDataCon DataCon
| PatSynCon PatSyn
conLikeName :: ConLike -> Name
......@@ -73,7 +73,9 @@ import GHC.Core.Coercion
import GHC.Core.Unify
import GHC.Core.TyCon
import GHC.Core.Multiplicity
import {-# SOURCE #-} GHC.Types.TyThing
import GHC.Types.FieldLabel
import GHC.Types.SourceText
import GHC.Core.Class
import GHC.Types.Name
import GHC.Builtin.Names
......@@ -674,7 +676,7 @@ data DataConRep
-- emit a warning (in checkValidDataCon) and treat it like
-- @(HsSrcBang _ NoSrcUnpack SrcLazy)@
data HsSrcBang =
HsSrcBang SourceText -- Note [Pragma source text] in GHC.Types.Basic
HsSrcBang SourceText -- Note [Pragma source text] in GHC.Types.SourceText
SrcUnpackedness
SrcStrictness
deriving Data.Data
......@@ -1194,11 +1196,11 @@ dataConWrapId dc = case dcRep dc of
-- the union of the 'dataConWorkId' and the 'dataConWrapId'
dataConImplicitTyThings :: DataCon -> [TyThing]
dataConImplicitTyThings (MkData { dcWorkId = work, dcRep = rep })
= [AnId work] ++ wrap_ids
= [mkAnId work] ++ wrap_ids
where
wrap_ids = case rep of
NoDataConRep -> []
DCR { dcr_wrap_id = wrap } -> [AnId wrap]
DCR { dcr_wrap_id = wrap } -> [mkAnId wrap]
-- | The labels for the fields of this particular 'DataCon'
dataConFieldLabels :: DataCon -> [FieldLabel]
......
......@@ -226,7 +226,7 @@ instance Outputable FamInst where
pprFamInst :: FamInst -> SDoc
-- Prints the FamInst as a family instance declaration
-- NB: This function, FamInstEnv.pprFamInst, is used only for internal,
-- debug printing. See GHC.Core.Ppr.TyThing.pprFamInst for printing for the user
-- debug printing. See GHC.Types.TyThing.Ppr.pprFamInst for printing for the user
pprFamInst (FamInst { fi_flavor = flavor, fi_axiom = ax
, fi_tvs = tvs, fi_tys = tys, fi_rhs = rhs })
= hang (ppr_tc_sort <+> text "instance"
......
......@@ -27,6 +27,10 @@ module GHC.Core.Lint (
import GHC.Prelude
import GHC.Driver.Session
import GHC.Driver.Ppr
import GHC.Driver.Env
import GHC.Core
import GHC.Core.FVs
import GHC.Core.Utils
......@@ -73,10 +77,10 @@ import GHC.Core.InstEnv ( instanceDFunId )
import GHC.Core.Coercion.Opt ( checkAxInstCo )
import GHC.Core.Opt.Arity ( typeArity )
import GHC.Types.Demand ( splitStrictSig, isDeadEndDiv )
import GHC.Types.TypeEnv
import GHC.Unit.Module.ModGuts
import GHC.Runtime.Context
import GHC.Driver.Types hiding (Usage)
import GHC.Driver.Session
import GHC.Driver.Ppr
import Control.Monad
import GHC.Utils.Monad
import Data.Foldable ( toList )
......@@ -437,7 +441,7 @@ lintInteractiveExpr what hsc_env expr
interactiveInScope :: HscEnv -> [Var]
-- In GHCi we may lint expressions, or bindings arising from 'deriving'
-- clauses, that mention variables bound in the interactive context.
-- These are Local things (see Note [Interactively-bound Ids in GHCi] in GHC.Driver.Types).
-- These are Local things (see Note [Interactively-bound Ids in GHCi] in GHC.Runtime.Context).
-- So we have to tell Lint about them, lest it reports them as out of scope.
--
-- We do this by find local-named things that may appear free in interactive
......
......@@ -55,37 +55,39 @@ module GHC.Core.Make (
#include "HsVersions.h"
import GHC.Prelude
import GHC.Platform
import GHC.Types.Id
import GHC.Types.Var ( EvVar, setTyVarUnique )
import GHC.Types.TyThing
import GHC.Types.Id.Info
import GHC.Types.Demand
import GHC.Types.Cpr
import GHC.Types.Name hiding ( varName )
import GHC.Types.Literal
import GHC.Types.Unique.Supply
import GHC.Types.Basic
import GHC.Core
import GHC.Core.Utils ( exprType, needsCaseBinding, mkSingleAltCase, bindNonRec )
import GHC.Types.Literal
import GHC.Driver.Types
import GHC.Platform
import GHC.Builtin.Types
import GHC.Builtin.Names
import GHC.Hs.Utils ( mkChunkified, chunkify )