module GHC.Unit.Env
( UnitEnv (..)
, preloadUnitsInfo
, preloadUnitsInfo'
)
where
import GHC.Prelude
import GHC.Unit.State
import GHC.Unit.Home
import GHC.Unit.Types
import GHC.Platform
import GHC.Settings
import GHC.Data.Maybe
data UnitEnv = UnitEnv
{ UnitEnv -> UnitState
ue_units :: !UnitState
, UnitEnv -> HomeUnit
ue_home_unit :: !HomeUnit
, UnitEnv -> Platform
ue_platform :: !Platform
, UnitEnv -> GhcNameVersion
ue_namever :: !GhcNameVersion
}
preloadUnitsInfo' :: UnitEnv -> [UnitId] -> MaybeErr UnitErr [UnitInfo]
preloadUnitsInfo' :: UnitEnv -> [UnitId] -> MaybeErr UnitErr [UnitInfo]
preloadUnitsInfo' UnitEnv
unit_env [UnitId]
ids0 = MaybeErr UnitErr [UnitInfo]
all_infos
where
home_unit :: HomeUnit
home_unit = UnitEnv -> HomeUnit
ue_home_unit UnitEnv
unit_env
unit_state :: UnitState
unit_state = UnitEnv -> UnitState
ue_units UnitEnv
unit_env
ids :: [UnitId]
ids = [UnitId]
ids0 [UnitId] -> [UnitId] -> [UnitId]
forall a. [a] -> [a] -> [a]
++ [UnitId]
inst_ids
inst_ids :: [UnitId]
inst_ids
| HomeUnit -> Bool
forall u. GenHomeUnit u -> Bool
isHomeUnitIndefinite HomeUnit
home_unit = []
| Bool
otherwise = ((ModuleName, GenModule Unit) -> UnitId)
-> [(ModuleName, GenModule Unit)] -> [UnitId]
forall a b. (a -> b) -> [a] -> [b]
map (Unit -> UnitId
toUnitId (Unit -> UnitId)
-> ((ModuleName, GenModule Unit) -> Unit)
-> (ModuleName, GenModule Unit)
-> UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenModule Unit -> Unit
forall unit. GenModule unit -> unit
moduleUnit (GenModule Unit -> Unit)
-> ((ModuleName, GenModule Unit) -> GenModule Unit)
-> (ModuleName, GenModule Unit)
-> Unit
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ModuleName, GenModule Unit) -> GenModule Unit
forall a b. (a, b) -> b
snd) (HomeUnit -> [(ModuleName, GenModule Unit)]
forall u. GenHomeUnit u -> GenInstantiations u
homeUnitInstantiations HomeUnit
home_unit)
pkg_map :: UnitInfoMap
pkg_map = UnitState -> UnitInfoMap
unitInfoMap UnitState
unit_state
preload :: [UnitId]
preload = UnitState -> [UnitId]
preloadUnits UnitState
unit_state
all_pkgs :: MaybeErr UnitErr [UnitId]
all_pkgs = UnitInfoMap
-> [UnitId]
-> [(UnitId, Maybe UnitId)]
-> MaybeErr UnitErr [UnitId]
closeUnitDeps' UnitInfoMap
pkg_map [UnitId]
preload ([UnitId]
ids [UnitId] -> [Maybe UnitId] -> [(UnitId, Maybe UnitId)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` Maybe UnitId -> [Maybe UnitId]
forall a. a -> [a]
repeat Maybe UnitId
forall a. Maybe a
Nothing)
all_infos :: MaybeErr UnitErr [UnitInfo]
all_infos = (UnitId -> UnitInfo) -> [UnitId] -> [UnitInfo]
forall a b. (a -> b) -> [a] -> [b]
map (HasDebugCallStack => UnitState -> UnitId -> UnitInfo
UnitState -> UnitId -> UnitInfo
unsafeLookupUnitId UnitState
unit_state) ([UnitId] -> [UnitInfo])
-> MaybeErr UnitErr [UnitId] -> MaybeErr UnitErr [UnitInfo]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MaybeErr UnitErr [UnitId]
all_pkgs
preloadUnitsInfo :: UnitEnv -> MaybeErr UnitErr [UnitInfo]
preloadUnitsInfo :: UnitEnv -> MaybeErr UnitErr [UnitInfo]
preloadUnitsInfo UnitEnv
unit_env = UnitEnv -> [UnitId] -> MaybeErr UnitErr [UnitInfo]
preloadUnitsInfo' UnitEnv
unit_env []