[project @ 2000-10-16 10:05:00 by sewardj]
[ghc-hetmet.git] / ghc / compiler / ghci / CmCompile.lhs
index 47efd0b..f06b793 100644 (file)
@@ -5,37 +5,48 @@
 
 \begin{code}
 module CmCompile ( cmCompile,
-                   ModDetails,       -- abstract
-                   ModIFace,         -- abstract
-                   PCS, emptyPCS,    -- abstract
-                   HST,              -- not abstract (CM needs to see it)
-                   HIT,              -- ditto
+                   ModDetails,         -- abstract
+                   ModIFace,           -- abstract
+                   PersistentCompilerState, emptyPCS,    -- abstract
+                   HomeSymbolTable,    -- not abstract (CM needs to see it)
+                   HomeInterfaceTable, -- ditto
                    CompResult(..)
                  )
 where
 
 #include "HsVersions.h"
 
-import CmLink          ( Linkable(..) )
-import Outputable      ( SDoc )
-import CmFind          ( Finder )
-import CmSummarise     ( ModSummary, name_of_summary )
-import FiniteMap       ( FiniteMap, emptyFM )
-
-import Module          ( Module )
-import RnMonad         ( Avails, GlobalRdrEnv, DeclsMap, 
-                          WhetherHasOrphans, ImportVersion,
-                          IfaceInsts, IfaceRules, ExportItem )
-import TcEnv           ( TyThing, InstEnv )
-import Name            ( Name, OccName )
-import BasicTypes      ( Fixity, Version )
-import Id              ( Id )
-import CoreSyn         ( CoreRule )
-import RdrHsSyn                ( RdrNameDeprecation, RdrNameRuleDecl, RdrNameFixitySig,
-                          RdrNameHsDecl, RdrNameInstDecl )
-
+-- many of these need to be moved to HscTypes
+--import CmLink                ( Linkable(..) )
+--import Outputable    ( SDoc )
+--import CmFind                ( Finder )
+--import CmSummarise   ( ModSummary, name_of_summary )
+--import FiniteMap     ( FiniteMap, emptyFM )
+
+--import Module                ( Module )
+--import RnMonad               ( Avails, GlobalRdrEnv, DeclsMap, 
+--                          WhetherHasOrphans, ImportVersion,
+--                          IfaceInsts, IfaceRules, ExportItem )
+--import TcEnv         ( TyThing, InstEnv )
+--import Name          ( Name, OccName )
+--import BasicTypes    ( Fixity, Version )
+--import Id            ( Id )
+--import CoreSyn               ( CoreRule )
+--import RdrHsSyn              ( RdrNameDeprecation, RdrNameRuleDecl, RdrNameFixitySig,
+--                          RdrNameHsDecl, RdrNameInstDecl )
+
+import HscTypes                ( )
 
 \end{code}
+
+
+%************************************************************************
+%*                                                                     *
+\subsection{The main compiler interface}
+%*                                                                     *
+%************************************************************************
+
+
 \begin{code}
 cmCompile :: Finder                  -- to find modules
           -> ModSummary              -- summary, including source
@@ -69,12 +80,6 @@ data CompResult
               [SDoc]                  -- errors
               [SDoc]                  -- warnings
 
-emptyPCS :: IO PersistentCompilerState
-emptyPCS = return (PersistentCompilerState 
-                      { pcs_modmap = emptyFM,
-                        pcs_pit    = emptyPIT,
-                        pcs_pst    = emptyPST,
-                        pcs_hp     = emptyHoldingPen })
 
 -- These two are only here to avoid recursion between CmCompile and
 -- CompManager.  They really ought to be in the latter.
@@ -83,67 +88,76 @@ type ModuleEnv a = UniqFM a   -- Domain is Module
 type HomeModMap         = FiniteMap ModuleName Module -- domain: home mods only
 type HomeSymbolTable    = ModuleEnv ModDetails        -- ditto
 type HomeInterfaceTable = ModuleEnv ModIFace
+\end{code}
 
-data PersistentCompilerState 
-   = PersistentCompilerState {
-        pcs_modmap :: PackageModMap,         -- domain: package mods only
-        pcs_pit    :: PackageInterfaceTable, -- Package interface table
-        pcs_pst    :: PackageSymbolTable,    -- Package symbol table
-        pcs_hp     :: HoldingPen             -- pre slurped interface bits and pieces
-     }
 
