{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
-- Note [Pass sensitive types]
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-- |
-- Module      :  Haddock.Types
-- Copyright   :  (c) Simon Marlow      2003-2006,
--                    David Waern       2006-2009,
--                    Mateusz Kowalczyk 2013
-- License     :  BSD-like
--
-- Maintainer  :  haddock@projects.haskellorg
-- Stability   :  experimental
-- Portability :  portable
--
-- Types that are commonly used through-out Haddock. Some of the most
-- important types are defined here, like 'Interface' and 'DocName'.
module Haddock.Types
  ( module Haddock.Types
  , HsDocString
  , LHsDocString
  , Fixity (..)
  , module Documentation.Haddock.Types
  ) where

import Control.DeepSeq
import Control.Exception (throw)
import Control.Monad.Catch
import Control.Monad.State.Strict
import Data.Data (Data)
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Set as Set
import GHC
import qualified GHC.Data.Strict as Strict
import GHC.Driver.Session (Language)
import qualified GHC.LanguageExtensions as LangExt
import GHC.Core.InstEnv (is_dfun_name)
import GHC.Types.Fixity (Fixity (..))
import GHC.Types.Name (stableNameCmp)
import GHC.Types.Name.Occurrence
import GHC.Types.Name.Reader (RdrName (..))
import GHC.Types.SrcLoc (BufPos (..), BufSpan (..), srcSpanToRealSrcSpan)
import GHC.Types.Var (Specificity)
import GHC.Utils.Outputable

import Documentation.Haddock.Types

-----------------------------------------------------------------------------

-- * Convenient synonyms

-----------------------------------------------------------------------------

type IfaceMap = Map Module Interface
type InstIfaceMap = Map Module InstalledInterface -- TODO: rename
type DocMap a = Map Name (MDoc a)
type ArgMap a = Map Name (Map Int (MDoc a))
type SubMap = Map Name [Name]
type DeclMap = Map Name DeclMapEntry
type InstMap = Map RealSrcSpan Name
type FixMap = Map Name Fixity
data DocPaths = DocPaths
  { DocPaths -> FilePath
docPathsHtml :: FilePath
  -- ^ path to HTML Haddocks
  , DocPaths -> Maybe FilePath
docPathsSources :: Maybe FilePath
  -- ^ path to hyperlinked sources
  }
type WarningMap = Map Name (Doc Name)

-----------------------------------------------------------------------------

-- * Interfaces and Interface creation

-----------------------------------------------------------------------------

-- | 'Interface' holds all information used to render a single Haddock page.
-- It represents the /interface/ of a module. The core business of Haddock
-- lies in creating this structure. Note that the record contains some fields
-- that are only used to create the final record, and that are not used by the
-- backends.
data Interface = Interface
  { Interface -> Module
ifaceMod :: !Module
  -- ^ The module behind this interface.
  , Interface -> Bool
ifaceIsSig :: !Bool
  -- ^ Is this a signature?
  , Interface -> HaddockModInfo Name
ifaceInfo :: !(HaddockModInfo Name)
  -- ^ Textual information about the module.
  , Interface -> Documentation Name
ifaceDoc :: !(Documentation Name)
  -- ^ Documentation header.
  , Interface -> Documentation DocName
ifaceRnDoc :: !(Documentation DocName)
  -- ^ Documentation header with cross-reference information.
  , Interface -> [DocOption]
ifaceOptions :: [DocOption]
  -- ^ Haddock options for this module (prune, ignore-exports, etc).
  , Interface -> DocMap Name
ifaceDocMap :: !(DocMap Name)
  -- ^ Documentation of declarations originating from the module (including
  -- subordinates).
  , Interface -> ArgMap Name
ifaceArgMap :: !(ArgMap Name)
  , Interface -> [(OccName, Name)]
ifaceDefMeths :: !([(OccName, Name)])
  -- ^ The names of all the default methods for classes defined in this module
  , Interface -> Map Name Fixity
ifaceFixMap :: !(Map Name Fixity)
  , Interface -> [ExportItem GhcRn]
ifaceExportItems :: [ExportItem GhcRn]
  , Interface -> [ExportItem DocNameI]
ifaceRnExportItems :: [ExportItem DocNameI]
  , Interface -> [Name]
ifaceExports :: [Name]
  -- ^ All names exported by the module.
  , Interface -> [Name]
ifaceVisibleExports :: [Name]
  -- ^ All \"visible\" names exported by the module.
  -- A visible name is a name that will show up in the documentation of the
  -- module.
  --
  -- Names from modules that are entirely re-exported don't count as visible.
  , Interface -> [ClsInst]
ifaceInstances :: [ClsInst]
  -- ^ Instances exported by the module.
  , Interface -> [DocInstance GhcRn]
ifaceOrphanInstances :: [DocInstance GhcRn]
  -- ^ Orphan instances
  , Interface -> [DocInstance DocNameI]
ifaceRnOrphanInstances :: [DocInstance DocNameI]
  , Interface -> (Int, Int)
ifaceHaddockCoverage :: (Int, Int)
  -- ^ The number of haddockable and haddocked items in the module, as a
  -- tuple. Haddockable items are the exports and the module itself.
  , Interface -> WarningMap
ifaceWarningMap :: WarningMap
  -- ^ Warnings for things defined in this module.
  , Interface -> FilePath
ifaceHieFile :: !FilePath
  -- ^ Tokenized source code of module (available if Haddock is invoked with
  -- source generation flag).
  , Interface -> DynFlags
ifaceDynFlags :: !DynFlags
  }

-- | A subset of the fields of 'Interface' that we store in the interface
-- files.
data InstalledInterface = InstalledInterface
  { InstalledInterface -> Module
instMod :: Module
  -- ^ The module represented by this interface.
  , InstalledInterface -> Bool
instIsSig :: Bool
  -- ^ Is this a signature?
  , InstalledInterface -> HaddockModInfo Name
instInfo :: HaddockModInfo Name
  -- ^ Textual information about the module.
  , InstalledInterface -> DocMap Name
instDocMap :: DocMap Name
  -- ^ Documentation of declarations originating from the module (including
  -- subordinates).
  , InstalledInterface -> ArgMap Name
instArgMap :: ArgMap Name
  , InstalledInterface -> [(OccName, Name)]
instDefMeths :: [(OccName, Name)]
  -- ^ The names of all the default methods for classes defined in this module
  , InstalledInterface -> [Name]
instExports :: [Name]
  -- ^ All names exported by this module.
  , InstalledInterface -> [Name]
instVisibleExports :: [Name]
  -- ^ All \"visible\" names exported by the module.
  -- A visible name is a name that will show up in the documentation of the
  -- module.
  , InstalledInterface -> [DocOption]
instOptions :: [DocOption]
  -- ^ Haddock options for this module (prune, ignore-exports, etc).
  , InstalledInterface -> Map Name Fixity
instFixMap :: Map Name Fixity
  , InstalledInterface -> WarningMap
instWarningMap :: WarningMap
  , InstalledInterface -> Map Name RealSrcSpan
instInstanceLocMap :: Map Name RealSrcSpan
  }

-- | Convert an 'Interface' to an 'InstalledInterface'
toInstalledIface :: Interface -> InstalledInterface
toInstalledIface :: Interface -> InstalledInterface
toInstalledIface Interface
interface =
  InstalledInterface
    { instMod :: Module
instMod = Interface
interface.ifaceMod
    , instIsSig :: Bool
instIsSig = Interface
interface.ifaceIsSig
    , instInfo :: HaddockModInfo Name
instInfo = Interface
interface.ifaceInfo
    , instDocMap :: DocMap Name
instDocMap = Interface
interface.ifaceDocMap
    , instArgMap :: ArgMap Name
instArgMap = Interface
interface.ifaceArgMap
    , instExports :: [Name]
instExports = Interface
interface.ifaceExports
    , instVisibleExports :: [Name]
instVisibleExports = Interface
interface.ifaceVisibleExports
    , instOptions :: [DocOption]
instOptions = Interface
interface.ifaceOptions
    , instFixMap :: Map Name Fixity
instFixMap = Interface
interface.ifaceFixMap
    , instDefMeths :: [(OccName, Name)]
instDefMeths = Interface
interface.ifaceDefMeths
    , instWarningMap :: WarningMap
instWarningMap = Interface
interface.ifaceWarningMap
    , instInstanceLocMap :: Map Name RealSrcSpan
instInstanceLocMap = [(Name, RealSrcSpan)] -> Map Name RealSrcSpan
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Name
inst_name, RealSrcSpan
loc) |  ClsInst
i <- Interface
interface.ifaceInstances, let inst_name :: Name
inst_name = ClsInst -> Name
is_dfun_name ClsInst
i, Just RealSrcSpan
loc <- [SrcSpan -> Maybe RealSrcSpan
srcSpanToRealSrcSpan (Name -> SrcSpan
nameSrcSpan Name
inst_name)]]
    }

-- | A monad in which we create Haddock interfaces. Not to be confused with
-- `GHC.Tc.Types.IfM` which is used to write GHC interfaces.
--
-- In the past `createInterface` was running in the `Ghc` monad but proved hard
-- to sustain as soon as we moved over for Haddock to be a plugin. Also abstracting
-- over the Ghc specific clarifies where side effects happen.
newtype IfM m a = IfM {forall (m :: Type -> Type) a. IfM m a -> StateT (IfEnv m) m a
unIfM :: StateT (IfEnv m) m a}

