pprModuleName,
moduleNameFS,
moduleNameString,
+ moduleNameSlashes,
mkModuleName,
mkModuleNameFS,
+ -- * The PackageId type
+ PackageId,
+ fsToPackageId,
+ packageIdFS,
+ stringToPackageId,
+ packageIdString,
+
+ -- * Wired-in PackageIds
+ primPackageId,
+ integerPackageId,
+ basePackageId,
+ rtsPackageId,
+ haskell98PackageId,
+ thPackageId,
+ ndpPackageId,
+ mainPackageId,
+
-- * The Module type
Module,
modulePackageId, moduleName,
extendModuleEnvList_C, plusModuleEnv_C,
delModuleEnvList, delModuleEnv, plusModuleEnv, lookupModuleEnv,
lookupWithDefaultModuleEnv, mapModuleEnv, mkModuleEnv, emptyModuleEnv,
- moduleEnvElts, unitModuleEnv, isEmptyModuleEnv, foldModuleEnv,
- extendModuleEnv_C, filterModuleEnv,
+ moduleEnvKeys, moduleEnvElts, unitModuleEnv, isEmptyModuleEnv,
+ foldModuleEnv, extendModuleEnv_C, filterModuleEnv,
-- * ModuleName mappings
ModuleNameEnv,
elemModuleSet
) where
-#include "HsVersions.h"
import Outputable
+import qualified Pretty
import Unique
import FiniteMap
-import UniqFM
-import PackageConfig
+import LazyUniqFM
import FastString
import Binary
+
+import System.FilePath
\end{code}
%************************************************************************
mkModuleNameFS :: FastString -> ModuleName
mkModuleNameFS s = ModuleName s
+
+-- Returns the string version of the module name, with dots replaced by slashes
+moduleNameSlashes :: ModuleName -> String
+moduleNameSlashes = dots_to_slashes . moduleNameString
+ where dots_to_slashes = map (\c -> if c == '.' then pathSeparator else c)
\end{code}
%************************************************************************
put_ bh (Module p n) = put_ bh p >> put_ bh n
get bh = do p <- get bh; n <- get bh; return (Module p n)
+instance Uniquable PackageId where
+ getUnique pid = getUnique (packageIdFS pid)
+
mkModule :: PackageId -> ModuleName -> Module
mkModule = Module
pprModule :: Module -> SDoc
pprModule mod@(Module p n) = pprPackagePrefix p mod <> pprModuleName n
+pprPackagePrefix :: PackageId -> Module -> PprStyle -> Pretty.Doc
pprPackagePrefix p mod = getPprStyle doc
where
doc sty
if p == mainPackageId
then empty -- never qualify the main package in code
else ftext (zEncodeFS (packageIdFS p)) <> char '_'
- | Just pkg <- qualModule sty mod = ftext (packageIdFS pkg) <> char ':'
+ | qualModule sty mod = ftext (packageIdFS (modulePackageId mod)) <> char ':'
-- the PrintUnqualified tells us which modules have to
-- be qualified with package names
| otherwise = empty
%************************************************************************
%* *
+\subsection{PackageId}
+%* *
+%************************************************************************
+
+\begin{code}
+newtype PackageId = PId FastString deriving( Eq, Ord ) -- includes the version
+ -- here to avoid module loops with PackageConfig
+
+instance Outputable PackageId where
+ ppr pid = text (packageIdString pid)
+
+instance Binary PackageId where
+ put_ bh pid = put_ bh (packageIdFS pid)
+ get bh = do { fs <- get bh; return (fsToPackageId fs) }
+
+fsToPackageId :: FastString -> PackageId
+fsToPackageId = PId
+
+packageIdFS :: PackageId -> FastString
+packageIdFS (PId fs) = fs
+
+stringToPackageId :: String -> PackageId
+stringToPackageId = fsToPackageId . mkFastString
+
+packageIdString :: PackageId -> String
+packageIdString = unpackFS . packageIdFS
+
+
+-- -----------------------------------------------------------------------------
+-- Package Ids that are wired in
+
+-- Certain packages are "known" to the compiler, in that we know about certain
+-- entities that reside in these packages, and the compiler needs to
+-- declare static Modules and Names that refer to these packages. Hence
+-- the wired-in packages can't include version numbers, since we don't want
+-- to bake the version numbers of these packages into GHC.
+--
+-- So here's the plan. Wired-in packages are still versioned as
+-- normal in the packages database, and you can still have multiple
+-- versions of them installed. However, for each invocation of GHC,
+-- only a single instance of each wired-in package will be recognised
+-- (the desired one is selected via -package/-hide-package), and GHC
+-- will use the unversioned PackageId below when referring to it,
+-- including in .hi files and object file symbols. Unselected
+-- versions of wired-in packages will be ignored, as will any other
+-- package that depends directly or indirectly on it (much as if you
+-- had used -ignore-package).
+
+integerPackageId, primPackageId,
+ basePackageId, rtsPackageId, haskell98PackageId,
+ thPackageId, ndpPackageId, mainPackageId :: PackageId
+primPackageId = fsToPackageId (fsLit "ghc-prim")
+integerPackageId = fsToPackageId (fsLit "integer")
+basePackageId = fsToPackageId (fsLit "base")
+rtsPackageId = fsToPackageId (fsLit "rts")
+haskell98PackageId = fsToPackageId (fsLit "haskell98")
+thPackageId = fsToPackageId (fsLit "template-haskell")
+ndpPackageId = fsToPackageId (fsLit "ndp")
+
+-- This is the package Id for the program. It is the default package
+-- Id if you don't specify a package name. We don't add this prefix
+-- to symbol name, since there can be only one main package per program.
+mainPackageId = fsToPackageId (fsLit "main")
+\end{code}
+
+%************************************************************************
+%* *
\subsection{@ModuleEnv@s}
%* *
%************************************************************************
delModuleEnv :: ModuleEnv a -> Module -> ModuleEnv a
plusModuleEnv_C :: (a -> a -> a) -> ModuleEnv a -> ModuleEnv a -> ModuleEnv a
mapModuleEnv :: (a -> b) -> ModuleEnv a -> ModuleEnv b
+moduleEnvKeys :: ModuleEnv a -> [Module]
moduleEnvElts :: ModuleEnv a -> [a]
isEmptyModuleEnv :: ModuleEnv a -> Bool
mapModuleEnv f = mapFM (\_ v -> f v)
mkModuleEnv = listToFM
emptyModuleEnv = emptyFM
+moduleEnvKeys = keysFM
moduleEnvElts = eltsFM
unitModuleEnv = unitFM
isEmptyModuleEnv = isEmptyFM