-type PackageModMap         = FiniteMap ModuleName Module
-type PackageInterfaceTable = ModuleEnv ModIFace
-type PackageSymbolTable    = ModuleEnv ModDetails
-
-emptyPIT :: PackageInterfaceTable
-emptyPIT = emptyFM
-
-emptyPST :: PackageSymbolTable
-emptyPST = emptyFM
-
--- ModIFace is nearly the same as RnMonad.ParsedIface.
--- Right now it's identical :)
-data ModIFace 
-   = ModIFace {
-        mi_mod       :: Module,                   -- Complete with package info
-        mi_vers      :: Version,                  -- Module version number
-        mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
-        mi_usages    :: [ImportVersion OccName],  -- Usages
-        mi_exports   :: [ExportItem],             -- Exports
-        mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
-        mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
-        mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
-                                                       -- with their version
-        mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
-        mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
-     }
+%************************************************************************
+%*                                                                     *
+\subsection{Module details}
+%*                                                                     *
+%************************************************************************
 
-data ModDetails
-   = ModDetails {
-        moduleExports :: Avails,
-        moduleEnv     :: GlobalRdrEnv,           -- == FM RdrName [Name]
-        typeEnv       :: FiniteMap Name TyThing, -- TyThing is in TcEnv.lhs
-        instEnv       :: InstEnv,
-        fixityEnv     :: FiniteMap Name Fixity,
-        ruleEnv       :: FiniteMap Id [CoreRule]
-     }
+A @ModDetails@ summarises everything we know about a compiled module
 
--- This should eventually replace RnMonad.Ifaces
-data HoldingPen
-   = HoldingPen {
-        iDecls :: DeclsMap,     -- A single, global map of Names to decls
+Auxiliary definitions
 
-        iInsts :: IfaceInsts,
-        -- The as-yet un-slurped instance decls; this bag is depleted when we
-        -- slurp an instance decl so that we don't slurp the same one twice.
-        -- Each is 'gated' by the names that must be available before
-        -- this instance decl is needed.
+\begin{code}
+{- I DONT think this should be here -- should be in HscTypes 
+type DeprecationEnv = NameEnv DeprecTxt                -- Give reason for deprecation
+
+type GlobalRdrEnv = RdrNameEnv [Name]  -- The list is because there may be name clashes
+                                       -- These only get reported on lookup,
+                                       -- not on construction
+
+data GenAvailInfo name = Avail name     -- An ordinary identifier
+                       | AvailTC name   -- The name of the type or class
+                                 [name] -- The available pieces of type/class.
+                                        -- NB: If the type or class is itself
+                                        -- to be in scope, it must be in this list.
+                                        -- Thus, typically: AvailTC Eq [Eq, ==, /=]
+                       deriving( Eq )
+                       -- Equality used when deciding if the interface has changed
+
+type AvailEnv    = NameEnv AvailInfo   -- Maps a Name to the AvailInfo that contains it
+type AvailInfo    = GenAvailInfo Name
+type RdrAvailInfo = GenAvailInfo OccName
+type Avails      = [AvailInfo]
+-}
+\end{code}
+
+
+%************************************************************************
+%*                                                                     *
+\subsection{The persistent compiler state}
+%*                                                                     *
+%************************************************************************
 
-        iRules :: IfaceRules
-        -- Similar to instance decls, only for rules
+\begin{code}
+data PersistentCompilerState 
+   = PCS {
+        pcsPST    :: PackageSymbolTable,       -- Domain = non-home-package modules
+        pcsHP     :: RnMonad.HoldingPen,       -- Pre-slurped interface bits and pieces
+       pcsNS     :: NameSupply                 -- Allocate uniques for names
      }
 
-emptyHoldingPen :: HoldingPen
-emptyHoldingPen = error "emptyHoldingPen:unimp"
+type PackageSymbolTable = ModuleEnv ModDetails
+
+data NameSupply
+ = NS { nsUniqs  :: UniqSupply,
+       nsNames  :: FiniteMap (Module,OccName) Name     -- Ensures that one original name gets one unique
+       nsIParam :: FiniteMap OccName Name              -- Ensures that one implicit parameter name gets one unique
+   }
+=======
+>>>>>>> 1.9
+=======
+
+-- should be somewhere else?
+emptyPCS :: IO PersistentCompilerState
+emptyPCS = return (PersistentCompilerState 
+                      { pcs_modmap = emptyFM,
+                        pcs_pit    = emptyPIT,
+                        pcs_pst    = emptyPST,
+                        pcs_hp     = emptyHoldingPen })
+>>>>>>> 1.10
 \end{code}
+