[project @ 2000-10-11 16:26:04 by simonmar]
[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{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 Auxiliary definitions
38
39 \begin{code}
40 type DeprecationEnv = NameEnv DeprecTxt         -- Give reason for deprecation
41
42 type GlobalRdrEnv = RdrNameEnv [Name]   -- The list is because there may be name clashes
43                                         -- These only get reported on lookup,
44                                         -- not on construction
45
46 data GenAvailInfo name  = Avail name     -- An ordinary identifier
47                         | AvailTC name   -- The name of the type or class
48                                   [name] -- The available pieces of type/class.
49                                          -- NB: If the type or class is itself
50                                          -- to be in scope, it must be in this list.
51                                          -- Thus, typically: AvailTC Eq [Eq, ==, /=]
52                         deriving( Eq )
53                         -- Equality used when deciding if the interface has changed
54
55 type AvailEnv     = NameEnv AvailInfo   -- Maps a Name to the AvailInfo that contains it
56 type AvailInfo    = GenAvailInfo Name
57 type RdrAvailInfo = GenAvailInfo OccName
58 type Avails       = [AvailInfo]
59 \end{code}
60
61
62 %************************************************************************
63 %*                                                                      *
64 \subsection{ModIface}
65 %*                                                                      *
66 %************************************************************************
67
68 \begin{code}
69 -- ModIFace is nearly the same as RnMonad.ParsedIface.
70 -- Right now it's identical :)
71 data ModIFace 
72    = ModIFace {
73         mi_mod       :: Module,                   -- Complete with package info
74         mi_vers      :: Version,                  -- Module version number
75         mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
76         mi_usages    :: [ImportVersion OccName],  -- Usages
77         mi_exports   :: [ExportItem],             -- Exports
78         mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
79         mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
80         mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
81                                                        -- with their version
82         mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
83         mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
84      }
85 \end{code}
86
87 %************************************************************************
88 %*                                                                      *
89 \subsection{The persistent compiler state}
90 %*                                                                      *
91 %************************************************************************
92
93 \begin{code}
94 data PersistentCompilerState 
95    = PCS {
96         pcsPST    :: PackageSymbolTable,        -- Domain = non-home-package modules
97         pcsHP     :: HoldingPen,                -- Pre-slurped interface bits and pieces
98         pcsNS     :: NameSupply                 -- Allocate uniques for names
99      }
100
101 type PackageSymbolTable = ModuleEnv ModDetails
102
103 data NameSupply
104  = NS { nsUniqs  :: UniqSupply,
105         nsNames  :: FiniteMap (Module,OccName) Name     -- Ensures that one original name gets one unique
106         nsIParam :: FiniteMap OccName Name              -- Ensures that one implicit parameter name gets one unique
107    }
108 \end{code}
109
110 %************************************************************************
111 %*                                                                      *
112 \subsection{The result of compiling one module}
113 %*                                                                      *
114 %************************************************************************
115
116 \begin{code}
117 data CompResult
118    = CompOK   ModDetails  -- new details (HST additions)
119               (Maybe (ModIFace, Linkable))
120                        -- summary and code; Nothing => compilation not reqd
121                        -- (old summary and code are still valid)
122               PersistentCompilerState -- updated PCS
123               [SDoc]                  -- warnings
124
125    | CompErrs PersistentCompilerState -- updated PCS
126               [SDoc]                  -- errors
127               [SDoc]                  -- warnings
128
129
130 -- The driver sits between 'compile' and 'hscMain', translating calls
131 -- to the former into calls to the latter, and results from the latter
132 -- into results from the former.  It does things like preprocessing
133 -- the .hs file if necessary, and compiling up the .stub_c files to
134 -- generate Linkables.
135
136 data HscResult
137    = HscOK   ModDetails                 -- new details (HomeSymbolTable additions)
138              Maybe ModIFace             -- new iface (if any compilation was done)
139              Maybe String               -- generated stub_h
140              Maybe String               -- generated stub_c
141              PersistentCompilerState    -- updated PCS
142              [SDoc]                     -- warnings
143
144    | HscErrs PersistentCompilerState    -- updated PCS
145              [SDoc]                     -- errors
146              [SDoc]                     -- warnings
147
148         
149
150 -- These two are only here to avoid recursion between CmCompile and
151 -- CompManager.  They really ought to be in the latter.
152 type ModuleEnv a = UniqFM a   -- Domain is Module
153
154 type HomeModMap         = FiniteMap ModuleName Module -- domain: home mods only
155 type HomeSymbolTable    = ModuleEnv ModDetails        -- ditto
156 type HomeInterfaceTable = ModuleEnv ModIFace
157
158 \end{code}
159
160