64e2a6b6a767a90e3ef6d69580ed65a3c01ae4ea
[ghc-hetmet.git] / ghc / compiler / main / HscTypes.lhs
1 %
2 % (c) The University of Glasgow, 2000
3 %
4 \section[HscTypes]{Types for the per-module compiler}
5
6 \begin{code}
7 module HscTypes  ( )
8 where
9
10 #include "HsVersions.h"
11
12 \end{code}
13
14 %************************************************************************
15 %*                                                                      *
16 \subsection{Symbol tables and Module details}
17 %*                                                                      *
18 %************************************************************************
19
20 A @ModDetails@ summarises everything we know about a compiled module
21
22 \begin{code}
23 data ModDetails
24    = ModDetails {
25         moduleExports :: Avails,                -- What it exports
26         moduleEnv     :: GlobalRdrEnv,          -- Its top level environment
27
28         fixityEnv     :: NameEnv Fixity,
29         deprecEnv     :: NameEnv DeprecTxt,
30         typeEnv       :: NameEnv TyThing,       -- TyThing is in TcEnv.lhs
31
32         instEnv       :: InstEnv,
33         ruleEnv       :: IdEnv [CoreRule]       -- Domain includes Ids from other modules
34      }
35 \end{code}
36
37 Symbol tables map modules to ModDetails:
38
39 \begin{code}
40 type HomeSymbolTable    = ModuleEnv ModDetails  -- Domain = modules in the home package
41 type PackageSymbolTable = ModuleEnv ModDetails  -- Domain = modules in the some other package
42 type GlobalSymbolTable  = ModuleEnv ModDetails  -- Domain = all modules
43 \end{code}
44
45
46 Auxiliary definitions
47
48 \begin{code}
49 data TyThing = AnId   Id
50              | ATyCon TyCon
51              | AClass Class
52
53 type DeprecationEnv = NameEnv DeprecTxt         -- Give reason for deprecation
54
55 type GlobalRdrEnv = RdrNameEnv [Name]   -- The list is because there may be name clashes
56                                         -- These only get reported on lookup,
57                                         -- not on construction
58
59 data GenAvailInfo name  = Avail name     -- An ordinary identifier
60                         | AvailTC name   -- The name of the type or class
61                                   [name] -- The available pieces of type/class.
62                                          -- NB: If the type or class is itself
63                                          -- to be in scope, it must be in this list.
64                                          -- Thus, typically: AvailTC Eq [Eq, ==, /=]
65                         deriving( Eq )
66                         -- Equality used when deciding if the interface has changed
67
68 type AvailEnv     = NameEnv AvailInfo   -- Maps a Name to the AvailInfo that contains it
69 type AvailInfo    = GenAvailInfo Name
70 type RdrAvailInfo = GenAvailInfo OccName
71 type Avails       = [AvailInfo]
72 \end{code}
73
74
75 %************************************************************************
76 %*                                                                      *
77 \subsection{ModIface}
78 %*                                                                      *
79 %************************************************************************
80
81 \begin{code}
82 -- ModIFace is nearly the same as RnMonad.ParsedIface.
83 -- Right now it's identical :)
84 data ModIFace 
85    = ModIFace {
86         mi_mod       :: Module,                   -- Complete with package info
87         mi_vers      :: Version,                  -- Module version number
88         mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
89         mi_usages    :: [ImportVersion OccName],  -- Usages
90         mi_exports   :: [ExportItem],             -- Exports
91         mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
92         mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
93         mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
94                                                        -- with their version
95         mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
96         mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
97      }
98 \end{code}
99
100
101 %************************************************************************
102 %*                                                                      *
103 \subsection{The persistent compiler state}
104 %*                                                                      *
105 %************************************************************************
106
107 \begin{code}
108 data PersistentCompilerState 
109    = PCS {
110         pcsPST :: PackageSymbolTable,           -- Domain = non-home-package modules
111         pcsPRS :: PersistentRenamerState
112      }
113 \end{code}
114
115 The @PersistentRenamerState@ persists across successive calls to the
116 compiler.
117
118 It contains:
119   * a name supply, which deals with allocating unique names to
120     (Module,OccName) original names, 
121  
122   * a "holding pen" for declarations that have been read out of
123     interface files but not yet sucked in, renamed, and typechecked
124
125 \begin{code}
126 data PersistentRenamerState
127   = PRS { prsNS    :: NameSupply,
128           prsDecls :: DeclsMap,
129           prsInsts :: IfaceInsts,
130           prsRules :: IfaceRules,
131     }
132
133 data NameSupply
134  = NS { nsUniqs  :: UniqSupply,
135         nsNames  :: FiniteMap (Module,OccName) Name     -- Ensures that one original name gets one unique
136         nsIParam :: FiniteMap OccName Name              -- Ensures that one implicit parameter name gets one unique
137    }
138
139 type DeclsMap = NameEnv (Version, AvailInfo, Bool, (Module, RdrNameHsDecl))
140                 -- A DeclsMap contains a binding for each Name in the declaration
141                 -- including the constructors of a type decl etc.
142                 -- The Bool is True just for the 'main' Name.
143
144 type IfaceInsts = Bag GatedDecl
145 type IfaceRules = Bag GatedDecl
146
147 type GatedDecl = (NameSet, (Module, RdrNameHsDecl))
148 \end{code}
149
150
151 %************************************************************************
152 %*                                                                      *
153 \subsection{The result of compiling one module}
154 %*                                                                      *
155 %************************************************************************
156
157 \begin{code}
158 data CompResult
159    = CompOK   ModDetails  -- new details (HST additions)
160               (Maybe (ModIFace, Linkable))
161                        -- summary and code; Nothing => compilation not reqd
162                        -- (old summary and code are still valid)
163               PersistentCompilerState   -- updated PCS
164               (Bag WarnMsg)             -- warnings
165
166    | CompErrs PersistentCompilerState   -- updated PCS
167               (Bag ErrMsg)              -- errors
168               (Bag WarnMsg)             -- warnings
169
170
171 -- The driver sits between 'compile' and 'hscMain', translating calls
172 -- to the former into calls to the latter, and results from the latter
173 -- into results from the former.  It does things like preprocessing
174 -- the .hs file if necessary, and compiling up the .stub_c files to
175 -- generate Linkables.
176
177 data HscResult
178    = HscOK   ModDetails                 -- new details (HomeSymbolTable additions)
179              Maybe ModIFace             -- new iface (if any compilation was done)
180              Maybe String               -- generated stub_h
181              Maybe String               -- generated stub_c
182              PersistentCompilerState    -- updated PCS
183              [SDoc]                     -- warnings
184
185    | HscErrs PersistentCompilerState    -- updated PCS
186              [SDoc]                     -- errors
187              [SDoc]                     -- warnings
188
189         
190 -- These two are only here to avoid recursion between CmCompile and
191 -- CompManager.  They really ought to be in the latter.
192 type ModuleEnv a = UniqFM a   -- Domain is Module
193
194 type HomeModMap         = FiniteMap ModuleName Module -- domain: home mods only
195 type HomeInterfaceTable = ModuleEnv ModIFace
196 \end{code}
197
198