Moduleghc-9.14.1GHC2021
GHC.Unit.Home.Graph
A HomeUnitGraph (HUG) collects information about all the home units. Crucially, each node in a HomeUnitGraph includes a HomePackageTable.
Often, we don't want to query just a single HomePackageTable, but rather all HomePackageTables of all home units.
This module is responsible for maintaining this bridge between querying all
home units vs querying the home package table directly. Think lookupHug vs
lookupHpt, hugAllInstances vs hptAllInstances, where the hug version
replies with information from all home units, and the hpt version with
information pertaining to a single home unit.
Meant to be imported qualified as HUG.
Example usage:
import GHC.Unit.Home.Graph (HomeUnitGraph, HomeUnitEnv)
import qualified GHC.Unit.Home.Graph as HUG
usage = ... HUG.insertHug hug uid modname modinfo ...
- 3 types
- 32 values
- Packageghc-9.14.1
- Exports35
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceGraph.hs
Constructors
HomeUnitEnvhomeUnitEnv_units :: !UnitStateExternal units
homeUnitEnv_unit_dbs :: !Maybe [UnitDatabase UnitId]homeUnitEnv_dflags :: DynFlagsThe dynamic flag settings
homeUnitEnv_hpt :: HomePackageTableThe home package table describes already-compiled home-package modules, excluding the module we are compiling right now. (In one-shot mode the current module is the only home-package module, so homeUnitEnv_hpt is empty. All other modules count as "external-package" modules. However, even in GHCi mode, hi-boot interfaces are demand-loaded into the external-package table.)
homeUnitEnv_hpt is not mutable because we only demand-load external packages; the home package is eagerly loaded, module by module, by the compilation manager.
The HPT may contain modules compiled earlier by
--makebut not actually below the current module in the dependency graph.(This changes a previous invariant: changed Jan 05.)
homeUnitEnv_home_unit :: !Maybe HomeUnitHome-unit
Operations
5 declarationsAdd an entry to the HomePackageTable under the unit of that entry.
Thin each HPT variable to only contain keys from the given dependencies. This is used at the end of upsweep to make sure that only completely successfully loaded modules are visible for subsequent operations.
Rename a unit id in the HomeUnitGraph
renameUnitId oldUnit newUnit hug, if oldUnit is not found in hug, returns Nothing.
If it exists, the result maps newUnit to the HomeUnitEnv of the
oldUnit (and oldUnit is removed from hug)
Retrieve all UnitIds of units in the HomeUnitGraph.
Set the DynFlags of the HomeUnitEnv for unit in the HomeModuleGraph
Lookups
Lookup the HomeModInfo of a Module in the HomeUnitGraph given its UnitId and ModuleName (via the HomePackageTable of the corresponding unit)
Lookup the HomeModInfo of a Module in the HomeUnitGraph (via the HomePackageTable of the corresponding unit)
Lookup up the HomeUnitEnv by the Unit in the HomeUnitGraph. If the Unit can be turned into a UnitId, we behave identical to lookupHugUnitId.
A HoleUnit is never part of the HomeUnitGraph, only instantiated Units
Lookup a HomeUnitEnv by UnitId in a HomeUnitGraph
Lookup all HomeModInfo that have the same ModuleName as the given ModuleName. ModuleNames are not unique in the case of multiple home units, so there can be more than one possible HomeModInfo.
You should always prefer lookupHug and lookupHugByModule when possible.
Check whether the Unit is present in the HomeUnitGraph
A HoleUnit is never part of the HomeUnitGraph, only instantiated Units
Check whether the UnitId is present in the HomeUnitGraph
Reachability
Compute the transitive closure of a unit in the HomeUnitGraph. If the argument unit is not present in the graph returns Nothing.
Very important queries
4 declarationsFind all the instance declarations (of classes and families) from
the Home Package Table filtered by the provided predicate function.
Used in tcRnImports, to select the instances that are in the
transitive closure of imports from the currently compiled module.
Get all CompleteMatches (arising from COMPLETE pragmas) present across all home units.
Utilities
2 declarationsPrinting
Auxiliary internal structure
11 declarationsConstructors
UnitEnvGraphunitEnv_graph :: Map UnitEnvGraphKey v
Instances3Functor, Foldable, Traversable
Functor UnitEnvGraphDefined in ghc-9.14.1 · GHC.Unit.Home.GraphFoldable UnitEnvGraphDefined in ghc-9.14.1 · GHC.Unit.Home.GraphTraversable UnitEnvGraphDefined in ghc-9.14.1 · GHC.Unit.Home.Graph