deriving newtype instance Functor m => Functor (IfM m)
deriving newtype instance (Monad m, Applicative m) => Applicative (IfM m)
deriving newtype instance Monad m => Monad (IfM m)
deriving newtype instance MonadIO m => MonadIO (IfM m)
deriving newtype instance Monad m => MonadState (IfEnv m) (IfM m)

-- | Interface creation environment. The name sets are used primarily during
-- processing of doc strings to avoid emitting the same type of warning for the
-- same name twice. This was previously done using a Writer monad and then
-- nubbing the list of warning messages after accumulation. This new approach
-- was implemented to avoid the nubbing of potentially large lists of strings.
data IfEnv m = IfEnv
  { forall (m :: Type -> Type). IfEnv m -> Name -> m (Maybe TyThing)
ifeLookupName :: Name -> m (Maybe TyThing)
  -- ^ Lookup names in the environment.
  , forall (m :: Type -> Type). IfEnv m -> Set FilePath
ifeOutOfScopeNames :: !(Set.Set String)
  -- ^ Names which we have warned about for being out of scope
  , forall (m :: Type -> Type). IfEnv m -> Set FilePath
ifeAmbiguousNames :: !(Set.Set String)
  -- ^ Names which we have warned about for being ambiguous
  }

-- | Run an `IfM` action.
runIfM
  :: Monad m
  => (Name -> m (Maybe TyThing))
  -- ^ Lookup a global name in the current session. Used in cases
  -- where declarations don't
  -> IfM m a
  -- ^ The action to run.
  -> m a
  -- ^ Result and accumulated error/warning messages.
runIfM :: forall (m :: Type -> Type) a.
Monad m =>
(Name -> m (Maybe TyThing)) -> IfM m a -> m a
runIfM Name -> m (Maybe TyThing)
lookup_name IfM m a
action = do
  let
    if_env :: IfEnv m
if_env =
      IfEnv
        { ifeLookupName :: Name -> m (Maybe TyThing)
ifeLookupName = Name -> m (Maybe TyThing)
lookup_name
        , ifeOutOfScopeNames :: Set FilePath
ifeOutOfScopeNames = Set FilePath
forall a. Set a
Set.empty
        , ifeAmbiguousNames :: Set FilePath
ifeAmbiguousNames = Set FilePath
forall a. Set a
Set.empty
        }
  StateT (IfEnv m) m a -> IfEnv m -> m a
forall (m :: Type -> Type) s a. Monad m => StateT s m a -> s -> m a
evalStateT (IfM m a -> StateT (IfEnv m) m a
forall (m :: Type -> Type) a. IfM m a -> StateT (IfEnv m) m a
unIfM IfM m a
action) IfEnv m
if_env

-- | Look up a name in the current environment
lookupName :: Monad m => Name -> IfM m (Maybe TyThing)
lookupName :: forall (m :: Type -> Type).
Monad m =>
Name -> IfM m (Maybe TyThing)
lookupName Name
name = StateT (IfEnv m) m (Maybe TyThing) -> IfM m (Maybe TyThing)
forall (m :: Type -> Type) a. StateT (IfEnv m) m a -> IfM m a
IfM (StateT (IfEnv m) m (Maybe TyThing) -> IfM m (Maybe TyThing))
-> StateT (IfEnv m) m (Maybe TyThing) -> IfM m (Maybe TyThing)
forall a b. (a -> b) -> a -> b
$ do
  lookup_name <- (IfEnv m -> Name -> m (Maybe TyThing))
-> StateT (IfEnv m) m (Name -> m (Maybe TyThing))
forall s (m :: Type -> Type) a. MonadState s m => (s -> a) -> m a
gets IfEnv m -> Name -> m (Maybe TyThing)
forall (m :: Type -> Type). IfEnv m -> Name -> m (Maybe TyThing)
ifeLookupName
  lift (lookup_name name)

-- | Very basic logging function that simply prints to stdout
warn :: MonadIO m => String -> IfM m ()
warn :: forall (m :: Type -> Type). MonadIO m => FilePath -> IfM m ()
warn FilePath
msg = IO () -> IfM m ()
forall a. IO a -> IfM m a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> IfM m ()) -> IO () -> IfM m ()
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
putStrLn FilePath
msg

-----------------------------------------------------------------------------

-- * Export items & declarations

-----------------------------------------------------------------------------

data ExportItem name
  = -- | An exported declaration.
    ExportDecl (XExportDecl name)
  | -- | An exported entity for which we have no documentation (perhaps because it
    -- resides in another package).
    ExportNoDecl
      { forall name. ExportItem name -> IdP name
expItemName :: !(IdP name)
      , forall name. ExportItem name -> [IdP name]
expItemSubs :: [IdP name]
      -- ^ Subordinate names.
      }
  | -- | A section heading.
    ExportGroup
      { forall name. ExportItem name -> Int
expItemSectionLevel :: !Int
      -- ^ Section level (1, 2, 3, ...).
      , forall name. ExportItem name -> FilePath
expItemSectionId :: !String
      -- ^ Section id (for hyperlinks).
      , forall name. ExportItem name -> Doc (IdP name)
expItemSectionText :: !(Doc (IdP name))
      -- ^ Section heading text.
      }
  | -- | Some documentation.
    ExportDoc !(MDoc (IdP name))
  | -- | A cross-reference to another module.
    ExportModule !Module

-- | A type family mapping a name type index to types of export declarations.
-- The pre-renaming type index ('GhcRn') is mapped to the type of export
-- declarations which do not include Hoogle output ('ExportD'), since Hoogle output is
-- generated during the Haddock renaming step. The post-renaming type index
-- ('DocNameI') is mapped to the type of export declarations which do include
-- Hoogle output ('RnExportD').
type family XExportDecl x where
  XExportDecl GhcRn = ExportD GhcRn
  XExportDecl DocNameI = RnExportD

-- | Represents an export declaration that Haddock has discovered to be exported
-- from a module. The @name@ index indicated whether the declaration has been
-- renamed such that each 'Name' points to it's optimal link destination.
data ExportD name = ExportD
  { forall name. ExportD name -> LHsDecl name
expDDecl :: !(LHsDecl name)
  -- ^ A declaration.
  , forall name. ExportD name -> [(HsDecl name, DocForDecl (IdP name))]
expDPats :: [(HsDecl name, DocForDecl (IdP name))]
  -- ^ Bundled patterns for a data type declaration
  , forall name. ExportD name -> DocForDecl (IdP name)
expDMbDoc :: !(DocForDecl (IdP name))
  -- ^ Maybe a doc comment, and possibly docs for arguments (if this
  -- decl is a function or type-synonym).
  , forall name. ExportD name -> [(IdP name, DocForDecl (IdP name))]
expDSubDocs :: [(IdP name, DocForDecl (IdP name))]
  -- ^ Subordinate names, possibly with documentation.
  , forall name. ExportD name -> [DocInstance name]
expDInstances :: [DocInstance name]
  -- ^ Instances relevant to this declaration, possibly with
  -- documentation.
  , forall name. ExportD name -> [(IdP name, Fixity)]
expDFixities :: [(IdP name, Fixity)]
  -- ^ Fixity decls relevant to this declaration (including subordinates).
  , forall name. ExportD name -> Bool
expDSpliced :: !Bool
  -- ^ Whether the ExportD is from a TH splice or not, for generating
  -- the appropriate type of Source link.
  }

