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

Safe Haskell | Ignore
Language | GHC2021

GHC.Unit.Env

Contents

- Unit Env helper functions
- HomeUnitEnv
- UnitEnvGraph
- Invariants
- Preload units info
- Home Module functions

Synopsis

- data UnitEnv = UnitEnv {
  - ue_eps :: !ExternalUnitCache
  - ue_current_unit :: UnitId
  - ue_home_unit_graph :: !HomeUnitGraph
  - ue_platform :: !Platform
  - ue_namever :: !GhcNameVersion
  }
- initUnitEnv :: UnitId -> HomeUnitGraph -> GhcNameVersion -> Platform -> IO UnitEnv
- ueEPS :: UnitEnv -> IO ExternalPackageState
- unsafeGetHomeUnit :: UnitEnv -> HomeUnit
- updateHug :: (HomeUnitGraph -> HomeUnitGraph) -> UnitEnv -> UnitEnv
- updateHpt_lazy :: (HomePackageTable -> HomePackageTable) -> UnitEnv -> UnitEnv
- updateHpt :: (HomePackageTable -> HomePackageTable) -> UnitEnv -> UnitEnv
- ue_units :: HasDebugCallStack => UnitEnv -> UnitState
- ue_currentHomeUnitEnv :: HasDebugCallStack => UnitEnv -> HomeUnitEnv
- ue_setUnits :: UnitState -> UnitEnv -> UnitEnv
- ue_setUnitFlags :: HasDebugCallStack => UnitId -> DynFlags -> UnitEnv -> UnitEnv
- ue_unit_dbs :: UnitEnv -> Maybe [UnitDatabase UnitId]
- ue_all_home_unit_ids :: UnitEnv -> Set UnitId
- ue_setUnitDbs :: Maybe [UnitDatabase UnitId] -> UnitEnv -> UnitEnv
- ue_hpt :: HasDebugCallStack => UnitEnv -> HomePackageTable
- ue_homeUnit :: UnitEnv -> Maybe HomeUnit
- ue_unsafeHomeUnit :: UnitEnv -> HomeUnit
- ue_setFlags :: HasDebugCallStack => DynFlags -> UnitEnv -> UnitEnv
- ue_setActiveUnit :: UnitId -> UnitEnv -> UnitEnv
- ue_currentUnit :: UnitEnv -> UnitId
- ue_findHomeUnitEnv :: HasDebugCallStack => UnitId -> UnitEnv -> HomeUnitEnv
- ue_updateHomeUnitEnv :: (HomeUnitEnv -> HomeUnitEnv) -> UnitId -> UnitEnv -> UnitEnv
- ue_unitHomeUnit :: UnitId -> UnitEnv -> HomeUnit
- ue_unitFlags :: HasDebugCallStack => UnitId -> UnitEnv -> DynFlags
- ue_renameUnitId :: HasDebugCallStack => UnitId -> UnitId -> UnitEnv -> UnitEnv
- ue_transitiveHomeDeps :: UnitId -> UnitEnv -> [UnitId]
- type HomeUnitGraph = UnitEnvGraph HomeUnitEnv
- data HomeUnitEnv = HomeUnitEnv {
  - homeUnitEnv_units :: !UnitState
  - homeUnitEnv_unit_dbs :: !(Maybe [UnitDatabase UnitId])
  - homeUnitEnv_dflags :: DynFlags
  - homeUnitEnv_hpt :: HomePackageTable
  - homeUnitEnv_home_unit :: !(Maybe HomeUnit)
  }
- mkHomeUnitEnv :: DynFlags -> HomePackageTable -> Maybe HomeUnit -> HomeUnitEnv
- lookupHugByModule :: Module -> HomeUnitGraph -> Maybe HomeModInfo
- hugElts :: HomeUnitGraph -> [(UnitId, HomeUnitEnv)]
- lookupHug :: HomeUnitGraph -> UnitId -> ModuleName -> Maybe HomeModInfo
- addHomeModInfoToHug :: HomeModInfo -> HomeUnitGraph -> HomeUnitGraph
- newtype UnitEnvGraph v = UnitEnvGraph {
  - unitEnv_graph :: Map UnitEnvGraphKey v
  }
- type UnitEnvGraphKey = UnitId
- unitEnv_insert :: UnitEnvGraphKey -> v -> UnitEnvGraph v -> UnitEnvGraph v
- unitEnv_delete :: UnitEnvGraphKey -> UnitEnvGraph v -> UnitEnvGraph v
- unitEnv_adjust :: (v -> v) -> UnitEnvGraphKey -> UnitEnvGraph v -> UnitEnvGraph v
- unitEnv_new :: Map UnitEnvGraphKey v -> UnitEnvGraph v
- unitEnv_singleton :: UnitEnvGraphKey -> v -> UnitEnvGraph v
- unitEnv_map :: (v -> v) -> UnitEnvGraph v -> UnitEnvGraph v
- unitEnv_member :: UnitEnvGraphKey -> UnitEnvGraph v -> Bool
- unitEnv_lookup_maybe :: UnitEnvGraphKey -> UnitEnvGraph v -> Maybe v
- unitEnv_lookup :: UnitEnvGraphKey -> UnitEnvGraph v -> v
- unitEnv_keys :: UnitEnvGraph v -> Set UnitEnvGraphKey
- unitEnv_elts :: UnitEnvGraph v -> [(UnitEnvGraphKey, v)]
- unitEnv_hpts :: UnitEnvGraph HomeUnitEnv -> [HomePackageTable]
- unitEnv_foldWithKey :: (b -> UnitEnvGraphKey -> a -> b) -> b -> UnitEnvGraph a -> b
- unitEnv_union :: (a -> a -> a) -> UnitEnvGraph a -> UnitEnvGraph a -> UnitEnvGraph a
- unitEnv_mapWithKey :: (UnitEnvGraphKey -> v -> b) -> UnitEnvGraph v -> UnitEnvGraph b
- assertUnitEnvInvariant :: HasDebugCallStack => UnitEnv -> UnitEnv
- preloadUnitsInfo :: UnitEnv -> MaybeErr UnitErr [UnitInfo]
- preloadUnitsInfo' :: UnitEnv -> [UnitId] -> MaybeErr UnitErr [UnitInfo]
- isUnitEnvInstalledModule :: UnitEnv -> InstalledModule -> Bool

# Documentation

data UnitEnv Source #

Constructors

UnitEnv |

Fields

- ue_eps :: !ExternalUnitCache

  Information about the currently loaded external packages. This is mutable because packages will be demand-loaded during a compilation run as required.

- ue_current_unit :: UnitId
- ue_home_unit_graph :: !HomeUnitGraph
- ue_platform :: !Platform

  Platform

- ue_namever :: !GhcNameVersion

  GHC name/version (used for dynamic library suffix)

initUnitEnv :: UnitId -> HomeUnitGraph -> GhcNameVersion -> Platform -> IO UnitEnv Source #

ueEPS :: UnitEnv -> IO ExternalPackageState Source #

unsafeGetHomeUnit :: UnitEnv -> HomeUnit Source #

Get home-unit

Unsafe because the home-unit may not be set

updateHug :: (HomeUnitGraph -> HomeUnitGraph) -> UnitEnv -> UnitEnv Source #

updateHpt_lazy :: (HomePackageTable -> HomePackageTable) -> UnitEnv -> UnitEnv Source #

updateHpt :: (HomePackageTable -> HomePackageTable) -> UnitEnv -> UnitEnv Source #

# Unit Env helper functions

ue_units :: HasDebugCallStack => UnitEnv -> UnitState Source #

ue_currentHomeUnitEnv :: HasDebugCallStack => UnitEnv -> HomeUnitEnv Source #

ue_setUnits :: UnitState -> UnitEnv -> UnitEnv Source #

ue_setUnitFlags :: HasDebugCallStack => UnitId -> DynFlags -> UnitEnv -> UnitEnv Source #

ue_unit_dbs :: UnitEnv -> Maybe [UnitDatabase UnitId] Source #

ue_all_home_unit_ids :: UnitEnv -> Set UnitId Source #

ue_setUnitDbs :: Maybe [UnitDatabase UnitId] -> UnitEnv -> UnitEnv Source #

ue_hpt :: HasDebugCallStack => UnitEnv -> HomePackageTable Source #

ue_homeUnit :: UnitEnv -> Maybe HomeUnit Source #

ue_unsafeHomeUnit :: UnitEnv -> HomeUnit Source #

ue_setFlags :: HasDebugCallStack => DynFlags -> UnitEnv -> UnitEnv Source #

ue_setActiveUnit :: UnitId -> UnitEnv -> UnitEnv Source #

ue_currentUnit :: UnitEnv -> UnitId Source #

ue_findHomeUnitEnv :: HasDebugCallStack => UnitId -> UnitEnv -> HomeUnitEnv Source #

ue_updateHomeUnitEnv :: (HomeUnitEnv -> HomeUnitEnv) -> UnitId -> UnitEnv -> UnitEnv Source #

ue_unitHomeUnit :: UnitId -> UnitEnv -> HomeUnit Source #

ue_unitFlags :: HasDebugCallStack => UnitId -> UnitEnv -> DynFlags Source #

ue_renameUnitId :: HasDebugCallStack => UnitId -> UnitId -> UnitEnv -> UnitEnv Source #

Rename a unit id in the internal unit env.

``ue_renameUnitId` oldUnit newUnit UnitEnv`, it is assumed that the `oldUnit` exists in the map, otherwise we panic. The `DynFlags` associated with the home unit will have its field `homeUnitId` set to `newUnit`.

ue_transitiveHomeDeps :: UnitId -> UnitEnv -> [UnitId] Source #

# HomeUnitEnv

type HomeUnitGraph = UnitEnvGraph HomeUnitEnv Source #

data HomeUnitEnv Source #

Constructors

HomeUnitEnv |

Fields

- 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

#### Instances

Instances details

Outputable HomeUnitEnv Source # |
Instance details Defined in GHC.Unit.Env Methods ppr :: HomeUnitEnv -> SDoc Source #
Outputable (UnitEnvGraph HomeUnitEnv) Source # |
Instance details Defined in GHC.Unit.Env Methods ppr :: UnitEnvGraph HomeUnitEnv -> SDoc Source #

mkHomeUnitEnv :: DynFlags -> HomePackageTable -> Maybe HomeUnit -> HomeUnitEnv Source #

lookupHugByModule :: Module -> HomeUnitGraph -> Maybe HomeModInfo Source #

hugElts :: HomeUnitGraph -> [(UnitId, HomeUnitEnv)] Source #

lookupHug :: HomeUnitGraph -> UnitId -> ModuleName -> Maybe HomeModInfo Source #

addHomeModInfoToHug :: HomeModInfo -> HomeUnitGraph -> HomeUnitGraph Source #

# UnitEnvGraph

newtype UnitEnvGraph v Source #

Constructors

UnitEnvGraph |

Fields

- unitEnv_graph :: Map UnitEnvGraphKey v

#### Instances

Instances details

Functor UnitEnvGraph Source # |
Instance details Defined in GHC.Unit.Env Methods fmap :: (a -> b) -> UnitEnvGraph a -> UnitEnvGraph b Source # (<$) :: a -> UnitEnvGraph b -> UnitEnvGraph a Source #
Foldable UnitEnvGraph Source # |

Instance details

Defined in GHC.Unit.Env

Methods

fold :: Monoid m => UnitEnvGraph m -> m Source #

foldMap :: Monoid m => (a -> m) -> UnitEnvGraph a -> m Source #

foldMap' :: Monoid m => (a -> m) -> UnitEnvGraph a -> m Source #

foldr :: (a -> b -> b) -> b -> UnitEnvGraph a -> b Source #

foldr' :: (a -> b -> b) -> b -> UnitEnvGraph a -> b Source #

foldl :: (b -> a -> b) -> b -> UnitEnvGraph a -> b Source #

foldl' :: (b -> a -> b) -> b -> UnitEnvGraph a -> b Source #

foldr1 :: (a -> a -> a) -> UnitEnvGraph a -> a Source #

foldl1 :: (a -> a -> a) -> UnitEnvGraph a -> a Source #

toList :: UnitEnvGraph a -> [a] Source #

null :: UnitEnvGraph a -> Bool Source #

length :: UnitEnvGraph a -> Int Source #

elem :: Eq a => a -> UnitEnvGraph a -> Bool Source #

maximum :: Ord a => UnitEnvGraph a -> a Source #

minimum :: Ord a => UnitEnvGraph a -> a Source #

sum :: Num a => UnitEnvGraph a -> a Source #

product :: Num a => UnitEnvGraph a -> a Source #

Traversable UnitEnvGraph Source # |
Instance details Defined in GHC.Unit.Env Methods traverse :: Applicative f => (a -> f b) -> UnitEnvGraph a -> f (UnitEnvGraph b) Source # sequenceA :: Applicative f => UnitEnvGraph (f a) -> f (UnitEnvGraph a) Source # mapM :: Monad m => (a -> m b) -> UnitEnvGraph a -> m (UnitEnvGraph b) Source # sequence :: Monad m => UnitEnvGraph (m a) -> m (UnitEnvGraph a) Source #
Outputable (UnitEnvGraph HomeUnitEnv) Source # |
Instance details Defined in GHC.Unit.Env Methods ppr :: UnitEnvGraph HomeUnitEnv -> SDoc Source #

type UnitEnvGraphKey = UnitId Source #

unitEnv_insert :: UnitEnvGraphKey -> v -> UnitEnvGraph v -> UnitEnvGraph v Source #

unitEnv_delete :: UnitEnvGraphKey -> UnitEnvGraph v -> UnitEnvGraph v Source #

unitEnv_adjust :: (v -> v) -> UnitEnvGraphKey -> UnitEnvGraph v -> UnitEnvGraph v Source #

unitEnv_new :: Map UnitEnvGraphKey v -> UnitEnvGraph v Source #

unitEnv_singleton :: UnitEnvGraphKey -> v -> UnitEnvGraph v Source #

unitEnv_map :: (v -> v) -> UnitEnvGraph v -> UnitEnvGraph v Source #

unitEnv_member :: UnitEnvGraphKey -> UnitEnvGraph v -> Bool Source #

unitEnv_lookup_maybe :: UnitEnvGraphKey -> UnitEnvGraph v -> Maybe v Source #

unitEnv_lookup :: UnitEnvGraphKey -> UnitEnvGraph v -> v Source #

unitEnv_keys :: UnitEnvGraph v -> Set UnitEnvGraphKey Source #

unitEnv_elts :: UnitEnvGraph v -> [(UnitEnvGraphKey, v)] Source #

unitEnv_hpts :: UnitEnvGraph HomeUnitEnv -> [HomePackageTable] Source #

unitEnv_foldWithKey :: (b -> UnitEnvGraphKey -> a -> b) -> b -> UnitEnvGraph a -> b Source #

unitEnv_union :: (a -> a -> a) -> UnitEnvGraph a -> UnitEnvGraph a -> UnitEnvGraph a Source #

unitEnv_mapWithKey :: (UnitEnvGraphKey -> v -> b) -> UnitEnvGraph v -> UnitEnvGraph b Source #

# Invariants

assertUnitEnvInvariant :: HasDebugCallStack => UnitEnv -> UnitEnv Source #

# Preload units info

preloadUnitsInfo :: UnitEnv -> MaybeErr UnitErr [UnitInfo] Source #

Lookup `UnitInfo` for every preload unit from the UnitState and for every unit used to instantiate the home unit.

preloadUnitsInfo' :: UnitEnv -> [UnitId] -> MaybeErr UnitErr [UnitInfo] Source #

Lookup `UnitInfo` for every preload unit from the UnitState, for every unit used to instantiate the home unit, and for every unit explicitly passed in the given list of UnitId.

# Home Module functions

isUnitEnvInstalledModule :: UnitEnv -> InstalledModule -> Bool Source #

Test if the module comes from the home unit