1module GHC.Unit.Module.ModGuts
2   ( ModGuts (..)
3   , CgGuts (..)
4   )
5where
6
7import GHC.Prelude
8
9import GHC.ByteCode.Types
10import GHC.ForeignSrcLang
11
12import GHC.Hs
13
14import GHC.Unit
15import GHC.Unit.Module.Deps
16import GHC.Unit.Module.Warnings
17
18import GHC.Core.InstEnv ( InstEnv, ClsInst )
19import GHC.Core.FamInstEnv
20import GHC.Core         ( CoreProgram, CoreRule )
21import GHC.Core.TyCon
22import GHC.Core.PatSyn
23
24import GHC.Linker.Types ( SptEntry(..) )
25
26import GHC.Types.Annotations ( Annotation )
27import GHC.Types.Avail
28import GHC.Types.CompleteMatch
29import GHC.Types.Fixity.Env
30import GHC.Types.ForeignStubs
31import GHC.Types.HpcInfo
32import GHC.Types.Name.Reader
33import GHC.Types.SafeHaskell
34import GHC.Types.SourceFile ( HscSource(..) )
35import GHC.Types.SrcLoc
36
37
38-- | A ModGuts is carried through the compiler, accumulating stuff as it goes
39-- There is only one ModGuts at any time, the one for the module
40-- being compiled right now.  Once it is compiled, a 'ModIface' and
41-- 'ModDetails' are extracted and the ModGuts is discarded.
42data ModGuts
43  = ModGuts {
44        mg_module    :: !Module,         -- ^ Module being compiled
45        mg_hsc_src   :: HscSource,       -- ^ Whether it's an hs-boot module
46        mg_loc       :: SrcSpan,         -- ^ For error messages from inner passes
47        mg_exports   :: ![AvailInfo],    -- ^ What it exports
48        mg_deps      :: !Dependencies,   -- ^ What it depends on, directly or
49                                         -- otherwise
50        mg_usages    :: ![Usage],        -- ^ What was used?  Used for interfaces.
51
52        mg_used_th   :: !Bool,           -- ^ Did we run a TH splice?
53        mg_rdr_env   :: !GlobalRdrEnv,   -- ^ Top-level lexical environment
54
55        -- These fields all describe the things **declared in this module**
56        mg_fix_env   :: !FixityEnv,      -- ^ Fixities declared in this module.
57                                         -- Used for creating interface files.
58        mg_tcs       :: ![TyCon],        -- ^ TyCons declared in this module
59                                         -- (includes TyCons for classes)
60        mg_insts     :: ![ClsInst],      -- ^ Class instances declared in this module
61        mg_fam_insts :: ![FamInst],
62                                         -- ^ Family instances declared in this module
63        mg_patsyns   :: ![PatSyn],       -- ^ Pattern synonyms declared in this module
64        mg_rules     :: ![CoreRule],     -- ^ Before the core pipeline starts, contains
65                                         -- See Note [Overall plumbing for rules] in "GHC.Core.Rules"
66        mg_binds     :: !CoreProgram,    -- ^ Bindings for this module
67        mg_foreign   :: !ForeignStubs,   -- ^ Foreign exports declared in this module
68        mg_foreign_files :: ![(ForeignSrcLang, FilePath)],
69        -- ^ Files to be compiled with the C compiler
70        mg_warns     :: !Warnings,       -- ^ Warnings declared in the module
71        mg_anns      :: [Annotation],    -- ^ Annotations declared in this module
72        mg_complete_matches :: [CompleteMatch], -- ^ Complete Matches
73        mg_hpc_info  :: !HpcInfo,        -- ^ Coverage tick boxes in the module
74        mg_modBreaks :: !(Maybe ModBreaks), -- ^ Breakpoints for the module
75
76                        -- The next two fields are unusual, because they give instance
77                        -- environments for *all* modules in the home package, including
78                        -- this module, rather than for *just* this module.
79                        -- Reason: when looking up an instance we don't want to have to
80                        --         look at each module in the home package in turn
81        mg_inst_env     :: InstEnv,             -- ^ Class instance environment for
82                                                -- /home-package/ modules (including this
83                                                -- one); c.f. 'tcg_inst_env'
84        mg_fam_inst_env :: FamInstEnv,          -- ^ Type-family instance environment for
85                                                -- /home-package/ modules (including this
86                                                -- one); c.f. 'tcg_fam_inst_env'
87
88        mg_safe_haskell :: SafeHaskellMode,     -- ^ Safe Haskell mode
89        mg_trust_pkg    :: Bool,                -- ^ Do we need to trust our
90                                                -- own package for Safe Haskell?
91                                                -- See Note [Trust Own Package]
92                                                -- in "GHC.Rename.Names"
93
94        mg_doc_hdr       :: !(Maybe HsDocString), -- ^ Module header.
95        mg_decl_docs     :: !DeclDocMap,     -- ^ Docs on declarations.
96        mg_arg_docs      :: !ArgDocMap       -- ^ Docs on arguments.
97    }
98
99-- The ModGuts takes on several slightly different forms:
100--
101-- After simplification, the following fields change slightly:
102--      mg_rules        Orphan rules only (local ones now attached to binds)
103--      mg_binds        With rules attached
104
105---------------------------------------------------------
106-- The Tidy pass forks the information about this module:
107--      * one lot goes to interface file generation (ModIface)
108--        and later compilations (ModDetails)
109--      * the other lot goes to code generation (CgGuts)
110
111-- | A restricted form of 'ModGuts' for code generation purposes
112data CgGuts
113  = CgGuts {
114        cg_module    :: !Module,
115                -- ^ Module being compiled
116
117        cg_tycons    :: [TyCon],
118                -- ^ Algebraic data types (including ones that started
119                -- life as classes); generate constructors and info
120                -- tables. Includes newtypes, just for the benefit of
121                -- External Core
122
123        cg_binds     :: CoreProgram,
124                -- ^ The tidied main bindings, including
125                -- previously-implicit bindings for record and class
126                -- selectors, and data constructor wrappers.  But *not*
127                -- data constructor workers; reason: we regard them
128                -- as part of the code-gen of tycons
129
130        cg_foreign   :: !ForeignStubs,   -- ^ Foreign export stubs
131        cg_foreign_files :: ![(ForeignSrcLang, FilePath)],
132        cg_dep_pkgs  :: ![UnitId], -- ^ Dependent packages, used to
133                                            -- generate #includes for C code gen
134        cg_hpc_info  :: !HpcInfo,           -- ^ Program coverage tick box information
135        cg_modBreaks :: !(Maybe ModBreaks), -- ^ Module breakpoints
136        cg_spt_entries :: [SptEntry]
137                -- ^ Static pointer table entries for static forms defined in
138                -- the module.
139                -- See Note [Grand plan for static forms] in "GHC.Iface.Tidy.StaticPtrTable"
140    }
141