Commit db9ccb5b authored by Edward Z. Yang's avatar Edward Z. Yang

Add a Module data type.

Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent e65fe1f2
......@@ -30,7 +30,7 @@ module Distribution.InstalledPackageInfo (
InstalledPackageInfo(..),
installedComponentId,
installedPackageId,
OriginalModule(..), ExposedModule(..),
ExposedModule(..),
ParseResult(..), PError(..), PWarning,
emptyInstalledPackageInfo,
parseInstalledPackageInfo,
......@@ -162,29 +162,13 @@ emptyInstalledPackageInfo
-- -----------------------------------------------------------------------------
-- Exposed modules
data OriginalModule
= OriginalModule {
originalPackageId :: UnitId,
originalModuleName :: ModuleName
}
deriving (Generic, Eq, Read, Show)
data ExposedModule
= ExposedModule {
exposedName :: ModuleName,
exposedReexport :: Maybe OriginalModule
exposedReexport :: Maybe Module
}
deriving (Eq, Generic, Read, Show)
instance Text OriginalModule where
disp (OriginalModule ipi m) =
disp ipi <> Disp.char ':' <> disp m
parse = do
ipi <- parse
_ <- Parse.char ':'
m <- parse
return (OriginalModule ipi m)
instance Text ExposedModule where
disp (ExposedModule m reexport) =
Disp.sep [ disp m
......@@ -202,8 +186,6 @@ instance Text ExposedModule where
return (ExposedModule m reexport)
instance Binary OriginalModule
instance Binary ExposedModule
-- To maintain backwards-compatibility, we accept both comma/non-comma
......
......@@ -30,6 +30,9 @@ module Distribution.Package (
getHSLibraryName,
InstalledPackageId, -- backwards compat
-- * Modules
Module(..),
-- * ABI hash
AbiHash(..),
......@@ -55,6 +58,7 @@ import qualified Text.PrettyPrint as Disp
import Distribution.Compat.ReadP
import Distribution.Compat.Binary
import Distribution.Text
import Distribution.ModuleName
import Control.DeepSeq (NFData(..))
import qualified Data.Char as Char
......@@ -111,9 +115,32 @@ instance Text PackageIdentifier where
instance NFData PackageIdentifier where
rnf (PackageIdentifier name version) = rnf name `seq` rnf version
-- ------------------------------------------------------------
-- * Component Source Hash
-- ------------------------------------------------------------
-- | A module identity uniquely identifies a Haskell module by
-- qualifying a 'ModuleName' with the 'UnitId' which defined
-- it. This type distinguishes between two packages
-- which provide a module with the same name, or a module
-- from the same package compiled with different dependencies.
-- There are a few cases where Cabal needs to know about
-- module identities, e.g., when writing out reexported modules in
-- the 'InstalledPackageInfo'.
data Module =
Module { moduleUnitId :: UnitId,
moduleName :: ModuleName }
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
instance Binary Module
instance Text Module where
disp (Module uid mod_name) =
disp uid <> Disp.text ":" <> disp mod_name
parse = do
uid <- parse
_ <- Parse.char ':'
mod_name <- parse
return (Module uid mod_name)
instance NFData Module where
rnf (Module uid mod_name) = rnf uid `seq` rnf mod_name
-- | A 'ComponentId' uniquely identifies the transitive source
-- code closure of a component. For non-Backpack components, it also
......
......@@ -1740,8 +1740,8 @@ resolveModuleReexports installedPackages srcpkgid key externalPkgDeps lib =
, let exportingPackageName = packageName srcpkgid
definingModuleName = visibleModuleName
definingPackageId = key
originalModule = Installed.OriginalModule definingPackageId
definingModuleName
originalModule = Module definingPackageId
definingModuleName
exposedModule = Installed.ExposedModule visibleModuleName
(Just originalModule)
]
......@@ -1758,7 +1758,7 @@ resolveModuleReexports installedPackages srcpkgid key externalPkgDeps lib =
-- In this case the reexport will point to this package.
Nothing -> return exposedModule {
Installed.exposedReexport =
Just (Installed.OriginalModule
Just (Module
(Installed.installedUnitId pkg)
(Installed.exposedName exposedModule)) }
-- On the other hand, a visible module might actually be itself
......
......@@ -614,8 +614,8 @@ moduleNameIndex index =
IPI.ExposedModule m reexport <- IPI.exposedModules pkg
case reexport of
Nothing -> return (m, [pkg])
Just (IPI.OriginalModule _ m') | m == m' -> []
| otherwise -> return (m', [pkg])
Just (Module _ m') | m == m' -> []
| otherwise -> return (m', [pkg])
-- The heuristic is this: we want to prefer the original package
-- which originally exported a module. However, if a reexport
-- also *renamed* the module (m /= m'), then we have to use the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment