GHC.Unit.Env

ghc-lib-parser-9.10.1.20250103: 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 #

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 #

ueEPS :: UnitEnv -> IO ExternalPackageState #

unsafeGetHomeUnit :: UnitEnv -> HomeUnit #

Get home-unit

Unsafe because the home-unit may not be set

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

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

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

# Unit Env helper functions

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 #

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] #

# HomeUnitEnv

type HomeUnitGraph = UnitEnvGraph HomeUnitEnv #

data HomeUnitEnv #

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 # |
Instance details Defined in GHC.Unit.Env Methods ppr :: HomeUnitEnv -> SDoc #
Outputable (UnitEnvGraph HomeUnitEnv) # |
Instance details Defined in GHC.Unit.Env Methods ppr :: UnitEnvGraph HomeUnitEnv -> SDoc #

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 #

# UnitEnvGraph

newtype UnitEnvGraph v #

Constructors

UnitEnvGraph |
Fields unitEnv_graph :: Map UnitEnvGraphKey v

#### Instances

Instances details

Functor UnitEnvGraph # |
Instance details Defined in GHC.Unit.Env Methods fmap :: (a -> b) -> UnitEnvGraph a -> UnitEnvGraph b # (<$) :: a -> UnitEnvGraph b -> UnitEnvGraph a #
Foldable UnitEnvGraph # |
Instance details Defined in GHC.Unit.Env Methods fold :: Monoid m => UnitEnvGraph m -> m # foldMap :: Monoid m => (a -> m) -> UnitEnvGraph a -> m # foldMap' :: Monoid m => (a -> m) -> UnitEnvGraph a -> m # foldr :: (a -> b -> b) -> b -> UnitEnvGraph a -> b # foldr' :: (a -> b -> b) -> b -> UnitEnvGraph a -> b # foldl :: (b -> a -> b) -> b -> UnitEnvGraph a -> b # foldl' :: (b -> a -> b) -> b -> UnitEnvGraph a -> b # foldr1 :: (a -> a -> a) -> UnitEnvGraph a -> a # foldl1 :: (a -> a -> a) -> UnitEnvGraph a -> a # toList :: UnitEnvGraph a -> [a] # null :: UnitEnvGraph a -> Bool # length :: UnitEnvGraph a -> Int # elem :: Eq a => a -> UnitEnvGraph a -> Bool # maximum :: Ord a => UnitEnvGraph a -> a # minimum :: Ord a => UnitEnvGraph a -> a # sum :: Num a => UnitEnvGraph a -> a # product :: Num a => UnitEnvGraph a -> a #
Traversable UnitEnvGraph # |
Instance details Defined in GHC.Unit.Env Methods traverse :: Applicative f => (a -> f b) -> UnitEnvGraph a -> f (UnitEnvGraph b) # sequenceA :: Applicative f => UnitEnvGraph (f a) -> f (UnitEnvGraph a) # mapM :: Monad m => (a -> m b) -> UnitEnvGraph a -> m (UnitEnvGraph b) # sequence :: Monad m => UnitEnvGraph (m a) -> m (UnitEnvGraph a) #
Outputable (UnitEnvGraph HomeUnitEnv) # |
Instance details Defined in GHC.Unit.Env Methods ppr :: UnitEnvGraph HomeUnitEnv -> SDoc #

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 #

# Invariants

assertUnitEnvInvariant :: HasDebugCallStack => UnitEnv -> UnitEnv #

# Preload units info

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

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] #

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 #

Test if the module comes from the home unit