diff options
author | Edward Z. Yang <ezyang@cs.stanford.edu> | 2014-11-15 00:08:53 -0800 |
---|---|---|
committer | Edward Z. Yang <ezyang@cs.stanford.edu> | 2014-11-15 00:36:03 -0800 |
commit | e14a973215102cb3774e3b4370c64edcff0e10bc (patch) | |
tree | e5c3e310619fbf642af8a0febaed515030b807a3 /libraries | |
parent | 452d6aa95b754a08e1e61800680ccbf6f968aef0 (diff) | |
download | haskell-e14a973215102cb3774e3b4370c64edcff0e10bc.tar.gz |
Generalize exposed-modules field in installed package database
Summary:
Instead of recording exposed-modules and reexported-modules as seperate
fields in the installed package database, this commit merges them into
a single field (exposed-modules). The motivation for this change is
in preparation for the inclusion of *signatures* into the installed
package database, which may also be reexported. Merging the representation
means that we can treat reexports uniformly, no matter if they're a normal
module or a signature.
This commit adds a stub for signatures, but that code isn't wired up to
anything yet.
Contains Cabal submodule update to accommodate these changes.
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate
Reviewers: simonpj, duncan, austin
Subscribers: thomie, carter, simonmar
Differential Revision: https://phabricator.haskell.org/D421
Diffstat (limited to 'libraries')
m--------- | libraries/Cabal | 0 | ||||
-rw-r--r-- | libraries/bin-package-db/GHC/PackageDb.hs | 98 |
2 files changed, 69 insertions, 29 deletions
diff --git a/libraries/Cabal b/libraries/Cabal -Subproject bb7e8f8b0170deb9c0486b10f4a9898503427d9 +Subproject 1f8a0a20c7a010b50fbafc0effde9bcd663d871 diff --git a/libraries/bin-package-db/GHC/PackageDb.hs b/libraries/bin-package-db/GHC/PackageDb.hs index 76fa697990..e1715e69e5 100644 --- a/libraries/bin-package-db/GHC/PackageDb.hs +++ b/libraries/bin-package-db/GHC/PackageDb.hs @@ -37,7 +37,8 @@ -- module GHC.PackageDb ( InstalledPackageInfo(..), - ModuleExport(..), + ExposedModule(..), + OriginalModule(..), BinaryStringRep(..), emptyInstalledPackageInfo, readPackageDbForGhc, @@ -86,26 +87,58 @@ data InstalledPackageInfo instpkgid srcpkgid srcpkgname pkgkey modulename includeDirs :: [FilePath], haddockInterfaces :: [FilePath], haddockHTMLs :: [FilePath], - exposedModules :: [modulename], + exposedModules :: [ExposedModule instpkgid modulename], hiddenModules :: [modulename], - reexportedModules :: [ModuleExport instpkgid modulename], exposed :: Bool, trusted :: Bool } deriving (Eq, Show) -class BinaryStringRep a where - fromStringRep :: BS.ByteString -> a - toStringRep :: a -> BS.ByteString +-- | An original module is a fully-qualified module name (installed package ID +-- plus module name) representing where a module was *originally* defined +-- (i.e., the 'exposedReexport' field of the original ExposedModule entry should +-- be 'Nothing'). Invariant: an OriginalModule never points to a reexport. +data OriginalModule instpkgid modulename + = OriginalModule { + originalPackageId :: instpkgid, + originalModuleName :: modulename + } + deriving (Eq, Show) -data ModuleExport instpkgid modulename - = ModuleExport { - exportModuleName :: modulename, - exportOriginalPackageId :: instpkgid, - exportOriginalModuleName :: modulename +-- | Represents a module name which is exported by a package, stored in the +-- 'exposedModules' field. A module export may be a reexport (in which +-- case 'exposedReexport' is filled in with the original source of the module), +-- and may be a signature (in which case 'exposedSignature is filled in with +-- what the signature was compiled against). Thus: +-- +-- * @ExposedModule n Nothing Nothing@ represents an exposed module @n@ which +-- was defined in this package. +-- +-- * @ExposedModule n (Just o) Nothing@ represents a reexported module @n@ +-- which was originally defined in @o@. +-- +-- * @ExposedModule n Nothing (Just s)@ represents an exposed signature @n@ +-- which was compiled against the implementation @s@. +-- +-- * @ExposedModule n (Just o) (Just s)@ represents a reexported signature +-- which was originally defined in @o@ and was compiled against the +-- implementation @s@. +-- +-- We use two 'Maybe' data types instead of an ADT with four branches or +-- four fields because this representation allows us to treat +-- reexports/signatures uniformly. +data ExposedModule instpkgid modulename + = ExposedModule { + exposedName :: modulename, + exposedReexport :: Maybe (OriginalModule instpkgid modulename), + exposedSignature :: Maybe (OriginalModule instpkgid modulename) } deriving (Eq, Show) +class BinaryStringRep a where + fromStringRep :: BS.ByteString -> a + toStringRep :: a -> BS.ByteString + emptyInstalledPackageInfo :: (BinaryStringRep a, BinaryStringRep b, BinaryStringRep c, BinaryStringRep d) => InstalledPackageInfo a b c d e @@ -132,7 +165,6 @@ emptyInstalledPackageInfo = haddockHTMLs = [], exposedModules = [], hiddenModules = [], - reexportedModules = [], exposed = False, trusted = False } @@ -288,7 +320,7 @@ instance (BinaryStringRep a, BinaryStringRep b, BinaryStringRep c, ldOptions ccOptions includes includeDirs haddockInterfaces haddockHTMLs - exposedModules hiddenModules reexportedModules + exposedModules hiddenModules exposed trusted) = do put (toStringRep installedPackageId) put (toStringRep sourcePackageId) @@ -309,9 +341,8 @@ instance (BinaryStringRep a, BinaryStringRep b, BinaryStringRep c, put includeDirs put haddockInterfaces put haddockHTMLs - put (map toStringRep exposedModules) + put exposedModules put (map toStringRep hiddenModules) - put reexportedModules put exposed put trusted @@ -337,7 +368,6 @@ instance (BinaryStringRep a, BinaryStringRep b, BinaryStringRep c, haddockHTMLs <- get exposedModules <- get hiddenModules <- get - reexportedModules <- get exposed <- get trusted <- get return (InstalledPackageInfo @@ -352,9 +382,8 @@ instance (BinaryStringRep a, BinaryStringRep b, BinaryStringRep c, ldOptions ccOptions includes includeDirs haddockInterfaces haddockHTMLs - (map fromStringRep exposedModules) + exposedModules (map fromStringRep hiddenModules) - reexportedModules exposed trusted) instance Binary Version where @@ -367,15 +396,26 @@ instance Binary Version where return (Version a b) instance (BinaryStringRep a, BinaryStringRep b) => - Binary (ModuleExport a b) where - put (ModuleExport a b c) = do - put (toStringRep a) - put (toStringRep b) - put (toStringRep c) + Binary (OriginalModule a b) where + put (OriginalModule originalPackageId originalModuleName) = do + put (toStringRep originalPackageId) + put (toStringRep originalModuleName) get = do - a <- get - b <- get - c <- get - return (ModuleExport (fromStringRep a) - (fromStringRep b) - (fromStringRep c)) + originalPackageId <- get + originalModuleName <- get + return (OriginalModule (fromStringRep originalPackageId) + (fromStringRep originalModuleName)) + +instance (BinaryStringRep a, BinaryStringRep b) => + Binary (ExposedModule a b) where + put (ExposedModule exposedName exposedReexport exposedSignature) = do + put (toStringRep exposedName) + put exposedReexport + put exposedSignature + get = do + exposedName <- get + exposedReexport <- get + exposedSignature <- get + return (ExposedModule (fromStringRep exposedName) + exposedReexport + exposedSignature) |