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

Safe Haskell | Ignore
Language | GHC2021

GHC.Unit.Module.Deps

Description

Dependencies and Usage of a module

Synopsis

- data Dependencies where
  - pattern Dependencies :: Set (IfaceImportLevel, UnitId, ModuleNameWithIsBoot) -> Set (IfaceImportLevel, UnitId) -> Set UnitId -> [ModuleName] -> Set UnitId -> Set (UnitId, ModuleNameWithIsBoot) -> [Module] -> [Module] -> Dependencies
- dep_orphs_update :: Monad m => Dependencies -> ([Module] -> m [Module]) -> m Dependencies
- dep_finsts_update :: Monad m => Dependencies -> ([Module] -> m [Module]) -> m Dependencies
- mkDependencies :: HomeUnit -> Module -> ImportAvails -> [Module] -> Dependencies
- noDependencies :: Dependencies
- pprDeps :: UnitState -> Dependencies -> SDoc
- data Usage
  - = UsagePackageModule {
    - usg_mod :: Module
    - usg_mod_hash :: Fingerprint
    - usg_safe :: IsSafeImport
    }
  - | UsageHomeModule {
    - usg_mod_name :: ModuleName
    - usg_unit_id :: UnitId
    - usg_mod_hash :: Fingerprint
    - usg_entities :: [(OccName, Fingerprint)]
    - usg_exports :: Maybe HomeModImport
    - usg_safe :: IsSafeImport
    }
  - | UsageFile {
    - usg_file_path :: FastString
    - usg_file_hash :: Fingerprint
    - usg_file_label :: Maybe String
    }
  - | UsageHomeModuleInterface {
    - usg_mod_name :: ModuleName
    - usg_unit_id :: UnitId
    - usg_iface_hash :: Fingerprint
    }
  - | UsageMergedRequirement {
    - usg_mod :: Module
    - usg_mod_hash :: Fingerprint
    }
- data HomeModImport = HomeModImport {
  - hmiu_orphanLikeHash :: Fingerprint
  - hmiu_importedAvails :: HomeModImportedAvails
  }
- data HomeModImportedAvails
  - = HMIA_Explicit {
    - hmia_imported_avails :: DetOrdAvails
    - hmia_parents_with_implicits :: NameSet
    }
  - | HMIA_Implicit {
    - hmia_exportedAvailsHash :: Fingerprint
    }
- data ImportAvails = ImportAvails {
  - imp_mods :: ImportedMods
  - imp_direct_dep_mods :: InstalledModuleEnv (Set ImportLevel, ModuleNameWithIsBoot)
  - imp_dep_direct_pkgs :: Set (ImportLevel, UnitId)
  - imp_trust_own_pkg :: Bool
  - imp_trust_pkgs :: Set UnitId
  - imp_boot_mods :: InstalledModuleEnv ModuleNameWithIsBoot
  - imp_sig_mods :: [ModuleName]
  - imp_orphs :: [Module]
  - imp_finsts :: [Module]
  }
- newtype IfaceImportLevel = IfaceImportLevel ImportLevel
- tcImportLevel :: IfaceImportLevel -> ImportLevel

# Documentation

data Dependencies where #

Dependency information about ALL modules and packages below this one in the import hierarchy. This is the serialisable version of `ImportAvails`.

Invariant: the dependencies of a module `M` never includes `M`.

Invariant: none of the lists contain duplicates.

Invariant: lists are ordered canonically (e.g. using stableModuleCmp)

See Note [Transitive Information in Dependencies]

Bundled Patterns

pattern Dependencies :: Set (IfaceImportLevel, UnitId, ModuleNameWithIsBoot) -> Set (IfaceImportLevel, UnitId) -> Set UnitId -> [ModuleName] -> Set UnitId -> Set (UnitId, ModuleNameWithIsBoot) -> [Module] -> [Module] -> Dependencies |

#### Instances

Instances details

NFData Dependencies # |
Instance details Defined in GHC.Unit.Module.Deps Methods rnf :: Dependencies -> () #
Binary Dependencies # |
Instance details Defined in GHC.Unit.Module.Deps Methods put_ :: WriteBinHandle -> Dependencies -> IO () # put :: WriteBinHandle -> Dependencies -> IO (Bin Dependencies) # get :: ReadBinHandle -> IO Dependencies #
Eq Dependencies # |
Instance details Defined in GHC.Unit.Module.Deps Methods (==) :: Dependencies -> Dependencies -> Bool # (/=) :: Dependencies -> Dependencies -> Bool #

dep_orphs_update :: Monad m => Dependencies -> ([Module] -> m [Module]) -> m Dependencies #

Update module dependencies containing orphans (used by Backpack)

dep_finsts_update :: Monad m => Dependencies -> ([Module] -> m [Module]) -> m Dependencies #

Update module dependencies containing family instances (used by Backpack)

mkDependencies :: HomeUnit -> Module -> ImportAvails -> [Module] -> Dependencies #

