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

Safe Haskell | Ignore
Language | GHC2021

GHC.Unit.Module.ModIface

Synopsis

- type ModIface = ModIface_ 'ModIfaceFinal
- data ModIface_ (phase :: ModIfacePhase) = ModIface {
  - mi_module :: !Module
  - mi_sig_of :: !(Maybe Module)
  - mi_hsc_src :: !HscSource
  - mi_deps :: Dependencies
  - mi_usages :: [Usage]
  - mi_exports :: ![IfaceExport]
  - mi_used_th :: !Bool
  - mi_fixities :: [(OccName, Fixity)]
  - mi_warns :: IfaceWarnings
  - mi_anns :: [IfaceAnnotation]
  - mi_decls :: [IfaceDeclExts phase]
  - mi_extra_decls :: Maybe [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]
  - mi_globals :: !(Maybe IfGlobalRdrEnv)
  - mi_insts :: [IfaceClsInst]
  - mi_fam_insts :: [IfaceFamInst]
  - mi_rules :: [IfaceRule]
  - mi_hpc :: !AnyHpcUsage
  - mi_trust :: !IfaceTrustInfo
  - mi_trust_pkg :: !Bool
  - mi_complete_matches :: ![IfaceCompleteMatch]
  - mi_docs :: !(Maybe Docs)
  - mi_final_exts :: !(IfaceBackendExts phase)
  - mi_ext_fields :: !ExtensibleFields
  - mi_src_hash :: !Fingerprint
  }
- type PartialModIface = ModIface_ 'ModIfaceCore
- data ModIfaceBackend = ModIfaceBackend {
  - mi_iface_hash :: !Fingerprint
  - mi_mod_hash :: !Fingerprint
  - mi_flag_hash :: !Fingerprint
  - mi_opt_hash :: !Fingerprint
  - mi_hpc_hash :: !Fingerprint
  - mi_plugin_hash :: !Fingerprint
  - mi_orphan :: !WhetherHasOrphans
  - mi_finsts :: !WhetherHasFamInst
  - mi_exp_hash :: !Fingerprint
  - mi_orphan_hash :: !Fingerprint
  - mi_decl_warn_fn :: !(OccName -> Maybe (WarningTxt GhcRn))
  - mi_export_warn_fn :: !(Name -> Maybe (WarningTxt GhcRn))
  - mi_fix_fn :: !(OccName -> Maybe Fixity)
  - mi_hash_fn :: !(OccName -> Maybe (OccName, Fingerprint))
  }
- type family IfaceDeclExts (phase :: ModIfacePhase) = (decl :: Type) | decl -> phase where ...
- type family IfaceBackendExts (phase :: ModIfacePhase) = (bk :: Type) | bk -> phase where ...
- type IfaceExport = AvailInfo
- type WhetherHasOrphans = Bool
- type WhetherHasFamInst = Bool
- mi_boot :: ModIface -> IsBootInterface
- mi_fix :: ModIface -> OccName -> Fixity
- mi_semantic_module :: forall (a :: ModIfacePhase). ModIface_ a -> Module
- mi_free_holes :: ModIface -> UniqDSet ModuleName
- mi_mnwib :: ModIface -> ModuleNameWithIsBoot
- renameFreeHoles :: UniqDSet ModuleName -> [(ModuleName, Module)] -> UniqDSet ModuleName
- emptyPartialModIface :: Module -> PartialModIface
- emptyFullModIface :: Module -> ModIface
- mkIfaceHashCache :: [(Fingerprint, IfaceDecl)] -> OccName -> Maybe (OccName, Fingerprint)
- emptyIfaceHashCache :: OccName -> Maybe (OccName, Fingerprint)
- forceModIface :: ModIface -> IO ()

# Documentation

type ModIface = ModIface_ 'ModIfaceFinal #

data ModIface_ (phase :: ModIfacePhase) #

A `ModIface` plus a `ModDetails` summarises everything we know about a compiled module. The `ModIface` is the stuff *before* linking, and can be written out to an interface file. The 'ModDetails is after linking and can be completely recovered from just the `ModIface`.

When we read an interface file, we also construct a `ModIface` from it, except that we explicitly make the `mi_decls` and a few other fields empty; as when reading we consolidate the declarations etc. into a number of indexed maps and environments in the `ExternalPackageState`.

See Note [Strictness in ModIface] to learn about why some fields are strict and others are not.

Constructors

ModIface |

Fields

- mi_module :: !Module

  Name of the module we are for

