HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Moduleghc-lib-parser-9.14.1.20251220GHC2021

GHC.Unit.Env

A UnitEnv provides the complete interface into everything that is loaded into a GHC session, including the HomeUnitGraph for mapping home units to their HomePackageTables (which store information about all home modules), and the ExternalPackageState which provides access to all external packages loaded.

This module is meant to be imported as UnitEnv when calling insertHpt:

import GHC.Unit.Env (UnitEnv, HomeUnitGraph, HomeUnitEnv)
import GHC.Unit.Env as UnitEnv

Here is an overview of how the UnitEnv, ModuleGraph, HUG, HPT, and EPS interact:

┌────────────────┐┌────────────────────┐┌───────────┐
│HomePackageTable││ExternalPackageState││ModuleGraph│
└┬───────────────┘└┬───────────────────┘└┬──────────┘
┌▽────────────┐    │                     │
│HomeUnitGraph│    │                     │
└┬────────────┘    │                     │
┌▽─────────────────▽─────────────────────▽┐
│UnitEnv                                  │
└┬─────────────-──────────────────────────┘
 │
 │
┌▽──────────────────────────────────────▽┐
│HscEnv                                  │
└────────────────────────────────────────┘

The UnitEnv references the HomeUnitGraph (with all the home unit modules), the ExternalPackageState (information about all non-home/external units), and the ModuleGraph (which describes the relationship between the modules being compiled). The HscEnv references this UnitEnv. The HomeUnitGraph has one HomePackageTable for every unit.

Contents
  1. Unit Env helper functions
  2. HUG Re-export
  3. Invariants
  4. Preload units info
  5. Home Module functions
  6. Operations on the UnitEnv
  7. Modifying the current active home unit
  8. Queries
  9. Queries on the current active home unit
  10. Reachability
  11. Instances, rules, type fams, annotations, etc..
  12. Legacy API
Synopsis
datadata UnitEnv
#

Constructors

Unit Env helper functions

HUG Re-export

datadata HomeUnitEnv
#

Constructors

  • HomeUnitEnv
    • homeUnitEnv_units :: !UnitState

      External units

    • homeUnitEnv_unit_dbs :: !Maybe [UnitDatabase UnitId]

      Stack of unit databases for the target platform.

      This field is populated with the result of initUnits.

      Nothing means the databases have never been read from disk.

      Usually we don't reload the databases from disk if they are cached, even if the database flags changed!

    • homeUnitEnv_dflags :: DynFlags

      The dynamic flag settings

    • homeUnitEnv_hpt :: HomePackageTable

      The 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 --make but not actually below the current module in the dependency graph.

      (This changes a previous invariant: changed Jan 05.)

    • homeUnitEnv_home_unit :: !Maybe HomeUnit

      Home-unit

Invariants

Preload units info

Home Module functions

Operations on the UnitEnv

Modifying the current active home unit

Queries

Queries on the current active home unit

Reachability

Instances, rules, type fams, annotations, etc..

The hug prefix means the function returns only things found in home units.

Legacy API

This API is deprecated!