{-# LANGUAGE DeriveGeneric #-}
module Distribution.Backpack.FullUnitId (
    FullUnitId(..),
    FullDb,
    expandOpenUnitId,
    expandUnitId
) where

import Distribution.Backpack
import Distribution.Types.ComponentId
import Distribution.Compat.Prelude

-- Unlike OpenUnitId, which could direct to a UnitId.
data FullUnitId = FullUnitId ComponentId OpenModuleSubst
    deriving (Int -> FullUnitId -> ShowS
[FullUnitId] -> ShowS
FullUnitId -> String
(Int -> FullUnitId -> ShowS)
-> (FullUnitId -> String)
-> ([FullUnitId] -> ShowS)
-> Show FullUnitId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FullUnitId] -> ShowS
$cshowList :: [FullUnitId] -> ShowS
show :: FullUnitId -> String
$cshow :: FullUnitId -> String
showsPrec :: Int -> FullUnitId -> ShowS
$cshowsPrec :: Int -> FullUnitId -> ShowS
Show, (forall x. FullUnitId -> Rep FullUnitId x)
-> (forall x. Rep FullUnitId x -> FullUnitId) -> Generic FullUnitId
forall x. Rep FullUnitId x -> FullUnitId
forall x. FullUnitId -> Rep FullUnitId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FullUnitId x -> FullUnitId
$cfrom :: forall x. FullUnitId -> Rep FullUnitId x
Generic)

type FullDb = DefUnitId -> FullUnitId

expandOpenUnitId :: FullDb -> OpenUnitId -> FullUnitId
expandOpenUnitId :: FullDb -> OpenUnitId -> FullUnitId
expandOpenUnitId FullDb
_db (IndefFullUnitId ComponentId
cid OpenModuleSubst
subst)
    = ComponentId -> OpenModuleSubst -> FullUnitId
FullUnitId ComponentId
cid OpenModuleSubst
subst
expandOpenUnitId FullDb
db (DefiniteUnitId DefUnitId
uid)
    = FullDb -> FullDb
expandUnitId FullDb
db DefUnitId
uid

expandUnitId :: FullDb -> DefUnitId -> FullUnitId
expandUnitId :: FullDb -> FullDb
expandUnitId FullDb
db DefUnitId
uid = FullDb
db DefUnitId
uid