HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleCabal-3.12.1.0Haskell2010

Distribution.Simple.PackageIndex

An index of packages whose primary key is UnitId. Public libraries are additionally indexed by PackageName and Version. Technically, these are an index of *units* (so we should eventually rename it to UnitIndex); but in the absence of internal libraries or Backpack each unit is equivalent to a package.

While PackageIndex is parametric over what it actually records, it is in fact only ever instantiated with a single element: The InstalledPackageIndex (defined here) contains a graph of InstalledPackageInfos representing the packages in a package database stack. It is used in a variety of ways:

  • The primary use to let Cabal access the same installed package database which is used by GHC during compilation. For example, this data structure is used by 'ghc-pkg' and Cabal to do consistency checks on the database (are the references closed).

  • Given a set of dependencies, we can compute the transitive closure of dependencies. This is to check if the versions of packages are consistent, and also needed by multiple tools (Haddock must be explicitly told about the every transitive package to do cross-package linking; preprocessors must know about the include paths of all transitive dependencies.)

This PackageIndex is NOT to be confused with PackageIndex, which indexes packages only by PackageName (this makes it suitable for indexing source packages, for which we don't know UnitIds.)

  • 3 types
  • 29 values
  • PackageCabal-3.12.1.0
  • Exports32
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePackageIndex.hs

Package index data type

2 declarations
datadata PackageIndex a
#

The collection of information about packages from one or more PackageDBs. These packages generally should have an instance of PackageInstalled

Packages are uniquely identified in by their UnitId, they can also be efficiently looked up by package name or by name and version.

Instances9Eq, Read, Show, Generic, Semigroup, Monoid, …

Creating an index

1 declaration

Updates

5 declarations

Merge two indexes.

Packages from the second mask packages from the first if they have the exact same UnitId.

For packages with the same source PackageId, packages from the second are "preferred" over those from the first. Being preferred means they are top result when we do a lookup by source PackageId. This is the mechanism we use to prefer user packages over global packages.

Queries

0 declarations

Precise lookups

Case-insensitive searches

Does a case-insensitive search by package name.

If there is only one package that compares case-insensitively to this name then the search is unambiguous and we get back all versions of that package. If several match case-insensitively but one matches exactly then it is also unambiguous.

If however several match case-insensitively and none match exactly then we have an ambiguous result, and we get back all the versions of all the packages. The list of ambiguous results is split by exact package name. So it is a non-empty list of non-empty lists.

Bulk queries

Special queries

Given a package index where we assume we want to use all the packages (use dependencyClosure if you need to get such a index subset) find out if the dependencies within it use consistent versions of each package. Return all cases where multiple packages depend on different versions of some other package.

Each element in the result is a package name along with the packages that depend on it and the versions they require. These are guaranteed to be distinct.

valuedependencyCycles :: PackageInstalled a => PackageIndex a -> [[a]]
#

Find if there are any cycles in the dependency graph. If there are no cycles the result is [].

This actually computes the strongly connected components. So it gives us a list of groups of packages where within each group they all depend on each other, directly or indirectly.