Commit 42364776 authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Add some more Backpack utility functions to InstalledPackageInfo.

Signed-off-by: default avatarEdward Z. Yang <>
parent fd893156
......@@ -74,13 +74,9 @@ emptyModuleShape = ModuleShape Map.empty Set.empty
shapeInstalledPackage :: IPI.InstalledPackageInfo -> ModuleShape
shapeInstalledPackage ipi = ModuleShape (Map.fromList provs) reqs
insts = Map.fromList (IPI.instantiatedWith ipi)
uid =
if Set.null (indefModuleSubstFreeHoles insts)
then DefiniteUnitId (IPI.installedUnitId ipi)
else IndefFullUnitId (IPI.installedComponentId ipi) insts
uid = installedIndefUnitId ipi
provs = map shapeExposedModule (IPI.exposedModules ipi)
reqs = indefModuleSubstFreeHoles (Map.fromList (IPI.instantiatedWith ipi))
reqs = requiredSignatures ipi
shapeExposedModule (IPI.ExposedModule mod_name Nothing)
= (mod_name, IndefModule uid mod_name)
shapeExposedModule (IPI.ExposedModule mod_name (Just mod))
......@@ -31,6 +31,9 @@ module Distribution.InstalledPackageInfo (
ParseResult(..), PError(..), PWarning,
......@@ -58,6 +61,8 @@ import Distribution.Compat.Graph
import Text.PrettyPrint as Disp
import qualified Data.Char as Char
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Set (Set)
-- -----------------------------------------------------------------------------
-- The InstalledPackageInfo type
......@@ -114,6 +119,30 @@ data InstalledPackageInfo
deriving (Eq, Generic, Read, Show)
-- | Returns 'True' if this is an interface-file only indefinite
-- package which has not been instantiated.
indefinite :: InstalledPackageInfo -> Bool
indefinite ipi =
-- TODO: optimize a little
Set.null (indefModuleSubstFreeHoles (Map.fromList (instantiatedWith ipi)))
-- | Get the indefinite unit identity representing this package.
-- This IS NOT guaranteed to give you a substitution; for
-- instantiated packages you will get @DefiniteUnitId (installedUnitId ipi)@.
-- For indefinite libraries, however, you will correctly get
-- an @IndefUnitId@ with the appropriate 'IndefModuleSubst'.
installedIndefUnitId :: InstalledPackageInfo -> IndefUnitId
installedIndefUnitId ipi =
if indefinite ipi
then IndefFullUnitId (installedComponentId ipi)
(Map.fromList (instantiatedWith ipi))
else DefiniteUnitId (installedUnitId ipi)
-- | Returns the set of module names which need to be filled for
-- an indefinite package, or the empty set if the package is definite.
requiredSignatures :: InstalledPackageInfo -> Set ModuleName
requiredSignatures ipi = indefModuleSubstFreeHoles (Map.fromList (instantiatedWith ipi))
installedComponentId :: InstalledPackageInfo -> ComponentId
installedComponentId ipi = unitIdComponentId (installedUnitId ipi)
Supports Markdown
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