Extract information from the rename and typecheck phases to produce a dependencies information for the module being compiled.

The fourth argument is a list of plugin modules.

noDependencies :: Dependencies #

pprDeps :: UnitState -> Dependencies -> SDoc #

Pretty-print unit dependencies

data Usage #

Records modules for which changes may force recompilation of this module See wiki: https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/recompilation-avoidance

This differs from Dependencies. A module X may be in the dep_mods of this module (via an import chain) but if we don't use anything from X it won't appear in our Usage

Constructors

UsagePackageModule | Module from another package

Fields

- usg_mod :: Module

  External package module depended on

- usg_mod_hash :: Fingerprint

  Cached module ABI fingerprint (corresponds to mi_mod_hash)

- usg_safe :: IsSafeImport

  Was this module imported as a safe import

UsageHomeModule | Module from the current package

Fields

- usg_mod_name :: ModuleName

  Name of the module

- usg_unit_id :: UnitId

  UnitId of the HomeUnit the module is from

- usg_mod_hash :: Fingerprint

  Cached module ABI fingerprint (corresponds to mi_mod_hash)

- usg_entities :: [(OccName, Fingerprint)]

  Entities we depend on, sorted by occurrence name and fingerprinted. NB: usages are for parent names only, e.g. type constructors but not the associated data constructors.

- usg_exports :: Maybe HomeModImport

  What we depend on from the exports of the module; see `HomeModImport`.

- usg_safe :: IsSafeImport

  Was this module imported as a safe import

UsageFile | A file upon which the module depends, e.g. a CPP #include, or using TH's `addDependentFile`

Fields

- usg_file_path :: FastString

  External file dependency. From a CPP #include or TH addDependentFile. Should be absolute.

- usg_file_hash :: Fingerprint

  `Fingerprint` of the file contents.

- usg_file_label :: Maybe String

  An optional string which is used in recompilation messages if file in question has changed.

UsageHomeModuleInterface |

Fields

- usg_mod_name :: ModuleName

  Name of the module

- usg_unit_id :: UnitId

  UnitId of the HomeUnit the module is from

- usg_iface_hash :: Fingerprint

  The *interface* hash of the module, not the ABI hash. This changes when anything about the interface (and hence the module) has changed.

UsageMergedRequirement | A requirement which was merged into this one.

Fields

- usg_mod :: Module

  External package module depended on

- usg_mod_hash :: Fingerprint

  Cached module ABI fingerprint (corresponds to mi_mod_hash)

#### Instances

Instances details

NFData Usage # |
Instance details Defined in GHC.Unit.Module.Deps Methods rnf :: Usage -> () #
Binary Usage # |
Instance details Defined in GHC.Unit.Module.Deps Methods put_ :: WriteBinHandle -> Usage -> IO () # put :: WriteBinHandle -> Usage -> IO (Bin Usage) # get :: ReadBinHandle -> IO Usage #
Eq Usage # |
Instance details Defined in GHC.Unit.Module.Deps Methods (==) :: Usage -> Usage -> Bool # (/=) :: Usage -> Usage -> Bool #

data HomeModImport #

Records the imports that we depend on from a home module, for recompilation checking.

See Note [When to recompile when export lists change?] in GHC.Iface.Recomp.

Constructors

HomeModImport |

Fields

- hmiu_orphanLikeHash :: Fingerprint

  Hash of orphans, dependencies, orphans of dependencies etc...

  See Note [Orphan-like hash].

  If this changes, we definitely need to recompile.

- hmiu_importedAvails :: HomeModImportedAvails

  The avails we are importing; see `HomeModImportedAvails`.

#### Instances

Instances details

NFData HomeModImport # |
Instance details Defined in GHC.Unit.Module.Deps Methods rnf :: HomeModImport -> () #
Binary HomeModImport # |
Instance details Defined in GHC.Unit.Module.Deps Methods put_ :: WriteBinHandle -> HomeModImport -> IO () # put :: WriteBinHandle -> HomeModImport -> IO (Bin HomeModImport) # get :: ReadBinHandle -> IO HomeModImport #
Outputable HomeModImport # |
Instance details Defined in GHC.Unit.Module.Deps Methods ppr :: HomeModImport -> SDoc #
Eq HomeModImport # |
Instance details Defined in GHC.Unit.Module.Deps Methods (==) :: HomeModImport -> HomeModImport -> Bool # (/=) :: HomeModImport -> HomeModImport -> Bool #

data HomeModImportedAvails #

Records all the `Avail`s we are importing from a home module.

Constructors

HMIA_Explicit | All import lists are explicit import lists, but some identifiers may still be implicitly imported, e.g. `import M(a, b, T(..))`. In this case, recompilation is keyed by the names we are importing, with their `Avail` structure.

Fields

- hmia_imported_avails :: DetOrdAvails

  The avails we are importing

- hmia_parents_with_implicits :: NameSet

  The `Name`s of all `AvailTC` imports which implicitly import children

