2 % (c) The University of Glasgow, 2000
4 \section[HscTypes]{Types for the per-module compiler}
10 #include "HsVersions.h"
14 %************************************************************************
16 \subsection{Symbol tables and Module details}
18 %************************************************************************
20 A @ModDetails@ summarises everything we know about a compiled module
25 moduleExports :: Avails, -- What it exports
26 moduleEnv :: GlobalRdrEnv, -- Its top level environment
28 fixityEnv :: NameEnv Fixity,
29 deprecEnv :: NameEnv DeprecTxt,
30 typeEnv :: NameEnv TyThing, -- TyThing is in TcEnv.lhs
33 ruleEnv :: IdEnv [CoreRule] -- Domain includes Ids from other modules
37 Symbol tables map modules to ModDetails:
40 type SymbolTable = ModuleEnv ModDetails
41 type HomeSymbolTable = SymbolTable -- Domain = modules in the home package
42 type PackageSymbolTable = SymbolTable -- Domain = modules in the some other package
43 type GlobalSymbolTable = SymbolTable -- Domain = all modules
47 Simple lookups in the symbol table
50 lookupFixityEnv :: SymbolTable -> Name -> Fixity
51 -- Returns defaultFixity if there isn't an explicit fixity
52 lookupFixityEnv tbl name
53 = case lookupModuleEnv tbl (nameModule name) of
54 Nothing -> defaultFixity
55 Just details -> case lookupNameEnv (fixityEnv details) name of
57 Nothing -> defaultFixity
59 lookupTypeEnv :: SymbolTable -> Name -> Maybe TyThing
60 lookupTypeEnv tbl name
61 = case lookupModuleEnv tbl (nameModule name) of
62 Just details -> lookupNameEnv (typeEnv details) name
67 %************************************************************************
69 \subsection{Auxiliary types}
71 %************************************************************************
73 These types are defined here because they are mentioned in ModDetails,
74 but they are mostly elaborated elsewhere
77 data TyThing = AnId Id
81 type DeprecationEnv = NameEnv DeprecTxt -- Give reason for deprecation
83 type GlobalRdrEnv = RdrNameEnv [Name] -- The list is because there may be name clashes
84 -- These only get reported on lookup,
85 -- not on construction
87 type InstEnv = UniqFM ClsInstEnv -- Maps Class to instances for that class
88 type ClsInstEnv = [(TyVarSet, [Type], Id)] -- The instances for a particular class
93 type Avails = [AvailInfo]
94 type AvailInfo = GenAvailInfo Name
95 type RdrAvailInfo = GenAvailInfo OccName
97 data GenAvailInfo name = Avail name -- An ordinary identifier
98 | AvailTC name -- The name of the type or class
99 [name] -- The available pieces of type/class.
100 -- NB: If the type or class is itself
101 -- to be in scope, it must be in this list.
102 -- Thus, typically: AvailTC Eq [Eq, ==, /=]
104 -- Equality used when deciding if the interface has changed
106 type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contains it
110 %************************************************************************
112 \subsection{ModIface}
114 %************************************************************************
117 -- ModIFace is nearly the same as RnMonad.ParsedIface.
118 -- Right now it's identical :)
121 mi_mod :: Module, -- Complete with package info
122 mi_vers :: Version, -- Module version number
123 mi_orphan :: WhetherHasOrphans, -- Whether this module has orphans
124 mi_usages :: [ImportVersion OccName], -- Usages
125 mi_exports :: [ExportItem], -- Exports
126 mi_insts :: [RdrNameInstDecl], -- Local instance declarations
127 mi_decls :: [(Version, RdrNameHsDecl)], -- Local definitions
128 mi_fixity :: (Version, [RdrNameFixitySig]), -- Local fixity declarations,
129 -- with their version
130 mi_rules :: (Version, [RdrNameRuleDecl]), -- Rules, with their version
131 mi_deprecs :: [RdrNameDeprecation] -- Deprecations
136 %************************************************************************
138 \subsection{The persistent compiler state}
140 %************************************************************************
143 data PersistentCompilerState
145 pcsPST :: PackageSymbolTable, -- Domain = non-home-package modules
146 pcsPRS :: PersistentRenamerState
150 The @PersistentRenamerState@ persists across successive calls to the
154 * a name supply, which deals with allocating unique names to
155 (Module,OccName) original names,
157 * a "holding pen" for declarations that have been read out of
158 interface files but not yet sucked in, renamed, and typechecked
161 data PersistentRenamerState
162 = PRS { prsNS :: NameSupply,
163 prsDecls :: DeclsMap,
164 prsInsts :: IfaceInsts,
165 prsRules :: IfaceRules,
169 = NS { nsUniqs :: UniqSupply,
170 nsNames :: FiniteMap (Module,OccName) Name -- Ensures that one original name gets one unique
171 nsIParam :: FiniteMap OccName Name -- Ensures that one implicit parameter name gets one unique
174 type DeclsMap = NameEnv (Version, AvailInfo, Bool, (Module, RdrNameHsDecl))
175 -- A DeclsMap contains a binding for each Name in the declaration
176 -- including the constructors of a type decl etc.
177 -- The Bool is True just for the 'main' Name.
179 type IfaceInsts = Bag GatedDecl
180 type IfaceRules = Bag GatedDecl
182 type GatedDecl = (NameSet, (Module, RdrNameHsDecl))
186 %************************************************************************
188 \subsection{The result of compiling one module}
190 %************************************************************************
194 = CompOK ModDetails -- new details (HST additions)
195 (Maybe (ModIFace, Linkable))
196 -- summary and code; Nothing => compilation not reqd
197 -- (old summary and code are still valid)
198 PersistentCompilerState -- updated PCS
199 (Bag WarnMsg) -- warnings
201 | CompErrs PersistentCompilerState -- updated PCS
202 (Bag ErrMsg) -- errors
203 (Bag WarnMsg) -- warnings
206 -- The driver sits between 'compile' and 'hscMain', translating calls
207 -- to the former into calls to the latter, and results from the latter
208 -- into results from the former. It does things like preprocessing
209 -- the .hs file if necessary, and compiling up the .stub_c files to
210 -- generate Linkables.
213 = HscOK ModDetails -- new details (HomeSymbolTable additions)
214 Maybe ModIFace -- new iface (if any compilation was done)
215 Maybe String -- generated stub_h
216 Maybe String -- generated stub_c
217 PersistentCompilerState -- updated PCS
220 | HscErrs PersistentCompilerState -- updated PCS
225 -- These two are only here to avoid recursion between CmCompile and
226 -- CompManager. They really ought to be in the latter.
227 type ModuleEnv a = UniqFM a -- Domain is Module
229 type HomeModMap = FiniteMap ModuleName Module -- domain: home mods only
230 type HomeInterfaceTable = ModuleEnv ModIFace