ghc-10.0.0.20260917: The GHC API
Safe HaskellNone
LanguageGHC2024

GHC.Unit.External.Database

Synopsis

ExternalUnitDatabases

data ExternalUnitDatabases unit Source #

Caches unit databases in-memory.

UnitDatabase and how to merge them.

data UnitDatabase unit Source #

Unit database entry.

Instances

Instances details
Outputable u => Outputable (UnitDatabase u) Source # 
Instance details

Defined in GHC.Unit.External.Database

Methods

ppr :: UnitDatabase u -> SDoc Source #

mergeDatabases :: Logger -> [UnitDatabase UnitId] -> IO (UnitInfoMap, UnitPrecedenceMap) Source #

Given a list of databases, merge them together, where units with the same unit id in later databases override earlier ones. This does NOT check if the resulting database makes sense (that's done by validateDatabase).

type UnitPrecedenceMap = UniqMap UnitId Int Source #

For each unit, a mapping from uid -> i indicates that this unit was brought into GHC by the ith -package-db flag on the command line. We use this mapping to make sure we prefer units that were defined later on the command line, if there is an ambiguity.

sortByPreference :: UnitPrecedenceMap -> [UnitInfo] -> [UnitInfo] Source #

This sorts a list of packages, putting "preferred" packages first. See compareByPreference for the semantics of "preference".

compareByPreference :: UnitPrecedenceMap -> UnitInfo -> UnitInfo -> Ordering Source #

Returns GT if pkg should be preferred over pkg' when picking which should be "active". Here is the order of preference:

  1. First, prefer the latest version
  2. If the versions are the same, prefer the package that came in the latest package database.

Pursuant to #12518, we could change this policy to, for example, remove the version preference, meaning that we would always prefer the units in later unit database.

Reading packages from disk.

readUnitDatabase :: Logger -> UnitDbConfig -> OsPath -> IO (UnitDatabase UnitId) Source #

Read the UnitDatabase at the given location.

resolveUnitDatabase :: UnitDbConfig -> PkgDbRef -> IO (Maybe OsPath) Source #

Return the path of a package database from a PkgDbRef. Return Nothing when the user database filepath is expected but the latter doesn't exist.

NB: This logic is reimplemented in Cabal, so if you change it, make sure you update Cabal. (Or, better yet, dump it in the compiler info so Cabal can use the info.)