HMIA_Implicit | One import is a whole module import, or a `import module M hiding(..)` import. In this case, recompilation is keyed on the hash of the exported avails of the module we are importing.

Fields

- hmia_exportedAvailsHash :: Fingerprint

  The export avails hash of the module we are importing

#### Instances

Instances details

NFData HomeModImportedAvails # |
Instance details Defined in GHC.Unit.Module.Deps Methods rnf :: HomeModImportedAvails -> () #
Binary HomeModImportedAvails # |
Instance details Defined in GHC.Unit.Module.Deps Methods put_ :: WriteBinHandle -> HomeModImportedAvails -> IO () # put :: WriteBinHandle -> HomeModImportedAvails -> IO (Bin HomeModImportedAvails) # get :: ReadBinHandle -> IO HomeModImportedAvails #
Outputable HomeModImportedAvails # |
Instance details Defined in GHC.Unit.Module.Deps Methods ppr :: HomeModImportedAvails -> SDoc #
Eq HomeModImportedAvails # |
Instance details Defined in GHC.Unit.Module.Deps Methods (==) :: HomeModImportedAvails -> HomeModImportedAvails -> Bool # (/=) :: HomeModImportedAvails -> HomeModImportedAvails -> Bool #

data ImportAvails #

`ImportAvails` summarises what was imported from where, irrespective of whether the imported things are actually used or not. It is used:

- when processing the export list,
- when constructing usage info for the interface file,
- to identify the list of directly imported modules for initialisation purposes and for optimised overlap checking of family instances,
- when figuring out what things are really unused

Constructors

ImportAvails |

Fields

- imp_mods :: ImportedMods

  Domain is all directly-imported modules

  See the documentation on ImportedModsVal in GHC.Unit.Module.Imported for the meaning of the fields.

  We need a full ModuleEnv rather than a ModuleNameEnv here, because we might be importing modules of the same name from different packages. (currently not the case, but might be in the future).

- imp_direct_dep_mods :: InstalledModuleEnv (Set ImportLevel, ModuleNameWithIsBoot)

  Home-package modules directly imported by the module being compiled.

- imp_dep_direct_pkgs :: Set (ImportLevel, UnitId)

  Packages directly needed by the module being compiled

- imp_trust_own_pkg :: Bool

  Do we require that our own package is trusted? This is to handle efficiently the case where a Safe module imports a Trustworthy module that resides in the same package as it. See Note [Trust Own Package] in GHC.Rename.Names

- imp_trust_pkgs :: Set UnitId

  This records the packages the current module needs to trust for Safe Haskell compilation to succeed. A package is required to be trusted if we are dependent on a trustworthy module in that package. See Note [Tracking Trust Transitively] in GHC.Rename.Names

- imp_boot_mods :: InstalledModuleEnv ModuleNameWithIsBoot

  Domain is all modules which have hs-boot files, and whether we should import the boot version of interface file. Only used in one-shot mode to populate eps_is_boot.

- imp_sig_mods :: [ModuleName]

  Signature modules below this one

- imp_orphs :: [Module]

  Orphan modules below us in the import tree (and maybe including us for imported modules)

- imp_finsts :: [Module]

  Family instance modules below us in the import tree (and maybe including us for imported modules)

newtype IfaceImportLevel #

Constructors

IfaceImportLevel ImportLevel |

#### Instances

Instances details

NFData IfaceImportLevel # |
Instance details Defined in GHC.Unit.Module.Deps Methods rnf :: IfaceImportLevel -> () #
Binary IfaceImportLevel # |
Instance details Defined in GHC.Unit.Module.Deps Methods put_ :: WriteBinHandle -> IfaceImportLevel -> IO () # put :: WriteBinHandle -> IfaceImportLevel -> IO (Bin IfaceImportLevel) # get :: ReadBinHandle -> IO IfaceImportLevel #
Outputable IfaceImportLevel # |
Instance details Defined in GHC.Unit.Module.Deps Methods ppr :: IfaceImportLevel -> SDoc #
Eq IfaceImportLevel # |
Instance details Defined in GHC.Unit.Module.Deps Methods (==) :: IfaceImportLevel -> IfaceImportLevel -> Bool # (/=) :: IfaceImportLevel -> IfaceImportLevel -> Bool #
Ord IfaceImportLevel # |

Instance details

Defined in GHC.Unit.Module.Deps

Methods

compare :: IfaceImportLevel -> IfaceImportLevel -> Ordering #

(<) :: IfaceImportLevel -> IfaceImportLevel -> Bool #

(<=) :: IfaceImportLevel -> IfaceImportLevel -> Bool #

(>) :: IfaceImportLevel -> IfaceImportLevel -> Bool #

(>=) :: IfaceImportLevel -> IfaceImportLevel -> Bool #

max :: IfaceImportLevel -> IfaceImportLevel -> IfaceImportLevel #

min :: IfaceImportLevel -> IfaceImportLevel -> IfaceImportLevel #

tcImportLevel :: IfaceImportLevel -> ImportLevel #