module GHC.Unit.External
( ExternalUnitCache (..)
, initExternalUnitCache
, ExternalPackageState (..)
, initExternalPackageState
, EpsStats(..)
, addEpsInStats
, PackageTypeEnv
, PackageIfaceTable
, PackageInstEnv
, PackageFamInstEnv
, PackageRuleBase
, PackageCompleteMatches
, emptyPackageIfaceTable
)
where
import GHC.Prelude
import GHC.Unit
import GHC.Unit.Module.ModIface
import GHC.Core ( RuleBase )
import GHC.Core.FamInstEnv
import GHC.Core.InstEnv ( InstEnv, emptyInstEnv )
import GHC.Core.Opt.ConstantFold
import GHC.Core.Rules (mkRuleBase)
import GHC.Types.Annotations ( AnnEnv, emptyAnnEnv )
import GHC.Types.CompleteMatch
import GHC.Types.TypeEnv
import GHC.Types.Unique.DSet
import Data.IORef
type PackageTypeEnv = TypeEnv
type PackageRuleBase = RuleBase
type PackageInstEnv = InstEnv
type PackageFamInstEnv = FamInstEnv
type PackageAnnEnv = AnnEnv
type PackageCompleteMatches = CompleteMatches
type PackageIfaceTable = ModuleEnv ModIface
emptyPackageIfaceTable :: PackageIfaceTable
emptyPackageIfaceTable :: PackageIfaceTable
emptyPackageIfaceTable = PackageIfaceTable
forall a. ModuleEnv a
emptyModuleEnv
newtype ExternalUnitCache = ExternalUnitCache
{ ExternalUnitCache -> IORef ExternalPackageState
euc_eps :: IORef ExternalPackageState
}
initExternalUnitCache :: IO ExternalUnitCache
initExternalUnitCache :: IO ExternalUnitCache
initExternalUnitCache = IORef ExternalPackageState -> ExternalUnitCache
ExternalUnitCache (IORef ExternalPackageState -> ExternalUnitCache)
-> IO (IORef ExternalPackageState) -> IO ExternalUnitCache
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ExternalPackageState -> IO (IORef ExternalPackageState)
forall a. a -> IO (IORef a)
newIORef ExternalPackageState
initExternalPackageState
initExternalPackageState :: ExternalPackageState
initExternalPackageState :: ExternalPackageState
initExternalPackageState = EPS
{ eps_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot
eps_is_boot = InstalledModuleEnv ModuleNameWithIsBoot
forall a. InstalledModuleEnv a
emptyInstalledModuleEnv
, eps_PIT :: PackageIfaceTable
eps_PIT = PackageIfaceTable
emptyPackageIfaceTable
, eps_free_holes :: InstalledModuleEnv (UniqDSet ModuleName)
eps_free_holes = InstalledModuleEnv (UniqDSet ModuleName)
forall a. InstalledModuleEnv a
emptyInstalledModuleEnv
, eps_PTE :: PackageTypeEnv
eps_PTE = PackageTypeEnv
emptyTypeEnv
, eps_inst_env :: PackageInstEnv
eps_inst_env = PackageInstEnv
emptyInstEnv
, eps_fam_inst_env :: PackageFamInstEnv
eps_fam_inst_env = PackageFamInstEnv
emptyFamInstEnv
, eps_rule_base :: PackageRuleBase
eps_rule_base = [CoreRule] -> PackageRuleBase
mkRuleBase [CoreRule]
builtinRules
,
eps_mod_fam_inst_env :: ModuleEnv PackageFamInstEnv
eps_mod_fam_inst_env = ModuleEnv PackageFamInstEnv
forall a. ModuleEnv a
emptyModuleEnv
, eps_complete_matches :: PackageCompleteMatches
eps_complete_matches = []
, eps_ann_env :: PackageAnnEnv
eps_ann_env = PackageAnnEnv
emptyAnnEnv
, eps_stats :: EpsStats
eps_stats = EpsStats
{ n_ifaces_in :: Int
n_ifaces_in = Int
0
, n_decls_in :: Int
n_decls_in = Int
0
, n_decls_out :: Int
n_decls_out = Int
0
, n_insts_in :: Int
n_insts_in = Int
0
, n_insts_out :: Int
n_insts_out = Int
0
, n_rules_in :: Int
n_rules_in = [CoreRule] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CoreRule]
builtinRules
, n_rules_out :: Int
n_rules_out = Int
0
}
}
data ExternalPackageState
= EPS {
ExternalPackageState -> InstalledModuleEnv ModuleNameWithIsBoot
eps_is_boot :: !(InstalledModuleEnv ModuleNameWithIsBoot),
ExternalPackageState -> PackageIfaceTable
eps_PIT :: !PackageIfaceTable,
ExternalPackageState -> InstalledModuleEnv (UniqDSet ModuleName)
eps_free_holes :: InstalledModuleEnv (UniqDSet ModuleName),
ExternalPackageState -> PackageTypeEnv
eps_PTE :: !PackageTypeEnv,
ExternalPackageState -> PackageInstEnv
eps_inst_env :: !PackageInstEnv,
ExternalPackageState -> PackageFamInstEnv
eps_fam_inst_env :: !PackageFamInstEnv,
ExternalPackageState -> PackageRuleBase
eps_rule_base :: !PackageRuleBase,
ExternalPackageState -> PackageAnnEnv
eps_ann_env :: !PackageAnnEnv,
ExternalPackageState -> PackageCompleteMatches
eps_complete_matches :: !PackageCompleteMatches,
ExternalPackageState -> ModuleEnv PackageFamInstEnv
eps_mod_fam_inst_env :: !(ModuleEnv FamInstEnv),
ExternalPackageState -> EpsStats
eps_stats :: !EpsStats
}
data EpsStats = EpsStats { EpsStats -> Int
n_ifaces_in
, EpsStats -> Int
n_decls_in, EpsStats -> Int
n_decls_out
, EpsStats -> Int
n_rules_in, EpsStats -> Int
n_rules_out
, EpsStats -> Int
n_insts_in, EpsStats -> Int
n_insts_out :: !Int }
addEpsInStats :: EpsStats -> Int -> Int -> Int -> EpsStats
addEpsInStats :: EpsStats -> Int -> Int -> Int -> EpsStats
addEpsInStats EpsStats
stats Int
n_decls Int
n_insts Int
n_rules
= EpsStats
stats { n_ifaces_in :: Int
n_ifaces_in = EpsStats -> Int
n_ifaces_in EpsStats
stats Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
, n_decls_in :: Int
n_decls_in = EpsStats -> Int
n_decls_in EpsStats
stats Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n_decls
, n_insts_in :: Int
n_insts_in = EpsStats -> Int
n_insts_in EpsStats
stats Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n_insts
, n_rules_in :: Int
n_rules_in = EpsStats -> Int
n_rules_in EpsStats
stats Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n_rules }