module GHC.Unit.Module
( module GHC.Unit.Types
, module GHC.Unit.Module.Name
, module GHC.Unit.Module.Location
, module GHC.Unit.Module.Env
, getModuleInstantiation
, getUnitInstantiations
, uninstantiateInstantiatedUnit
, uninstantiateInstantiatedModule
, mkHoleModule
, isHoleModule
, stableModuleCmp
, moduleStableString
, moduleIsDefinite
, HasModule(..)
, ContainsModule(..)
, installedModuleEq
) where
import GHC.Prelude
import GHC.Types.Unique.DSet
import GHC.Unit.Types
import GHC.Unit.Module.Name
import GHC.Unit.Module.Location
import GHC.Unit.Module.Env
import GHC.Utils.Misc
moduleIsDefinite :: Module -> Bool
moduleIsDefinite = isEmptyUniqDSet . moduleFreeHoles
moduleStableString :: Module -> String
moduleStableString Module{..} =
"$" ++ unitString moduleUnit ++ "$" ++ moduleNameString moduleName
stableModuleCmp :: Module -> Module -> Ordering
stableModuleCmp (Module p1 n1) (Module p2 n2)
= (p1 `stableUnitCmp` p2) `thenCmp`
(n1 `stableModuleNameCmp` n2)
class ContainsModule t where
extractModule :: t -> Module
class HasModule m where
getModule :: m Module
installedModuleEq :: InstalledModule -> Module -> Bool
installedModuleEq imod mod =
fst (getModuleInstantiation mod) == imod
getModuleInstantiation :: Module -> (InstalledModule, Maybe InstantiatedModule)
getModuleInstantiation m =
let (uid, mb_iuid) = getUnitInstantiations (moduleUnit m)
in (Module uid (moduleName m),
fmap (\iuid -> Module iuid (moduleName m)) mb_iuid)
getUnitInstantiations :: Unit -> (UnitId, Maybe InstantiatedUnit)
getUnitInstantiations (VirtUnit iuid) = (indefUnit (instUnitInstanceOf iuid), Just iuid)
getUnitInstantiations (RealUnit (Definite uid)) = (uid, Nothing)
getUnitInstantiations HoleUnit = error "Hole unit"
uninstantiateInstantiatedUnit :: InstantiatedUnit -> InstantiatedUnit
uninstantiateInstantiatedUnit u =
mkInstantiatedUnit (instUnitInstanceOf u)
(map (\(m,_) -> (m, mkHoleModule m))
(instUnitInsts u))
uninstantiateInstantiatedModule :: InstantiatedModule -> InstantiatedModule
uninstantiateInstantiatedModule (Module uid n) = Module (uninstantiateInstantiatedUnit uid) n
isHoleModule :: GenModule (GenUnit u) -> Bool
isHoleModule (Module HoleUnit _) = True
isHoleModule _ = False
mkHoleModule :: ModuleName -> GenModule (GenUnit u)
mkHoleModule = Module HoleUnit