-- | Represents export declarations that have undergone renaming such that every
-- 'Name' in the declaration points to an optimal link destination. Since Hoogle
-- output is also generated during the renaming step, each declaration is also
-- attached to its Hoogle textual database entries, /if/ Hoogle output is
-- enabled and the module is not hidden in the generated documentation using the
-- @{-# OPTIONS_HADDOCK hide #-}@ pragma.
data RnExportD = RnExportD
  { RnExportD -> ExportD DocNameI
rnExpDExpD :: !(ExportD DocNameI)
  -- ^ The renamed export declaration
  , RnExportD -> [FilePath]
rnExpDHoogle :: [String]
  -- ^ If Hoogle textbase (textual database) output is enabled, the text
  -- output lines for this declaration. If Hoogle output is not enabled, the
  -- list will be empty.
  }

data Documentation name = Documentation
  { forall name. Documentation name -> Maybe (MDoc name)
documentationDoc :: Maybe (MDoc name)
  , forall name. Documentation name -> Maybe (Doc name)
documentationWarning :: Maybe (Doc name)
  }
  deriving ((forall a b. (a -> b) -> Documentation a -> Documentation b)
-> (forall a b. a -> Documentation b -> Documentation a)
-> Functor Documentation
forall a b. a -> Documentation b -> Documentation a
forall a b. (a -> b) -> Documentation a -> Documentation b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Documentation a -> Documentation b
fmap :: forall a b. (a -> b) -> Documentation a -> Documentation b
$c<$ :: forall a b. a -> Documentation b -> Documentation a
<$ :: forall a b. a -> Documentation b -> Documentation a
Functor)

instance NFData name => NFData (Documentation name) where
  rnf :: Documentation name -> ()
rnf (Documentation Maybe (MDoc name)
d Maybe (Doc name)
w) = Maybe (MDoc name)
d Maybe (MDoc name) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Maybe (Doc name)
w Maybe (Doc name) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

-- | Arguments and result are indexed by Int, zero-based from the left,
-- because that's the easiest to use when recursing over types.
type FnArgsDoc name = Map Int (MDoc name)

type DocForDecl name = (Documentation name, FnArgsDoc name)

noDocForDecl :: DocForDecl name
noDocForDecl :: forall name. DocForDecl name
noDocForDecl = (Maybe (MDoc name) -> Maybe (Doc name) -> Documentation name
forall name.
Maybe (MDoc name) -> Maybe (Doc name) -> Documentation name
Documentation Maybe (MDoc name)
forall a. Maybe a
Nothing Maybe (Doc name)
forall a. Maybe a
Nothing, FnArgsDoc name
forall a. Monoid a => a
mempty)

-- | As we build the declaration map, we really only care to track whether we
-- have only seen a value declaration for a 'Name', or anything else. This type
-- is used to represent those cases. If the only declaration attached to a
-- 'Name' is a 'ValD', we will consult the GHC interface file to determine the
-- type of the value, and attach the 'SrcSpan' from the 'EValD' constructor to
-- it. If we see any other type of declaration for the 'Name', we can just use
-- it.
--
-- This type saves us from storing /every/ declaration we see for a given 'Name'
-- in the map, which is unnecessary and very problematic for overall memory
-- usage.
data DeclMapEntry
  = EValD !SrcSpan
  | EOther (LHsDecl GhcRn)

instance Semigroup DeclMapEntry where
  (EValD SrcSpan
_) <> :: DeclMapEntry -> DeclMapEntry -> DeclMapEntry
<> DeclMapEntry
e = DeclMapEntry
e
  DeclMapEntry
e <> DeclMapEntry
_ = DeclMapEntry
e

-- | Transform a declaration into a 'DeclMapEntry'. If it is a 'ValD'
-- declaration, only the source location will be noted (since that is all we
-- care to store in the 'DeclMap' due to the way top-level bindings with no type
-- signatures are handled). Otherwise, the entire declaration will be kept.
toDeclMapEntry :: LHsDecl GhcRn -> DeclMapEntry
toDeclMapEntry :: LHsDecl GhcRn -> DeclMapEntry
toDeclMapEntry (L SrcSpanAnnA
l (ValD XValD GhcRn
_ HsBind GhcRn
_)) = SrcSpan -> DeclMapEntry
EValD (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
l)
toDeclMapEntry LHsDecl GhcRn
d = LHsDecl GhcRn -> DeclMapEntry
EOther LHsDecl GhcRn
d

-----------------------------------------------------------------------------

-- * Cross-referencing

-----------------------------------------------------------------------------

-- | Type of environment used to cross-reference identifiers in the syntax.
type LinkEnv = Map Name Module

-- | An 'RdrName' tagged with some type/value namespace information.
data NsRdrName = NsRdrName
  { NsRdrName -> Namespace
namespace :: !Namespace
  , NsRdrName -> RdrName
rdrName :: !RdrName
  }

instance NFData NsRdrName where
  rnf :: NsRdrName -> ()
rnf (NsRdrName Namespace
ns RdrName
rdrN) = Namespace
ns Namespace -> () -> ()
forall a b. a -> b -> b
`seq` RdrName
rdrN RdrName -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

-- | Extends 'Name' with cross-reference information.
data DocName
  = -- | This thing is part of the (existing or resulting)
    -- documentation. The 'Module' is the preferred place
    -- in the documentation to refer to.
    Documented Name Module
  | -- | This thing is not part of the (existing or resulting)
    -- documentation, as far as Haddock knows.
    Undocumented Name
  deriving (DocName -> DocName -> Bool
(DocName -> DocName -> Bool)
-> (DocName -> DocName -> Bool) -> Eq DocName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocName -> DocName -> Bool
== :: DocName -> DocName -> Bool
$c/= :: DocName -> DocName -> Bool
/= :: DocName -> DocName -> Bool
Eq, Typeable DocName
Typeable DocName =>
(forall (c :: Type -> Type).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> DocName -> c DocName)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DocName)
-> (DocName -> Constr)
-> (DocName -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DocName))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DocName))
-> ((forall b. Data b => b -> b) -> DocName -> DocName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DocName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DocName -> r)
-> (forall u. (forall d. Data d => d -> u) -> DocName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> DocName -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> DocName -> m DocName)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DocName -> m DocName)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DocName -> m DocName)
-> Data DocName
DocName -> Constr
DocName -> DataType
(forall b. Data b => b -> b) -> DocName -> DocName
forall a.
Typeable a =>
(forall (c :: Type -> Type).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> DocName -> u
forall u. (forall d. Data d => d -> u) -> DocName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DocName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DocName -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DocName
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DocName -> c DocName
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DocName)
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DocName)
$cgfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DocName -> c DocName
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DocName -> c DocName
$cgunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DocName
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DocName
$ctoConstr :: DocName -> Constr
toConstr :: DocName -> Constr
$cdataTypeOf :: DocName -> DataType
dataTypeOf :: DocName -> DataType
$cdataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DocName)
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DocName)
$cdataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DocName)
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DocName)
$cgmapT :: (forall b. Data b => b -> b) -> DocName -> DocName
gmapT :: (forall b. Data b => b -> b) -> DocName -> DocName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DocName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DocName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DocName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DocName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DocName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> DocName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DocName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DocName -> u
$cgmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
$cgmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
$cgmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DocName -> m DocName
Data)

data DocNameI

type instance NoGhcTc DocNameI = DocNameI

type instance IdP DocNameI = DocName

instance CollectPass DocNameI where
  collectXXPat :: CollectFlag DocNameI
-> XXPat DocNameI -> [IdP DocNameI] -> [IdP DocNameI]
collectXXPat CollectFlag DocNameI
_ XXPat DocNameI
ext = DataConCantHappen -> [DocName] -> [DocName]
forall a. DataConCantHappen -> a
dataConCantHappen XXPat DocNameI
DataConCantHappen
ext
  collectXXHsBindsLR :: forall pR.
XXHsBindsLR DocNameI pR -> [IdP DocNameI] -> [IdP DocNameI]
collectXXHsBindsLR XXHsBindsLR DocNameI pR
ext = DataConCantHappen -> [DocName] -> [DocName]
forall a. DataConCantHappen -> a
dataConCantHappen XXHsBindsLR DocNameI pR
DataConCantHappen
ext
  collectXSplicePat :: CollectFlag DocNameI
-> XSplicePat DocNameI -> [IdP DocNameI] -> [IdP DocNameI]
collectXSplicePat CollectFlag DocNameI
_ XSplicePat DocNameI
ext = DataConCantHappen -> [DocName] -> [DocName]
forall a. DataConCantHappen -> a
dataConCantHappen XSplicePat DocNameI
DataConCantHappen
ext

instance NamedThing DocName where
  getName :: DocName -> Name
getName (Documented Name
name Module
_) = Name
name
  getName (Undocumented Name
name) = Name
name

-- | Useful for debugging
instance Outputable DocName where
  ppr :: DocName -> SDoc
ppr = Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SDoc) -> (DocName -> Name) -> DocName -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocName -> Name
forall a. NamedThing a => a -> Name
getName

instance OutputableBndr DocName where
  pprBndr :: BindingSite -> DocName -> SDoc
pprBndr BindingSite
_ = Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SDoc) -> (DocName -> Name) -> DocName -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocName -> Name
forall a. NamedThing a => a -> Name
getName
  pprPrefixOcc :: DocName -> SDoc
pprPrefixOcc = Name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Name -> SDoc) -> (DocName -> Name) -> DocName -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocName -> Name
forall a. NamedThing a => a -> Name
getName
  pprInfixOcc :: DocName -> SDoc
pprInfixOcc = Name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (Name -> SDoc) -> (DocName -> Name) -> DocName -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocName -> Name
forall a. NamedThing a => a -> Name
getName

class NamedThing name => SetName name where
  setName :: Name -> name -> name

instance SetName Name where
  setName :: Name -> Name -> Name
setName Name
name' Name
_ = Name
name'

instance SetName DocName where
  setName :: Name -> DocName -> DocName
setName Name
name' (Documented Name
_ Module
mdl) = Name -> Module -> DocName
Documented Name
name' Module
mdl
  setName Name
name' (Undocumented Name
_) = Name -> DocName
Undocumented Name
name'

