HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Unit.Types

Unit & Module types

This module is used to resolve the loops between Unit and Module types (Module references a Unit and vice-versa).

  • 19 types
  • 1 class
  • 43 values
  • Packageghc-9.10.3
  • Exports64
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceTypes.hs

Modules

10 declarations
datadata GenModule unit
#

A generic module is a pair of a unit identifier and a ModuleName.

Constructors

Instances10Functor, Outputable, Uniquable, Eq, Data, Ord, …

Calculate the free holes of a Module. If this set is non-empty, this module was defined in an indefinite library that had required signatures.

If a module has free holes, that means that substitutions can operate on it; if it has no free holes, substituting over a module has no effect.

Units

26 declarations
classclass IsUnitId u where
#

Class for types that are used as unit identifiers (UnitKey, UnitId, Unit)

We need this class because we create new unit ids for virtual units (see VirtUnit) and they have to to be made from units with different kinds of identifiers.

Instances4IsUnitId
datadata GenUnit uid
#

A unit identifier identifies a (possibly partially) instantiated library. It is primarily used as part of Module, which in turn is used in Name, which is used to give names to entities when typechecking.

There are two possible forms for a Unit:

1) It can be a RealUnit, in which case we just have a DefUnitId that uniquely identifies some fully compiled, installed library we have on disk.

2) It can be an VirtUnit. When we are typechecking a library with missing holes, we may need to instantiate a library on the fly (in which case we don't have any on-disk representation.) In that case, you have an InstantiatedUnit, which explicitly records the instantiation, so that we can substitute over it.

Constructors

  • RealUnit !(Definite uid)

    Installed definite unit (either a fully instantiated unit or a closed unit)

  • VirtUnit !(GenInstantiatedUnit uid)

    Virtual unit instantiated on-the-fly. It may be definite if all the holes are instantiated but we don't have code objects for it.

  • HoleUnit

    Fake hole unit

Instances11Data, Ord, Show, NFData, Outputable, Binary, …
newtypenewtype UnitId
#

A UnitId identifies a built library in a database and is used to generate unique symbols, etc. It's usually of the form:

pkgname-1.2:libname+hash

These UnitId are provided to us via the -this-unit-id flag.

The library in question may be definite or indefinite; if it is indefinite, none of the holes have been filled (we never install partially instantiated libraries as we can cheaply instantiate them on-the-fly, cf VirtUnit). Put another way, an installed unit id is either fully instantiated, or not instantiated at all.

Constructors

Instances19Eq, Data, Ord, Show, NFData, Outputable, …
datadata GenInstantiatedUnit unit
#

An instantiated unit.

It identifies an indefinite library (with holes) that has been instantiated.

This unit may be indefinite or not (i.e. with remaining holes or not). If it is definite, we don't know if it has already been compiled and installed in a database. Nevertheless, we have a mechanism called "improvement" to try to match a fully instantiated unit with existing compiled and installed units: see Note [VirtUnit to RealUnit improvement].

An indefinite unit identifier pretty-prints to something like p[H=H,A=aimpl:A>] (p is the UnitId, and the brackets enclose the module substitution).

Constructors

Instances5Outputable, Binary, Eq, Ord

Generate a uniquely identifying hash (internal unit-id) for an instantiated unit.

This is a one-way function. If the indefinite unit has not been instantiated at all, we return its unit-id.

This hash is completely internal to GHC and is not used for symbol names or file paths. It is different from the hash Cabal would produce for the same instantiated unit.

valuefsToUnit :: FastString -> Unit
#

Create a new simple unit identifier from a FastString. Internally, this is primarily used to specify wired-in unit identifiers.

valuetoUnitId :: Unit -> UnitId
#

Return the UnitId of the Unit. For on-the-fly instantiated units, return the UnitId of the indefinite unit this unit is an instance of.

Unit Ids

2 declarations

Utils

1 declaration
newtypenewtype Definite unit
#

A definite unit (i.e. without any free module hole)

Constructors

Instances7Functor, Eq, Ord, Outputable, Uniquable, Binary, …

Wired-in units

21 declarations
valuemainUnitId :: UnitId
#

This is the package Id for the current program. It is the default package Id if you don't specify a package name. We don't add this prefix to symbol names, since there can be only one main package per program.

Boot modules

4 declarations
datadata IsBootInterface
#

Indicates whether a module name is referring to a boot interface (hs-boot file) or regular module (hs file). We need to treat boot modules specially when building compilation graphs, since they break cycles. Regular source files and signature files are treated equivalently.

Instances5Eq, Data, Ord, Show, Binary
datadata GenWithIsBoot mod
#

This data type just pairs a value mod with an IsBootInterface flag. In practice, mod is usually a Module or ModuleName'.

Instances8Functor, Foldable, Traversable, Eq, Ord, Show, …

Orphan instances

1 instance