Commit 3d2acdeb authored by batterseapower's avatar batterseapower
Browse files

Document HscTypes, refactor it somewhat, remove unused type and add MonadThings

parent 058f3b6f
......@@ -4,6 +4,7 @@
\section[HscTypes]{Types for the per-module compiler}
\begin{code}
-- | Types for the per-module compiler
module HscTypes (
-- * Sessions and compilation state
Session(..), withSession, modifySession,
......@@ -12,39 +13,54 @@ module HscTypes (
Target(..), TargetId(..), pprTarget, pprTargetId,
ModuleGraph, emptyMG,
-- * Information about modules
ModDetails(..), emptyModDetails,
ModGuts(..), CoreModule(..), CgGuts(..), ModImports(..), ForeignStubs(..),
ModGuts(..), CoreModule(..), CgGuts(..), ForeignStubs(..),
ImportedMods,
ModSummary(..), ms_mod_name, showModMsg, isBootSummary,
msHsFilePath, msHiFilePath, msObjFilePath,
msHsFilePath, msHiFilePath, msObjFilePath,
-- * Information about the module being compiled
HscSource(..), isHsBoot, hscSourceString, -- Re-exported from DriverPhases
-- * State relating to modules in this package
HomePackageTable, HomeModInfo(..), emptyHomePackageTable,
hptInstances, hptRules, hptVectInfo,
-- * State relating to known packages
ExternalPackageState(..), EpsStats(..), addEpsInStats,
PackageTypeEnv, PackageIfaceTable, emptyPackageIfaceTable,
lookupIfaceByModule, emptyModIface,
PackageInstEnv, PackageRuleBase,
-- * Interactive context
InteractiveContext(..), emptyInteractiveContext,
icPrintUnqual, mkPrintUnqualified, extendInteractiveContext,
substInteractiveContext,
-- * Interfaces
ModIface(..), mkIfaceWarnCache, mkIfaceHashCache, mkIfaceFixCache,
emptyIfaceWarnCache,
-- * Fixity
FixityEnv, FixItem(..), lookupFixity, emptyFixityEnv,
-- * TyThings and type environments
TyThing(..),
tyThingClass, tyThingTyCon, tyThingDataCon, tyThingId,
implicitTyThings, isImplicitTyThing,
TyThing(..), tyThingClass, tyThingTyCon, tyThingDataCon, tyThingId,
TypeEnv, lookupType, mkTypeEnv, emptyTypeEnv,
TypeEnv, lookupType, lookupTypeHscEnv, mkTypeEnv, emptyTypeEnv,
extendTypeEnv, extendTypeEnvList, extendTypeEnvWithIds, lookupTypeEnv,
typeEnvElts, typeEnvClasses, typeEnvTyCons, typeEnvIds,
typeEnvDataCons,
-- * MonadThings
MonadThings(..),
-- * Information on imports and exports
WhetherHasOrphans, IsBootInterface, Usage(..),
Dependencies(..), noDependencies,
NameCache(..), OrigNameCache, OrigIParamCache,
......@@ -52,20 +68,21 @@ module HscTypes (
GenAvailInfo(..), AvailInfo, RdrAvailInfo,
IfaceExport,
-- * Warnings
Warnings(..), WarningTxt(..), plusWarns,
PackageInstEnv, PackageRuleBase,
-- Linker stuff
-- * Linker stuff
Linkable(..), isObjectLinkable,
Unlinked(..), CompiledByteCode,
isObject, nameOfObject, isInterpretable, byteCodeOfObject,
-- * Program coverage
HpcInfo(..), emptyHpcInfo, isHpcUsed, AnyHpcUsage,
-- Breakpoints
-- * Breakpoints
ModBreaks (..), BreakIndex, emptyModBreaks,
-- Vectorisation information
-- * Vectorisation information
VectInfo(..), IfaceVectInfo(..), noVectInfo, plusVectInfo,
noIfaceVectInfo
) where
......@@ -121,7 +138,7 @@ import System.Time ( ClockTime )
import Data.IORef
import Data.Array ( Array, array )
import Data.List
import Control.Monad ( mplus )
import Control.Monad ( mplus, guard, liftM )
\end{code}
......@@ -146,72 +163,87 @@ modifySession :: Session -> (HscEnv -> HscEnv) -> IO ()
modifySession (Session ref) f = do h <- readIORef ref; writeIORef ref $! f h
\end{code}
HscEnv is like Session, except that some of the fields are immutable.
An HscEnv is used to compile a single module from plain Haskell source
code (after preprocessing) to either C, assembly or C--. Things like
the module graph don't change during a single compilation.
Historical note: "hsc" used to be the name of the compiler binary,
when there was a separate driver and compiler. To compile a single
module, the driver would invoke hsc on the source code... so nowadays
we think of hsc as the layer of the compiler that deals with compiling
a single module.
\begin{code}
-- | HscEnv is like 'Session', except that some of the fields are immutable.
-- An HscEnv is used to compile a single module from plain Haskell source
-- code (after preprocessing) to either C, assembly or C--. Things like
-- the module graph don't change during a single compilation.
--
-- Historical note: \"hsc\" used to be the name of the compiler binary,
-- when there was a separate driver and compiler. To compile a single
-- module, the driver would invoke hsc on the source code... so nowadays
-- we think of hsc as the layer of the compiler that deals with compiling
-- a single module.
data HscEnv
= HscEnv {
hsc_dflags :: DynFlags,
-- The dynamic flag settings
-- ^ The dynamic flag settings
hsc_targets :: [Target],
-- The targets (or roots) of the current session
-- ^ The targets (or roots) of the current session
hsc_mod_graph :: ModuleGraph,
-- The module graph of the current session
-- ^ The module graph of the current session
hsc_IC :: InteractiveContext,
-- The context for evaluating interactive statements
-- ^ The context for evaluating interactive statements
hsc_HPT :: HomePackageTable,
-- The home package table describes already-compiled
-- home-packge modules, *excluding* the module we
-- ^ The home package table describes already-compiled
-- home-package modules, /excluding/ the module we
-- are compiling right now.
-- (In one-shot mode the current module is the only
-- home-package module, so hsc_HPT is empty. All other
-- modules count as "external-package" modules.
-- modules count as \"external-package\" modules.
-- However, even in GHCi mode, hi-boot interfaces are
-- demand-loadeded into the external-package table.)
-- demand-loaded into the external-package table.)
--
-- hsc_HPT is not mutable because we only demand-load
-- 'hsc_HPT' is not mutable because we only demand-load
-- external packages; the home package is eagerly
-- loaded, module by module, by the compilation manager.
--
-- The HPT may contain modules compiled earlier by --make
-- The HPT may contain modules compiled earlier by @--make@
-- but not actually below the current module in the dependency
-- graph. (This changes a previous invariant: changed Jan 05.)
-- graph.
-- (This changes a previous invariant: changed Jan 05.)
hsc_EPS :: {-# UNPACK #-} !(IORef ExternalPackageState),
-- ^ Information about the currently loaded external packages.
-- This is mutable because packages will be demand-loaded during
-- a compilation run as required.
hsc_NC :: {-# UNPACK #-} !(IORef NameCache),
-- These are side-effected by compiling to reflect
-- sucking in interface files. They cache the state of
-- ^ As with 'hsc_EPS', this is side-effected by compiling to
-- reflect sucking in interface files. They cache the state of
-- external interface files, in effect.
hsc_FC :: {-# UNPACK #-} !(IORef FinderCache),
-- ^ The cached result of performing finding in the file system
hsc_MLC :: {-# UNPACK #-} !(IORef ModLocationCache),
-- The finder's cache. This caches the location of modules,
-- so we don't have to search the filesystem multiple times.
-- ^ This caches the location of modules, so we don't have to
-- search the filesystem multiple times. See also 'hsc_FC'.
hsc_OptFuel :: OptFuelState,
-- Settings to control the use of optimization fuel:
-- ^ Settings to control the use of \"optimization fuel\":
-- by limiting the number of transformations,
-- we can use binary search to help find compiler bugs.
hsc_type_env_var :: Maybe (Module, IORef TypeEnv),
-- Used for one-shot compilation only, to initialise
-- the IfGblEnv. See TcRnTypes.TcGblEnv.tcg_type_env_var
-- ^ Used for one-shot compilation only, to initialise
-- the 'IfGblEnv'. See 'TcRnTypes.tcg_type_env_var' for
-- 'TcRunTypes.TcGblEnv'
hsc_global_rdr_env :: GlobalRdrEnv,
-- ^ A mapping from 'RdrName's that are in global scope during
-- the compilation of the current file to more detailed
-- information about those names. Not necessarily just the
-- names directly imported by the module being compiled!
hsc_global_type_env :: TypeEnv
-- ^ Typing information about all those things in global scope.
-- Not necessarily just the things directly imported by the module
-- being compiled!
}
hscEPS :: HscEnv -> IO ExternalPackageState
......@@ -248,9 +280,12 @@ pprTargetId (TargetFile f _) = text f
instance Outputable TargetId where
ppr = pprTargetId
-- | Helps us find information about modules in the home package
type HomePackageTable = ModuleNameEnv HomeModInfo
-- Domain = modules in the home package
-- Domain = modules in the home package that have been fully compiled
-- "home" package name cached here for convenience
-- | Helps us find information about modules in the imported packages
type PackageIfaceTable = ModuleEnv ModIface
-- Domain = modules in the imported packages
......@@ -260,22 +295,35 @@ emptyHomePackageTable = emptyUFM
emptyPackageIfaceTable :: PackageIfaceTable
emptyPackageIfaceTable = emptyModuleEnv
-- | Information about modules in the package being compiled
data HomeModInfo
= HomeModInfo { hm_iface :: !ModIface,
hm_details :: !ModDetails,
hm_linkable :: !(Maybe Linkable) }
-- hm_linkable might be Nothing if:
-- a) this is an .hs-boot module
-- b) temporarily during compilation if we pruned away
= HomeModInfo { hm_iface :: !ModIface, -- ^ The basic loaded interface file: every
-- loaded module has one of these, even if
-- it is imported from another package
hm_details :: !ModDetails, -- ^ Extra information that has been created
-- from the 'ModIface' for the module,
-- typically during typechecking
hm_linkable :: !(Maybe Linkable)
-- ^ The actual artifact we would like to link to access
-- things in this module.
--
-- 'hm_linkable' might be Nothing:
--
-- 1. If this is an .hs-boot module
--
-- 2. Temporarily during compilation if we pruned away
-- the old linkable because it was out of date.
-- after a complete compilation (GHC.load), all hm_linkable
-- fields in the HPT will be Just.
--
-- When re-linking a module (hscNoRecomp), we construct
-- the HomModInfo by building a new ModDetails from the
-- old ModIface (only).
-- After a complete compilation ('GHC.load'), all 'hm_linkable'
-- fields in the 'HomePackageTable' will be @Just@.
--
-- When re-linking a module ('HscMain.HscNoRecomp'), we construct
-- the 'HomeModInfo' by building a new 'ModDetails' from the
-- old 'ModIface' (only).
}
-- | Find the 'ModIface' for a 'Module'
-- | Find the 'ModIface' for a 'Module', searching in both the loaded home
-- and external package module information
lookupIfaceByModule
:: DynFlags
-> HomePackageTable
......@@ -303,58 +351,63 @@ lookupIfaceByModule dflags hpt pit mod
\begin{code}
hptInstances :: HscEnv -> (ModuleName -> Bool) -> ([Instance], [FamInst])
-- Find all the instance declarations (of classes and families) that are in
-- ^ Find all the instance declarations (of classes and families) that are in
-- modules imported by this one, directly or indirectly, and are in the Home
-- Package Table. This ensures that we don't see instances from modules --make
-- Package Table. This ensures that we don't see instances from modules @--make@
-- compiled before this one, but which are not below this one.
hptInstances hsc_env want_this_module
= let (insts, famInsts) = unzip
[ (md_insts details, md_fam_insts details)
| mod_info <- eltsUFM (hsc_HPT hsc_env)
, want_this_module (moduleName (mi_module (hm_iface mod_info)))
, let details = hm_details mod_info ]
in
(concat insts, concat famInsts)
= let (insts, famInsts) = unzip $ flip hptAllThings hsc_env $ \mod_info -> do
guard (want_this_module (moduleName (mi_module (hm_iface mod_info))))
let details = hm_details mod_info
return (md_insts details, md_fam_insts details)
in (concat insts, concat famInsts)
hptVectInfo :: HscEnv -> VectInfo
-- ^ Get the combined VectInfo of all modules in the home package table. In
-- contrast to instances and rules, we don't care whether the modules are
-- \"below\" us in the dependency sense. The VectInfo of those modules not \"below\"
-- us does not affect the compilation of the current module.
hptVectInfo = concatVectInfo . hptAllThings ((: []) . md_vect_info . hm_details)
hptRules :: HscEnv -> [(ModuleName, IsBootInterface)] -> [CoreRule]
-- Get rules from modules "below" this one (in the dependency sense)
-- ^ Get rules from modules \"below\" this one (in the dependency sense)
hptRules = hptSomeThingsBelowUs (md_rules . hm_details) False
hptAllThings :: (HomeModInfo -> [a]) -> HscEnv -> [a]
hptAllThings extract hsc_env = concatMap extract (eltsUFM (hsc_HPT hsc_env))
hptSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> [(ModuleName, IsBootInterface)] -> [a]
-- Get things from modules \"below\" this one (in the dependency sense)
-- C.f Inst.hptInstances
hptRules hsc_env deps
| isOneShot (ghcMode (hsc_dflags hsc_env)) = []
hptSomeThingsBelowUs extract include_hi_boot hsc_env deps
| isOneShot (ghcMode (hsc_dflags hsc_env)) = []
| otherwise
= let
hpt = hsc_HPT hsc_env
in
[ rule
[ thing
| -- Find each non-hi-boot module below me
(mod, False) <- deps
(mod, is_boot_mod) <- deps
, include_hi_boot || not is_boot_mod
-- unsavoury: when compiling the base package with --make, we
-- sometimes try to look up RULES for GHC.Prim. GHC.Prim won't
-- sometimes try to look up RULES etc for GHC.Prim. GHC.Prim won't
-- be in the HPT, because we never compile it; it's in the EPT
-- instead. ToDo: clean up, and remove this slightly bogus
-- filter:
, mod /= moduleName gHC_PRIM
-- Look it up in the HPT
, let rules = case lookupUFM hpt mod of
Just info -> md_rules (hm_details info)
Nothing -> pprTrace "WARNING in hptRules" msg []
, let things = case lookupUFM hpt mod of
Just info -> extract info
Nothing -> pprTrace "WARNING in hptSomeThingsBelowUs" msg []
msg = vcat [ptext (sLit "missing module") <+> ppr mod,
ptext (sLit "Probable cause: out-of-date interface files")]
-- This really shouldn't happen, but see Trac #962
-- And get its dfuns
, rule <- rules ]
, thing <- things ]
hptVectInfo :: HscEnv -> VectInfo
-- Get the combined VectInfo of all modules in the home package table. In
-- contrast to instances and rules, we don't care whether the modules are
-- "below" or us. The VectInfo of those modules not "below" us does not
-- affect the compilation of the current module.
hptVectInfo hsc_env
= foldr plusVectInfo noVectInfo [ md_vect_info (hm_details mod_info)
| mod_info <- eltsUFM (hsc_HPT hsc_env)]
\end{code}
%************************************************************************
......@@ -377,21 +430,21 @@ type FinderCache = ModuleNameEnv FindResult
-- | The result of searching for an imported module.
data FindResult
= Found ModLocation Module
-- the module was found
-- ^ The module was found
| NoPackage PackageId
-- the requested package was not found
-- ^ The requested package was not found
| FoundMultiple [PackageId]
-- _error_: both in multiple packages
-- ^ _Error_: both in multiple packages
| PackageHidden PackageId
-- for an explicit source import: the package containing the module is
-- ^ For an explicit source import, the package containing the module is
-- not exposed.
| ModuleHidden PackageId
-- for an explicit source import: the package containing the module is
-- ^ For an explicit source import, the package containing the module is
-- exposed, but the module itself is hidden.
| NotFound [FilePath] (Maybe PackageId)
-- the module was not found, the specified places were searched
-- ^ The module was not found, the specified places were searched
| NotFoundInPackage PackageId
-- the module was not found in this package
-- ^ The module was not found in this package
-- | Cache that remembers where we found a particular module. Contains both
-- home modules and package modules. On @:load@, only home modules are
......@@ -405,48 +458,56 @@ type ModLocationCache = ModuleEnv ModLocation
%* *
%************************************************************************
A @ModIface@ plus a @ModDetails@ summarises everything we know
about a compiled module. The @ModIface@ is the stuff *before* linking,
and can be written out to an interface file. (The @ModDetails@ is after
linking; it is the "linked" form of the mi_decls field.)
When we *read* an interface file, we also construct a @ModIface@ from it,
except that the mi_decls part is empty; when reading we consolidate
the declarations into a single indexed map in the @PersistentRenamerState@.
\begin{code}
-- | A 'ModIface' plus a 'ModDetails' summarises everything we know
-- about a compiled module. The 'ModIface' is the stuff *before* linking,
-- and can be written out to an interface file. The 'ModDetails is after
-- linking and can be completely recovered from just the 'ModIface'.
--
-- When we read an interface file, we also construct a 'ModIface' from it,
-- except that we explicitly make the 'mi_decls' and a few other fields empty;
-- as when reading we consolidate the declarations etc. into a number of indexed
-- maps and environments in the 'ExternalPackageState'.
data ModIface
= ModIface {
mi_module :: !Module,
mi_iface_hash :: !Fingerprint, -- Hash of the whole interface
mi_mod_hash :: !Fingerprint, -- Hash of the ABI only
mi_module :: !Module, -- ^ Name of the module we are for
mi_iface_hash :: !Fingerprint, -- ^ Hash of the whole interface
mi_mod_hash :: !Fingerprint, -- ^ Hash of the ABI only
mi_orphan :: !WhetherHasOrphans, -- Whether this module has orphans
mi_finsts :: !WhetherHasFamInst, -- Whether module has family insts
mi_boot :: !IsBootInterface, -- Read from an hi-boot file?
mi_orphan :: !WhetherHasOrphans, -- ^ Whether this module has orphans
mi_finsts :: !WhetherHasFamInst, -- ^ Whether this module has family instances
mi_boot :: !IsBootInterface, -- ^ Read from an hi-boot file?
mi_deps :: Dependencies,
-- ^ The dependencies of the module, consulted for directly
-- imported modules only
-- This is consulted for directly-imported modules,
-- but not for anything else (hence lazy)
-- Usages; kept sorted so that it's easy to decide
mi_usages :: [Usage],
-- ^ Usages; kept sorted so that it's easy to decide
-- whether to write a new iface file (changing usages
-- doesn't affect the hash of this module)
mi_usages :: [Usage],
-- NOT STRICT! we read this field lazily from the interface file
-- It is *only* consulted by the recompilation checker
-- Exports
-- Kept sorted by (mod,occ), to make version comparisons easier
mi_exports :: ![IfaceExport],
mi_exp_hash :: !Fingerprint, -- Hash of export list
-- ^ Records the modules that are the declaration points for things
-- exported by this module, and the 'OccName's of those things
mi_exp_hash :: !Fingerprint, -- ^ Hash of export list
-- Fixities
mi_fixities :: [(OccName,Fixity)],
-- ^ Fixities
-- NOT STRICT! we read this field lazily from the interface file
-- Warnings
mi_warns :: Warnings,
-- ^ Warnings
-- NOT STRICT! we read this field lazily from the interface file
-- Type, class and variable declarations
......@@ -454,11 +515,11 @@ data ModIface
-- (as well as its type of course)
-- Ditto data constructors, class operations, except that
-- the hash of the parent class/tycon changes
mi_decls :: [(Fingerprint,IfaceDecl)], -- Sorted
mi_decls :: [(Fingerprint,IfaceDecl)], -- ^ Sorted type, variable, class etc. declarations
mi_globals :: !(Maybe GlobalRdrEnv),
-- Binds all the things defined at the top level in
-- the *original source* code for this module. which
-- ^ Binds all the things defined at the top level in
-- the /original source/ code for this module. which
-- is NOT the same as mi_exports, nor mi_decls (which
-- may contains declarations for things not actually
-- defined by the user). Used for GHCi and for inspecting
......@@ -466,47 +527,48 @@ data ModIface
--
-- (We need the source file to figure out the
-- top-level environment, if we didn't compile this module
-- from source then this field contains Nothing).
-- from source then this field contains @Nothing@).
--
-- Strictly speaking this field should live in the
-- HomeModInfo, but that leads to more plumbing.
-- 'HomeModInfo', but that leads to more plumbing.
-- Instance declarations and rules
mi_insts :: [IfaceInst], -- Sorted
mi_fam_insts :: [IfaceFamInst], -- Sorted
mi_rules :: [IfaceRule], -- Sorted
mi_orphan_hash :: !Fingerprint, -- Hash for orphan rules and
-- instances (for classes and families)
mi_insts :: [IfaceInst], -- ^ Sorted class instance
mi_fam_insts :: [IfaceFamInst], -- ^ Sorted family instances
mi_rules :: [IfaceRule], -- ^ Sorted rules
mi_orphan_hash :: !Fingerprint, -- ^ Hash for orphan rules and
-- class and family instances
-- combined
-- Vectorisation information
mi_vect_info :: !IfaceVectInfo,
mi_vect_info :: !IfaceVectInfo, -- ^ Vectorisation information
-- Cached environments for easy lookup
-- These are computed (lazily) from other fields
-- and are not put into the interface file
mi_warn_fn :: Name -> Maybe WarningTxt, -- Cached lookup for mi_warns
mi_fix_fn :: OccName -> Fixity, -- Cached lookup for mi_fixities
mi_warn_fn :: Name -> Maybe WarningTxt, -- ^ Cached lookup for 'mi_warns'
mi_fix_fn :: OccName -> Fixity, -- ^ Cached lookup for 'mi_fixities'
mi_hash_fn :: OccName -> Maybe (OccName, Fingerprint),
-- Cached lookup for mi_decls
-- The Nothing in mi_hash_fn means that the thing
-- ^ Cached lookup for 'mi_decls'.
-- The @Nothing@ in 'mi_hash_fn' means that the thing
-- isn't in decls. It's useful to know that when
-- seeing if we are up to date wrt the old interface
-- seeing if we are up to date wrt. the old interface.
-- The 'OccName' is the parent of the name, if it has one.
mi_hpc :: !AnyHpcUsage
-- True if this program uses Hpc at any point in the program.
-- ^ True if this program uses Hpc at any point in the program.
}
-- Should be able to construct ModDetails from mi_decls in ModIface
-- | The 'ModDetails' is essentially a cache for information in the 'ModIface'
-- for home modules only. Information relating to packages will be loaded into
-- global environments in 'ExternalPackageState'.
data ModDetails
= ModDetails {
-- The next two fields are created by the typechecker
md_exports :: [AvailInfo],
md_types :: !TypeEnv,
md_insts :: ![Instance], -- Dfun-ids for the instances in this module
md_types :: !TypeEnv, -- ^ Local type environment for this particular module
md_insts :: ![Instance], -- ^ 'DFunId's for the instances in this module
md_fam_insts :: ![FamInst],
md_rules :: ![CoreRule], -- Domain may include Ids from other modules
md_vect_info :: !VectInfo -- Vectorisation information
md_rules :: ![CoreRule], -- ^ Domain may include 'Id's from other modules
md_vect_info :: !VectInfo -- ^ Module vectorisation information
}
emptyModDetails :: ModDetails
......@@ -518,38 +580,44 @@ emptyModDetails = ModDetails { md_types = emptyTypeEnv,
md_vect_info = noVectInfo
}
-- A ModGuts is carried through the compiler, accumulating stuff as it goes
-- There is only one ModGuts at any time, the one for the module
-- being compiled right now. Once it is compiled, a ModIface and
-- ModDetails are extracted and the ModGuts is dicarded.
-- | Records the modules directly imported by a module for extracting e.g. usage information
type ImportedMods = ModuleEnv [(ModuleName, Bool, SrcSpan)]
-- TODO: we are not actually using the codomain of this type at all, so it can be
-- replaced with ModuleEnv ()
-- | A ModGuts is carried through the compiler, accumulating stuff as it goes
-- There is only one ModGuts at any time, the one for the module
-- being compiled right now. Once it is compiled, a 'ModIface' and
-- 'ModDetails' are extracted and the ModGuts is dicarded.
data ModGuts
= ModGuts {
mg_module :: !Module,
mg_boot :: IsBootInterface, -- Whether it's an hs-boot module
mg_exports :: ![AvailInfo], -- What it exports
mg_deps :: !Dependencies, -- What is below it, directly or
-- otherwise
mg_dir_imps :: !ImportedMods, -- Directly-imported modules; used to
-- generate initialisation code
mg_used_names:: !NameSet, -- What it needed (used in mkIface)
mg_module :: !Module, -- ^ Module being compiled
mg_boot :: IsBootInterface, -- ^ Whether it's an hs-boot module
mg_exports :: ![AvailInfo], -- ^ What it exports
mg_deps :: !Dependencies, -- ^ What it depends on, directly or
-- otherwise
mg_dir_imps :: !ImportedMods, -- ^ Directly-imported modules; used to
-- generate initialisation code
mg_used_names:: !NameSet, -- ^ What the module needed (used in 'MkIface.mkIface')
mg_rdr_env :: !GlobalRdrEnv, -- Top-level lexical environment
mg_rdr_env :: !GlobalRdrEnv, -- ^ Top-level lexical environment
-- These fields all describe the things **declared in this module**
mg_fix_env :: !FixityEnv, -- Fixities
mg_types :: !TypeEnv,
mg_insts :: ![Instance], -- Instances
mg_fam_insts :: ![FamInst], -- Instances
mg_rules :: ![CoreRule], -- Rules from this module
mg_binds :: ![CoreBind], -- Bindings for this module
mg_foreign :: !ForeignStubs,
mg_warns :: !Warnings, -- Warnings declared in the module
mg_hpc_info :: !HpcInfo, -- info about coverage tick boxes
mg_modBreaks :: !ModBreaks,
mg_vect_info :: !VectInfo, -- Pool of vectorised declarations
mg_fix_env :: !FixityEnv, -- ^ Fixities declared in this module
-- TODO: I'm unconvinced this is actually used anywhere
mg_types :: !TypeEnv, -- ^ Types declared in this module
mg_insts :: ![Instance], -- ^ Class instances declared in this module
mg_fam_insts :: ![FamInst], -- ^ Family instances declared in this module
mg_rules :: ![CoreRule], -- ^ Before the core pipeline starts, contains
-- rules declared in this module. After the core
-- pipeline starts, it is changed to contain all
-- known rules for those things imported
mg_binds :: ![CoreBind], -- ^ Bindings for this module
mg_foreign :: !ForeignStubs, -- ^ Foreign exports declared in this module
mg_warns :: !Warnings, -- ^ Warnings declared in the module
mg_hpc_info :: !HpcInfo, -- ^ Coverage tick boxes in the module
mg_modBreaks :: !ModBreaks, -- ^ Breakpoints for the module
mg_vect_info :: !VectInfo, -- ^ Pool of vectorised declarations in the module
-- The next two fields are unusual, because they give instance
-- environments for *all* modules in the home package, including
......@@ -557,24 +625,30 @@ data ModGuts
-- Reason: when looking up an instance we don't want to have to
-- look at each module in the home package in turn
mg_inst_env :: InstEnv,
-- ^ Class instance enviroment from /home-package/ modules (including
-- this one); c.f. tcg_inst_env
-- ^ Class instance environment from /home-package/ modules (including
-- this one); c.f. 'tcg_inst_env'
mg_fam_inst_env :: FamInstEnv
-- ^ Type-family instance enviroment for /home-package/ modules
-- (including this one); c.f. tcg_fam_inst_env
-- (including this one); c.f. 'tcg_fam_inst_env'
}
-- A CoreModule consists of just the fields of a ModGuts that are needed for
-- the compileToCoreModule interface.
-- The ModGuts takes on several slightly different forms:
--
-- After simplification, the following fields change slightly:
-- mg_rules Orphan rules only (local ones now attached to binds)
-- mg_binds With rules attached