-- | Adds extra "wrapper" information to a name.
--
-- This is to work around the fact that most name types in GHC ('Name', 'RdrName',
-- 'OccName', ...) don't include backticks or parens.
data Wrap n
  = -- | don't do anything to the name
    Unadorned {forall n. Wrap n -> n
unwrap :: n}
  | -- | add parentheses around the name
    Parenthesized {unwrap :: n}
  | -- | add backticks around the name
    Backticked {unwrap :: n}
  deriving (Int -> Wrap n -> ShowS
[Wrap n] -> ShowS
Wrap n -> FilePath
(Int -> Wrap n -> ShowS)
-> (Wrap n -> FilePath) -> ([Wrap n] -> ShowS) -> Show (Wrap n)
forall n. Show n => Int -> Wrap n -> ShowS
forall n. Show n => [Wrap n] -> ShowS
forall n. Show n => Wrap n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall n. Show n => Int -> Wrap n -> ShowS
showsPrec :: Int -> Wrap n -> ShowS
$cshow :: forall n. Show n => Wrap n -> FilePath
show :: Wrap n -> FilePath
$cshowList :: forall n. Show n => [Wrap n] -> ShowS
showList :: [Wrap n] -> ShowS
Show, (forall a b. (a -> b) -> Wrap a -> Wrap b)
-> (forall a b. a -> Wrap b -> Wrap a) -> Functor Wrap
forall a b. a -> Wrap b -> Wrap a
forall a b. (a -> b) -> Wrap a -> Wrap b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Wrap a -> Wrap b
fmap :: forall a b. (a -> b) -> Wrap a -> Wrap b
$c<$ :: forall a b. a -> Wrap b -> Wrap a
<$ :: forall a b. a -> Wrap b -> Wrap a
Functor, (forall m. Monoid m => Wrap m -> m)
-> (forall m a. Monoid m => (a -> m) -> Wrap a -> m)
-> (forall m a. Monoid m => (a -> m) -> Wrap a -> m)
-> (forall a b. (a -> b -> b) -> b -> Wrap a -> b)
-> (forall a b. (a -> b -> b) -> b -> Wrap a -> b)
-> (forall b a. (b -> a -> b) -> b -> Wrap a -> b)
-> (forall b a. (b -> a -> b) -> b -> Wrap a -> b)
-> (forall a. (a -> a -> a) -> Wrap a -> a)
-> (forall a. (a -> a -> a) -> Wrap a -> a)
-> (forall a. Wrap a -> [a])
-> (forall a. Wrap a -> Bool)
-> (forall a. Wrap a -> Int)
-> (forall a. Eq a => a -> Wrap a -> Bool)
-> (forall a. Ord a => Wrap a -> a)
-> (forall a. Ord a => Wrap a -> a)
-> (forall a. Num a => Wrap a -> a)
-> (forall a. Num a => Wrap a -> a)
-> Foldable Wrap
forall a. Eq a => a -> Wrap a -> Bool
forall a. Num a => Wrap a -> a
forall a. Ord a => Wrap a -> a
forall m. Monoid m => Wrap m -> m
forall a. Wrap a -> Bool
forall a. Wrap a -> Int
forall a. Wrap a -> [a]
forall a. (a -> a -> a) -> Wrap a -> a
forall m a. Monoid m => (a -> m) -> Wrap a -> m
forall b a. (b -> a -> b) -> b -> Wrap a -> b
forall a b. (a -> b -> b) -> b -> Wrap a -> b
forall (t :: Type -> Type).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Wrap m -> m
fold :: forall m. Monoid m => Wrap m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Wrap a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Wrap a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Wrap a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Wrap a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Wrap a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Wrap a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Wrap a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Wrap a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Wrap a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Wrap a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Wrap a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Wrap a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Wrap a -> a
foldr1 :: forall a. (a -> a -> a) -> Wrap a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Wrap a -> a
foldl1 :: forall a. (a -> a -> a) -> Wrap a -> a
$ctoList :: forall a. Wrap a -> [a]
toList :: forall a. Wrap a -> [a]
$cnull :: forall a. Wrap a -> Bool
null :: forall a. Wrap a -> Bool
$clength :: forall a. Wrap a -> Int
length :: forall a. Wrap a -> Int
$celem :: forall a. Eq a => a -> Wrap a -> Bool
elem :: forall a. Eq a => a -> Wrap a -> Bool
$cmaximum :: forall a. Ord a => Wrap a -> a
maximum :: forall a. Ord a => Wrap a -> a
$cminimum :: forall a. Ord a => Wrap a -> a
minimum :: forall a. Ord a => Wrap a -> a
$csum :: forall a. Num a => Wrap a -> a
sum :: forall a. Num a => Wrap a -> a
$cproduct :: forall a. Num a => Wrap a -> a
product :: forall a. Num a => Wrap a -> a
Foldable, Functor Wrap
Foldable Wrap
(Functor Wrap, Foldable Wrap) =>
(forall (f :: Type -> Type) a b.
 Applicative f =>
 (a -> f b) -> Wrap a -> f (Wrap b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    Wrap (f a) -> f (Wrap a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> Wrap a -> m (Wrap b))
-> (forall (m :: Type -> Type) a.
    Monad m =>
    Wrap (m a) -> m (Wrap a))
-> Traversable Wrap
forall (t :: Type -> Type).
(Functor t, Foldable t) =>
(forall (f :: Type -> Type) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    t (f a) -> f (t a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: Type -> Type) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: Type -> Type) a. Monad m => Wrap (m a) -> m (Wrap a)
forall (f :: Type -> Type) a.
Applicative f =>
Wrap (f a) -> f (Wrap a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Wrap a -> m (Wrap b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Wrap a -> f (Wrap b)
$ctraverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Wrap a -> f (Wrap b)
traverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Wrap a -> f (Wrap b)
$csequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
Wrap (f a) -> f (Wrap a)
sequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
Wrap (f a) -> f (Wrap a)
$cmapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Wrap a -> m (Wrap b)
mapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Wrap a -> m (Wrap b)
$csequence :: forall (m :: Type -> Type) a. Monad m => Wrap (m a) -> m (Wrap a)
sequence :: forall (m :: Type -> Type) a. Monad m => Wrap (m a) -> m (Wrap a)
Traversable)

instance NFData n => NFData (Wrap n) where
  rnf :: Wrap n -> ()
rnf Wrap n
w = case Wrap n
w of
    Unadorned n
n -> n -> ()
forall a. NFData a => a -> ()
rnf n
n
    Parenthesized n
n -> n -> ()
forall a. NFData a => a -> ()
rnf n
n
    Backticked n
n -> n -> ()
forall a. NFData a => a -> ()
rnf n
n

-- | Useful for debugging
instance Outputable n => Outputable (Wrap n) where
  ppr :: Wrap n -> SDoc
ppr (Unadorned n
n) = n -> SDoc
forall a. Outputable a => a -> SDoc
ppr n
n
  ppr (Parenthesized n
n) = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat [Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'(', n -> SDoc
forall a. Outputable a => a -> SDoc
ppr n
n, Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
')']
  ppr (Backticked n
n) = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat [Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'`', n -> SDoc
forall a. Outputable a => a -> SDoc
ppr n
n, Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'`']

showWrapped :: (a -> String) -> Wrap a -> String
showWrapped :: forall a. (a -> FilePath) -> Wrap a -> FilePath
showWrapped a -> FilePath
f (Unadorned a
n) = a -> FilePath
f a
n
showWrapped a -> FilePath
f (Parenthesized a
n) = FilePath
"(" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> FilePath
f a
n FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
")"
showWrapped a -> FilePath
f (Backticked a
n) = FilePath
"`" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> FilePath
f a
n FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"`"

instance HasOccName DocName where
  occName :: DocName -> OccName
occName = Name -> OccName
forall name. HasOccName name => name -> OccName
occName (Name -> OccName) -> (DocName -> Name) -> DocName -> OccName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocName -> Name
forall a. NamedThing a => a -> Name
getName

-----------------------------------------------------------------------------

-- * Instances

-----------------------------------------------------------------------------

-- | Stable name for stable comparisons. GHC's `Name` uses unstable
-- ordering based on their `Unique`'s.
newtype SName = SName Name
  deriving newtype (SName -> ()
(SName -> ()) -> NFData SName
forall a. (a -> ()) -> NFData a
$crnf :: SName -> ()
rnf :: SName -> ()
NFData)

instance Eq SName where
  SName Name
n1 == :: SName -> SName -> Bool
== SName Name
n2 = Name
n1 Name -> Name -> Ordering
`stableNameCmp` Name
n2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ

instance Ord SName where
  SName Name
n1 compare :: SName -> SName -> Ordering
`compare` SName Name
n2 = Name
n1 Name -> Name -> Ordering
`stableNameCmp` Name
n2

-- | Simplified type for sorting types, ignoring qualification (not visible
-- in Haddock output) and unifying special tycons with normal ones.
-- For the benefit of the user (looks nice and predictable) and the
-- tests (which prefer output to be deterministic).
data SimpleType
  = SimpleType SName [SimpleType]
  | SimpleIntTyLit Integer
  | SimpleStringTyLit String
  | SimpleCharTyLit Char
  deriving (SimpleType -> SimpleType -> Bool
(SimpleType -> SimpleType -> Bool)
-> (SimpleType -> SimpleType -> Bool) -> Eq SimpleType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SimpleType -> SimpleType -> Bool
== :: SimpleType -> SimpleType -> Bool
$c/= :: SimpleType -> SimpleType -> Bool
/= :: SimpleType -> SimpleType -> Bool
Eq, Eq SimpleType
Eq SimpleType =>
(SimpleType -> SimpleType -> Ordering)
-> (SimpleType -> SimpleType -> Bool)
-> (SimpleType -> SimpleType -> Bool)
-> (SimpleType -> SimpleType -> Bool)
-> (SimpleType -> SimpleType -> Bool)
-> (SimpleType -> SimpleType -> SimpleType)
-> (SimpleType -> SimpleType -> SimpleType)
-> Ord SimpleType
SimpleType -> SimpleType -> Bool
SimpleType -> SimpleType -> Ordering
SimpleType -> SimpleType -> SimpleType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SimpleType -> SimpleType -> Ordering
compare :: SimpleType -> SimpleType -> Ordering
$c< :: SimpleType -> SimpleType -> Bool
< :: SimpleType -> SimpleType -> Bool
$c<= :: SimpleType -> SimpleType -> Bool
<= :: SimpleType -> SimpleType -> Bool
$c> :: SimpleType -> SimpleType -> Bool
> :: SimpleType -> SimpleType -> Bool
$c>= :: SimpleType -> SimpleType -> Bool
>= :: SimpleType -> SimpleType -> Bool
$cmax :: SimpleType -> SimpleType -> SimpleType
max :: SimpleType -> SimpleType -> SimpleType
$cmin :: SimpleType -> SimpleType -> SimpleType
min :: SimpleType -> SimpleType -> SimpleType
Ord)

instance NFData SimpleType where
  rnf :: SimpleType -> ()
rnf SimpleType
st =
    case SimpleType
st of
      SimpleType SName
sn [SimpleType]
sts -> SName
sn SName -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` [SimpleType]
sts [SimpleType] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
      SimpleIntTyLit Integer
i -> Integer -> ()
forall a. NFData a => a -> ()
rnf Integer
i
      SimpleStringTyLit FilePath
s -> FilePath -> ()
forall a. NFData a => a -> ()
rnf FilePath
s
      SimpleCharTyLit Char
c -> Char -> ()
forall a. NFData a => a -> ()
rnf Char
c

-- | The three types of instances
data InstType name
  = ClassInst
      { forall name. InstType name -> [HsType name]
clsiCtx :: [HsType name]
      , forall name. InstType name -> LHsQTyVars name
clsiTyVars :: LHsQTyVars name
      , forall name. InstType name -> [Sig name]
clsiSigs :: [Sig name]
      , forall name. InstType name -> [DocInstance name]
clsiAssocTys :: [DocInstance name]
      }
  | -- | Body (right-hand side)
    TypeInst (Maybe (HsType name))
  | -- | Data constructors
    DataInst (TyClDecl name)

instance
  OutputableBndrId p
  => Outputable (InstType (GhcPass p))
  where
  ppr :: InstType (GhcPass p) -> SDoc
ppr (ClassInst{[DocInstance (GhcPass p)]
[HsType (GhcPass p)]
[Sig (GhcPass p)]
LHsQTyVars (GhcPass p)
clsiCtx :: forall name. InstType name -> [HsType name]
clsiTyVars :: forall name. InstType name -> LHsQTyVars name
clsiSigs :: forall name. InstType name -> [Sig name]
clsiAssocTys :: forall name. InstType name -> [DocInstance name]
clsiCtx :: [HsType (GhcPass p)]
clsiTyVars :: LHsQTyVars (GhcPass p)
clsiSigs :: [Sig (GhcPass p)]
clsiAssocTys :: [DocInstance (GhcPass p)]
..}) =
    FilePath -> SDoc
forall doc. IsLine doc => FilePath -> doc
text FilePath
"ClassInst"
      SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [HsType (GhcPass p)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [HsType (GhcPass p)]
clsiCtx
      SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> LHsQTyVars (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsQTyVars (GhcPass p)
clsiTyVars
      SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Sig (GhcPass p)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Sig (GhcPass p)]
clsiSigs
  ppr (TypeInst Maybe (HsType (GhcPass p))
a) = FilePath -> SDoc
forall doc. IsLine doc => FilePath -> doc
text FilePath
"TypeInst" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr Maybe (HsType (GhcPass p))
a
  ppr (DataInst TyClDecl (GhcPass p)
a) = FilePath -> SDoc
forall doc. IsLine doc => FilePath -> doc
text FilePath
"DataInst" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TyClDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyClDecl (GhcPass p)
a

-- | An instance head that may have documentation and a source location.
type DocInstance name = (InstHead name, Maybe (MDoc (IdP name)), Located (IdP name), Maybe Module)

-- | The head of an instance. Consists of a class name, a list of type
-- parameters (which may be annotated with kinds), and an instance type
data InstHead name = InstHead
  { forall name. InstHead name -> IdP name
ihdClsName :: IdP name
  , forall name. InstHead name -> [HsType name]
ihdTypes :: [HsType name]
  , forall name. InstHead name -> InstType name
ihdInstType :: InstType name
  }

-- | An instance origin information.
--
-- This is used primarily in HTML backend to generate unique instance
-- identifiers (for expandable sections).
data InstOrigin name
  = OriginClass name
  | OriginData name
  | OriginFamily name

instance NamedThing name => NamedThing (InstOrigin name) where
  getName :: InstOrigin name -> Name
getName (OriginClass name
name) = name -> Name
forall a. NamedThing a => a -> Name
getName name
name
  getName (OriginData name
name) = name -> Name
forall a. NamedThing a => a -> Name
getName name
name
  getName (OriginFamily name
name) = name -> Name
forall a. NamedThing a => a -> Name
getName name
name

-----------------------------------------------------------------------------

-- * Documentation comments

-----------------------------------------------------------------------------

type LDoc id = Located (Doc id)

type Doc id = DocH (Wrap (ModuleName, OccName)) (Wrap id)
type MDoc id = MetaDoc (Wrap (ModuleName, OccName)) (Wrap id)

type DocMarkup id a = DocMarkupH (Wrap (ModuleName, OccName)) id a

instance NFData MetaSince where
  rnf :: MetaSince -> ()
rnf (MetaSince Maybe FilePath
v Version
p) = Maybe FilePath
v Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Version
p Version -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData Meta where
  rnf :: Meta -> ()
rnf (Meta Maybe MetaSince
since) = Maybe MetaSince
since Maybe MetaSince -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (MDoc id) where
  rnf :: MDoc id -> ()
rnf (MetaDoc Meta
m DocH (Wrap (ModuleName, OccName)) (Wrap id)
d) = Meta
m Meta -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` DocH (Wrap (ModuleName, OccName)) (Wrap id)
d DocH (Wrap (ModuleName, OccName)) (Wrap id) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance
  (NFData a, NFData mod)
  => NFData (DocH mod a)
  where
  rnf :: DocH mod a -> ()
rnf DocH mod a
doc = case DocH mod a
doc of
    DocH mod a
DocEmpty -> ()
    DocAppend DocH mod a
a DocH mod a
b -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` DocH mod a
b DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocString FilePath
a -> FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocParagraph DocH mod a
a -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocIdentifier a
a -> a
a a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocIdentifierUnchecked mod
a -> mod
a mod -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocModule ModLink (DocH mod a)
a -> ModLink (DocH mod a)
a ModLink (DocH mod a) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocWarning DocH mod a
a -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocEmphasis DocH mod a
a -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocBold DocH mod a
a -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocMonospaced DocH mod a
a -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocUnorderedList [DocH mod a]
a -> [DocH mod a]
a [DocH mod a] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocOrderedList [(Int, DocH mod a)]
a -> [(Int, DocH mod a)]
a [(Int, DocH mod a)] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocDefList [(DocH mod a, DocH mod a)]
a -> [(DocH mod a, DocH mod a)]
a [(DocH mod a, DocH mod a)] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocCodeBlock DocH mod a
a -> DocH mod a
a DocH mod a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocHyperlink Hyperlink (DocH mod a)
a -> Hyperlink (DocH mod a)
a Hyperlink (DocH mod a) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocPic Picture
a -> Picture
a Picture -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocMathInline FilePath
a -> FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocMathDisplay FilePath
a -> FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocAName FilePath
a -> FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocProperty FilePath
a -> FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocExamples [Example]
a -> [Example]
a [Example] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocHeader Header (DocH mod a)
a -> Header (DocH mod a)
a Header (DocH mod a) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
    DocTable Table (DocH mod a)
a -> Table (DocH mod a)
a Table (DocH mod a) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (Header id) where
  rnf :: Header id -> ()
rnf (Header Int
a id
b) = Int
a Int -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` id
b id -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (Hyperlink id) where
  rnf :: Hyperlink id -> ()
rnf (Hyperlink FilePath
a Maybe id
b) = FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Maybe id
b Maybe id -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (ModLink id) where
  rnf :: ModLink id -> ()
rnf (ModLink FilePath
a Maybe id
b) = FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Maybe id
b Maybe id -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData Picture where
  rnf :: Picture -> ()
rnf (Picture FilePath
a Maybe FilePath
b) = FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Maybe FilePath
b Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData Example where
  rnf :: Example -> ()
rnf (Example FilePath
a [FilePath]
b) = FilePath
a FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` [FilePath]
b [FilePath] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (Table id) where
  rnf :: Table id -> ()
rnf (Table [TableRow id]
h [TableRow id]
b) = [TableRow id]
h [TableRow id] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` [TableRow id]
b [TableRow id] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (TableRow id) where
  rnf :: TableRow id -> ()
rnf (TableRow [TableCell id]
cs) = [TableCell id]
cs [TableCell id] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData id => NFData (TableCell id) where
  rnf :: TableCell id -> ()
rnf (TableCell Int
i Int
j id
c) = Int
i Int -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Int
j Int -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` id
c id -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

exampleToString :: Example -> String
exampleToString :: Example -> FilePath
exampleToString (Example FilePath
expression [FilePath]
result) =
  FilePath
">>> " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
expression FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"\n" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ [FilePath] -> FilePath
unlines [FilePath]
result

instance NFData name => NFData (HaddockModInfo name) where
  rnf :: HaddockModInfo name -> ()
rnf (HaddockModInfo{[Extension]
Maybe FilePath
Maybe Language
Maybe (Doc name)
hmi_description :: Maybe (Doc name)
hmi_copyright :: Maybe FilePath
hmi_license :: Maybe FilePath
hmi_maintainer :: Maybe FilePath
hmi_stability :: Maybe FilePath
hmi_portability :: Maybe FilePath
hmi_safety :: Maybe FilePath
hmi_language :: Maybe Language
hmi_extensions :: [Extension]
hmi_extensions :: forall name. HaddockModInfo name -> [Extension]
hmi_language :: forall name. HaddockModInfo name -> Maybe Language
hmi_safety :: forall name. HaddockModInfo name -> Maybe FilePath
hmi_portability :: forall name. HaddockModInfo name -> Maybe FilePath
hmi_stability :: forall name. HaddockModInfo name -> Maybe FilePath
hmi_maintainer :: forall name. HaddockModInfo name -> Maybe FilePath
hmi_license :: forall name. HaddockModInfo name -> Maybe FilePath
hmi_copyright :: forall name. HaddockModInfo name -> Maybe FilePath
hmi_description :: forall name. HaddockModInfo name -> Maybe (Doc name)
..}) =
    Maybe (Doc name)
hmi_description Maybe (Doc name) -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      Maybe FilePath
hmi_copyright Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        Maybe FilePath
hmi_license Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          Maybe FilePath
hmi_maintainer Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
            Maybe FilePath
hmi_stability Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
              Maybe FilePath
hmi_portability Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
                Maybe FilePath
hmi_safety Maybe FilePath -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
                  Maybe Language
hmi_language Maybe Language -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
                    [Extension]
hmi_extensions [Extension] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
                      ()

instance NFData LangExt.Extension

data HaddockModInfo name = HaddockModInfo
  { forall name. HaddockModInfo name -> Maybe (Doc name)
hmi_description :: Maybe (Doc name)
  , forall name. HaddockModInfo name -> Maybe FilePath
hmi_copyright :: Maybe String
  , forall name. HaddockModInfo name -> Maybe FilePath
hmi_license :: Maybe String
  , forall name. HaddockModInfo name -> Maybe FilePath
hmi_maintainer :: Maybe String
  , forall name. HaddockModInfo name -> Maybe FilePath
hmi_stability :: Maybe String
  , forall name. HaddockModInfo name -> Maybe FilePath
hmi_portability :: Maybe String
  , forall name. HaddockModInfo name -> Maybe FilePath
hmi_safety :: Maybe String
  , forall name. HaddockModInfo name -> Maybe Language
hmi_language :: Maybe Language
  , forall name. HaddockModInfo name -> [Extension]
hmi_extensions :: [LangExt.Extension]
  }

emptyHaddockModInfo :: HaddockModInfo a
emptyHaddockModInfo :: forall a. HaddockModInfo a
emptyHaddockModInfo =
  HaddockModInfo
    { hmi_description :: Maybe (Doc a)
hmi_description = Maybe (Doc a)
forall a. Maybe a
Nothing
    , hmi_copyright :: Maybe FilePath
hmi_copyright = Maybe FilePath
forall a. Maybe a
Nothing
    , hmi_license :: Maybe FilePath
hmi_license = Maybe FilePath
forall a. Maybe a
Nothing
    , hmi_maintainer :: Maybe FilePath
hmi_maintainer = Maybe FilePath
forall a. Maybe a
Nothing
    , hmi_stability :: Maybe FilePath
hmi_stability = Maybe FilePath
forall a. Maybe a
Nothing
    , hmi_portability :: Maybe FilePath
hmi_portability = Maybe FilePath
forall a. Maybe a
Nothing
    , hmi_safety :: Maybe FilePath
hmi_safety = Maybe FilePath
forall a. Maybe a
Nothing
    , hmi_language :: Maybe Language
hmi_language = Maybe Language
forall a. Maybe a
Nothing
    , hmi_extensions :: [Extension]
hmi_extensions = []
    }

-----------------------------------------------------------------------------

-- * Options

-----------------------------------------------------------------------------

-- | Source-level options for controlling the documentation.
data DocOption
  = -- | This module should not appear in the docs.
    OptHide
  | OptPrune
  | -- | Pretend everything is exported.
    OptIgnoreExports
  | -- | Not the best place to get docs for things
    -- exported by this module.
    OptNotHome
  | -- | Render enabled extensions for this module.
    OptShowExtensions
  | -- | Render runtime reps for this module (see
    -- the GHC @-fprint-explicit-runtime-reps@ flag)
    OptPrintRuntimeRep
  deriving (DocOption -> DocOption -> Bool
(DocOption -> DocOption -> Bool)
-> (DocOption -> DocOption -> Bool) -> Eq DocOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocOption -> DocOption -> Bool
== :: DocOption -> DocOption -> Bool
$c/= :: DocOption -> DocOption -> Bool
/= :: DocOption -> DocOption -> Bool
Eq, Int -> DocOption -> ShowS
[DocOption] -> ShowS
DocOption -> FilePath
(Int -> DocOption -> ShowS)
-> (DocOption -> FilePath)
-> ([DocOption] -> ShowS)
-> Show DocOption
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DocOption -> ShowS
showsPrec :: Int -> DocOption -> ShowS
$cshow :: DocOption -> FilePath
show :: DocOption -> FilePath
$cshowList :: [DocOption] -> ShowS
showList :: [DocOption] -> ShowS
Show)

-- | Option controlling how to qualify names
data QualOption
  = -- | Never qualify any names.
    OptNoQual
  | -- | Qualify all names fully.
    OptFullQual
  | -- | Qualify all imported names fully.
    OptLocalQual
  | -- | Like local, but strip module prefix
    --   from modules in the same hierarchy.
    OptRelativeQual

data Qualification
  = NoQual
  | FullQual
  | LocalQual Module
  | RelativeQual Module

makeContentsQual :: QualOption -> Qualification
makeContentsQual :: QualOption -> Qualification
makeContentsQual QualOption
qual =
  case QualOption
qual of
    QualOption
OptNoQual -> Qualification
NoQual
    QualOption
_ -> Qualification
FullQual

makeModuleQual :: QualOption -> Module -> Qualification
makeModuleQual :: QualOption -> Module -> Qualification
makeModuleQual QualOption
qual Module
mdl =
  case QualOption
qual of
    QualOption
OptLocalQual -> Module -> Qualification
LocalQual Module
mdl
    QualOption
OptRelativeQual -> Module -> Qualification
RelativeQual Module
mdl
    QualOption
OptFullQual -> Qualification
FullQual
    QualOption
OptNoQual -> Qualification
NoQual

-- | Whether to hide empty contexts
-- Since pattern synonyms have two contexts with different semantics, it is
-- important to all of them, even if one of them is empty.
data HideEmptyContexts
  = HideEmptyContexts
  | ShowEmptyToplevelContexts

-- | When to qualify @since@ annotations with their package
data SinceQual
  = Always
  | -- | only qualify when the thing being annotated is from
    -- an external package
    External

-----------------------------------------------------------------------------

-- * Renaming

-----------------------------------------------------------------------------

-- | Renames an identifier.
-- The first input is the identifier as it occurred in the comment
-- The second input is the possible namespaces of the identifier
type Renamer = String -> (NameSpace -> Bool) -> [Name]

-----------------------------------------------------------------------------

-- * Error handling

-----------------------------------------------------------------------------

-- | Haddock's own exception type.
data HaddockException
  = HaddockException String
  | WithContext [String] SomeException

instance Show HaddockException where
  show :: HaddockException -> FilePath
show (HaddockException FilePath
str) = FilePath
str
  show (WithContext [FilePath]
ctxts SomeException
se) = [FilePath] -> FilePath
unlines ([FilePath] -> FilePath) -> [FilePath] -> FilePath
forall a b. (a -> b) -> a -> b
$ [FilePath
"While " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
ctxt FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
":\n" | FilePath
ctxt <- [FilePath] -> [FilePath]
forall a. [a] -> [a]
reverse [FilePath]
ctxts] [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [SomeException -> FilePath
forall a. Show a => a -> FilePath
show SomeException
se]

throwE :: String -> a
instance Exception HaddockException
throwE :: forall a. FilePath -> a
throwE FilePath
str = HaddockException -> a
forall a e. (HasCallStack, Exception e) => e -> a
throw (FilePath -> HaddockException
HaddockException FilePath
str)

withExceptionContext :: MonadCatch m => String -> m a -> m a
withExceptionContext :: forall (m :: Type -> Type) a.
MonadCatch m =>
FilePath -> m a -> m a
withExceptionContext FilePath
ctxt =
  (HaddockException -> m a) -> m a -> m a
forall (m :: Type -> Type) e a.
(HasCallStack, MonadCatch m, Exception e) =>
(e -> m a) -> m a -> m a
handle
    ( \HaddockException
ex ->
        case HaddockException
ex of
          HaddockException FilePath
_ -> HaddockException -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: Type -> Type) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (HaddockException -> m a) -> HaddockException -> m a
forall a b. (a -> b) -> a -> b
$ [FilePath] -> SomeException -> HaddockException
WithContext [FilePath
ctxt] (HaddockException -> SomeException
forall e. Exception e => e -> SomeException
toException HaddockException
ex)
          WithContext [FilePath]
ctxts SomeException
se -> HaddockException -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: Type -> Type) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (HaddockException -> m a) -> HaddockException -> m a
forall a b. (a -> b) -> a -> b
$ [FilePath] -> SomeException -> HaddockException
WithContext (FilePath
ctxt FilePath -> [FilePath] -> [FilePath]
forall a. a -> [a] -> [a]
: [FilePath]
ctxts) SomeException
se
    )
    (m a -> m a) -> (m a -> m a) -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SomeException -> m a) -> m a -> m a
forall (m :: Type -> Type) e a.
(HasCallStack, MonadCatch m, Exception e) =>
(e -> m a) -> m a -> m a
handle (HaddockException -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: Type -> Type) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (HaddockException -> m a)
-> (SomeException -> HaddockException) -> SomeException -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FilePath] -> SomeException -> HaddockException
WithContext [FilePath
ctxt])

-----------------------------------------------------------------------------

-- * Pass sensitive types

-----------------------------------------------------------------------------

type instance XRec DocNameI a = GenLocated (Anno a) a
instance UnXRec DocNameI where
  unXRec :: forall a. XRec DocNameI a -> a
unXRec = XRec DocNameI a -> a
GenLocated (Anno a) a -> a
forall l e. GenLocated l e -> e
unLoc
instance MapXRec DocNameI where
  mapXRec :: forall a b.
(Anno a ~ Anno b) =>
(a -> b) -> XRec DocNameI a -> XRec DocNameI b
mapXRec = (a -> b) -> XRec DocNameI a -> XRec DocNameI b
(a -> b) -> GenLocated (Anno b) a -> GenLocated (Anno b) b
forall a b.
(a -> b) -> GenLocated (Anno b) a -> GenLocated (Anno b) b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
instance WrapXRec DocNameI (HsType DocNameI) where
  wrapXRec :: HsType DocNameI -> XRec DocNameI (HsType DocNameI)
wrapXRec = HsType DocNameI -> XRec DocNameI (HsType DocNameI)
HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA

type instance Anno DocName = SrcSpanAnnN
type instance Anno (HsTyVarBndr flag DocNameI) = SrcSpanAnnA
type instance Anno [LocatedA (HsType DocNameI)] = SrcSpanAnnC
type instance Anno (HsType DocNameI) = SrcSpanAnnA
type instance Anno (DataFamInstDecl DocNameI) = SrcSpanAnnA
type instance Anno (DerivStrategy DocNameI) = EpAnn NoEpAnns
type instance Anno (FieldOcc DocNameI) = SrcSpanAnnA
type instance Anno (ConDeclField DocNameI) = SrcSpan
type instance Anno (Located (ConDeclField DocNameI)) = SrcSpan
type instance Anno [Located (ConDeclField DocNameI)] = SrcSpan
type instance Anno (ConDecl DocNameI) = SrcSpan
type instance Anno (FunDep DocNameI) = SrcSpan
type instance Anno (TyFamInstDecl DocNameI) = SrcSpanAnnA
type instance Anno [LocatedA (TyFamInstDecl DocNameI)] = SrcSpanAnnL
type instance Anno (FamilyDecl DocNameI) = SrcSpan
type instance Anno (Sig DocNameI) = SrcSpan
type instance Anno (InjectivityAnn DocNameI) = EpAnn NoEpAnns
type instance Anno (HsDecl DocNameI) = SrcSpanAnnA
type instance Anno (FamilyResultSig DocNameI) = EpAnn NoEpAnns
type instance Anno (HsOuterTyVarBndrs Specificity DocNameI) = SrcSpanAnnA
type instance Anno (HsSigType DocNameI) = SrcSpanAnnA

type XRecCond a =
  ( XParTy a ~ AnnParen
  , NoGhcTc a ~ a
  , MapXRec a
  , UnXRec a
  , WrapXRec a (HsType a)
  )

type instance XValArg DocNameI = NoExtField
type instance XTypeArg DocNameI = NoExtField
type instance XArgPar DocNameI = NoExtField
type instance XXArg DocNameI = DataConCantHappen

type instance XBndrRequired DocNameI = NoExtField
type instance XBndrInvisible DocNameI = NoExtField
type instance XXBndrVis DocNameI = DataConCantHappen

type instance XUnrestrictedArrow _ DocNameI = NoExtField
type instance XLinearArrow _ DocNameI = NoExtField
type instance XExplicitMult _ DocNameI = NoExtField
type instance XXArrow _ DocNameI = DataConCantHappen

type instance XForAllTy DocNameI = EpAnn [AddEpAnn]
type instance XQualTy DocNameI = EpAnn [AddEpAnn]
type instance XTyVar DocNameI = EpAnn [AddEpAnn]
type instance XStarTy DocNameI = EpAnn [AddEpAnn]
type instance XAppTy DocNameI = EpAnn [AddEpAnn]
type instance XAppKindTy DocNameI = EpAnn [AddEpAnn]
type instance XFunTy DocNameI = EpAnn [AddEpAnn]
type instance XListTy DocNameI = EpAnn AnnParen
type instance XTupleTy DocNameI = EpAnn AnnParen
type instance XSumTy DocNameI = EpAnn AnnParen
type instance XOpTy DocNameI = EpAnn [AddEpAnn]
type instance XParTy DocNameI = AnnParen
type instance XIParamTy DocNameI = EpAnn [AddEpAnn]
type instance XKindSig DocNameI = EpAnn [AddEpAnn]
type instance XSpliceTy DocNameI = DataConCantHappen
type instance XDocTy DocNameI = EpAnn [AddEpAnn]
type instance XBangTy DocNameI = EpAnn [AddEpAnn]
type instance XRecTy DocNameI = EpAnn [AddEpAnn]
type instance XExplicitListTy DocNameI = EpAnn [AddEpAnn]
type instance XExplicitTupleTy DocNameI = EpAnn [AddEpAnn]
type instance XTyLit DocNameI = EpAnn [AddEpAnn]
type instance XWildCardTy DocNameI = EpAnn [AddEpAnn]
type instance XXType DocNameI = HsCoreTy

type instance XNumTy DocNameI = NoExtField
type instance XStrTy DocNameI = NoExtField
type instance XCharTy DocNameI = NoExtField
type instance XXTyLit DocNameI = DataConCantHappen

type instance XHsForAllVis DocNameI = NoExtField
type instance XHsForAllInvis DocNameI = NoExtField
type instance XXHsForAllTelescope DocNameI = DataConCantHappen

type instance XTyVarBndr DocNameI = NoExtField
type instance XXTyVarBndr DocNameI = DataConCantHappen

type instance XBndrVar DocNameI = NoExtField
type instance XBndrWildCard DocNameI = NoExtField
type instance XXBndrVar DocNameI = DataConCantHappen

type instance XBndrKind DocNameI = NoExtField
type instance XBndrNoKind DocNameI = NoExtField
type instance XXBndrKind DocNameI = DataConCantHappen

type instance XCFieldOcc DocNameI = DocName
type instance XXFieldOcc DocNameI = NoExtField

type instance XFixitySig DocNameI = NoExtField
type instance XFixSig DocNameI = NoExtField
type instance XPatSynSig DocNameI = NoExtField
type instance XClassOpSig DocNameI = NoExtField
type instance XTypeSig DocNameI = NoExtField
type instance XMinimalSig DocNameI = NoExtField

type instance XForeignExport DocNameI = NoExtField
type instance XForeignImport DocNameI = NoExtField

type instance XCImport DocNameI = NoExtField
type instance XCExport DocNameI = NoExtField

type instance XXForeignImport DocNameI = DataConCantHappen
type instance XXForeignExport DocNameI = DataConCantHappen

type instance XConDeclGADT DocNameI = NoExtField
type instance XConDeclH98 DocNameI = NoExtField
type instance XXConDecl DocNameI = DataConCantHappen

type instance XPrefixConGADT DocNameI = NoExtField
type instance XRecConGADT DocNameI = NoExtField
type instance XXConDeclGADTDetails DocNameI = DataConCantHappen

type instance XDerivD DocNameI = NoExtField
type instance XInstD DocNameI = NoExtField
type instance XForD DocNameI = NoExtField
type instance XSigD DocNameI = NoExtField
type instance XTyClD DocNameI = NoExtField

type instance XNoSig DocNameI = NoExtField
type instance XCKindSig DocNameI = NoExtField
type instance XTyVarSig DocNameI = NoExtField
type instance XXFamilyResultSig DocNameI = DataConCantHappen

type instance XCFamEqn DocNameI _ = NoExtField
type instance XXFamEqn DocNameI _ = DataConCantHappen

type instance XCClsInstDecl DocNameI = NoExtField
type instance XCDerivDecl DocNameI = NoExtField
type instance XStockStrategy DocNameI = NoExtField
type instance XAnyClassStrategy DocNameI = NoExtField
type instance XNewtypeStrategy DocNameI = NoExtField
type instance XViaStrategy DocNameI = LHsSigType DocNameI
type instance XDataFamInstD DocNameI = NoExtField
type instance XTyFamInstD DocNameI = NoExtField
type instance XClsInstD DocNameI = NoExtField
type instance XCHsDataDefn DocNameI = NoExtField
type instance XCFamilyDecl DocNameI = NoExtField
type instance XClassDecl DocNameI = NoExtField
type instance XDataDecl DocNameI = NoExtField
type instance XSynDecl DocNameI = NoExtField
type instance XFamDecl DocNameI = NoExtField
type instance XXFamilyDecl DocNameI = DataConCantHappen
type instance XXTyClDecl DocNameI = DataConCantHappen

type instance XHsWC DocNameI _ = NoExtField

type instance XHsOuterExplicit DocNameI _ = NoExtField
type instance XHsOuterImplicit DocNameI = NoExtField
type instance XXHsOuterTyVarBndrs DocNameI = DataConCantHappen

type instance XHsSig DocNameI = NoExtField
type instance XXHsSigType DocNameI = DataConCantHappen

type instance XHsQTvs DocNameI = NoExtField
type instance XConDeclField DocNameI = NoExtField
type instance XXConDeclField DocNameI = DataConCantHappen

type instance XXPat DocNameI = DataConCantHappen
type instance XXHsBindsLR DocNameI a = DataConCantHappen

type instance XSplicePat DocNameI = DataConCantHappen

type instance XCInjectivityAnn DocNameI = NoExtField

type instance XCFunDep DocNameI = NoExtField

type instance XCTyFamInstDecl DocNameI = NoExtField

-----------------------------------------------------------------------------

-- * NFData instances for GHC types

-----------------------------------------------------------------------------

instance NFData RdrName where
  rnf :: RdrName -> ()
rnf (Unqual OccName
on) = OccName -> ()
forall a. NFData a => a -> ()
rnf OccName
on
  rnf (Qual ModuleName
mn OccName
on) = ModuleName
mn ModuleName -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` OccName
on OccName -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
  rnf (Orig Module
m OccName
on) = Module
m Module -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` OccName
on OccName -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
  rnf (Exact Name
n) = Name -> ()
forall a. NFData a => a -> ()
rnf Name
n

instance NFData FixityDirection where
  rnf :: FixityDirection -> ()
rnf FixityDirection
InfixL = ()
  rnf FixityDirection
InfixR = ()
  rnf FixityDirection
InfixN = ()

instance NFData Fixity where
  rnf :: Fixity -> ()
rnf (Fixity Int
n FixityDirection
dir) =
    Int
n Int -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` FixityDirection
dir FixityDirection -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData (EpAnn NameAnn) where
  rnf :: EpAnn NameAnn -> ()
rnf (EpAnn EpaLocation
en NameAnn
ann EpAnnComments
cs) = EpaLocation
en EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` NameAnn
ann NameAnn -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` EpAnnComments
cs EpAnnComments -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData NameAnn where
  rnf :: NameAnn -> ()
rnf (NameAnn NameAdornment
a EpaLocation
b EpaLocation
c EpaLocation
d [TrailingAnn]
e) =
    NameAdornment
a NameAdornment -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      EpaLocation
b EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        EpaLocation
c EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          EpaLocation
d EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
            [TrailingAnn]
e [TrailingAnn] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
              ()
  rnf (NameAnnCommas NameAdornment
a EpaLocation
b [EpaLocation]
c EpaLocation
d [TrailingAnn]
e) =
    NameAdornment
a NameAdornment -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      EpaLocation
b EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        [EpaLocation]
c [EpaLocation] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          EpaLocation
d EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
            [TrailingAnn]
e [TrailingAnn] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
              ()
  rnf (NameAnnBars NameAdornment
a EpaLocation
b [EpaLocation]
c EpaLocation
d [TrailingAnn]
e) =
    NameAdornment
a NameAdornment -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      EpaLocation
b EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        [EpaLocation]
c [EpaLocation] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          EpaLocation
d EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
            [TrailingAnn]
e [TrailingAnn] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
              ()
  rnf (NameAnnOnly NameAdornment
a EpaLocation
b EpaLocation
c [TrailingAnn]
d) =
    NameAdornment
a NameAdornment -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      EpaLocation
b EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        EpaLocation
c EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          [TrailingAnn]
d [TrailingAnn] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
            ()
  rnf (NameAnnRArrow Bool
a Maybe EpaLocation
b EpaLocation
c Maybe EpaLocation
d [TrailingAnn]
e) =
    Bool
a Bool -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      Maybe EpaLocation
b Maybe EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        EpaLocation
c EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          Maybe EpaLocation
d Maybe EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
            [TrailingAnn]
e [TrailingAnn] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
              ()
  rnf (NameAnnQuote EpaLocation
a EpAnn NameAnn
b [TrailingAnn]
c) =
    EpaLocation
a EpaLocation -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
      EpAnn NameAnn
b EpAnn NameAnn -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
        [TrailingAnn]
c [TrailingAnn] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq`
          ()
  rnf (NameAnnTrailing [TrailingAnn]
a) = [TrailingAnn] -> ()
forall a. NFData a => a -> ()
rnf [TrailingAnn]
a

instance NFData TrailingAnn where
  rnf :: TrailingAnn -> ()
rnf (AddSemiAnn EpaLocation
epaL) = EpaLocation -> ()
forall a. NFData a => a -> ()
rnf EpaLocation
epaL
  rnf (AddCommaAnn EpaLocation
epaL) = EpaLocation -> ()
forall a. NFData a => a -> ()
rnf EpaLocation
epaL
  rnf (AddVbarAnn EpaLocation
epaL) = EpaLocation -> ()
forall a. NFData a => a -> ()
rnf EpaLocation
epaL
  rnf (AddDarrowAnn EpaLocation
epaL) = EpaLocation -> ()
forall a. NFData a => a -> ()
rnf EpaLocation
epaL
  rnf (AddDarrowUAnn EpaLocation
epaL) = EpaLocation -> ()
forall a. NFData a => a -> ()
rnf EpaLocation
epaL

instance NFData NameAdornment where
  rnf :: NameAdornment -> ()
rnf NameAdornment
NameParens = ()
  rnf NameAdornment
NameParensHash = ()
  rnf NameAdornment
NameBackquotes = ()
  rnf NameAdornment
NameSquare = ()

instance NFData NoComments where
  rnf :: NoComments -> ()
rnf NoComments
NoComments = ()

instance NFData a => NFData (EpaLocation' a) where
  rnf :: EpaLocation' a -> ()
rnf (EpaSpan SrcSpan
ss) = SrcSpan -> ()
forall a. NFData a => a -> ()
rnf SrcSpan
ss
  rnf (EpaDelta SrcSpan
ss DeltaPos
dp a
lc) = SrcSpan
ss SrcSpan -> () -> ()
forall a b. a -> b -> b
`seq` DeltaPos
dp DeltaPos -> () -> ()
forall a b. a -> b -> b
`seq` a
lc a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData EpAnnComments where
  rnf :: EpAnnComments -> ()
rnf (EpaComments [LEpaComment]
cs) = [LEpaComment] -> ()
forall a. NFData a => a -> ()
rnf [LEpaComment]
cs
  rnf (EpaCommentsBalanced [LEpaComment]
cs1 [LEpaComment]
cs2) = [LEpaComment]
cs1 [LEpaComment] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` [LEpaComment]
cs2 [LEpaComment] -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData EpaComment where
  rnf :: EpaComment -> ()
rnf (EpaComment EpaCommentTok
t RealSrcSpan
rss) = EpaCommentTok
t EpaCommentTok -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` RealSrcSpan
rss RealSrcSpan -> () -> ()
forall a b. a -> b -> b
`seq` ()

instance NFData EpaCommentTok where
  rnf :: EpaCommentTok -> ()
rnf (EpaDocComment HsDocString
ds) = HsDocString -> ()
forall a. NFData a => a -> ()
rnf HsDocString
ds
  rnf (EpaDocOptions FilePath
s) = FilePath -> ()
forall a. NFData a => a -> ()
rnf FilePath
s
  rnf (EpaLineComment FilePath
s) = FilePath -> ()
forall a. NFData a => a -> ()
rnf FilePath
s
  rnf (EpaBlockComment FilePath
s) = FilePath -> ()
forall a. NFData a => a -> ()
rnf FilePath
s

instance NFData a => NFData (Strict.Maybe a) where
  rnf :: Maybe a -> ()
rnf Maybe a
Strict.Nothing = ()
  rnf (Strict.Just a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x

instance NFData BufSpan where
  rnf :: BufSpan -> ()
rnf (BufSpan BufPos
p1 BufPos
p2) = BufPos
p1 BufPos -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` BufPos
p2 BufPos -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()

instance NFData BufPos where
  rnf :: BufPos -> ()
rnf (BufPos Int
n) = Int -> ()
forall a. NFData a => a -> ()
rnf Int
n

instance NFData DeltaPos where
  rnf :: DeltaPos -> ()
rnf (SameLine Int
n) = Int -> ()
forall a. NFData a => a -> ()
rnf Int
n
  rnf (DifferentLine Int
n Int
m) = Int
n Int -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` Int
m Int -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()