Commit 3de0e4c4 authored by Edward Z. Yang's avatar Edward Z. Yang

Backpack InstalledPackageInfo representation changes

New field, @instantiated-with@, which records the full
module substitution (it is dropped when we do 'improveUnitId').

For flexibility in the case of indefinite packages, some
occurences of Module are relaxed to IndefModule (exposedReexport).
This is just for convenience; in the case of a definite package
these reexports and instantiations are guaranteed to be 'Module's.

This patch also includes the minimal changes in other modules
needed due to the representation change.
parent 305935d9
......@@ -47,6 +47,7 @@ import Distribution.Compat.Prelude
import Distribution.ParseUtils
import Distribution.License
import Distribution.Package hiding (installedUnitId, installedPackageId)
import Distribution.Backpack
import qualified Distribution.Package as Package
import Distribution.ModuleName
import Distribution.Version
......@@ -56,6 +57,7 @@ import Distribution.Compat.Graph
import Text.PrettyPrint as Disp
import qualified Data.Char as Char
import qualified Data.Map as Map
-- -----------------------------------------------------------------------------
-- The InstalledPackageInfo type
......@@ -67,6 +69,11 @@ data InstalledPackageInfo
-- these parts are exactly the same as PackageDescription
sourcePackageId :: PackageId,
installedUnitId :: UnitId,
-- INVARIANT: if this package is definite, IndefModule's
-- IndefUnitId directly records UnitId. If it is
-- indefinite, IndefModule is always an IndefModuleVar
-- with the same ModuleName as the key.
instantiatedWith :: [(ModuleName, IndefModule)],
compatPackageKey :: String,
license :: License,
copyright :: String,
......@@ -81,6 +88,8 @@ data InstalledPackageInfo
-- these parts are required by an installed package only:
abiHash :: AbiHash,
exposed :: Bool,
-- INVARIANT: if the package is definite, IndefModule's
-- IndefUnitId directly records UnitId.
exposedModules :: [ExposedModule],
hiddenModules :: [ModuleName],
trusted :: Bool,
......@@ -92,6 +101,8 @@ data InstalledPackageInfo
extraGHCiLibraries:: [String], -- overrides extraLibraries for GHCi
includeDirs :: [FilePath],
includes :: [String],
-- INVARIANT: if the package is definite, UnitId is NOT
-- a ComponentId of an indefinite package
depends :: [UnitId],
ccOptions :: [String],
ldOptions :: [String],
......@@ -135,6 +146,7 @@ emptyInstalledPackageInfo
= InstalledPackageInfo {
sourcePackageId = PackageIdentifier (mkPackageName "") nullVersion,
installedUnitId = mkUnitId "",
instantiatedWith = [],
compatPackageKey = "",
license = UnspecifiedLicense,
copyright = "",
......@@ -175,7 +187,7 @@ emptyInstalledPackageInfo
data ExposedModule
= ExposedModule {
exposedName :: ModuleName,
exposedReexport :: Maybe Module
exposedReexport :: Maybe IndefModule
}
deriving (Eq, Generic, Read, Show)
......@@ -195,7 +207,6 @@ instance Text ExposedModule where
fmap Just parse
return (ExposedModule m reexport)
instance Binary ExposedModule
-- To maintain backwards-compatibility, we accept both comma/non-comma
......@@ -257,6 +268,9 @@ basicFieldDescrs =
, simpleField "id"
disp parse
installedUnitId (\pk pkg -> pkg{installedUnitId=pk})
, simpleField "instantiated-with"
(dispIndefModuleSubst . Map.fromList) (fmap Map.toList parseIndefModuleSubst)
instantiatedWith (\iw pkg -> pkg{instantiatedWith=iw})
, simpleField "key"
dispCompatPackageKey parseCompatPackageKey
compatPackageKey (\pk pkg -> pkg{compatPackageKey=pk})
......
......@@ -66,6 +66,7 @@ import Distribution.Utils.NubList
import Distribution.Simple.Compiler hiding (Flag)
import Distribution.Simple.PreProcess
import Distribution.Package
import Distribution.Backpack
import qualified Distribution.InstalledPackageInfo as Installed
import Distribution.InstalledPackageInfo (InstalledPackageInfo
,emptyInstalledPackageInfo)
......@@ -2004,8 +2005,8 @@ resolveModuleReexports installedPackages srcpkgid key externalPkgDeps lib =
, let exportingPackageName = packageName srcpkgid
definingModuleName = visibleModuleName
definingPackageId = key
originalModule = Module definingPackageId
definingModuleName
originalModule = IndefModule (IndefUnitId definingPackageId)
definingModuleName
exposedModule = Installed.ExposedModule visibleModuleName
(Just originalModule)
]
......@@ -2022,8 +2023,8 @@ resolveModuleReexports installedPackages srcpkgid key externalPkgDeps lib =
-- In this case the reexport will point to this package.
Nothing -> return exposedModule {
Installed.exposedReexport =
Just (Module
(Installed.installedUnitId pkg)
Just (IndefModule
(IndefUnitId (Installed.installedUnitId pkg))
(Installed.exposedName exposedModule)) }
-- On the other hand, a visible module might actually be itself
-- a re-export! In this case, the re-export info for the package
......
......@@ -69,6 +69,7 @@ toCurrent ipi@InstalledPackageInfo{} =
in Current.InstalledPackageInfo {
Current.sourcePackageId = pid,
Current.installedUnitId = Current.mkLegacyUnitId pid,
Current.instantiatedWith = [],
Current.compatPackageKey = "",
Current.abiHash = Current.mkAbiHash "", -- bogus but old GHCs don't care.
Current.license = convertLicense (license ipi),
......
......@@ -113,6 +113,7 @@ import Prelude ()
import Distribution.Compat.Prelude hiding (lookup)
import Distribution.Package
import Distribution.Backpack
import Distribution.ModuleName
import qualified Distribution.InstalledPackageInfo as IPI
import Distribution.Version
......@@ -666,8 +667,9 @@ moduleNameIndex index =
IPI.ExposedModule m reexport <- IPI.exposedModules pkg
case reexport of
Nothing -> return (m, [pkg])
Just (Module _ m') | m == m' -> []
| otherwise -> return (m', [pkg])
Just (IndefModuleVar _) -> []
Just (IndefModule _ 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
......
......@@ -389,6 +389,7 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
pkgName = componentCompatPackageName clbi
},
IPI.installedUnitId = componentUnitId clbi,
IPI.instantiatedWith = [], --TODO fill in properly
IPI.compatPackageKey = componentCompatPackageKey clbi,
IPI.license = license pkg,
IPI.copyright = copyright pkg,
......
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