2 % (c) The University of Glasgow, 2000
4 \section[CmCompile]{Compiler for GHCI}
7 module CmCompile ( cmCompile,
8 ModDetails, -- abstract
10 PersistentCompilerState, emptyPCS, -- abstract
11 HomeSymbolTable, -- not abstract (CM needs to see it)
12 HomeInterfaceTable, -- ditto
17 #include "HsVersions.h"
19 -- many of these need to be moved to HscTypes
20 --import CmLink ( Linkable(..) )
21 --import Outputable ( SDoc )
22 --import CmFind ( Finder )
23 --import CmSummarise ( ModSummary, name_of_summary )
24 --import FiniteMap ( FiniteMap, emptyFM )
26 --import Module ( Module )
27 --import RnMonad ( Avails, GlobalRdrEnv, DeclsMap,
28 -- WhetherHasOrphans, ImportVersion,
29 -- IfaceInsts, IfaceRules, ExportItem )
30 --import TcEnv ( TyThing, InstEnv )
31 --import Name ( Name, OccName )
32 --import BasicTypes ( Fixity, Version )
34 --import CoreSyn ( CoreRule )
35 --import RdrHsSyn ( RdrNameDeprecation, RdrNameRuleDecl, RdrNameFixitySig,
36 -- RdrNameHsDecl, RdrNameInstDecl )
43 %************************************************************************
45 \subsection{The main compiler interface}
47 %************************************************************************
51 cmCompile :: Finder -- to find modules
52 -> ModSummary -- summary, including source
53 -> Maybe ModIFace -- old interface, if available
54 -> HomeModMap -- ModuleName -> Module
55 -> HomeSymbolTable -- for home module ModDetails
56 -> PersistentCompilerState -- IN: persistent compiler state
59 cmCompile finder summary old_iface hst pcs
60 = do putStrLn ("cmCompile: compiling " ++ name_of_summary summary)
61 return (CompOK (error "cmCompile:modDetails")
62 (Just (error "cmCompile:modIFace",
63 --error "cmCompile:Linkable"
64 --LM (name_of_summary summary) []
65 LM (name_of_summary summary) []
72 = CompOK ModDetails -- new details (HST additions)
73 (Maybe (ModIFace, Linkable))
74 -- summary and code; Nothing => compilation not reqd
75 -- (old summary and code are still valid)
76 PersistentCompilerState -- updated PCS
79 | CompErrs PersistentCompilerState -- updated PCS
84 -- These two are only here to avoid recursion between CmCompile and
85 -- CompManager. They really ought to be in the latter.
86 type ModuleEnv a = UniqFM a -- Domain is Module
88 type HomeModMap = FiniteMap ModuleName Module -- domain: home mods only
89 type HomeSymbolTable = ModuleEnv ModDetails -- ditto
90 type HomeInterfaceTable = ModuleEnv ModIFace
94 %************************************************************************
96 \subsection{Module details}
98 %************************************************************************
100 A @ModDetails@ summarises everything we know about a compiled module
105 moduleExports :: Avails, -- What it exports
106 moduleEnv :: GlobalRdrEnv, -- Its top level environment
108 fixityEnv :: NameEnv Fixity,
109 deprecEnv :: NameEnv DeprecTxt,
110 typeEnv :: NameEnv TcEnv.TyThing,
113 ruleEnv :: IdEnv [CoreRule] -- Domain includes Ids from other modules
117 Auxiliary definitions
120 type DeprecationEnv = NameEnv DeprecTxt -- Give reason for deprecation
122 type GlobalRdrEnv = RdrNameEnv [Name] -- The list is because there may be name clashes
123 -- These only get reported on lookup,
124 -- not on construction
126 data GenAvailInfo name = Avail name -- An ordinary identifier
127 | AvailTC name -- The name of the type or class
128 [name] -- The available pieces of type/class.
129 -- NB: If the type or class is itself
130 -- to be in scope, it must be in this list.
131 -- Thus, typically: AvailTC Eq [Eq, ==, /=]
133 -- Equality used when deciding if the interface has changed
135 type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contains it
136 type AvailInfo = GenAvailInfo Name
137 type RdrAvailInfo = GenAvailInfo OccName
138 type Avails = [AvailInfo]
142 %************************************************************************
144 \subsection{The persistent compiler state}
146 %************************************************************************
149 data PersistentCompilerState
151 pcsPST :: PackageSymbolTable, -- Domain = non-home-package modules
152 pcsHP :: RnMonad.HoldingPen, -- Pre-slurped interface bits and pieces
153 pcsNS :: NameSupply -- Allocate uniques for names
156 type PackageSymbolTable = ModuleEnv ModDetails
159 = NS { nsUniqs :: UniqSupply,
160 nsNames :: FiniteMap (Module,OccName) Name -- Ensures that one original name gets one unique
161 nsIParam :: FiniteMap OccName Name -- Ensures that one implicit parameter name gets one unique
167 -- should be somewhere else?
168 emptyPCS :: IO PersistentCompilerState
169 emptyPCS = return (PersistentCompilerState
170 { pcs_modmap = emptyFM,
173 pcs_hp = emptyHoldingPen })