ghc-lib-parser-9.12.2.20250421: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Unit.Module.Graph

Synopsis

- data ModuleGraph
- data ModuleGraphNode
  - = InstantiationNode UnitId InstantiatedUnit
  - | ModuleNode [NodeKey] ModSummary
  - | LinkNode [NodeKey] UnitId
- nodeDependencies :: Bool -> ModuleGraphNode -> [NodeKey]
- emptyMG :: ModuleGraph
- mkModuleGraph :: [ModuleGraphNode] -> ModuleGraph
- extendMG :: ModuleGraph -> [NodeKey] -> ModSummary -> ModuleGraph
- extendMGInst :: ModuleGraph -> UnitId -> InstantiatedUnit -> ModuleGraph
- extendMG' :: ModuleGraph -> ModuleGraphNode -> ModuleGraph
- unionMG :: ModuleGraph -> ModuleGraph -> ModuleGraph
- isTemplateHaskellOrQQNonBoot :: ModSummary -> Bool
- filterToposortToModules :: [SCC ModuleGraphNode] -> [SCC ModSummary]
- mapMG :: (ModSummary -> ModSummary) -> ModuleGraph -> ModuleGraph
- mgModSummaries :: ModuleGraph -> [ModSummary]
- mgModSummaries' :: ModuleGraph -> [ModuleGraphNode]
- mgLookupModule :: ModuleGraph -> Module -> Maybe ModSummary
- mgTransDeps :: ModuleGraph -> Map NodeKey (Set NodeKey)
- showModMsg :: DynFlags -> Bool -> ModuleGraphNode -> SDoc
- moduleGraphNodeModule :: ModuleGraphNode -> Maybe ModuleName
- moduleGraphNodeModSum :: ModuleGraphNode -> Maybe ModSummary
- moduleGraphModulesBelow :: ModuleGraph -> UnitId -> ModuleNameWithIsBoot -> Set ModNodeKeyWithUid
- moduleGraphNodes :: Bool -> [ModuleGraphNode] -> (Graph SummaryNode, NodeKey -> Maybe SummaryNode)
- type SummaryNode = Node Int ModuleGraphNode
- summaryNodeSummary :: SummaryNode -> ModuleGraphNode
- data NodeKey
  - = NodeKey_Unit !InstantiatedUnit
  - | NodeKey_Module !ModNodeKeyWithUid
  - | NodeKey_Link !UnitId
- nodeKeyUnitId :: NodeKey -> UnitId
- nodeKeyModName :: NodeKey -> Maybe ModuleName
- type ModNodeKey = ModuleNameWithIsBoot
- mkNodeKey :: ModuleGraphNode -> NodeKey
- msKey :: ModSummary -> ModNodeKeyWithUid
- moduleGraphNodeUnitId :: ModuleGraphNode -> UnitId
- data ModNodeKeyWithUid = ModNodeKeyWithUid {
  - mnkModuleName :: !ModuleNameWithIsBoot
  - mnkUnitId :: !UnitId
  }

# Documentation

data ModuleGraph Source #

A '`ModuleGraph`' contains all the nodes from the home package (only). See '`ModuleGraphNode`' for information about the nodes.