- mi_sig_of :: !(Maybe Module)

  Are we a sig of another mod?

- mi_hsc_src :: !HscSource

  Boot? Signature?

- mi_deps :: Dependencies

  The dependencies of the module. This is consulted for directly-imported modules, but not for anything else (hence lazy)

- mi_usages :: [Usage]

  Usages; kept sorted so that it's easy to decide whether to write a new iface file (changing usages doesn't affect the hash of this module) NOT STRICT! we read this field lazily from the interface file It is *only* consulted by the recompilation checker

- mi_exports :: ![IfaceExport]

  Exports Kept sorted by (mod,occ), to make version comparisons easier Records the modules that are the declaration points for things exported by this module, and the `OccName`s of those things

- mi_used_th :: !Bool

  Module required TH splices when it was compiled. This disables recompilation avoidance (see #481).

- mi_fixities :: [(OccName, Fixity)]

  Fixities NOT STRICT! we read this field lazily from the interface file

- mi_warns :: IfaceWarnings

  Warnings NOT STRICT! we read this field lazily from the interface file

- mi_anns :: [IfaceAnnotation]

  Annotations NOT STRICT! we read this field lazily from the interface file

- mi_decls :: [IfaceDeclExts phase]

  Type, class and variable declarations The hash of an Id changes if its fixity or deprecations change (as well as its type of course) Ditto data constructors, class operations, except that the hash of the parent class/tycon changes

- mi_extra_decls :: Maybe [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]

  Extra variable definitions which are **NOT** exposed but when combined with mi_decls allows us to restart code generation. See Note [Interface Files with Core Definitions] and Note [Interface File with Core: Sharing RHSs]

- mi_globals :: !(Maybe IfGlobalRdrEnv)

  Binds all the things defined at the top level in the original source code for this module. which is NOT the same as mi_exports, nor mi_decls (which may contains declarations for things not actually defined by the user). Used for GHCi and for inspecting the contents of modules via the GHC API only.

  (We need the source file to figure out the top-level environment, if we didn't compile this module from source then this field contains `Nothing`).

  Strictly speaking this field should live in the `HomeModInfo`, but that leads to more plumbing.

- mi_insts :: [IfaceClsInst]

  Sorted class instance

- mi_fam_insts :: [IfaceFamInst]

  Sorted family instances

- mi_rules :: [IfaceRule]

  Sorted rules

- mi_hpc :: !AnyHpcUsage

  True if this program uses Hpc at any point in the program.

- mi_trust :: !IfaceTrustInfo

  Safe Haskell Trust information for this module.

- mi_trust_pkg :: !Bool

  Do we require the package this module resides in be trusted to trust this module? This is used for the situation where a module is Safe (so doesn't require the package be trusted itself) but imports some trustworthy modules from its own package (which does require its own package be trusted). See Note [Trust Own Package] in GHC.Rename.Names

- mi_complete_matches :: ![IfaceCompleteMatch]
- mi_docs :: !(Maybe Docs)

  Docstrings and related data for use by haddock, the ghci `:doc` command, and other tools.

  `Just _` `=` the module was built with `-haddock`.

- mi_final_exts :: !(IfaceBackendExts phase)

  Either `()` or `ModIfaceBackend` for a fully instantiated interface.

- mi_ext_fields :: !ExtensibleFields

  Additional optional fields, where the Map key represents the field name, resulting in a (size, serialized data) pair. Because the data is intended to be serialized through the internal `Binary` class (increasing compatibility with types using `Name` and `FastString`, such as HIE), this format is chosen over `ByteString`s.

- mi_src_hash :: !Fingerprint

  Hash of the .hs source, used for recompilation checking.

#### Instances

Instances details

Binary ModIface # |
Instance details Defined in GHC.Unit.Module.ModIface Methods put_ :: BinHandle -> ModIface -> IO () # put :: BinHandle -> ModIface -> IO (Bin ModIface) # get :: BinHandle -> IO ModIface #
(NFData (IfaceBackendExts phase), NFData (IfaceDeclExts phase)) => NFData (ModIface_ phase) # |
Instance details Defined in GHC.Unit.Module.ModIface Methods rnf :: ModIface_ phase -> () #

type PartialModIface = ModIface_ 'ModIfaceCore #

data ModIfaceBackend #

Extends a PartialModIface with information which is either: * Computed after codegen * Or computed just before writing the iface to disk. (Hashes) In order to fully instantiate it.

Constructors

ModIfaceBackend |

Fields

- mi_iface_hash :: !Fingerprint

  Hash of the whole interface

- mi_mod_hash :: !Fingerprint

  Hash of the ABI only

- mi_flag_hash :: !Fingerprint

  Hash of the important flags used when compiling the module, excluding optimisation flags

- mi_opt_hash :: !Fingerprint

  Hash of optimisation flags

- mi_hpc_hash :: !Fingerprint

  Hash of hpc flags

- mi_plugin_hash :: !Fingerprint

  Hash of plugins

- mi_orphan :: !WhetherHasOrphans

  Whether this module has orphans

- mi_finsts :: !WhetherHasFamInst

  Whether this module has family instances. See Note [The type family instance consistency story].

- mi_exp_hash :: !Fingerprint

  Hash of export list

- mi_orphan_hash :: !Fingerprint

  Hash for orphan rules, class and family instances combined

- mi_decl_warn_fn :: !(OccName -> Maybe (WarningTxt GhcRn))

  Cached lookup for `mi_warns` for declaration deprecations

- mi_export_warn_fn :: !(Name -> Maybe (WarningTxt GhcRn))

  Cached lookup for `mi_warns` for export deprecations

- mi_fix_fn :: !(OccName -> Maybe Fixity)

  Cached lookup for `mi_fixities`

- mi_hash_fn :: !(OccName -> Maybe (OccName, Fingerprint))

  Cached lookup for `mi_decls`. The `Nothing` in `mi_hash_fn` means that the thing isn't in decls. It's useful to know that when seeing if we are up to date wrt. the old interface. The `OccName` is the parent of the name, if it has one.

#### Instances

Instances details

NFData ModIfaceBackend # |
Instance details Defined in GHC.Unit.Module.ModIface Methods rnf :: ModIfaceBackend -> () #

type family IfaceDeclExts (phase :: ModIfacePhase) = (decl :: Type) | decl -> phase where ... #

Selects a IfaceDecl representation. For fully instantiated interfaces we also maintain a fingerprint, which is used for recompilation checks.

Equations

IfaceDeclExts 'ModIfaceCore = IfaceDecl |
IfaceDeclExts 'ModIfaceFinal = (Fingerprint, IfaceDecl) |

type family IfaceBackendExts (phase :: ModIfacePhase) = (bk :: Type) | bk -> phase where ... #

Equations

IfaceBackendExts 'ModIfaceCore = () |
IfaceBackendExts 'ModIfaceFinal = ModIfaceBackend |

type IfaceExport = AvailInfo #

The original names declared of a certain module that are exported

type WhetherHasOrphans = Bool #

Records whether a module has orphans. An "orphan" is one of:

- An instance declaration in a module other than the definition module for one of the type constructors or classes in the instance head
- A rewrite rule in a module other than the one defining the function in the head of the rule

type WhetherHasFamInst = Bool #

Does this module define family instances?

mi_boot :: ModIface -> IsBootInterface #

Old-style accessor for whether or not the ModIface came from an hs-boot file.

mi_fix :: ModIface -> OccName -> Fixity #

Lookups up a (possibly cached) fixity from a `ModIface`. If one cannot be found, `defaultFixity` is returned instead.

mi_semantic_module :: forall (a :: ModIfacePhase). ModIface_ a -> Module #

The semantic module for this interface; e.g., if it's a interface for a signature, if `mi_module` is `p[A=A]:A`, `mi_semantic_module` will be `A`.

mi_free_holes :: ModIface -> UniqDSet ModuleName #

The "precise" free holes, e.g., the signatures that this `ModIface` depends on.

mi_mnwib :: ModIface -> ModuleNameWithIsBoot #

renameFreeHoles :: UniqDSet ModuleName -> [(ModuleName, Module)] -> UniqDSet ModuleName #

Given a set of free holes, and a unit identifier, rename the free holes according to the instantiation of the unit identifier. For example, if we have A and B free, and our unit identity is `p[A=C,B=impl:B]`, the renamed free holes are just C.

emptyPartialModIface :: Module -> PartialModIface #

emptyFullModIface :: Module -> ModIface #

mkIfaceHashCache :: [(Fingerprint, IfaceDecl)] -> OccName -> Maybe (OccName, Fingerprint) #

Constructs cache for the `mi_hash_fn` field of a `ModIface`

emptyIfaceHashCache :: OccName -> Maybe (OccName, Fingerprint) #

forceModIface :: ModIface -> IO () #