diff --git a/Cabal/Distribution/InstalledPackageInfo.hs b/Cabal/Distribution/InstalledPackageInfo.hs index 94d4ade3198..08e197bc2e4 100644 --- a/Cabal/Distribution/InstalledPackageInfo.hs +++ b/Cabal/Distribution/InstalledPackageInfo.hs @@ -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 diff --git a/Cabal/Distribution/Package.hs b/Cabal/Distribution/Package.hs index 7f9628f3ea9..1fec1c8c0c4 100644 --- a/Cabal/Distribution/Package.hs +++ b/Cabal/Distribution/Package.hs @@ -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 diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index a0492aaa457..86a74a94b75 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -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 diff --git a/Cabal/Distribution/Simple/PackageIndex.hs b/Cabal/Distribution/Simple/PackageIndex.hs index 04e3367205f..9ad1249e7aa 100644 --- a/Cabal/Distribution/Simple/PackageIndex.hs +++ b/Cabal/Distribution/Simple/PackageIndex.hs @@ -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