Modules need to be compiled. hs-boots need to be typechecked before the associated "real" module so modules with {-# SOURCE #-} imports can be built. Instantiations also need to be typechecked to ensure that the module fits the signature. Substantiation typechecking is roughly comparable to the check that the module and its hs-boot agree.

The graph is not necessarily stored in topologically-sorted order. Use `topSortModuleGraph` and `flattenSCC` to achieve this.

data ModuleGraphNode Source #

A '`ModuleGraphNode`' is a node in the '`ModuleGraph`'. Edges between nodes mark dependencies arising from module imports and dependencies arising from backpack instantiations.

Constructors

InstantiationNode UnitId InstantiatedUnit | Instantiation nodes track the instantiation of other units (backpack dependencies) with the holes (signatures) of the current package.
ModuleNode [NodeKey] ModSummary | There is a module summary node for each module, signature, and boot module being built.
LinkNode [NodeKey] UnitId | Link nodes are whether are are creating a linked product (ie executable/shared object etc) for a unit.

#### Instances

Instances details

Outputable ModuleGraphNode Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods ppr :: ModuleGraphNode -> SDoc Source #
Eq ModuleGraphNode Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods (==) :: ModuleGraphNode -> ModuleGraphNode -> Bool Source # (/=) :: ModuleGraphNode -> ModuleGraphNode -> Bool Source #
Ord ModuleGraphNode Source # |

Instance details

Defined in GHC.Unit.Module.Graph

Methods

compare :: ModuleGraphNode -> ModuleGraphNode -> Ordering Source #

(<) :: ModuleGraphNode -> ModuleGraphNode -> Bool Source #

(<=) :: ModuleGraphNode -> ModuleGraphNode -> Bool Source #

(>) :: ModuleGraphNode -> ModuleGraphNode -> Bool Source #

(>=) :: ModuleGraphNode -> ModuleGraphNode -> Bool Source #

max :: ModuleGraphNode -> ModuleGraphNode -> ModuleGraphNode Source #

min :: ModuleGraphNode -> ModuleGraphNode -> ModuleGraphNode Source #

nodeDependencies :: Bool -> ModuleGraphNode -> [NodeKey] Source #

Collect the immediate dependencies of a ModuleGraphNode, optionally avoiding hs-boot dependencies. If the drop_hs_boot_nodes flag is False, and if this is a .hs and there is an equivalent .hs-boot, add a link from the former to the latter. This has the effect of detecting bogus cases where the .hs-boot depends on the .hs, by introducing a cycle. Additionally, it ensures that we will always process the .hs-boot before the .hs, and so the HomePackageTable will always have the most up to date information.

emptyMG :: ModuleGraph Source #

mkModuleGraph :: [ModuleGraphNode] -> ModuleGraph Source #

extendMG :: ModuleGraph -> [NodeKey] -> ModSummary -> ModuleGraph Source #

Add an ExtendedModSummary to ModuleGraph. Assumes that the new ModSummary is not an element of the ModuleGraph.

extendMGInst :: ModuleGraph -> UnitId -> InstantiatedUnit -> ModuleGraph Source #

extendMG' :: ModuleGraph -> ModuleGraphNode -> ModuleGraph Source #

unionMG :: ModuleGraph -> ModuleGraph -> ModuleGraph Source #

isTemplateHaskellOrQQNonBoot :: ModSummary -> Bool Source #

filterToposortToModules :: [SCC ModuleGraphNode] -> [SCC ModSummary] Source #

This function filters out all the instantiation nodes from each SCC of a topological sort. Use this with care, as the resulting "strongly connected components" may not really be strongly connected in a direct way, as instantiations have been removed. It would probably be best to eliminate uses of this function where possible.

mapMG :: (ModSummary -> ModSummary) -> ModuleGraph -> ModuleGraph Source #

Map a function `f` over all the `ModSummaries`. To preserve invariants `f` can't change the isBoot status.

mgModSummaries :: ModuleGraph -> [ModSummary] Source #

mgModSummaries' :: ModuleGraph -> [ModuleGraphNode] Source #

mgLookupModule :: ModuleGraph -> Module -> Maybe ModSummary Source #

Look up a ModSummary in the ModuleGraph Looks up the non-boot ModSummary Linear in the size of the module graph

mgTransDeps :: ModuleGraph -> Map NodeKey (Set NodeKey) Source #

showModMsg :: DynFlags -> Bool -> ModuleGraphNode -> SDoc Source #

moduleGraphNodeModule :: ModuleGraphNode -> Maybe ModuleName Source #

moduleGraphNodeModSum :: ModuleGraphNode -> Maybe ModSummary Source #

moduleGraphModulesBelow :: ModuleGraph -> UnitId -> ModuleNameWithIsBoot -> Set ModNodeKeyWithUid Source #

This function returns all the modules belonging to the home-unit that can be reached by following the given dependencies. Additionally, if both the boot module and the non-boot module can be reached, it only returns the non-boot one.

moduleGraphNodes :: Bool -> [ModuleGraphNode] -> (Graph SummaryNode, NodeKey -> Maybe SummaryNode) Source #

Turn a list of graph nodes into an efficient queriable graph. The first boolean parameter indicates whether nodes corresponding to hs-boot files should be collapsed into their relevant hs nodes.

type SummaryNode = Node Int ModuleGraphNode Source #

summaryNodeSummary :: SummaryNode -> ModuleGraphNode Source #

data NodeKey Source #

Constructors

NodeKey_Unit !InstantiatedUnit |
NodeKey_Module !ModNodeKeyWithUid |
NodeKey_Link !UnitId |

#### Instances

Instances details

Outputable NodeKey Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods ppr :: NodeKey -> SDoc Source #
Eq NodeKey Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods (==) :: NodeKey -> NodeKey -> Bool Source # (/=) :: NodeKey -> NodeKey -> Bool Source #
Ord NodeKey Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods compare :: NodeKey -> NodeKey -> Ordering Source # (<) :: NodeKey -> NodeKey -> Bool Source # (<=) :: NodeKey -> NodeKey -> Bool Source # (>) :: NodeKey -> NodeKey -> Bool Source # (>=) :: NodeKey -> NodeKey -> Bool Source # max :: NodeKey -> NodeKey -> NodeKey Source # min :: NodeKey -> NodeKey -> NodeKey Source #

nodeKeyUnitId :: NodeKey -> UnitId Source #

nodeKeyModName :: NodeKey -> Maybe ModuleName Source #

type ModNodeKey = ModuleNameWithIsBoot Source #

mkNodeKey :: ModuleGraphNode -> NodeKey Source #

msKey :: ModSummary -> ModNodeKeyWithUid Source #

moduleGraphNodeUnitId :: ModuleGraphNode -> UnitId Source #

data ModNodeKeyWithUid Source #

Constructors

ModNodeKeyWithUid |

Fields

- mnkModuleName :: !ModuleNameWithIsBoot
- mnkUnitId :: !UnitId

#### Instances

Instances details

Outputable ModNodeKeyWithUid Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods ppr :: ModNodeKeyWithUid -> SDoc Source #
Eq ModNodeKeyWithUid Source # |
Instance details Defined in GHC.Unit.Module.Graph Methods (==) :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Bool Source # (/=) :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Bool Source #
Ord ModNodeKeyWithUid Source # |

Instance details

Defined in GHC.Unit.Module.Graph

Methods

compare :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Ordering Source #

(<) :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Bool Source #

(<=) :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Bool Source #

(>) :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Bool Source #

(>=) :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> Bool Source #

max :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> ModNodeKeyWithUid Source #

min :: ModNodeKeyWithUid -> ModNodeKeyWithUid -> ModNodeKeyWithUid Source #