Move @compile@-related types to HscTypes.
#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}
pcs
[]
)
-
-data CompResult
- = CompOK ModDetails -- new details (HST additions)
- (Maybe (ModIFace, Linkable))
- -- summary and code; Nothing => compilation not reqd
- -- (old summary and code are still valid)
- PersistentCompilerState -- updated PCS
- [SDoc] -- warnings
-
- | CompErrs PersistentCompilerState -- updated PCS
- [SDoc] -- errors
- [SDoc] -- warnings
-
-
--- These two are only here to avoid recursion between CmCompile and
--- CompManager. They really ought to be in the latter.
-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}
-
-
-%************************************************************************
-%* *
-\subsection{Module details}
-%* *
-%************************************************************************
-
-A @ModDetails@ summarises everything we know about a compiled module
-
-\begin{code}
-data ModDetails
- = ModDetails {
- moduleExports :: Avails, -- What it exports
- moduleEnv :: GlobalRdrEnv, -- Its top level environment
-
- fixityEnv :: NameEnv Fixity,
- deprecEnv :: NameEnv DeprecTxt,
- typeEnv :: NameEnv TyThing, -- TyThing is in TcEnv.lhs
-
- instEnv :: InstEnv,
- ruleEnv :: IdEnv [CoreRule] -- Domain includes Ids from other modules
- }
-\end{code}
-
-Auxiliary definitions
-
-\begin{code}
-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}
-%* *
-%************************************************************************
-
-\begin{code}
-data PersistentCompilerState
- = PCS {
- pcsPST :: PackageSymbolTable, -- Domain = non-home-package modules
- pcsHP :: HoldingPen, -- Pre-slurped interface bits and pieces
- pcsNS :: NameSupply -- Allocate uniques for names
- }
-
-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
- }
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{ModIface}
-%* *
-%************************************************************************
-
-\begin{code}
--- 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
- }
-
-\end{code}
\section[CmFind]{Module finder for GHCI}
\begin{code}
-module CmFind ( Path, ModName, PkgName,
- ModLocation(..), ml_modname, isPackageLoc,
+module CmFind ( ModLocation(..), ml_modname, isPackageLoc,
Finder, newFinder )
where
import Directory ( doesFileExist, getModificationTime )
import Outputable
-import Module ( Module )
-import CmStaticInfo ( PCI(..), Package(..), Path, ModName, PkgName )
+import Module ( Module, ModuleName, PackageName )
+import CmStaticInfo ( PCI(..), Package(..) )
\end{code}
\begin{code}
+-- make a product type, with Maybe return --> Module,lhs
data ModLocation
- = SourceOnly ModName Path -- .hs
- | ObjectCode ModName Path Path -- .o, .hi
- | InPackage ModName PkgName
+ = SourceOnly ModuleName Path -- .hs
+ | ObjectCode ModuleName Path Path -- .o, .hi
+ | InPackage ModuleName PackageName
| NotFound
instance Outputable ModLocation where
-type Finder = ModName -> IO ModLocation
+type Finder = ModuleName -> IO ModLocation
ml_modname (SourceOnly nm _) = nm
ml_modname (ObjectCode nm _ _) = nm
isPackageLoc (InPackage _ _) = True
isPackageLoc _ = False
-mkFinder :: [(ModName,PkgName,Path)] -> [Path] -> Finder
+mkFinder :: [(ModuleName,PackageName,FilePath)] -> [FilePath] -> Finder
mkFinder pkg_ifaces home_dirs modnm
= do found <- mkFinderX pkg_ifaces home_dirs modnm
putStrLn ("FINDER: request = " ++ modnm ++ "\n" ++
return found
-mkFinderX :: [(ModName,PkgName,Path)] -> [Path] -> Finder
+mkFinderX :: [(ModuleName,PackageName,FilePath)] -> [FilePath] -> Finder
mkFinderX pkg_ifaces home_dirs modnm
-- If the module exists both as package and home, emit a warning
-- and (arbitrarily) choose the user's one.
-- See if a .hs or (.hi, .o) pair exist on the given path,
-- and return a ModLocation for whichever is younger
-homeModuleExists :: ModName -> Path -> IO (Maybe (ModLocation, ClockTime))
+homeModuleExists :: ModuleName -> FilePath -> IO (Maybe (ModLocation, ClockTime))
homeModuleExists modname path
= do m_ths <- maybeTime nm_hs
m_thi <- maybeTime nm_hi
-newFinder :: String{-temp debugging hack-}
+newFinder :: FilePath{-temp debugging hack-}
-> PCI -> IO Finder
newFinder path pci
= return (mkFinder (module_table pci) [path])
\section[CmStaticInfo]{Session-static info for the Compilation Manager}
\begin{code}
-module CmStaticInfo ( Path, ModName, PkgName,
- Package(..), PCI(..), mkPCI )
+module CmStaticInfo ( Package(..), PCI(..), mkPCI )
where
#include "HsVersions.h"
import List ( nub )
import Char ( isUpper )
import Directory ( getDirectoryContents )
+
+import Module ( ModuleName, PackageName )
\end{code}
\begin{code}
-type Path = String
-type ModName = String
-type PkgName = String
-
-data PCI
- = PCI {
- raw_package_info :: [Package], -- contents of packages.conf
- module_table :: [(ModName, PkgName, Path)]
- -- maps each available module to pkg and path
+data PackageConfigInfo
+ = PackageConfigInfo {
+ pci_rawinfo :: [Package], -- contents of packages.conf
+ pci_modtable :: [(ModuleName, PackageName, FilePath)]
+ -- maps each available module to pkg and path
}
-- copied from the driver
mkPCI :: [Package] -> IO PCI
mkPCI raw_package_info
= do mtab <- mk_module_table raw_package_info
- return (PCI { raw_package_info = raw_package_info,
- module_table = mtab })
+ return (PCI { pci_rawinfo = raw_package_info,
+ pci_modtable = mtab })
-mk_module_table :: [Package] -> IO [(ModName,PkgName,Path)]
+mk_module_table :: [Package] -> IO [(ModuleName,PackageName,FilePath)]
mk_module_table raw_info
= do
-- the list of directories where package interfaces are
- let p_i_dirs :: [(PkgName,Path)]
+ let -- p_i_dirs :: [(PkgName,Path)]
p_i_dirs = concatMap nm_and_paths raw_info
-- interface names in each directory
ifacess <- mapM ifaces_in_dir p_i_dirs
- let iface_table :: [(ModName,PkgName,Path)]
- iface_table = concat ifacess
+ let -- iface_table :: [(ModName,PkgName,Path)]
+ iface_table = map fsifyStrings (concat ifacess)
-- ToDo: allow a range of home package directories
return iface_table
where
- nm_and_paths :: Package -> [(PkgName,Path)]
+ fsifyStrings (mod_str, pkg_str, path_str)
+ = (mkFastString mod_str, mkFastString pkg_str, path_str)
+ -- nm_and_paths :: Package -> [(PkgName,Path)]
nm_and_paths package
= [(name package, path) | path <- nub (import_dirs package)]
- ifaces_in_dir :: (PkgName,Path) -> IO [(ModName,PkgName,Path)]
+ -- ifaces_in_dir :: (PkgName,Path) -> IO [(ModName,PkgName,Path)]
ifaces_in_dir (pkgname,path)
= getDirectoryContents path >>= \ entries ->
return [(zap_hi if_nm, pkgname, path)
-- Persistent state just for CM, excluding link & compile subsystems
-data PCMS
- = PCMS {
- hst :: HST, -- home symbol table
- hit :: HIT, -- home interface table
- ui :: UI, -- the unlinked images
- mg :: MG -- the module graph
+data PersistentCMState
+ = PersistentCMState {
+ hst :: HomeSymbolTable, -- home symbol table
+ hit :: HomeInterfaceTable, -- home interface table
+ ui :: UnlinkedImages, -- the unlinked images
+ mg :: ModuleGraph -- the module graph
}
-emptyPCMS :: PCMS
-emptyPCMS = PCMS { hst = emptyHST,
- hit = emptyHIT,
- ui = emptyUI,
- mg = emptyMG }
+emptyPCMS :: PersistentCMState
+emptyPCMS = PersistentCMState
+ { hmm = emptyHMM,
+ hst = emptyHST, hit = emptyHIT,
+ ui = emptyUI, mg = emptyMG }
-emptyHIT :: HIT
+emptyHIT :: HomeInterfaceTable
emptyHIT = emptyFM
-
-emptyHST :: HST
+emptyHST :: HomeSymbolTable
emptyHST = emptyFM
-- Persistent state for the entire system
data CmState
= CmState {
- pcms :: PCMS, -- CM's persistent state
- pcs :: PCS, -- compile's persistent state
- pls :: PLS, -- link's persistent state
- pci :: PCI, -- package config info, never changes
- finder :: Finder -- the module finder
+ pcms :: PersistentCMState, -- CM's persistent state
+ pcs :: PersistentCompilerState, -- compile's persistent state
+ pls :: PersistentLinkerState, -- link's persistent state
+ pci :: PackageConfigInfo, -- package config info, never changes
+ finder :: Finder -- the module finder
}
emptyCmState :: String{-temp debugging hack-}
finder = finder })
-- CM internal types
-type UI = [Linkable] -- the unlinked images (should be a set, really)
-emptyUI :: UI
+type UnlinkedImage = [Linkable] -- the unlinked images (should be a set, really)
+emptyUI :: UnlinkedImage
emptyUI = []
-
-type MG = [SCC ModSummary] -- the module graph, topologically sorted
-emptyMG :: MG
+type ModuleGraph = [SCC ModSummary] -- the module graph, topologically sorted
+emptyMG :: ModuleGraph
emptyMG = []
\end{code}
--- /dev/null
+%
+% (c) The University of Glasgow, 2000
+%
+\section[HscTypes]{Types for the per-module compiler}
+
+\begin{code}
+module HscTypes ( )
+where
+
+#include "HsVersions.h"
+
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Module details}
+%* *
+%************************************************************************
+
+A @ModDetails@ summarises everything we know about a compiled module
+
+\begin{code}
+data ModDetails
+ = ModDetails {
+ moduleExports :: Avails, -- What it exports
+ moduleEnv :: GlobalRdrEnv, -- Its top level environment
+
+ fixityEnv :: NameEnv Fixity,
+ deprecEnv :: NameEnv DeprecTxt,
+ typeEnv :: NameEnv TyThing, -- TyThing is in TcEnv.lhs
+
+ instEnv :: InstEnv,
+ ruleEnv :: IdEnv [CoreRule] -- Domain includes Ids from other modules
+ }
+\end{code}
+
+Auxiliary definitions
+
+\begin{code}
+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{ModIface}
+%* *
+%************************************************************************
+
+\begin{code}
+-- 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
+ }
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{The persistent compiler state}
+%* *
+%************************************************************************
+
+\begin{code}
+data PersistentCompilerState
+ = PCS {
+ pcsPST :: PackageSymbolTable, -- Domain = non-home-package modules
+ pcsHP :: HoldingPen, -- Pre-slurped interface bits and pieces
+ pcsNS :: NameSupply -- Allocate uniques for names
+ }
+
+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
+ }
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{The result of compiling one module}
+%* *
+%************************************************************************
+\begin{code}
+data CompResult
+ = CompOK ModDetails -- new details (HST additions)
+ (Maybe (ModIFace, Linkable))
+ -- summary and code; Nothing => compilation not reqd
+ -- (old summary and code are still valid)
+ PersistentCompilerState -- updated PCS
+ [SDoc] -- warnings
+
+ | CompErrs PersistentCompilerState -- updated PCS
+ [SDoc] -- errors
+ [SDoc] -- warnings
+
+
+-- These two are only here to avoid recursion between CmCompile and
+-- CompManager. They really ought to be in the latter.
+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}
+
+