    -- | Unit identifier pretty-printing
    module GHC.Unit.Ppr
       ( UnitPprInfo (..)
       )
    where

    import GHC.Prelude
    import GHC.Data.FastString
    import GHC.Utils.Outputable
    import Data.Version

    -- | Subset of UnitInfo: just enough to pretty-print a unit-id
    --
    -- Instead of printing the unit-id which may contain a hash, we print:
    --    package-version:componentname
    --
    data UnitPprInfo = UnitPprInfo
       { UnitPprInfo -> FastString
    unitPprId             :: FastString   -- ^ Identifier
       , UnitPprInfo -> String
    unitPprPackageName    :: String       -- ^ Source package name
       , UnitPprInfo -> Version
    unitPprPackageVersion :: Version      -- ^ Source package version
       , UnitPprInfo -> Maybe String
    unitPprComponentName  :: Maybe String -- ^ Component name
       }

    instance Outputable UnitPprInfo where
      ppr :: UnitPprInfo -> SDoc
    ppr UnitPprInfo
    pprinfo = (Bool -> SDoc) -> SDoc
    forall doc. IsOutput doc => (Bool -> doc) -> doc
    getPprDebug ((Bool -> SDoc) -> SDoc) -> (Bool -> SDoc) -> SDoc
    forall a b. (a -> b) -> a -> b
    $ \Bool
    debug ->
        if Bool
    debug
           then FastString -> SDoc
    forall doc. IsLine doc => FastString -> doc
    ftext (UnitPprInfo -> FastString
    unitPprId UnitPprInfo
    pprinfo)
           else String -> SDoc
    forall doc. IsLine doc => String -> doc
    text (String -> SDoc) -> String -> SDoc
    forall a b. (a -> b) -> a -> b
    $ [String] -> String
    forall a. Monoid a => [a] -> a
    mconcat
             [ UnitPprInfo -> String
    unitPprPackageName UnitPprInfo
    pprinfo
             , case UnitPprInfo -> Version
    unitPprPackageVersion UnitPprInfo
    pprinfo of
                Version [] [] -> String
    ""
                Version
    version       -> String
    "-" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ Version -> String
    showVersion Version
    version
             , case UnitPprInfo -> Maybe String
    unitPprComponentName UnitPprInfo
    pprinfo of
                Maybe String
    Nothing    -> String
    ""
                Just String
    cname -> String
    ":" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    cname
             ]