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 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
49 data TyThing = AnId Id
53 type DeprecationEnv = NameEnv DeprecTxt -- Give reason for deprecation
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
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, ==, /=]
66 -- Equality used when deciding if the interface has changed
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]
75 %************************************************************************
79 %************************************************************************
82 -- ModIFace is nearly the same as RnMonad.ParsedIface.
83 -- Right now it's identical :)
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,
95 mi_rules :: (Version, [RdrNameRuleDecl]), -- Rules, with their version
96 mi_deprecs :: [RdrNameDeprecation] -- Deprecations
101 %************************************************************************
103 \subsection{The persistent compiler state}
105 %************************************************************************
108 data PersistentCompilerState
110 pcsPST :: PackageSymbolTable, -- Domain = non-home-package modules
111 pcsPRS :: PersistentRenamerState
115 The @PersistentRenamerState@ persists across successive calls to the
119 * a name supply, which deals with allocating unique names to
120 (Module,OccName) original names,
122 * a "holding pen" for declarations that have been read out of
123 interface files but not yet sucked in, renamed, and typechecked
126 data PersistentRenamerState
127 = PRS { prsNS :: NameSupply,
128 prsDecls :: DeclsMap,
129 prsInsts :: IfaceInsts,
130 prsRules :: IfaceRules,
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
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.
144 type IfaceInsts = Bag GatedDecl
145 type IfaceRules = Bag GatedDecl
147 type GatedDecl = (NameSet, (Module, RdrNameHsDecl))
151 %************************************************************************
153 \subsection{The result of compiling one module}
155 %************************************************************************
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
166 | CompErrs PersistentCompilerState -- updated PCS
167 (Bag ErrMsg) -- errors
168 (Bag WarnMsg) -- warnings
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.
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
185 | HscErrs PersistentCompilerState -- updated PCS
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
194 type HomeModMap = FiniteMap ModuleName Module -- domain: home mods only
195 type HomeInterfaceTable = ModuleEnv ModIFace