{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}

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

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

-- |
-- Module      :  Haddock.Interface.Rename
-- Copyright   :  (c) Simon Marlow 2003-2006,
--                    David Waern  2006-2009
-- License     :  BSD-like
--
-- Maintainer  :  haddock@projects.haskell.org
-- Stability   :  experimental
-- Portability :  portable
module Haddock.Interface.Rename (renameInterface) where

import Prelude hiding (mapM)

import Control.Applicative ()
import Control.DeepSeq (force)
import Control.Monad hiding (mapM)
import Control.Monad.Reader
import Control.Monad.Trans.Maybe (MaybeT (..), hoistMaybe)
import Control.Monad.Trans.Writer.CPS (WriterT, runWriterT)
import Control.Monad.Writer.Class
import Data.Foldable (traverse_)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Traversable (mapM)

import GHC hiding (NoLink, HsTypeGhcPsExt (..))
import GHC.Builtin.Types (eqTyCon_RDR, tupleDataConName, tupleTyConName)
import GHC.Core.TyCon (tyConResKind)
import GHC.Driver.DynFlags (getDynFlags)
import GHC.Types.Basic (Boxity (..), TopLevelFlag (..), TupleSort (..))
import GHC.Types.Name
import GHC.Types.Name.Reader (RdrName (Exact))
import Language.Haskell.Syntax.BooleanFormula(BooleanFormula(..))

import Haddock.Backends.Hoogle (ppExportD)
import Haddock.Convert (synifyKindSig)
import Haddock.GhcUtils
import Haddock.Types

-- | Traverse docstrings and ASTs in the Haddock interface, renaming 'Name' to
-- 'DocName'.
--
-- What this really boils down to is: for each 'Name', figure out which of the
-- modules that export the name is the preferred place to link to.
--
-- The renamed output gets written into fields in the Haddock interface record
-- that were previously left empty.
renameInterface
  :: Map.Map (Maybe String) (Set.Set String)
  -- ^ Ignored symbols. A map from module names to unqualified names. Module
  -- 'Just M' mapping to name 'f' means that link warnings should not be
  -- generated for occurances of specifically 'M.f'. Module 'Nothing' mapping to
  -- name 'f' means that link warnings should not be generated for any 'f'.
  -> LinkEnv
  -- ^ Link environment. A map from 'Name' to 'Module', where name 'n' maps to
  -- module 'M' if 'M' is the preferred link destination for name 'n'.
  -> ExportInfo
  -> Bool
  -- ^ Are warnings enabled?
  -> Bool
  -- ^ Is Hoogle output enabled?
  -> Interface
  -- ^ The interface we are renaming.
  -> Ghc Interface
  -- ^ The renamed interface. The 'Ghc' monad is used to look up type
  -- information and to get dynamic flags.
renameInterface :: Map (Maybe String) (Set String)
-> LinkEnv
-> ExportInfo
-> Bool
-> Bool
-> Interface
-> Ghc Interface
renameInterface Map (Maybe String) (Set String)
ignoreSet LinkEnv
renamingEnv ExportInfo
expInfo Bool
warnings Bool
hoogle Interface
iface = do
  (iface', warnedNames) <-
    Module
-> LinkEnv
-> Maybe ExportInfo
-> (Name -> Bool)
-> Bool
-> RnM Interface
-> Ghc (Interface, Set Name)
forall a.
Module
-> LinkEnv
-> Maybe ExportInfo
-> (Name -> Bool)
-> Bool
-> RnM a
-> Ghc (a, Set Name)
runRnM
      Module
mdl
      LinkEnv
localLinkEnv
      (ExportInfo
expInfo ExportInfo -> Maybe () -> Maybe ExportInfo
forall a b. a -> Maybe b -> Maybe a
forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ Bool -> Maybe ()
forall (f :: Type -> Type). Alternative f => Bool -> f ()
guard (DocOption
OptRedactTypeSyns DocOption -> [DocOption] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: Type -> Type) a.
(Foldable t, Eq a) =>
a -> t a -> Bool
`elem` Interface -> [DocOption]
ifaceOptions Interface
iface))
      Name -> Bool
warnName
      (Bool
hoogle Bool -> Bool -> Bool
&& Bool -> Bool
not (DocOption
OptHide DocOption -> [DocOption] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: Type -> Type) a.
(Foldable t, Eq a) =>
a -> t a -> Bool
`elem` Interface -> [DocOption]
ifaceOptions Interface
iface))
      (Interface -> RnM Interface
renameInterfaceRn Interface
iface)
  reportMissingLinks mdl warnedNames
  return iface'
  where
    -- The current module
    mdl :: Module
    mdl :: Module
mdl = Interface -> Module
ifaceMod Interface
iface

    -- The local link environment, where every name exported by this module is
    -- mapped to the module itself, and everything else comes from the global
    -- renaming env
    localLinkEnv :: LinkEnv
    localLinkEnv :: LinkEnv
localLinkEnv = (Name -> LinkEnv -> LinkEnv) -> LinkEnv -> [Name] -> LinkEnv
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Name -> LinkEnv -> LinkEnv
forall {k}. Ord k => k -> Map k Module -> Map k Module
f LinkEnv
renamingEnv (Interface -> [Name]
ifaceVisibleExports Interface
iface)
      where
        f :: k -> Map k Module -> Map k Module
f k
name !Map k Module
env = k -> Module -> Map k Module -> Map k Module
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert k
name Module
mdl Map k Module
env

    -- The function used to determine whether we should warn about a name
    -- which we do not find in the renaming environment
    warnName :: Name -> Bool
warnName Name
name =
      -- Warnings must be enabled
      Bool
warnings
        -- Current module must not be hidden from Haddock
        Bool -> Bool -> Bool
&& Bool -> Bool
not (DocOption
OptHide DocOption -> [DocOption] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: Type -> Type) a.
(Foldable t, Eq a) =>
a -> t a -> Bool
`elem` Interface -> [DocOption]
ifaceOptions Interface
iface)
        -- Must be an external name that is not built-in syntax, not a type
        -- variable, and not '~'
        Bool -> Bool -> Bool
&& Name -> Bool
isExternalName Name
name
        Bool -> Bool -> Bool
&& Bool -> Bool
not (Name -> Bool
isBuiltInSyntax Name
name)
        Bool -> Bool -> Bool
&& Bool -> Bool
not (Name -> Bool
isTyVarName Name
name)
        Bool -> Bool -> Bool
&& Name -> RdrName
Exact Name
name RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
/= RdrName
eqTyCon_RDR
        -- Must not be in the set of ignored symbols for the module or the
        -- unqualified ignored symbols
        Bool -> Bool -> Bool
&& Bool -> Bool
not (Name -> String
forall a. NamedThing a => a -> String
getOccString Name
name String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set String
ignoreSet')
      where
        -- The set of ignored symbols within the module this name is located
        -- in unioned with the set of globally ignored symbols
        ignoreSet' :: Set.Set String
        ignoreSet' :: Set String
ignoreSet' =
          Set String -> Set String -> Set String
forall a. Ord a => Set a -> Set a -> Set a
Set.union
            (Set String
-> Maybe String -> Map (Maybe String) (Set String) -> Set String
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault Set String
forall a. Set a
Set.empty (String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ Name -> String
modString Name
name) Map (Maybe String) (Set String)
ignoreSet)
            (Set String
-> Maybe String -> Map (Maybe String) (Set String) -> Set String
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault Set String
forall a. Set a
Set.empty Maybe String
forall a. Maybe a
Nothing Map (Maybe String) (Set String)
ignoreSet)

        modString :: Name -> String
        modString :: Name -> String
modString = Module -> String
moduleString (Module -> String) -> (Name -> Module) -> Name -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasDebugCallStack => Name -> Module
Name -> Module
nameModule

-- | Output warning messages indicating that the renamer could not find link
-- destinations for the names in the given set as they occur in the given
-- module.
reportMissingLinks :: Module -> Set.Set Name -> Ghc ()
reportMissingLinks :: Module -> Set Name -> Ghc ()
reportMissingLinks Module
mdl Set Name
names
  | Set Name -> Bool
forall a. Set a -> Bool
Set.null Set Name
names = () -> Ghc ()
forall a. a -> Ghc a
forall (m :: Type -> Type) a. Monad m => a -> m a
return ()
  | Bool
otherwise =
      IO () -> Ghc ()
forall a. IO a -> Ghc a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO () -> Ghc ()) -> IO () -> Ghc ()
forall a b. (a -> b) -> a -> b
$ do
        String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Warning: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Module -> String
moduleString Module
mdl String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": could not find link destinations for: "
        (Name -> IO ()) -> Set Name -> IO ()
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (String -> IO ()
putStrLn (String -> IO ()) -> (Name -> String) -> Name -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
"\t- " String -> String -> String
forall a. [a] -> [a] -> [a]
++) (String -> String) -> (Name -> String) -> Name -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> String
qualifiedName) Set Name
names
  where
    qualifiedName :: Name -> String
    qualifiedName :: Name -> String
qualifiedName Name
name = Module -> String
moduleString (HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
name) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Name -> String
forall a. NamedThing a => a -> String
getOccString Name
name

--------------------------------------------------------------------------------
-- Monad for renaming
--------------------------------------------------------------------------------

-- | A renaming monad which provides 'MonadReader' access to a renaming
-- environment, and 'MonadWriter' access to a 'Set' of names for which link
-- warnings should be generated, based on the renaming environment.
newtype RnM a = RnM {forall a. RnM a -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
unRnM :: ReaderT RnMEnv (WriterT (Set.Set Name) Ghc) a}
  deriving newtype ((forall a b. (a -> b) -> RnM a -> RnM b)
-> (forall a b. a -> RnM b -> RnM a) -> Functor RnM
forall a b. a -> RnM b -> RnM a
forall a b. (a -> b) -> RnM a -> RnM 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) -> RnM a -> RnM b
fmap :: forall a b. (a -> b) -> RnM a -> RnM b
$c<$ :: forall a b. a -> RnM b -> RnM a
<$ :: forall a b. a -> RnM b -> RnM a
Functor, Functor RnM
Functor RnM =>
(forall a. a -> RnM a)
-> (forall a b. RnM (a -> b) -> RnM a -> RnM b)
-> (forall a b c. (a -> b -> c) -> RnM a -> RnM b -> RnM c)
-> (forall a b. RnM a -> RnM b -> RnM b)
-> (forall a b. RnM a -> RnM b -> RnM a)
-> Applicative RnM
forall a. a -> RnM a
forall a b. RnM a -> RnM b -> RnM a
forall a b. RnM a -> RnM b -> RnM b
forall a b. RnM (a -> b) -> RnM a -> RnM b
forall a b c. (a -> b -> c) -> RnM a -> RnM b -> RnM c
forall (f :: Type -> Type).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> RnM a
pure :: forall a. a -> RnM a
$c<*> :: forall a b. RnM (a -> b) -> RnM a -> RnM b
<*> :: forall a b. RnM (a -> b) -> RnM a -> RnM b
$cliftA2 :: forall a b c. (a -> b -> c) -> RnM a -> RnM b -> RnM c
liftA2 :: forall a b c. (a -> b -> c) -> RnM a -> RnM b -> RnM c
$c*> :: forall a b. RnM a -> RnM b -> RnM b
*> :: forall a b. RnM a -> RnM b -> RnM b
$c<* :: forall a b. RnM a -> RnM b -> RnM a
<* :: forall a b. RnM a -> RnM b -> RnM a
Applicative, Applicative RnM
Applicative RnM =>
(forall a b. RnM a -> (a -> RnM b) -> RnM b)
-> (forall a b. RnM a -> RnM b -> RnM b)
-> (forall a. a -> RnM a)
-> Monad RnM
forall a. a -> RnM a
forall a b. RnM a -> RnM b -> RnM b
forall a b. RnM a -> (a -> RnM b) -> RnM b
forall (m :: Type -> Type).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. RnM a -> (a -> RnM b) -> RnM b
>>= :: forall a b. RnM a -> (a -> RnM b) -> RnM b
$c>> :: forall a b. RnM a -> RnM b -> RnM b
>> :: forall a b. RnM a -> RnM b -> RnM b
$creturn :: forall a. a -> RnM a
return :: forall a. a -> RnM a
Monad, MonadReader RnMEnv, MonadWriter (Set.Set Name))

liftGhc :: Ghc a -> RnM a
liftGhc :: forall a. Ghc a -> RnM a
liftGhc = ReaderT RnMEnv (WriterT (Set Name) Ghc) a -> RnM a
forall a. ReaderT RnMEnv (WriterT (Set Name) Ghc) a -> RnM a
RnM (ReaderT RnMEnv (WriterT (Set Name) Ghc) a -> RnM a)
-> (Ghc a -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a)
-> Ghc a
-> RnM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT (Set Name) Ghc a
-> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
forall (m :: Type -> Type) a. Monad m => m a -> ReaderT RnMEnv m a
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (WriterT (Set Name) Ghc a
 -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a)
-> (Ghc a -> WriterT (Set Name) Ghc a)
-> Ghc a
-> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ghc a -> WriterT (Set Name) Ghc a
forall (m :: Type -> Type) a.
Monad m =>
m a -> WriterT (Set Name) m a
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift

-- | The renaming monad environment. Stores the linking environment (mapping
-- names to modules), the link warning predicate, and the current module.
data RnMEnv = RnMEnv
  { RnMEnv -> LinkEnv
rnLinkEnv :: LinkEnv
  -- ^ The linking environment (map from names to modules)
  , RnMEnv -> Maybe ExportInfo
rnExportInfo :: Maybe ExportInfo
  -- ^ Information about exported names and modules, only if
  -- redact-type-synonyms is enabled
  , RnMEnv -> Name -> Bool
rnWarnName :: (Name -> Bool)
  -- ^ Link warning predicate (whether failing to find a link destination
  -- for a given name should result in a warning)
  , RnMEnv -> String
rnModuleString :: String
  -- ^ The current module
  , RnMEnv -> Bool
rnHoogleOutput :: Bool
  -- ^ Should Hoogle output be generated for this module?
  }

-- | Run the renamer action in a renaming environment built using the given
-- module, link env, and link warning predicate. Returns the renamed value along
-- with a set of 'Name's that were not renamed and should be warned for (i.e.
-- they satisfied the link warning predicate).
runRnM :: Module -> LinkEnv -> Maybe ExportInfo -> (Name -> Bool) -> Bool -> RnM a -> Ghc (a, Set.Set Name)
runRnM :: forall a.
Module
-> LinkEnv
-> Maybe ExportInfo
-> (Name -> Bool)
-> Bool
-> RnM a
-> Ghc (a, Set Name)
runRnM Module
mdl LinkEnv
linkEnv Maybe ExportInfo
mbExpInfo Name -> Bool
warnName Bool
hoogleOutput RnM a
rn =
  WriterT (Set Name) Ghc a -> Ghc (a, Set Name)
forall w (m :: Type -> Type) a.
Monoid w =>
WriterT w m a -> m (a, w)
runWriterT (WriterT (Set Name) Ghc a -> Ghc (a, Set Name))
-> WriterT (Set Name) Ghc a -> Ghc (a, Set Name)
forall a b. (a -> b) -> a -> b
$ ReaderT RnMEnv (WriterT (Set Name) Ghc) a
-> RnMEnv -> WriterT (Set Name) Ghc a
forall r (m :: Type -> Type) a. ReaderT r m a -> r -> m a
runReaderT (RnM a -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
forall a. RnM a -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
unRnM RnM a
rn) RnMEnv
rnEnv
  where
    rnEnv :: RnMEnv
    rnEnv :: RnMEnv
rnEnv =
      RnMEnv
        { rnLinkEnv :: LinkEnv
rnLinkEnv = LinkEnv
linkEnv
        , rnExportInfo :: Maybe ExportInfo
rnExportInfo = Maybe ExportInfo
mbExpInfo
        , rnWarnName :: Name -> Bool
rnWarnName = Name -> Bool
warnName
        , rnModuleString :: String
rnModuleString = Module -> String
moduleString Module
mdl
        , rnHoogleOutput :: Bool
rnHoogleOutput = Bool
hoogleOutput
        }

--------------------------------------------------------------------------------
-- Renaming
--------------------------------------------------------------------------------

-- | Rename an `Interface` in the renaming environment.
renameInterfaceRn :: Interface -> RnM Interface
renameInterfaceRn :: Interface -> RnM Interface
renameInterfaceRn Interface
iface = do
  exportItems <- [ExportItem GhcRn] -> RnM [ExportItem DocNameI]
renameExportItems (Interface -> [ExportItem GhcRn]
ifaceExportItems Interface
iface)
  orphans <- mapM renameDocInstance (ifaceOrphanInstances iface)
  finalModDoc <- renameDocumentation (ifaceDoc iface)
  pure $!
    iface
      { ifaceRnDoc = finalModDoc
      , -- The un-renamed export items are not used after renaming
        ifaceRnExportItems = exportItems
      , ifaceExportItems = []
      , -- The un-renamed orphan instances are not used after renaming
        ifaceRnOrphanInstances = orphans
      , ifaceOrphanInstances = []
      }

-- | Lookup a 'Name' in the renaming environment.
lookupRn :: Name -> RnM DocName
lookupRn :: Name -> RnM DocName
lookupRn Name
name = ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName -> RnM DocName
forall a. ReaderT RnMEnv (WriterT (Set Name) Ghc) a -> RnM a
RnM (ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName -> RnM DocName)
-> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName -> RnM DocName
forall a b. (a -> b) -> a -> b
$ do
  linkEnv <- (RnMEnv -> LinkEnv)
-> ReaderT RnMEnv (WriterT (Set Name) Ghc) LinkEnv
forall r (m :: Type -> Type) a. MonadReader r m => (r -> a) -> m a
asks RnMEnv -> LinkEnv
rnLinkEnv
  case Map.lookup name linkEnv of
    Maybe Module
Nothing -> DocName -> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName
forall a. a -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (DocName -> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName)
-> DocName -> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName
forall a b. (a -> b) -> a -> b
$ Name -> DocName
Undocumented Name
name
    Just Module
mdl -> DocName -> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName
forall a. a -> ReaderT RnMEnv (WriterT (Set Name) Ghc) a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (DocName -> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName)
-> DocName -> ReaderT RnMEnv (WriterT (Set Name) Ghc) DocName
forall a b. (a -> b) -> a -> b
$ Name -> Module -> DocName
Documented Name
name Module
mdl

-- | Rename a 'Name' in the renaming environment. This is very similar to
-- 'lookupRn', but tracks any names not found in the renaming environment if the
-- `rnWarnName` predicate is true.
renameName :: Name -> RnM DocName
renameName :: Name -> RnM DocName
renameName Name
name = do
  warnName <- (RnMEnv -> Name -> Bool) -> RnM (Name -> Bool)
forall r (m :: Type -> Type) a. MonadReader r m => (r -> a) -> m a
asks RnMEnv -> Name -> Bool
rnWarnName
  docName <- lookupRn name
  case docName of
    Undocumented Name
_ -> do
      Bool -> RnM () -> RnM ()
forall (f :: Type -> Type). Applicative f => Bool -> f () -> f ()
when (Name -> Bool
warnName Name
name) (RnM () -> RnM ()) -> RnM () -> RnM ()
forall a b. (a -> b) -> a -> b
$
        Set Name -> RnM ()
forall w (m :: Type -> Type). MonadWriter w m => w -> m ()
tell (Set Name -> RnM ()) -> Set Name -> RnM ()
forall a b. (a -> b) -> a -> b
$
          Name -> Set Name
forall a. a -> Set a
Set.singleton Name
name
      DocName -> RnM DocName
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return DocName
docName
    DocName
_ -> DocName -> RnM DocName
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return DocName
docName

-- | Rename a located 'Name' in the current renaming environment.
renameNameL :: GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL :: forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL = (Name -> RnM DocName)
-> GenLocated l Name -> RnM (GenLocated l DocName)
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> GenLocated l a -> m (GenLocated l b)
mapM Name -> RnM DocName
renameName

-- | Rename a list of export items in the current renaming environment.
renameExportItems :: [ExportItem GhcRn] -> RnM [ExportItem DocNameI]
renameExportItems :: [ExportItem GhcRn] -> RnM [ExportItem DocNameI]
renameExportItems = (ExportItem GhcRn -> RnM (ExportItem DocNameI))
-> [ExportItem GhcRn] -> RnM [ExportItem DocNameI]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM ExportItem GhcRn -> RnM (ExportItem DocNameI)
renameExportItem

-- | Rename an 'ExportItem' in the current renaming environment.
renameExportItem :: ExportItem GhcRn -> RnM (ExportItem DocNameI)
renameExportItem :: ExportItem GhcRn -> RnM (ExportItem DocNameI)
renameExportItem ExportItem GhcRn
item = case ExportItem GhcRn
item of
  ExportModule Module
mdl -> ExportItem DocNameI -> RnM (ExportItem DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (Module -> ExportItem DocNameI
forall name. Module -> ExportItem name
ExportModule Module
mdl)
  ExportGroup Int
lev String
id_ Doc (IdP GhcRn)
doc -> do
    doc' <- DocH (Wrap (ModuleName, OccName)) (Wrap Name)
-> RnM (DocH (Wrap (ModuleName, OccName)) (Wrap DocName))
forall (t :: Type -> Type).
Traversable t =>
t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc Doc (IdP GhcRn)
DocH (Wrap (ModuleName, OccName)) (Wrap Name)
doc
    return (ExportGroup lev id_ doc')
  ExportDecl ed :: XExportDecl GhcRn
ed@(ExportD LHsDecl GhcRn
decl [(HsDecl GhcRn, DocForDecl (IdP GhcRn))]
pats DocForDecl (IdP GhcRn)
doc [(IdP GhcRn, DocForDecl (IdP GhcRn))]
subs [DocInstance GhcRn]
instances [(IdP GhcRn, Fixity)]
fixities Bool
splice) -> do
    -- If Hoogle output should be generated, generate it
    RnMEnv{..} <- RnM RnMEnv
forall r (m :: Type -> Type). MonadReader r m => m r
ask
    dflags0 <- liftGhc getDynFlags
    let !hoogleOut =
          [String] -> [String]
forall a. NFData a => a -> a
force ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$
            if Bool
rnHoogleOutput
              then
                -- Since Hoogle is line based, we want to avoid breaking long lines.
                let dflags :: DynFlags
dflags = DynFlags
dflags0{pprCols = maxBound}
                 in DynFlags -> ExportD GhcRn -> [String]
ppExportD DynFlags
dflags ExportD GhcRn
XExportDecl GhcRn
ed
              else []

    decl' <- renameLDecl decl
    pats' <- renamePats pats
    doc' <- renameDocForDecl doc
    subs' <- mapM renameSub subs
    instances' <- forM instances renameDocInstance
    fixities' <- forM fixities $ \(Name
name, Fixity
fixity) -> do
      name' <- Name -> RnM DocName
lookupRn Name
name
      return (name', fixity)

    return $
      ExportDecl
        RnExportD
          { rnExpDExpD = ExportD decl' pats' doc' subs' instances' fixities' splice
          , rnExpDHoogle = hoogleOut
          }
  ExportNoDecl IdP GhcRn
x [IdP GhcRn]
subs -> do
    x' <- Name -> RnM DocName
lookupRn IdP GhcRn
Name
x
    subs' <- mapM lookupRn subs
    return (ExportNoDecl x' subs')
  ExportDoc MDoc (IdP GhcRn)
doc -> do
    doc' <- MDoc Name -> RnM (MDoc DocName)
forall (t :: Type -> Type).
Traversable t =>
t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc MDoc (IdP GhcRn)
MDoc Name
doc
    return (ExportDoc doc')

renameDocForDecl :: DocForDecl Name -> RnM (DocForDecl DocName)
renameDocForDecl :: DocForDecl Name -> RnM (DocForDecl DocName)
renameDocForDecl (Documentation Name
doc, FnArgsDoc Name
fnArgsDoc) =
  (,) (Documentation DocName -> FnArgsDoc DocName -> DocForDecl DocName)
-> RnM (Documentation DocName)
-> RnM (FnArgsDoc DocName -> DocForDecl DocName)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Documentation Name -> RnM (Documentation DocName)
renameDocumentation Documentation Name
doc RnM (FnArgsDoc DocName -> DocForDecl DocName)
-> RnM (FnArgsDoc DocName) -> RnM (DocForDecl DocName)
forall a b. RnM (a -> b) -> RnM a -> RnM b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> FnArgsDoc Name -> RnM (FnArgsDoc DocName)
renameFnArgsDoc FnArgsDoc Name
fnArgsDoc

renameDocumentation :: Documentation Name -> RnM (Documentation DocName)
renameDocumentation :: Documentation Name -> RnM (Documentation DocName)
renameDocumentation (Documentation Maybe (MDoc Name)
mDoc Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap Name))
mWarning) =
  Maybe (MDoc DocName)
-> Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap DocName))
-> Documentation DocName
forall name.
Maybe (MDoc name) -> Maybe (Doc name) -> Documentation name
Documentation (Maybe (MDoc DocName)
 -> Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap DocName))
 -> Documentation DocName)
-> RnM (Maybe (MDoc DocName))
-> RnM
     (Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap DocName))
      -> Documentation DocName)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (MDoc Name -> RnM (MDoc DocName))
-> Maybe (MDoc Name) -> RnM (Maybe (MDoc DocName))
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
mapM MDoc Name -> RnM (MDoc DocName)
forall (t :: Type -> Type).
Traversable t =>
t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc Maybe (MDoc Name)
mDoc RnM
  (Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap DocName))
   -> Documentation DocName)
-> RnM (Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap DocName)))
-> RnM (Documentation DocName)
forall a b. RnM (a -> b) -> RnM a -> RnM b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> (DocH (Wrap (ModuleName, OccName)) (Wrap Name)
 -> RnM (DocH (Wrap (ModuleName, OccName)) (Wrap DocName)))
-> Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap Name))
-> RnM (Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap DocName)))
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
mapM DocH (Wrap (ModuleName, OccName)) (Wrap Name)
-> RnM (DocH (Wrap (ModuleName, OccName)) (Wrap DocName))
forall (t :: Type -> Type).
Traversable t =>
t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc Maybe (DocH (Wrap (ModuleName, OccName)) (Wrap Name))
mWarning

renameLDocHsSyn :: Located (WithHsDocIdentifiers HsDocString a) -> RnM (Located (WithHsDocIdentifiers HsDocString b))
renameLDocHsSyn :: forall a b.
Located (WithHsDocIdentifiers HsDocString a)
-> RnM (Located (WithHsDocIdentifiers HsDocString b))
renameLDocHsSyn (L SrcSpan
l WithHsDocIdentifiers HsDocString a
doc) = Located (WithHsDocIdentifiers HsDocString b)
-> RnM (Located (WithHsDocIdentifiers HsDocString b))
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (SrcSpan
-> WithHsDocIdentifiers HsDocString b
-> Located (WithHsDocIdentifiers HsDocString b)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (HsDocString
-> [Located (IdP b)] -> WithHsDocIdentifiers HsDocString b
forall a pass.
a -> [Located (IdP pass)] -> WithHsDocIdentifiers a pass
WithHsDocIdentifiers (WithHsDocIdentifiers HsDocString a -> HsDocString
forall a pass. WithHsDocIdentifiers a pass -> a
hsDocString WithHsDocIdentifiers HsDocString a
doc) []))

renameDoc :: Traversable t => t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc :: forall (t :: Type -> Type).
Traversable t =>
t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc = (Wrap Name -> RnM (Wrap DocName))
-> t (Wrap Name) -> RnM (t (Wrap DocName))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b)
traverse ((Name -> RnM DocName) -> Wrap Name -> RnM (Wrap DocName)
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Wrap a -> f (Wrap b)
traverse Name -> RnM DocName
renameName)

renameFnArgsDoc :: FnArgsDoc Name -> RnM (FnArgsDoc DocName)
renameFnArgsDoc :: FnArgsDoc Name -> RnM (FnArgsDoc DocName)
renameFnArgsDoc = (MDoc Name -> RnM (MDoc DocName))
-> FnArgsDoc Name -> RnM (FnArgsDoc DocName)
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Map Int a -> m (Map Int b)
mapM MDoc Name -> RnM (MDoc DocName)
forall (t :: Type -> Type).
Traversable t =>
t (Wrap Name) -> RnM (t (Wrap DocName))
renameDoc

renameLType :: LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType :: LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType = (HsType GhcRn -> RnM (HsType DocNameI))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b)
-> GenLocated SrcSpanAnnA a -> m (GenLocated SrcSpanAnnA b)
mapM HsType GhcRn -> RnM (HsType DocNameI)
renameType

renameLTypeArg :: LHsTypeArg GhcRn -> RnM (LHsTypeArg DocNameI)
renameLTypeArg :: LHsTypeArg GhcRn -> RnM (LHsTypeArg DocNameI)
renameLTypeArg (HsValArg XValArg GhcRn
_ LHsType GhcRn
ty) = do
  ty' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
ty
  return $ HsValArg noExtField ty'
renameLTypeArg (HsTypeArg XTypeArg GhcRn
_ LHsType GhcRn
ki) = do
  ki' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLKind LHsType GhcRn
ki
  return $ HsTypeArg noExtField ki'
renameLTypeArg (HsArgPar XArgPar GhcRn
_) = LHsTypeArg DocNameI -> RnM (LHsTypeArg DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (LHsTypeArg DocNameI -> RnM (LHsTypeArg DocNameI))
-> LHsTypeArg DocNameI -> RnM (LHsTypeArg DocNameI)
forall a b. (a -> b) -> a -> b
$ XArgPar DocNameI -> LHsTypeArg DocNameI
forall p tm ty. XArgPar p -> HsArg p tm ty
HsArgPar NoExtField
XArgPar DocNameI
noExtField

renameLSigType :: LHsSigType GhcRn -> RnM (LHsSigType DocNameI)
renameLSigType :: LHsSigType GhcRn -> RnM (LHsSigType DocNameI)
renameLSigType = (HsSigType GhcRn -> RnM (HsSigType DocNameI))
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsSigType DocNameI))
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b)
-> GenLocated SrcSpanAnnA a -> m (GenLocated SrcSpanAnnA b)
mapM HsSigType GhcRn -> RnM (HsSigType DocNameI)
renameSigType

renameLSigWcType :: LHsSigWcType GhcRn -> RnM (LHsSigWcType DocNameI)
renameLSigWcType :: LHsSigWcType GhcRn -> RnM (LHsSigWcType DocNameI)
renameLSigWcType = (GenLocated SrcSpanAnnA (HsSigType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsSigType DocNameI)))
-> HsWildCardBndrs GhcRn (GenLocated SrcSpanAnnA (HsSigType GhcRn))
-> RnM
     (HsWildCardBndrs
        DocNameI (GenLocated SrcSpanAnnA (HsSigType DocNameI)))
forall in_thing out_thing.
(in_thing -> RnM out_thing)
-> HsWildCardBndrs GhcRn in_thing
-> RnM (HsWildCardBndrs DocNameI out_thing)
renameWc LHsSigType GhcRn -> RnM (LHsSigType DocNameI)
GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsSigType DocNameI))
renameLSigType

renameLKind :: LHsKind GhcRn -> RnM (LHsKind DocNameI)
renameLKind :: LHsType GhcRn -> RnM (LHsType DocNameI)
renameLKind = LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType

renameMaybeLKind :: Maybe (LHsKind GhcRn) -> RnM (Maybe (LHsKind DocNameI))
renameMaybeLKind :: Maybe (LHsType GhcRn) -> RnM (Maybe (LHsType DocNameI))
renameMaybeLKind = (GenLocated SrcSpanAnnA (HsType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsType DocNameI)))
-> Maybe (GenLocated SrcSpanAnnA (HsType GhcRn))
-> RnM (Maybe (GenLocated SrcSpanAnnA (HsType DocNameI)))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse LHsType GhcRn -> RnM (LHsType DocNameI)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
renameLKind

renameFamilyResultSig :: LFamilyResultSig GhcRn -> RnM (LFamilyResultSig DocNameI)
renameFamilyResultSig :: LFamilyResultSig GhcRn -> RnM (LFamilyResultSig DocNameI)
renameFamilyResultSig (L EpAnn NoEpAnns
loc (NoSig XNoSig GhcRn
_)) =
  GenLocated (EpAnn NoEpAnns) (FamilyResultSig DocNameI)
-> RnM (GenLocated (EpAnn NoEpAnns) (FamilyResultSig DocNameI))
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (EpAnn NoEpAnns
-> FamilyResultSig DocNameI
-> GenLocated (EpAnn NoEpAnns) (FamilyResultSig DocNameI)
forall l e. l -> e -> GenLocated l e
L EpAnn NoEpAnns
loc (XNoSig DocNameI -> FamilyResultSig DocNameI
forall pass. XNoSig pass -> FamilyResultSig pass
NoSig XNoSig DocNameI
NoExtField
noExtField))
renameFamilyResultSig (L EpAnn NoEpAnns
loc (KindSig XCKindSig GhcRn
_ LHsType GhcRn
ki)) =
  do
    ki' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLKind LHsType GhcRn
ki
    return (L loc (KindSig noExtField ki'))
renameFamilyResultSig (L EpAnn NoEpAnns
loc (TyVarSig XTyVarSig GhcRn
_ LHsTyVarBndr () GhcRn
bndr)) =
  do
    bndr' <- (() -> RnM ())
-> LHsTyVarBndr () GhcRn -> RnM (LHsTyVarBndr () DocNameI)
forall flag flag'.
(flag -> RnM flag')
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr () -> RnM ()
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return LHsTyVarBndr () GhcRn
bndr
    return (L loc (TyVarSig noExtField bndr'))

renameInjectivityAnn :: LInjectivityAnn GhcRn -> RnM (LInjectivityAnn DocNameI)
renameInjectivityAnn :: LInjectivityAnn GhcRn -> RnM (LInjectivityAnn DocNameI)
renameInjectivityAnn (L EpAnn NoEpAnns
loc (InjectivityAnn XCInjectivityAnn GhcRn
_ LIdP GhcRn
lhs [LIdP GhcRn]
rhs)) =
  do
    lhs' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
lhs
    rhs' <- mapM renameNameL rhs
    return (L loc (InjectivityAnn noExtField lhs' rhs'))

renameMaybeInjectivityAnn
  :: Maybe (LInjectivityAnn GhcRn)
  -> RnM (Maybe (LInjectivityAnn DocNameI))
renameMaybeInjectivityAnn :: Maybe (LInjectivityAnn GhcRn)
-> RnM (Maybe (LInjectivityAnn DocNameI))
renameMaybeInjectivityAnn = (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn)
 -> RnM (GenLocated (EpAnn NoEpAnns) (InjectivityAnn DocNameI)))
-> Maybe (GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn))
-> RnM
     (Maybe (GenLocated (EpAnn NoEpAnns) (InjectivityAnn DocNameI)))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse LInjectivityAnn GhcRn -> RnM (LInjectivityAnn DocNameI)
GenLocated (EpAnn NoEpAnns) (InjectivityAnn GhcRn)
-> RnM (GenLocated (EpAnn NoEpAnns) (InjectivityAnn DocNameI))
renameInjectivityAnn

renameMultAnn :: HsMultAnn GhcRn -> RnM (HsMultAnn DocNameI)
renameMultAnn :: HsMultAnn GhcRn -> RnM (HsMultAnn DocNameI)
renameMultAnn (HsUnannotated XUnannotated (LHsType (NoGhcTc GhcRn)) GhcRn
_) = HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
-> RnM
     (HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XUnannotated (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
-> HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
forall mult pass. XUnannotated mult pass -> HsMultAnnOf mult pass
HsUnannotated NoExtField
XUnannotated (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
noExtField)
renameMultAnn (HsLinearAnn XLinearAnn (LHsType (NoGhcTc GhcRn)) GhcRn
_) = HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
-> RnM
     (HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XLinearAnn (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
-> HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
forall mult pass. XLinearAnn mult pass -> HsMultAnnOf mult pass
HsLinearAnn NoExtField
XLinearAnn (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
noExtField)
renameMultAnn (HsExplicitMult XExplicitMult (LHsType (NoGhcTc GhcRn)) GhcRn
_ LHsType (NoGhcTc GhcRn)
p) = XExplicitMult (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
-> GenLocated SrcSpanAnnA (HsType DocNameI)
-> HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
forall mult pass.
XExplicitMult mult pass -> mult -> HsMultAnnOf mult pass
HsExplicitMult NoExtField
XExplicitMult (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI
noExtField (GenLocated SrcSpanAnnA (HsType DocNameI)
 -> HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
-> RnM
     (HsMultAnnOf (GenLocated SrcSpanAnnA (HsType DocNameI)) DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType (NoGhcTc GhcRn)
LHsType GhcRn
p

renameType :: HsType GhcRn -> RnM (HsType DocNameI)
renameType :: HsType GhcRn -> RnM (HsType DocNameI)
renameType HsType GhcRn
t = case HsType GhcRn
t of
  HsForAllTy{hst_tele :: forall pass. HsType pass -> HsForAllTelescope pass
hst_tele = HsForAllTelescope GhcRn
tele, hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsType GhcRn
ltype} -> do
    tele' <- HsForAllTelescope GhcRn -> RnM (HsForAllTelescope DocNameI)
renameHsForAllTelescope HsForAllTelescope GhcRn
tele
    ltype' <- renameLType ltype
    return
      ( HsForAllTy
          { hst_xforall = noAnn
          , hst_tele = tele'
          , hst_body = ltype'
          }
      )
  HsQualTy{hst_ctxt :: forall pass. HsType pass -> LHsContext pass
hst_ctxt = LHsContext GhcRn
lcontext, hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsType GhcRn
ltype} -> do
    lcontext' <- LocatedC [LHsType GhcRn] -> RnM (LocatedC [LHsType DocNameI])
renameLContext LHsContext GhcRn
LocatedC [LHsType GhcRn]
lcontext
    ltype' <- renameLType ltype
    return (HsQualTy{hst_xqual = noAnn, hst_ctxt = lcontext', hst_body = ltype'})
  HsTyVar XTyVar GhcRn
_ PromotionFlag
ip (L SrcSpanAnnN
l WithUserRdr Name
n) -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (HsType DocNameI -> RnM (HsType DocNameI))
-> (DocName -> HsType DocNameI) -> DocName -> RnM (HsType DocNameI)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XTyVar DocNameI
-> PromotionFlag -> LIdOccP DocNameI -> HsType DocNameI
forall pass.
XTyVar pass -> PromotionFlag -> LIdOccP pass -> HsType pass
HsTyVar XTyVar DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn PromotionFlag
ip (GenLocated SrcSpanAnnN DocName -> HsType DocNameI)
-> (DocName -> GenLocated SrcSpanAnnN DocName)
-> DocName
-> HsType DocNameI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnN -> DocName -> GenLocated SrcSpanAnnN DocName
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l (DocName -> RnM (HsType DocNameI))
-> RnM DocName -> RnM (HsType DocNameI)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< Name -> RnM DocName
renameName (WithUserRdr Name -> Name
forall a. NamedThing a => a -> Name
getName WithUserRdr Name
n)
  HsStarTy XStarTy GhcRn
_ Bool
isUni -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XStarTy DocNameI -> Bool -> HsType DocNameI
forall pass. XStarTy pass -> Bool -> HsType pass
HsStarTy XStarTy DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn Bool
isUni)
  HsAppTy XAppTy GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b -> do
    a' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
a
    b' <- renameLType b
    return (HsAppTy noAnn a' b')
  HsAppKindTy XAppKindTy GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b -> do
    a' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
a
    b' <- renameLKind b
    return (HsAppKindTy noAnn a' b')
  HsFunTy XFunTy GhcRn
_ HsMultAnn GhcRn
w LHsType GhcRn
a LHsType GhcRn
b -> do
    a' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
a
    b' <- renameLType b
    w' <- renameMultAnn w
    return (HsFunTy noAnn w' a' b')
  HsListTy XListTy GhcRn
_ LHsType GhcRn
ty -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (HsType DocNameI -> RnM (HsType DocNameI))
-> (GenLocated SrcSpanAnnA (HsType DocNameI) -> HsType DocNameI)
-> GenLocated SrcSpanAnnA (HsType DocNameI)
-> RnM (HsType DocNameI)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (XListTy DocNameI -> LHsType DocNameI -> HsType DocNameI
forall pass. XListTy pass -> LHsType pass -> HsType pass
HsListTy XListTy DocNameI
EpAnn AnnParen
forall a. NoAnn a => a
noAnn) (GenLocated SrcSpanAnnA (HsType DocNameI) -> RnM (HsType DocNameI))
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
-> RnM (HsType DocNameI)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
ty
  HsIParamTy XIParamTy GhcRn
_ XRec GhcRn HsIPName
n LHsType GhcRn
ty -> (GenLocated SrcSpanAnnA (HsType DocNameI) -> HsType DocNameI)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
-> RnM (HsType DocNameI)
forall (m :: Type -> Type) a1 r.
Monad m =>
(a1 -> r) -> m a1 -> m r
liftM (XIParamTy DocNameI
-> XRec DocNameI HsIPName -> LHsType DocNameI -> HsType DocNameI
forall pass.
XIParamTy pass -> XRec pass HsIPName -> LHsType pass -> HsType pass
HsIParamTy XIParamTy DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn XRec GhcRn HsIPName
XRec DocNameI HsIPName
n) (LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
ty)
  -- Special-case unary boxed tuples so that they are pretty-printed as
  -- `Solo x`, not `(x)`
  HsTupleTy XTupleTy GhcRn
_ HsTupleSort
HsBoxedOrConstraintTuple [LHsType GhcRn
ty] -> do
    name <- Name -> RnM DocName
renameName (TupleSort -> Int -> Name
tupleTyConName TupleSort
BoxedTuple Int
1)
    let lhs = HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI))
-> HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI)
forall a b. (a -> b) -> a -> b
$ XTyVar DocNameI
-> PromotionFlag -> LIdOccP DocNameI -> HsType DocNameI
forall pass.
XTyVar pass -> PromotionFlag -> LIdOccP pass -> HsType pass
HsTyVar XTyVar DocNameI
forall a. NoAnn a => a
noAnn PromotionFlag
NotPromoted (DocName -> GenLocated SrcSpanAnnN DocName
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA DocName
name)
    rhs <- renameLType ty
    return (HsAppTy noAnn lhs rhs)
  HsTupleTy XTupleTy GhcRn
_ HsTupleSort
b [LHsType GhcRn]
ts -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (HsType DocNameI -> RnM (HsType DocNameI))
-> ([GenLocated SrcSpanAnnA (HsType DocNameI)] -> HsType DocNameI)
-> [GenLocated SrcSpanAnnA (HsType DocNameI)]
-> RnM (HsType DocNameI)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XTupleTy DocNameI
-> HsTupleSort -> [LHsType DocNameI] -> HsType DocNameI
forall pass.
XTupleTy pass -> HsTupleSort -> [LHsType pass] -> HsType pass
HsTupleTy XTupleTy DocNameI
EpAnn AnnParen
forall a. NoAnn a => a
noAnn HsTupleSort
b ([GenLocated SrcSpanAnnA (HsType DocNameI)]
 -> RnM (HsType DocNameI))
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
-> RnM (HsType DocNameI)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< (GenLocated SrcSpanAnnA (HsType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsType DocNameI)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsType GhcRn -> RnM (LHsType DocNameI)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
ts
  HsSumTy XSumTy GhcRn
_ [LHsType GhcRn]
ts -> XSumTy DocNameI -> [LHsType DocNameI] -> HsType DocNameI
forall pass. XSumTy pass -> [LHsType pass] -> HsType pass
HsSumTy XSumTy DocNameI
EpAnn AnnParen
forall a. NoAnn a => a
noAnn ([GenLocated SrcSpanAnnA (HsType DocNameI)] -> HsType DocNameI)
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
-> RnM (HsType DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsType DocNameI)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsType GhcRn -> RnM (LHsType DocNameI)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
ts
  HsOpTy XOpTy GhcRn
_ PromotionFlag
prom LHsType GhcRn
a (L SrcSpanAnnN
loc WithUserRdr Name
op) LHsType GhcRn
b -> do
    op' <- Name -> RnM DocName
renameName (WithUserRdr Name -> Name
forall a. NamedThing a => a -> Name
getName WithUserRdr Name
op)
    a' <- renameLType a
    b' <- renameLType b
    return (HsOpTy noAnn prom a' (L loc op') b')
  HsParTy XParTy GhcRn
_ LHsType GhcRn
ty -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (HsType DocNameI -> RnM (HsType DocNameI))
-> (GenLocated SrcSpanAnnA (HsType DocNameI) -> HsType DocNameI)
-> GenLocated SrcSpanAnnA (HsType DocNameI)
-> RnM (HsType DocNameI)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (XParTy DocNameI -> LHsType DocNameI -> HsType DocNameI
forall pass. XParTy pass -> LHsType pass -> HsType pass
HsParTy (EpToken "(", EpToken ")")
XParTy DocNameI
forall a. NoAnn a => a
noAnn) (GenLocated SrcSpanAnnA (HsType DocNameI) -> RnM (HsType DocNameI))
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
-> RnM (HsType DocNameI)
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
ty
  HsKindSig XKindSig GhcRn
_ LHsType GhcRn
ty LHsType GhcRn
k -> do
    ty' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
ty
    k' <- renameLKind k
    return (HsKindSig noAnn ty' k')
  HsDocTy XDocTy GhcRn
_ LHsType GhcRn
ty LHsDoc GhcRn
doc -> do
    ty' <- LHsType GhcRn -> RnM (LHsType DocNameI)
renameLType LHsType GhcRn
ty
    doc' <- renameLDocHsSyn doc
    return (HsDocTy noAnn ty' doc')
  HsTyLit XTyLit GhcRn
_ HsTyLit GhcRn
x -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XTyLit DocNameI -> HsTyLit DocNameI -> HsType DocNameI
forall pass. XTyLit pass -> HsTyLit pass -> HsType pass
HsTyLit XTyLit DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn (HsTyLit GhcRn -> HsTyLit DocNameI
renameTyLit HsTyLit GhcRn
x))
  XHsType XXType GhcRn
a -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (XXType DocNameI -> HsType DocNameI
forall pass. XXType pass -> HsType pass
XHsType (HsCoreTy -> HsTypeDocNameIExt
HsCoreTy XXType GhcRn
HsCoreTy
a))
  HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
a [LHsType GhcRn]
b -> XExplicitListTy DocNameI
-> PromotionFlag -> [LHsType DocNameI] -> HsType DocNameI
forall pass.
XExplicitListTy pass
-> PromotionFlag -> [LHsType pass] -> HsType pass
HsExplicitListTy XExplicitListTy DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn PromotionFlag
a ([GenLocated SrcSpanAnnA (HsType DocNameI)] -> HsType DocNameI)
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
-> RnM (HsType DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsType DocNameI)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsType GhcRn -> RnM (LHsType DocNameI)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
b
  -- Special-case unary boxed tuples so that they are pretty-printed as
  -- `'MkSolo x`, not `'(x)`
  HsExplicitTupleTy XExplicitTupleTy GhcRn
_ PromotionFlag
ip [LHsType GhcRn
ty] -> do
    name <- Name -> RnM DocName
renameName (Boxity -> Int -> Name
tupleDataConName Boxity
Boxed Int
1)
    let lhs = HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI))
-> HsType DocNameI -> GenLocated SrcSpanAnnA (HsType DocNameI)
forall a b. (a -> b) -> a -> b
$ XTyVar DocNameI
-> PromotionFlag -> LIdOccP DocNameI -> HsType DocNameI
forall pass.
XTyVar pass -> PromotionFlag -> LIdOccP pass -> HsType pass
HsTyVar XTyVar DocNameI
forall a. NoAnn a => a
noAnn PromotionFlag
ip (DocName -> GenLocated SrcSpanAnnN DocName
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA DocName
name)
    rhs <- renameLType ty
    return (HsAppTy noAnn lhs rhs)
  HsExplicitTupleTy XExplicitTupleTy GhcRn
_ PromotionFlag
ip [LHsType GhcRn]
b -> XExplicitTupleTy DocNameI
-> PromotionFlag -> [LHsType DocNameI] -> HsType DocNameI
forall pass.
XExplicitTupleTy pass
-> PromotionFlag -> [LHsType pass] -> HsType pass
HsExplicitTupleTy XExplicitTupleTy DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn PromotionFlag
ip ([GenLocated SrcSpanAnnA (HsType DocNameI)] -> HsType DocNameI)
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
-> RnM (HsType DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsType DocNameI)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsType GhcRn -> RnM (LHsType DocNameI)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
b
  HsSpliceTy (HsUntypedSpliceTop ThModFinalizers
_ GenLocated SrcSpanAnnA (HsType GhcRn)
st) HsUntypedSplice GhcRn
_ -> HsType GhcRn -> RnM (HsType DocNameI)
renameType (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsType GhcRn)
st)
  HsSpliceTy (HsUntypedSpliceNested Name
_) HsUntypedSplice GhcRn
_ -> String -> RnM (HsType DocNameI)
forall a. HasCallStack => String -> a
error String
"renameType: not an top level type splice"
  HsWildCardTy XWildCardTy GhcRn
_ -> HsType DocNameI -> RnM (HsType DocNameI)
forall a. a -> RnM a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (XWildCardTy DocNameI -> HsType DocNameI
forall pass. XWildCardTy pass -> HsType pass
HsWildCardTy XWildCardTy DocNameI
EpAnn NoEpAnns
forall a. NoAnn a => a
noAnn)

renameTyLit :: HsTyLit GhcRn -> HsTyLit DocNameI
renameTyLit :: HsTyLit GhcRn -> HsTyLit DocNameI
renameTyLit HsTyLit GhcRn
t = case HsTyLit GhcRn
t of
  HsNumTy XNumTy GhcRn
_ Integer
v -> XNumTy DocNameI -> Integer -> HsTyLit DocNameI
forall pass. XNumTy pass -> Integer -> HsTyLit pass
HsNumTy XNumTy DocNameI
NoExtField
noExtField Integer
v
  HsStrTy XStrTy GhcRn
_ FastString
v -> XStrTy DocNameI -> FastString -> HsTyLit DocNameI
forall pass. XStrTy pass -> FastString -> HsTyLit pass
HsStrTy XStrTy DocNameI
NoExtField
noExtField FastString
v
  HsCharTy XCharTy GhcRn
_ Char
v -> XCharTy DocNameI -> Char -> HsTyLit DocNameI
forall pass. XCharTy pass -> Char -> HsTyLit pass
HsCharTy XCharTy DocNameI
NoExtField
noExtField Char
v

renameSigType :: HsSigType GhcRn -> RnM (HsSigType DocNameI)
renameSigType :: HsSigType GhcRn -> RnM (HsSigType DocNameI)
renameSigType (HsSig{sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs = HsOuterSigTyVarBndrs GhcRn
bndrs, sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body = LHsType GhcRn
body}) = do
  bndrs' <- HsOuterSigTyVarBndrs GhcRn
-> RnM (HsOuterTyVarBndrs Specificity DocNameI)
forall flag.
HsOuterTyVarBndrs flag GhcRn
-> RnM (HsOuterTyVarBndrs flag DocNameI)
renameOuterTyVarBndrs HsOuterSigTyVarBndrs GhcRn
bndrs
  body' <- renameLType body
  pure $ HsSig{sig_ext = noExtField, sig_bndrs = bndrs', sig_body = body'}

renameLHsQTyVars :: LHsQTyVars GhcRn -> RnM (LHsQTyVars DocNameI)
renameLHsQTyVars :: LHsQTyVars GhcRn -> RnM (LHsQTyVars DocNameI)
renameLHsQTyVars (HsQTvs{hsq_explicit :: forall pass.
LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
hsq_explicit = [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
tvs}) =
  do
    tvs' <- (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
 -> RnM
      (GenLocated
         SrcSpanAnnA (HsTyVarBndr (HsBndrVis DocNameI) DocNameI)))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> RnM
     [GenLocated
        SrcSpanAnnA (HsTyVarBndr (HsBndrVis DocNameI) DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM ((HsBndrVis GhcRn -> RnM (HsBndrVis DocNameI))
-> LHsTyVarBndr (HsBndrVis GhcRn) GhcRn
-> RnM (LHsTyVarBndr (HsBndrVis DocNameI) DocNameI)
forall flag flag'.
(flag -> RnM flag')
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr HsBndrVis GhcRn -> RnM (HsBndrVis DocNameI)
renameHsBndrVis) [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
tvs
    return
      ( HsQTvs
          { hsq_ext = noExtField
          , hsq_explicit = tvs'
          }
      )

renameHsBndrVis :: HsBndrVis GhcRn -> RnM (HsBndrVis DocNameI)
renameHsBndrVis :: HsBndrVis GhcRn -> RnM (HsBndrVis DocNameI)
renameHsBndrVis (HsBndrRequired XBndrRequired GhcRn
_) = HsBndrVis DocNameI -> RnM (HsBndrVis DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XBndrRequired DocNameI -> HsBndrVis DocNameI
forall pass. XBndrRequired pass -> HsBndrVis pass
HsBndrRequired NoExtField
XBndrRequired DocNameI
noExtField)
renameHsBndrVis (HsBndrInvisible XBndrInvisible GhcRn
at) = HsBndrVis DocNameI -> RnM (HsBndrVis DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XBndrInvisible DocNameI -> HsBndrVis DocNameI
forall pass. XBndrInvisible pass -> HsBndrVis pass
HsBndrInvisible XBndrInvisible GhcRn
XBndrInvisible DocNameI
at)

renameHsForAllTelescope :: HsForAllTelescope GhcRn -> RnM (HsForAllTelescope DocNameI)
renameHsForAllTelescope :: HsForAllTelescope GhcRn -> RnM (HsForAllTelescope DocNameI)
renameHsForAllTelescope HsForAllTelescope GhcRn
tele = case HsForAllTelescope GhcRn
tele of
  HsForAllVis XHsForAllVis GhcRn
_ [LHsTyVarBndr () GhcRn]
bndrs -> do
    bndrs' <- (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsTyVarBndr () DocNameI)))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsTyVarBndr () DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM ((() -> RnM ())
-> LHsTyVarBndr () GhcRn -> RnM (LHsTyVarBndr () DocNameI)
forall flag flag'.
(flag -> RnM flag')
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr () -> RnM ()
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return) [LHsTyVarBndr () GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
bndrs
    pure $ HsForAllVis noExtField bndrs'
  HsForAllInvis XHsForAllInvis GhcRn
_ [LHsTyVarBndr Specificity GhcRn]
bndrs -> do
    bndrs' <- (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity DocNameI)))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsTyVarBndr Specificity DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM ((Specificity -> RnM Specificity)
-> LHsTyVarBndr Specificity GhcRn
-> RnM (LHsTyVarBndr Specificity DocNameI)
forall flag flag'.
(flag -> RnM flag')
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr Specificity -> RnM Specificity
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return) [LHsTyVarBndr Specificity GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
bndrs
    pure $ HsForAllInvis noExtField bndrs'

renameLTyVarBndr :: (flag -> RnM flag') -> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr :: forall flag flag'.
(flag -> RnM flag')
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr flag -> RnM flag'
rn_flag (L SrcSpanAnnA
loc (HsTvb XTyVarBndr GhcRn
_ flag
fl HsBndrVar GhcRn
n HsBndrKind GhcRn
kind)) =
  do
    fl' <- flag -> RnM flag'
rn_flag flag
fl
    n' <- renameHsBndrVar n
    kind' <- renameHsBndrKind kind
    return (L loc (HsTvb noExtField fl' n' kind'))

renameHsBndrVar :: HsBndrVar GhcRn -> RnM (HsBndrVar DocNameI)
renameHsBndrVar :: HsBndrVar GhcRn -> RnM (HsBndrVar DocNameI)
renameHsBndrVar (HsBndrVar XBndrVar GhcRn
_ LIdP GhcRn
n) = XBndrVar DocNameI -> LIdP DocNameI -> HsBndrVar DocNameI
forall pass. XBndrVar pass -> LIdP pass -> HsBndrVar pass
HsBndrVar NoExtField
XBndrVar DocNameI
noExtField (GenLocated SrcSpanAnnN DocName -> HsBndrVar DocNameI)
-> RnM (GenLocated SrcSpanAnnN DocName) -> RnM (HsBndrVar DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
n
renameHsBndrVar (HsBndrWildCard XBndrWildCard GhcRn
_) = HsBndrVar DocNameI -> RnM (HsBndrVar DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XBndrWildCard DocNameI -> HsBndrVar DocNameI
forall pass. XBndrWildCard pass -> HsBndrVar pass
HsBndrWildCard NoExtField
XBndrWildCard DocNameI
noExtField)

renameHsBndrKind :: HsBndrKind GhcRn -> RnM (HsBndrKind DocNameI)
renameHsBndrKind :: HsBndrKind GhcRn -> RnM (HsBndrKind DocNameI)
renameHsBndrKind (HsBndrNoKind XBndrNoKind GhcRn
_) = HsBndrKind DocNameI -> RnM (HsBndrKind DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XBndrNoKind DocNameI -> HsBndrKind DocNameI
forall pass. XBndrNoKind pass -> HsBndrKind pass
HsBndrNoKind NoExtField
XBndrNoKind DocNameI
noExtField)
renameHsBndrKind (HsBndrKind XBndrKind GhcRn
_ LHsType GhcRn
k) = XBndrKind DocNameI -> LHsType DocNameI -> HsBndrKind DocNameI
forall pass. XBndrKind pass -> LHsKind pass -> HsBndrKind pass
HsBndrKind NoExtField
XBndrKind DocNameI
noExtField (GenLocated SrcSpanAnnA (HsType DocNameI) -> HsBndrKind DocNameI)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
-> RnM (HsBndrKind DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> RnM (LHsType DocNameI)
renameLKind LHsType GhcRn
k

renameLContext :: LocatedC [LHsType GhcRn] -> RnM (LocatedC [LHsType DocNameI])
renameLContext :: LocatedC [LHsType GhcRn] -> RnM (LocatedC [LHsType DocNameI])
renameLContext (L SrcSpanAnnC
loc [LHsType GhcRn]
context) = do
  context' <- (GenLocated SrcSpanAnnA (HsType GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsType DocNameI)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsType DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsType GhcRn -> RnM (LHsType DocNameI)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> RnM (GenLocated SrcSpanAnnA (HsType DocNameI))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
context
  return (L loc context')

renameInstHead :: InstHead GhcRn -> RnM (InstHead DocNameI)
renameInstHead :: InstHead GhcRn -> RnM (InstHead DocNameI)
renameInstHead InstHead{[HsType GhcRn]
IdP GhcRn
InstType GhcRn
ihdClsName :: IdP GhcRn
ihdTypes :: [HsType GhcRn]
ihdInstType :: InstType GhcRn
ihdInstType :: forall name. InstHead name -> InstType name
ihdTypes :: forall name. InstHead name -> [HsType name]
ihdClsName :: forall name. InstHead name -> IdP name
..} = do
  cname <- Name -> RnM DocName
renameName IdP GhcRn
Name
ihdClsName
  types <- mapM renameType ihdTypes
  itype <- case ihdInstType of
    ClassInst{[DocInstance GhcRn]
[HsType GhcRn]
[Sig GhcRn]
LHsQTyVars GhcRn
clsiCtx :: [HsType GhcRn]
clsiTyVars :: LHsQTyVars GhcRn
clsiSigs :: [Sig GhcRn]
clsiAssocTys :: [DocInstance GhcRn]
clsiAssocTys :: forall name. InstType name -> [DocInstance name]
clsiSigs :: forall name. InstType name -> [Sig name]
clsiTyVars :: forall name. InstType name -> LHsQTyVars name
clsiCtx :: forall name. InstType name -> [HsType name]
..} ->
      [HsType DocNameI]
-> LHsQTyVars DocNameI
-> [Sig DocNameI]
-> [DocInstance DocNameI]
-> InstType DocNameI
[HsType DocNameI]
-> LHsQTyVars DocNameI
-> [Sig DocNameI]
-> [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
     Maybe Module)]
-> InstType DocNameI
forall name.
[HsType name]
-> LHsQTyVars name
-> [Sig name]
-> [DocInstance name]
-> InstType name
ClassInst
        ([HsType DocNameI]
 -> LHsQTyVars DocNameI
 -> [Sig DocNameI]
 -> [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
      Maybe Module)]
 -> InstType DocNameI)
-> RnM [HsType DocNameI]
-> RnM
     (LHsQTyVars DocNameI
      -> [Sig DocNameI]
      -> [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
           Maybe Module)]
      -> InstType DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (HsType GhcRn -> RnM (HsType DocNameI))
-> [HsType GhcRn] -> RnM [HsType DocNameI]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM HsType GhcRn -> RnM (HsType DocNameI)
renameType [HsType GhcRn]
clsiCtx
        RnM
  (LHsQTyVars DocNameI
   -> [Sig DocNameI]
   -> [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
        Maybe Module)]
   -> InstType DocNameI)
-> RnM (LHsQTyVars DocNameI)
-> RnM
     ([Sig DocNameI]
      -> [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
           Maybe Module)]
      -> InstType DocNameI)
forall a b. RnM (a -> b) -> RnM a -> RnM b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsQTyVars GhcRn -> RnM (LHsQTyVars DocNameI)
renameLHsQTyVars LHsQTyVars GhcRn
clsiTyVars
        RnM
  ([Sig DocNameI]
   -> [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
        Maybe Module)]
   -> InstType DocNameI)
-> RnM [Sig DocNameI]
-> RnM
     ([(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
        Maybe Module)]
      -> InstType DocNameI)
forall a b. RnM (a -> b) -> RnM a -> RnM b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> (Sig GhcRn -> RnM (Sig DocNameI))
-> [Sig GhcRn] -> RnM [Sig DocNameI]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM Sig GhcRn -> RnM (Sig DocNameI)
renameSig [Sig GhcRn]
clsiSigs
        RnM
  ([(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
     Maybe Module)]
   -> InstType DocNameI)
-> RnM
     [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
       Maybe Module)]
-> RnM (InstType DocNameI)
forall a b. RnM (a -> b) -> RnM a -> RnM b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> ((InstHead GhcRn, Maybe (MDoc Name), Located Name, Maybe Module)
 -> RnM
      (InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
       Maybe Module))
-> [(InstHead GhcRn, Maybe (MDoc Name), Located Name,
     Maybe Module)]
-> RnM
     [(InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
       Maybe Module)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM DocInstance GhcRn -> RnM (DocInstance DocNameI)
(InstHead GhcRn, Maybe (MDoc Name), Located Name, Maybe Module)
-> RnM
     (InstHead DocNameI, Maybe (MDoc DocName), Located DocName,
      Maybe Module)
renameDocInstance [DocInstance GhcRn]
[(InstHead GhcRn, Maybe (MDoc Name), Located Name, Maybe Module)]
clsiAssocTys
    TypeInst Maybe (HsType GhcRn)
ts -> Maybe (HsType DocNameI) -> InstType DocNameI
forall name. Maybe (HsType name) -> InstType name
TypeInst (Maybe (HsType DocNameI) -> InstType DocNameI)
-> RnM (Maybe (HsType DocNameI)) -> RnM (InstType DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (HsType GhcRn -> RnM (HsType DocNameI))
-> Maybe (HsType GhcRn) -> RnM (Maybe (HsType DocNameI))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse HsType GhcRn -> RnM (HsType DocNameI)
renameType Maybe (HsType GhcRn)
ts
    DataInst TyClDecl GhcRn
dd -> TyClDecl DocNameI -> InstType DocNameI
forall name. TyClDecl name -> InstType name
DataInst (TyClDecl DocNameI -> InstType DocNameI)
-> RnM (TyClDecl DocNameI) -> RnM (InstType DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> TyClDecl GhcRn -> RnM (TyClDecl DocNameI)
renameTyClD TyClDecl GhcRn
dd
  return
    InstHead
      { ihdClsName = cname
      , ihdTypes = types
      , ihdInstType = itype
      }

renameLDecl :: LHsDecl GhcRn -> RnM (LHsDecl DocNameI)
renameLDecl :: LHsDecl GhcRn -> RnM (LHsDecl DocNameI)
renameLDecl (L SrcSpanAnnA
loc HsDecl GhcRn
d) = GenLocated SrcSpanAnnA (HsDecl DocNameI)
-> RnM (GenLocated SrcSpanAnnA (HsDecl DocNameI))
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnA (HsDecl DocNameI)
 -> RnM (GenLocated SrcSpanAnnA (HsDecl DocNameI)))
-> (HsDecl DocNameI -> GenLocated SrcSpanAnnA (HsDecl DocNameI))
-> HsDecl DocNameI
-> RnM (GenLocated SrcSpanAnnA (HsDecl DocNameI))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA
-> HsDecl DocNameI -> GenLocated SrcSpanAnnA (HsDecl DocNameI)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (HsDecl DocNameI -> RnM (GenLocated SrcSpanAnnA (HsDecl DocNameI)))
-> RnM (HsDecl DocNameI)
-> RnM (GenLocated SrcSpanAnnA (HsDecl DocNameI))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< HsDecl GhcRn -> RnM (HsDecl DocNameI)
renameDecl HsDecl GhcRn
d

renamePats :: [(HsDecl GhcRn, DocForDecl Name)] -> RnM [(HsDecl DocNameI, DocForDecl DocName)]
renamePats :: [(HsDecl GhcRn, DocForDecl Name)]
-> RnM [(HsDecl DocNameI, DocForDecl DocName)]
renamePats =
  ((HsDecl GhcRn, DocForDecl Name)
 -> RnM (HsDecl DocNameI, DocForDecl DocName))
-> [(HsDecl GhcRn, DocForDecl Name)]
-> RnM [(HsDecl DocNameI, DocForDecl DocName)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM
    ( \(HsDecl GhcRn
d, DocForDecl Name
doc) -> do
        d' <- HsDecl GhcRn -> RnM (HsDecl DocNameI)
renameDecl HsDecl GhcRn
d
        doc' <- renameDocForDecl doc
        return (d', doc')
    )

renameDecl :: HsDecl GhcRn -> RnM (HsDecl DocNameI)
renameDecl :: HsDecl GhcRn -> RnM (HsDecl DocNameI)
renameDecl HsDecl GhcRn
decl = case HsDecl GhcRn
decl of
  TyClD XTyClD GhcRn
_ TyClDecl GhcRn
d -> do
    d' <- TyClDecl GhcRn -> RnM (TyClDecl DocNameI)
renameTyClD TyClDecl GhcRn
d
    return (TyClD noExtField d')
  SigD XSigD GhcRn
_ Sig GhcRn
s -> do
    s' <- Sig GhcRn -> RnM (Sig DocNameI)
renameSig Sig GhcRn
s
    return (SigD noExtField s')
  ForD XForD GhcRn
_ ForeignDecl GhcRn
d -> do
    d' <- ForeignDecl GhcRn -> RnM (ForeignDecl DocNameI)
renameForD ForeignDecl GhcRn
d
    return (ForD noExtField d')
  InstD XInstD GhcRn
_ InstDecl GhcRn
d -> do
    d' <- InstDecl GhcRn -> RnM (InstDecl DocNameI)
renameInstD InstDecl GhcRn
d
    return (InstD noExtField d')
  DerivD XDerivD GhcRn
_ DerivDecl GhcRn
d -> do
    d' <- DerivDecl GhcRn -> RnM (DerivDecl DocNameI)
renameDerivD DerivDecl GhcRn
d
    return (DerivD noExtField d')
  HsDecl GhcRn
_ -> String -> RnM (HsDecl DocNameI)
forall a. HasCallStack => String -> a
error String
"renameDecl"

renameLThing :: (a GhcRn -> RnM (a DocNameI)) -> LocatedAn an (a GhcRn) -> RnM (Located (a DocNameI))
renameLThing :: forall (a :: Type -> Type) an.
(a GhcRn -> RnM (a DocNameI))
-> LocatedAn an (a GhcRn) -> RnM (Located (a DocNameI))
renameLThing a GhcRn -> RnM (a DocNameI)
fn (L EpAnn an
loc a GhcRn
x) = Located (a DocNameI) -> RnM (Located (a DocNameI))
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (Located (a DocNameI) -> RnM (Located (a DocNameI)))
-> (a DocNameI -> Located (a DocNameI))
-> a DocNameI
-> RnM (Located (a DocNameI))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> a DocNameI -> Located (a DocNameI)
forall l e. l -> e -> GenLocated l e
L (EpAnn an -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA EpAnn an
loc) (a DocNameI -> RnM (Located (a DocNameI)))
-> RnM (a DocNameI) -> RnM (Located (a DocNameI))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< a GhcRn -> RnM (a DocNameI)
fn a GhcRn
x

renameTyClD :: TyClDecl GhcRn -> RnM (TyClDecl DocNameI)
renameTyClD :: TyClDecl GhcRn -> RnM (TyClDecl DocNameI)
renameTyClD TyClDecl GhcRn
d = case TyClDecl GhcRn
d of
  --  TyFamily flav lname ltyvars kind tckind -> do
  FamDecl{tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl GhcRn
decl} -> do
    decl' <- FamilyDecl GhcRn -> RnM (FamilyDecl DocNameI)
renameFamilyDecl FamilyDecl GhcRn
decl
    return (FamDecl{tcdFExt = noExtField, tcdFam = decl'})
  SynDecl{tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP GhcRn
lname, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
tyvars, tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdFixity = LexicalFixity
fixity, tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LHsType GhcRn
rhs} -> do
    lname' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname
    tyvars' <- renameLHsQTyVars tyvars
    rhs' <- maybe (renameLType rhs) pure <=< runMaybeT $ do
      expInfo <- MaybeT $ asks rnExportInfo
      -- Given that we have matched on a 'SynDecl', this lookup /really should/
      -- be 'ATyCon', and the 'synTyConRhs_maybe' result /really should/ be
      -- 'Just', but out of an abundance of caution, failing either expectation
      -- gracefully exits the monad instead of erroring.
      ATyCon tc <- MaybeT $ liftGhc $ GHC.lookupName $ getName lname
      guard . isTypeHidden expInfo <=< hoistMaybe $ synTyConRhs_maybe tc
      let hsKind = HsCoreTy -> LHsType GhcRn
synifyKindSig (HsCoreTy -> LHsType GhcRn) -> HsCoreTy -> LHsType GhcRn
forall a b. (a -> b) -> a -> b
$ TyCon -> HsCoreTy
tyConResKind TyCon
tc
      lift $ fmap (XHsType . HsRedacted) <$> renameLType hsKind
    return
      ( SynDecl
          { tcdSExt = noExtField
          , tcdLName = lname'
          , tcdTyVars = tyvars'
          , tcdFixity = fixity
          , tcdRhs = rhs'
          }
      )
  DataDecl{tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP GhcRn
lname, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
tyvars, tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdFixity = LexicalFixity
fixity, tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn GhcRn
defn} -> do
    lname' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname
    tyvars' <- renameLHsQTyVars tyvars
    defn' <- renameDataDefn defn
    return
      ( DataDecl
          { tcdDExt = noExtField
          , tcdLName = lname'
          , tcdTyVars = tyvars'
          , tcdFixity = fixity
          , tcdDataDefn = defn'
          }
      )
  ClassDecl
    { tcdCtxt :: forall pass. TyClDecl pass -> Maybe (LHsContext pass)
tcdCtxt = Maybe (LHsContext GhcRn)
lcontext
    , tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP GhcRn
lname
    , tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
ltyvars
    , tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdFixity = LexicalFixity
fixity
    , tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdFDs = [LHsFunDep GhcRn]
lfundeps
    , tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdSigs = [LSig GhcRn]
lsigs
    , tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATs = [LFamilyDecl GhcRn]
ats
    , tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATDefs = [LTyFamDefltDecl GhcRn]
at_defs
    } -> do
      lcontext' <- (LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)]
 -> RnM (LocatedC [GenLocated SrcSpanAnnA (HsType DocNameI)]))
-> Maybe (LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> RnM
     (Maybe (LocatedC [GenLocated SrcSpanAnnA (HsType DocNameI)]))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse LocatedC [LHsType GhcRn] -> RnM (LocatedC [LHsType DocNameI])
LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM (LocatedC [GenLocated SrcSpanAnnA (HsType DocNameI)])
renameLContext Maybe (LHsContext GhcRn)
Maybe (LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)])
lcontext
      lname' <- renameNameL lname
      ltyvars' <- renameLHsQTyVars ltyvars
      lfundeps' <- mapM renameLFunDep lfundeps
      lsigs' <- mapM renameLSig lsigs
      ats' <- mapM (renameLThing renameFamilyDecl) ats
      at_defs' <- mapM (mapM renameTyFamDefltD) at_defs
      -- we don't need the default methods or the already collected doc entities
      return
        ( ClassDecl
            { tcdCExt = noExtField
            , tcdCtxt = lcontext'
            , tcdLName = lname'
            , tcdTyVars = ltyvars'
            , tcdFixity = fixity
            , tcdFDs = lfundeps'
            , tcdSigs = lsigs'
            , tcdMeths = []
            , tcdATs = ats'
            , tcdATDefs = at_defs'
            , tcdDocs = []
            }
        )
  where
    renameLFunDep :: LHsFunDep GhcRn -> RnM (LHsFunDep DocNameI)
    renameLFunDep :: LHsFunDep GhcRn -> RnM (LHsFunDep DocNameI)
renameLFunDep (L SrcSpanAnnA
loc (FunDep XCFunDep GhcRn
_ [LIdP GhcRn]
xs [LIdP GhcRn]
ys)) = do
      xs' <- (Name -> RnM DocName) -> [Name] -> RnM [DocName]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM Name -> RnM DocName
renameName ((GenLocated SrcSpanAnnN Name -> Name)
-> [GenLocated SrcSpanAnnN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
xs)
      ys' <- mapM renameName (map unLoc ys)
      return (L (locA loc) (FunDep noExtField (map noLocA xs') (map noLocA ys')))

    renameLSig :: GenLocated a (Sig GhcRn) -> RnM (GenLocated SrcSpan (Sig DocNameI))
renameLSig (L a
loc Sig GhcRn
sig) = GenLocated SrcSpan (Sig DocNameI)
-> RnM (GenLocated SrcSpan (Sig DocNameI))
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (GenLocated SrcSpan (Sig DocNameI)
 -> RnM (GenLocated SrcSpan (Sig DocNameI)))
-> (Sig DocNameI -> GenLocated SrcSpan (Sig DocNameI))
-> Sig DocNameI
-> RnM (GenLocated SrcSpan (Sig DocNameI))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> Sig DocNameI -> GenLocated SrcSpan (Sig DocNameI)
forall l e. l -> e -> GenLocated l e
L (a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA a
loc) (Sig DocNameI -> RnM (GenLocated SrcSpan (Sig DocNameI)))
-> RnM (Sig DocNameI) -> RnM (GenLocated SrcSpan (Sig DocNameI))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
=<< Sig GhcRn -> RnM (Sig DocNameI)
renameSig Sig GhcRn
sig

renameFamilyDecl :: FamilyDecl GhcRn -> RnM (FamilyDecl DocNameI)
renameFamilyDecl :: FamilyDecl GhcRn -> RnM (FamilyDecl DocNameI)
renameFamilyDecl
  ( FamilyDecl
      { fdInfo :: forall pass. FamilyDecl pass -> FamilyInfo pass
fdInfo = FamilyInfo GhcRn
info
      , fdLName :: forall pass. FamilyDecl pass -> LIdP pass
fdLName = LIdP GhcRn
lname
      , fdTyVars :: forall pass. FamilyDecl pass -> LHsQTyVars pass
fdTyVars = LHsQTyVars GhcRn
ltyvars
      , fdFixity :: forall pass. FamilyDecl pass -> LexicalFixity
fdFixity = LexicalFixity
fixity
      , fdResultSig :: forall pass. FamilyDecl pass -> LFamilyResultSig pass
fdResultSig = LFamilyResultSig GhcRn
result
      , fdInjectivityAnn :: forall pass. FamilyDecl pass -> Maybe (LInjectivityAnn pass)
fdInjectivityAnn = Maybe (LInjectivityAnn GhcRn)
injectivity
      }
    ) = do
    info' <- FamilyInfo GhcRn -> RnM (FamilyInfo DocNameI)
renameFamilyInfo FamilyInfo GhcRn
info
    lname' <- renameNameL lname
    ltyvars' <- renameLHsQTyVars ltyvars
    result' <- renameFamilyResultSig result
    injectivity' <- renameMaybeInjectivityAnn injectivity
    return
      ( FamilyDecl
          { fdExt = noExtField
          , fdInfo = info'
          , fdTopLevel = TopLevel
          , fdLName = lname'
          , fdTyVars = ltyvars'
          , fdFixity = fixity
          , fdResultSig = result'
          , fdInjectivityAnn = injectivity'
          }
      )

renameFamilyInfo :: FamilyInfo GhcRn -> RnM (FamilyInfo DocNameI)
renameFamilyInfo :: FamilyInfo GhcRn -> RnM (FamilyInfo DocNameI)
renameFamilyInfo FamilyInfo GhcRn
DataFamily = FamilyInfo DocNameI -> RnM (FamilyInfo DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return FamilyInfo DocNameI
forall pass. FamilyInfo pass
DataFamily
renameFamilyInfo FamilyInfo GhcRn
OpenTypeFamily = FamilyInfo DocNameI -> RnM (FamilyInfo DocNameI)
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return FamilyInfo DocNameI
forall pass. FamilyInfo pass
OpenTypeFamily
renameFamilyInfo (ClosedTypeFamily Maybe [LTyFamInstEqn GhcRn]
eqns) =
  do
    eqns' <- ([GenLocated
    SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
 -> RnM
      [GenLocated
         SrcSpanAnnA
         (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI)))])
-> Maybe
     [GenLocated
        SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
-> RnM
     (Maybe
        [GenLocated
           SrcSpanAnnA
           (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI)))])
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
mapM ((GenLocated
   SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
 -> RnM
      (GenLocated
         SrcSpanAnnA
         (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI)))))
-> [GenLocated
      SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
-> RnM
     [GenLocated
        SrcSpanAnnA
        (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI)))]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM ((FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
 -> RnM
      (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI))))
-> GenLocated
     SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> RnM
     (GenLocated
        SrcSpanAnnA
        (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI))))
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b)
-> GenLocated SrcSpanAnnA a -> m (GenLocated SrcSpanAnnA b)
mapM TyFamInstEqn GhcRn -> RnM (TyFamInstEqn DocNameI)
FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn))
-> RnM (FamEqn DocNameI (GenLocated SrcSpanAnnA (HsType DocNameI)))
renameTyFamInstEqn)) Maybe [LTyFamInstEqn GhcRn]
Maybe
  [GenLocated
     SrcSpanAnnA (FamEqn GhcRn (GenLocated SrcSpanAnnA (HsType GhcRn)))]
eqns
    return $ ClosedTypeFamily eqns'

renameDataDefn :: HsDataDefn GhcRn -> RnM (HsDataDefn DocNameI)
renameDataDefn :: HsDataDefn GhcRn -> RnM (HsDataDefn DocNameI)
renameDataDefn
  ( HsDataDefn
      { dd_ctxt :: forall pass. HsDataDefn pass -> Maybe (LHsContext pass)
dd_ctxt = Maybe (LHsContext GhcRn)
lcontext
      , dd_cType :: forall pass. HsDataDefn pass -> Maybe (XRec pass CType)
dd_cType = Maybe (XRec GhcRn CType)
cType
      , dd_kindSig :: forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_kindSig = Maybe (LHsType GhcRn)
k
      , dd_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons = DataDefnCons (LConDecl GhcRn)
cons
      }
    ) = do
    lcontext' <- (LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)]
 -> RnM (LocatedC [GenLocated SrcSpanAnnA (HsType DocNameI)]))
-> Maybe (LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> RnM
     (Maybe (LocatedC [GenLocated SrcSpanAnnA (HsType DocNameI)]))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse LocatedC [LHsType GhcRn] -> RnM (LocatedC [LHsType DocNameI])
LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> RnM (LocatedC [GenLocated SrcSpanAnnA (HsType DocNameI)])
renameLContext Maybe (LHsContext GhcRn)
Maybe (LocatedC [GenLocated SrcSpanAnnA (HsType GhcRn)])
lcontext
    k' <- renameMaybeLKind k
    cons' <- mapM (mapMA renameCon) cons
    -- I don't think we need the derivings, so we return Nothing
    return
      ( HsDataDefn
          { dd_ext = noExtField
          , dd_ctxt = lcontext'
          , dd_cType = cType
          , dd_kindSig = k'
          , dd_cons = cons'
          , dd_derivs = []
          }
      )

renameCon :: ConDecl GhcRn -> RnM (ConDecl DocNameI)
renameCon :: ConDecl GhcRn -> RnM (ConDecl DocNameI)
renameCon
  decl :: ConDecl GhcRn
decl@( ConDeclH98
          { con_name :: forall pass. ConDecl pass -> LIdP pass
con_name = LIdP GhcRn
lname
          , con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_ex_tvs = [LHsTyVarBndr Specificity GhcRn]
ltyvars
          , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext GhcRn)
lcontext
          , con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_args = HsConDeclH98Details GhcRn
details
          , con_doc :: forall pass. ConDecl pass -> Maybe (LHsDoc pass)
con_doc = Maybe (LHsDoc GhcRn)
mbldoc
          , con_forall :: forall pass. ConDecl pass -> Bool
con_forall = Bool
forall_
          }
        ) = do
    lname' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname
    ltyvars' <- mapM (renameLTyVarBndr return) ltyvars
    lcontext' <- traverse renameLContext lcontext
    details' <- renameH98Details details
    mbldoc' <- mapM (renameLDocHsSyn) mbldoc
    return
      ( decl
          { con_ext = noExtField
          , con_name = lname'
          , con_ex_tvs = ltyvars'
          , con_mb_cxt = lcontext'
          , con_forall = forall_ -- Remove when #18311 is fixed
          , con_args = details'
          , con_doc = mbldoc'
          }
      )
renameCon
  ConDeclGADT
    { con_names :: forall pass. ConDecl pass -> NonEmpty (LIdP pass)
con_names = NonEmpty (LIdP GhcRn)
lnames
    , con_outer_bndrs :: forall pass. ConDecl pass -> XRec pass (HsOuterSigTyVarBndrs pass)
con_outer_bndrs = XRec GhcRn (HsOuterSigTyVarBndrs GhcRn)
outer_bndrs
    , con_inner_bndrs :: forall pass. ConDecl pass -> [HsForAllTelescope pass]
con_inner_bndrs = [HsForAllTelescope GhcRn]
inner_bndrs
    , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext GhcRn)
lcontext
    , con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_g_args = HsConDeclGADTDetails GhcRn
details
    , con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LHsType GhcRn
res_ty
    , con_doc :: forall pass. ConDecl pass -> Maybe (LHsDoc pass)
con_doc = Maybe (LHsDoc GhcRn)
mbldoc
    } = do
    lnames' <- (GenLocated SrcSpanAnnN Name
 -> RnM (GenLocated SrcSpanAnnN DocName))
-> NonEmpty (GenLocated SrcSpanAnnN Name)
-> RnM (NonEmpty (GenLocated SrcSpanAnnN DocName))
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> NonEmpty a -> m (NonEmpty b)
mapM GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL NonEmpty (LIdP GhcRn)
NonEmpty (GenLocated SrcSpanAnnN Name)
lnames
    outer_bndrs' <- mapM renameOuterTyVarBndrs outer_bndrs
    inner_bndrs' <- mapM renameHsForAllTelescope inner_bndrs
    lcontext' <- traverse renameLContext lcontext
    details' <- renameGADTDetails details
    res_ty' <- renameLType res_ty
    mbldoc' <- mapM renameLDocHsSyn mbldoc
    return
      ( ConDeclGADT
          { con_g_ext = noExtField
          , con_names = lnames'
          , con_outer_bndrs = outer_bndrs'
          , con_inner_bndrs = inner_bndrs'
          , con_mb_cxt = lcontext'
          , con_g_args = details'
          , con_res_ty = res_ty'
          , con_doc = mbldoc'
          }
      )

renameHsConDeclField
  :: HsConDeclField GhcRn
  -> RnM (HsConDeclField DocNameI)
renameHsConDeclField :: HsConDeclField GhcRn -> RnM (HsConDeclField DocNameI)
renameHsConDeclField HsConDeclField GhcRn
cdf = do
  w <- HsMultAnn GhcRn -> RnM (HsMultAnn DocNameI)
renameMultAnn (HsConDeclField GhcRn -> HsMultAnn GhcRn
forall pass. HsConDeclField pass -> HsMultAnn pass
cdf_multiplicity HsConDeclField GhcRn
cdf)
  ty <- renameLType (cdf_type cdf)
  doc <- mapM renameLDocHsSyn (cdf_doc cdf)
  return
    ( cdf
      { cdf_ext = noExtField
      , cdf_multiplicity = w
      , cdf_type = ty
      , cdf_doc = doc
      }
    )

renameH98Details
  :: HsConDeclH98Details GhcRn
  -> RnM (HsConDeclH98Details DocNameI)
renameH98Details :: HsConDeclH98Details GhcRn -> RnM (HsConDeclH98Details DocNameI)
renameH98Details (RecCon (L SrcSpanAnnL
l [GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)]
fields)) = do
  fields' <- (GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)
 -> RnM (GenLocated SrcSpan (HsConDeclRecField DocNameI)))
-> [GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)]
-> RnM [GenLocated SrcSpan (HsConDeclRecField DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsConDeclRecField GhcRn -> RnM (LHsConDeclRecField DocNameI)
GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)
-> RnM (GenLocated SrcSpan (HsConDeclRecField DocNameI))
renameHsConDeclRecFieldField [GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)]
fields
  return (RecCon (L (locA l) fields'))
renameH98Details (PrefixCon [HsConDeclField GhcRn]
ps) = [HsConDeclField DocNameI]
-> HsConDetails
     (HsConDeclField DocNameI)
     (GenLocated
        SrcSpan [GenLocated SrcSpan (HsConDeclRecField DocNameI)])
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon ([HsConDeclField DocNameI]
 -> HsConDetails
      (HsConDeclField DocNameI)
      (GenLocated
         SrcSpan [GenLocated SrcSpan (HsConDeclRecField DocNameI)]))
-> RnM [HsConDeclField DocNameI]
-> RnM
     (HsConDetails
        (HsConDeclField DocNameI)
        (GenLocated
           SrcSpan [GenLocated SrcSpan (HsConDeclRecField DocNameI)]))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (HsConDeclField GhcRn -> RnM (HsConDeclField DocNameI))
-> [HsConDeclField GhcRn] -> RnM [HsConDeclField DocNameI]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM HsConDeclField GhcRn -> RnM (HsConDeclField DocNameI)
renameHsConDeclField [HsConDeclField GhcRn]
ps
renameH98Details (InfixCon HsConDeclField GhcRn
a HsConDeclField GhcRn
b) = do
  a' <- HsConDeclField GhcRn -> RnM (HsConDeclField DocNameI)
renameHsConDeclField HsConDeclField GhcRn
a
  b' <- renameHsConDeclField b
  return (InfixCon a' b')

renameGADTDetails
  :: HsConDeclGADTDetails GhcRn
  -> RnM (HsConDeclGADTDetails DocNameI)
renameGADTDetails :: HsConDeclGADTDetails GhcRn -> RnM (HsConDeclGADTDetails DocNameI)
renameGADTDetails (RecConGADT XRecConGADT GhcRn
_ (L SrcSpanAnnL
l [GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)]
fields)) = do
  fields' <- (GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)
 -> RnM (GenLocated SrcSpan (HsConDeclRecField DocNameI)))
-> [GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)]
-> RnM [GenLocated SrcSpan (HsConDeclRecField DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LHsConDeclRecField GhcRn -> RnM (LHsConDeclRecField DocNameI)
GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)
-> RnM (GenLocated SrcSpan (HsConDeclRecField DocNameI))
renameHsConDeclRecFieldField [GenLocated SrcSpanAnnA (HsConDeclRecField GhcRn)]
fields
  return (RecConGADT noExtField (L (locA l) fields'))
renameGADTDetails (PrefixConGADT XPrefixConGADT GhcRn
_ [HsConDeclField GhcRn]
ps) = XPrefixConGADT DocNameI
-> [HsConDeclField DocNameI] -> HsConDeclGADTDetails DocNameI
forall pass.
XPrefixConGADT pass
-> [HsConDeclField pass] -> HsConDeclGADTDetails pass
PrefixConGADT NoExtField
XPrefixConGADT DocNameI
noExtField ([HsConDeclField DocNameI] -> HsConDeclGADTDetails DocNameI)
-> RnM [HsConDeclField DocNameI]
-> RnM (HsConDeclGADTDetails DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (HsConDeclField GhcRn -> RnM (HsConDeclField DocNameI))
-> [HsConDeclField GhcRn] -> RnM [HsConDeclField DocNameI]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM HsConDeclField GhcRn -> RnM (HsConDeclField DocNameI)
renameHsConDeclField [HsConDeclField GhcRn]
ps

renameHsConDeclRecFieldField :: LHsConDeclRecField GhcRn -> RnM (LHsConDeclRecField DocNameI)
renameHsConDeclRecFieldField :: LHsConDeclRecField GhcRn -> RnM (LHsConDeclRecField DocNameI)
renameHsConDeclRecFieldField (L SrcSpanAnnA
l (HsConDeclRecField XConDeclRecField GhcRn
_ [LFieldOcc GhcRn]
names HsConDeclField GhcRn
t)) = do
  names' <- (GenLocated SrcSpanAnnA (FieldOcc GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (FieldOcc DocNameI)))
-> [GenLocated SrcSpanAnnA (FieldOcc GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (FieldOcc DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM LFieldOcc GhcRn -> RnM (LFieldOcc DocNameI)
GenLocated SrcSpanAnnA (FieldOcc GhcRn)
-> RnM (GenLocated SrcSpanAnnA (FieldOcc DocNameI))
renameLFieldOcc [LFieldOcc GhcRn]
[GenLocated SrcSpanAnnA (FieldOcc GhcRn)]
names
  t' <- renameHsConDeclField t
  return $ L (locA l) (HsConDeclRecField noExtField names' t')

renameLFieldOcc :: LFieldOcc GhcRn -> RnM (LFieldOcc DocNameI)
renameLFieldOcc :: LFieldOcc GhcRn -> RnM (LFieldOcc DocNameI)
renameLFieldOcc (L SrcSpanAnnA
l (FieldOcc XCFieldOcc GhcRn
rdr (L SrcSpanAnnN
n Name
sel))) = do
  sel' <- Name -> RnM DocName
renameName Name
sel
  return $ L l (FieldOcc rdr (L n sel'))

renameSig :: Sig GhcRn -> RnM (Sig DocNameI)
renameSig :: Sig GhcRn -> RnM (Sig DocNameI)
renameSig Sig GhcRn
sig = case Sig GhcRn
sig of
  TypeSig XTypeSig GhcRn
_ [LIdP GhcRn]
lnames LHsSigWcType GhcRn
ltype -> do
    lnames' <- (GenLocated SrcSpanAnnN Name
 -> RnM (GenLocated SrcSpanAnnN DocName))
-> [GenLocated SrcSpanAnnN Name]
-> RnM [GenLocated SrcSpanAnnN DocName]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
lnames
    ltype' <- renameLSigWcType ltype
    return (TypeSig noExtField lnames' ltype')
  ClassOpSig XClassOpSig GhcRn
_ Bool
is_default [LIdP GhcRn]
lnames LHsSigType GhcRn
sig_ty -> do
    lnames' <- (GenLocated SrcSpanAnnN Name
 -> RnM (GenLocated SrcSpanAnnN DocName))
-> [GenLocated SrcSpanAnnN Name]
-> RnM [GenLocated SrcSpanAnnN DocName]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
lnames
    ltype' <- renameLSigType sig_ty
    return (ClassOpSig noExtField is_default lnames' ltype')
  PatSynSig XPatSynSig GhcRn
_ [LIdP GhcRn]
lnames LHsSigType GhcRn
sig_ty -> do
    lnames' <- (GenLocated SrcSpanAnnN Name
 -> RnM (GenLocated SrcSpanAnnN DocName))
-> [GenLocated SrcSpanAnnN Name]
-> RnM [GenLocated SrcSpanAnnN DocName]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
lnames
    sig_ty' <- renameLSigType sig_ty
    return $ PatSynSig noExtField lnames' sig_ty'
  FixSig XFixSig GhcRn
_ (FixitySig XFixitySig GhcRn
_ [LIdP GhcRn]
lnames Fixity
fixity) -> do
    lnames' <- (GenLocated SrcSpanAnnN Name
 -> RnM (GenLocated SrcSpanAnnN DocName))
-> [GenLocated SrcSpanAnnN Name]
-> RnM [GenLocated SrcSpanAnnN DocName]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
lnames
    return $ FixSig noExtField (FixitySig noExtField lnames' fixity)
  MinimalSig XMinimalSig GhcRn
_ (L SrcSpanAnnL
l BooleanFormula GhcRn
s) -> do
    s' <- (LIdP GhcRn -> RnM (LIdP DocNameI))
-> BooleanFormula GhcRn -> RnM (BooleanFormula DocNameI)
forall (f :: Type -> Type) (p :: Pass).
Applicative f =>
(LIdP (GhcPass p) -> f (LIdP DocNameI))
-> BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
bfTraverse ((Name -> RnM DocName)
-> GenLocated SrcSpanAnnN Name
-> RnM (GenLocated SrcSpanAnnN DocName)
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b)
-> GenLocated SrcSpanAnnN a -> f (GenLocated SrcSpanAnnN b)
traverse Name -> RnM DocName
lookupRn) BooleanFormula GhcRn
s
    return $ MinimalSig noExtField (L l s')
  -- we have filtered out all other kinds of signatures in Interface.Create
  Sig GhcRn
_ -> String -> RnM (Sig DocNameI)
forall a. HasCallStack => String -> a
error String
"expected TypeSig"

bfTraverse  :: Applicative f
            => (LIdP (GhcPass p) -> f (LIdP DocNameI))
            -> BooleanFormula (GhcPass p)
            -> f (BooleanFormula DocNameI)
bfTraverse :: forall (f :: Type -> Type) (p :: Pass).
Applicative f =>
(LIdP (GhcPass p) -> f (LIdP DocNameI))
-> BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
bfTraverse LIdP (GhcPass p) -> f (LIdP DocNameI)
f = BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
go
  where
    go :: BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
go (Var    LIdP (GhcPass p)
a  ) = LIdP DocNameI -> BooleanFormula DocNameI
GenLocated SrcSpanAnnN DocName -> BooleanFormula DocNameI
forall p. LIdP p -> BooleanFormula p
Var    (GenLocated SrcSpanAnnN DocName -> BooleanFormula DocNameI)
-> f (GenLocated SrcSpanAnnN DocName)
-> f (BooleanFormula DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LIdP (GhcPass p) -> f (LIdP DocNameI)
f LIdP (GhcPass p)
a
    go (And    [LBooleanFormula (GhcPass p)]
bfs) = [LBooleanFormula DocNameI] -> BooleanFormula DocNameI
[GenLocated SrcSpanAnnL (BooleanFormula DocNameI)]
-> BooleanFormula DocNameI
forall p. [LBooleanFormula p] -> BooleanFormula p
And    ([GenLocated SrcSpanAnnL (BooleanFormula DocNameI)]
 -> BooleanFormula DocNameI)
-> f [GenLocated SrcSpanAnnL (BooleanFormula DocNameI)]
-> f (BooleanFormula DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse @[] ((BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI))
-> GenLocated SrcSpanAnnL (BooleanFormula (GhcPass p))
-> f (GenLocated SrcSpanAnnL (BooleanFormula DocNameI))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b)
-> GenLocated SrcSpanAnnL a -> f (GenLocated SrcSpanAnnL b)
traverse BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
go) [LBooleanFormula (GhcPass p)]
[GenLocated SrcSpanAnnL (BooleanFormula (GhcPass p))]
bfs
    go (Or     [LBooleanFormula (GhcPass p)]
bfs) = [LBooleanFormula DocNameI] -> BooleanFormula DocNameI
[GenLocated SrcSpanAnnL (BooleanFormula DocNameI)]
-> BooleanFormula DocNameI
forall p. [LBooleanFormula p] -> BooleanFormula p
Or     ([GenLocated SrcSpanAnnL (BooleanFormula DocNameI)]
 -> BooleanFormula DocNameI)
-> f [GenLocated SrcSpanAnnL (BooleanFormula DocNameI)]
-> f (BooleanFormula DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse @[] ((BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI))
-> GenLocated SrcSpanAnnL (BooleanFormula (GhcPass p))
-> f (GenLocated SrcSpanAnnL (BooleanFormula DocNameI))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b)
-> GenLocated SrcSpanAnnL a -> f (GenLocated SrcSpanAnnL b)
traverse BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
go) [LBooleanFormula (GhcPass p)]
[GenLocated SrcSpanAnnL (BooleanFormula (GhcPass p))]
bfs
    go (Parens LBooleanFormula (GhcPass p)
bf ) = LBooleanFormula DocNameI -> BooleanFormula DocNameI
GenLocated SrcSpanAnnL (BooleanFormula DocNameI)
-> BooleanFormula DocNameI
forall p. LBooleanFormula p -> BooleanFormula p
Parens (GenLocated SrcSpanAnnL (BooleanFormula DocNameI)
 -> BooleanFormula DocNameI)
-> f (GenLocated SrcSpanAnnL (BooleanFormula DocNameI))
-> f (BooleanFormula DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI))
-> GenLocated SrcSpanAnnL (BooleanFormula (GhcPass p))
-> f (GenLocated SrcSpanAnnL (BooleanFormula DocNameI))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b)
-> GenLocated SrcSpanAnnL a -> f (GenLocated SrcSpanAnnL b)
traverse BooleanFormula (GhcPass p) -> f (BooleanFormula DocNameI)
go LBooleanFormula (GhcPass p)
GenLocated SrcSpanAnnL (BooleanFormula (GhcPass p))
bf

renameForD :: ForeignDecl GhcRn -> RnM (ForeignDecl DocNameI)
renameForD :: ForeignDecl GhcRn -> RnM (ForeignDecl DocNameI)
renameForD (ForeignImport XForeignImport GhcRn
_ LIdP GhcRn
lname LHsSigType GhcRn
ltype ForeignImport GhcRn
x) = do
  lname' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname
  ltype' <- renameLSigType ltype
  return (ForeignImport noExtField lname' ltype' (renameForI x))
renameForD (ForeignExport XForeignExport GhcRn
_ LIdP GhcRn
lname LHsSigType GhcRn
ltype ForeignExport GhcRn
x) = do
  lname' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname
  ltype' <- renameLSigType ltype
  return (ForeignExport noExtField lname' ltype' (renameForE x))

renameForI :: ForeignImport GhcRn -> ForeignImport DocNameI
renameForI :: ForeignImport GhcRn -> ForeignImport DocNameI
renameForI (CImport XCImport GhcRn
_ XRec GhcRn CCallConv
cconv XRec GhcRn Safety
safety Maybe Header
mHeader CImportSpec
spec) = XCImport DocNameI
-> XRec DocNameI CCallConv
-> XRec DocNameI Safety
-> Maybe Header
-> CImportSpec
-> ForeignImport DocNameI
forall pass.
XCImport pass
-> XRec pass CCallConv
-> XRec pass Safety
-> Maybe Header
-> CImportSpec
-> ForeignImport pass
CImport XCImport DocNameI
NoExtField
noExtField XRec GhcRn CCallConv
XRec DocNameI CCallConv
cconv XRec GhcRn Safety
XRec DocNameI Safety
safety Maybe Header
mHeader CImportSpec
spec

renameForE :: ForeignExport GhcRn -> ForeignExport DocNameI
renameForE :: ForeignExport GhcRn -> ForeignExport DocNameI
renameForE (CExport XCExport GhcRn
_ XRec GhcRn CExportSpec
spec) = XCExport DocNameI
-> XRec DocNameI CExportSpec -> ForeignExport DocNameI
forall pass.
XCExport pass -> XRec pass CExportSpec -> ForeignExport pass
CExport XCExport DocNameI
NoExtField
noExtField XRec GhcRn CExportSpec
XRec DocNameI CExportSpec
spec

renameInstD :: InstDecl GhcRn -> RnM (InstDecl DocNameI)
renameInstD :: InstDecl GhcRn -> RnM (InstDecl DocNameI)
renameInstD (ClsInstD{cid_inst :: forall pass. InstDecl pass -> ClsInstDecl pass
cid_inst = ClsInstDecl GhcRn
d}) = do
  d' <- ClsInstDecl GhcRn -> RnM (ClsInstDecl DocNameI)
renameClsInstD ClsInstDecl GhcRn
d
  return (ClsInstD{cid_d_ext = noExtField, cid_inst = d'})
renameInstD (TyFamInstD{tfid_inst :: forall pass. InstDecl pass -> TyFamInstDecl pass
tfid_inst = TyFamDefltDecl GhcRn
d}) = do
  d' <- TyFamDefltDecl GhcRn -> RnM (TyFamDefltDecl DocNameI)
renameTyFamInstD TyFamDefltDecl GhcRn
d
  return (TyFamInstD{tfid_ext = noExtField, tfid_inst = d'})
renameInstD (DataFamInstD{dfid_inst :: forall pass. InstDecl pass -> DataFamInstDecl pass
dfid_inst = DataFamInstDecl GhcRn
d}) = do
  d' <- DataFamInstDecl GhcRn -> RnM (DataFamInstDecl DocNameI)
renameDataFamInstD DataFamInstDecl GhcRn
d
  return (DataFamInstD{dfid_ext = noExtField, dfid_inst = d'})

renameDerivD :: DerivDecl GhcRn -> RnM (DerivDecl DocNameI)
renameDerivD :: DerivDecl GhcRn -> RnM (DerivDecl DocNameI)
renameDerivD
  ( DerivDecl
      { deriv_type :: forall pass. DerivDecl pass -> LHsSigWcType pass
deriv_type = LHsSigWcType GhcRn
ty
      , deriv_strategy :: forall pass. DerivDecl pass -> Maybe (LDerivStrategy pass)
deriv_strategy = Maybe (LDerivStrategy GhcRn)
strat
      , deriv_overlap_mode :: forall pass. DerivDecl pass -> Maybe (XRec pass OverlapMode)
deriv_overlap_mode = Maybe (XRec GhcRn OverlapMode)
omode
      }
    ) = do
    ty' <- LHsSigWcType GhcRn -> RnM (LHsSigWcType DocNameI)
renameLSigWcType LHsSigWcType GhcRn
ty
    strat' <- mapM (mapM renameDerivStrategy) strat
    return
      ( DerivDecl
          { deriv_ext = noExtField
          , deriv_type = ty'
          , deriv_strategy = strat'
          , deriv_overlap_mode = omode
          }
      )

renameDerivStrategy :: DerivStrategy GhcRn -> RnM (DerivStrategy DocNameI)
renameDerivStrategy :: DerivStrategy GhcRn -> RnM (DerivStrategy DocNameI)
renameDerivStrategy (StockStrategy XStockStrategy GhcRn
a) = DerivStrategy DocNameI -> RnM (DerivStrategy DocNameI)
forall a. a -> RnM a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (XStockStrategy DocNameI -> DerivStrategy DocNameI
forall pass. XStockStrategy pass -> DerivStrategy pass
StockStrategy XStockStrategy GhcRn
XStockStrategy DocNameI
a)
renameDerivStrategy (AnyclassStrategy XAnyClassStrategy GhcRn
a) = DerivStrategy DocNameI -> RnM (DerivStrategy DocNameI)
forall a. a -> RnM a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (XAnyClassStrategy DocNameI -> DerivStrategy DocNameI
forall pass. XAnyClassStrategy pass -> DerivStrategy pass
AnyclassStrategy XAnyClassStrategy GhcRn
XAnyClassStrategy DocNameI
a)
renameDerivStrategy (NewtypeStrategy XNewtypeStrategy GhcRn
a) = DerivStrategy DocNameI -> RnM (DerivStrategy DocNameI)
forall a. a -> RnM a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (XNewtypeStrategy DocNameI -> DerivStrategy DocNameI
forall pass. XNewtypeStrategy pass -> DerivStrategy pass
NewtypeStrategy XNewtypeStrategy GhcRn
XNewtypeStrategy DocNameI
a)
renameDerivStrategy (ViaStrategy XViaStrategy GhcRn
ty) = XViaStrategy DocNameI -> DerivStrategy DocNameI
GenLocated SrcSpanAnnA (HsSigType DocNameI)
-> DerivStrategy DocNameI
forall pass. XViaStrategy pass -> DerivStrategy pass
ViaStrategy (GenLocated SrcSpanAnnA (HsSigType DocNameI)
 -> DerivStrategy DocNameI)
-> RnM (GenLocated SrcSpanAnnA (HsSigType DocNameI))
-> RnM (DerivStrategy DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsSigType GhcRn -> RnM (LHsSigType DocNameI)
renameLSigType XViaStrategy GhcRn
LHsSigType GhcRn
ty

renameClsInstD :: ClsInstDecl GhcRn -> RnM (ClsInstDecl DocNameI)
renameClsInstD :: ClsInstDecl GhcRn -> RnM (ClsInstDecl DocNameI)
renameClsInstD
  ( ClsInstDecl
      { cid_overlap_mode :: forall pass. ClsInstDecl pass -> Maybe (XRec pass OverlapMode)
cid_overlap_mode = Maybe (XRec GhcRn OverlapMode)
omode
      , cid_poly_ty :: forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty = LHsSigType GhcRn
ltype
      , cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts = [LTyFamDefltDecl GhcRn]
lATs
      , cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts = [LDataFamInstDecl GhcRn]
lADTs
      }
    ) = do
    ltype' <- LHsSigType GhcRn -> RnM (LHsSigType DocNameI)
renameLSigType LHsSigType GhcRn
ltype
    lATs' <- mapM (mapM renameTyFamInstD) lATs
    lADTs' <- mapM (mapM renameDataFamInstD) lADTs
    return
      ( ClsInstDecl
          { cid_ext = noExtField
          , cid_overlap_mode = omode
          , cid_poly_ty = ltype'
          , cid_binds = []
          , cid_sigs = []
          , cid_tyfam_insts = lATs'
          , cid_datafam_insts = lADTs'
          }
      )

renameTyFamInstD :: TyFamInstDecl GhcRn -> RnM (TyFamInstDecl DocNameI)
renameTyFamInstD :: TyFamDefltDecl GhcRn -> RnM (TyFamDefltDecl DocNameI)
renameTyFamInstD (TyFamInstDecl{tfid_eqn :: forall pass. TyFamInstDecl pass -> TyFamInstEqn pass
tfid_eqn = TyFamInstEqn GhcRn
eqn}) =
  do
    eqn' <- TyFamInstEqn GhcRn -> RnM (TyFamInstEqn DocNameI)
renameTyFamInstEqn TyFamInstEqn GhcRn
eqn
    return (TyFamInstDecl{tfid_xtn = noExtField, tfid_eqn = eqn'})

renameTyFamInstEqn :: TyFamInstEqn GhcRn -> RnM (TyFamInstEqn DocNameI)
renameTyFamInstEqn :: TyFamInstEqn GhcRn -> RnM (TyFamInstEqn DocNameI)
renameTyFamInstEqn
  ( FamEqn
      { feqn_tycon :: forall pass rhs. FamEqn pass rhs -> LIdP pass
feqn_tycon = LIdP GhcRn
tc
      , feqn_bndrs :: forall pass rhs. FamEqn pass rhs -> HsOuterFamEqnTyVarBndrs pass
feqn_bndrs = HsOuterFamEqnTyVarBndrs GhcRn
bndrs
      , feqn_pats :: forall pass rhs. FamEqn pass rhs -> HsFamEqnPats pass
feqn_pats = HsFamEqnPats GhcRn
pats
      , feqn_fixity :: forall pass rhs. FamEqn pass rhs -> LexicalFixity
feqn_fixity = LexicalFixity
fixity
      , feqn_rhs :: forall pass rhs. FamEqn pass rhs -> rhs
feqn_rhs = LHsType GhcRn
rhs
      }
    ) =
    do
      tc' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
tc
      bndrs' <- renameOuterTyVarBndrs bndrs
      pats' <- mapM renameLTypeArg pats
      rhs' <- renameLType rhs
      return
        ( FamEqn
            { feqn_ext = noExtField
            , feqn_tycon = tc'
            , feqn_bndrs = bndrs'
            , feqn_pats = pats'
            , feqn_fixity = fixity
            , feqn_rhs = rhs'
            }
        )

renameTyFamDefltD :: TyFamDefltDecl GhcRn -> RnM (TyFamDefltDecl DocNameI)
renameTyFamDefltD :: TyFamDefltDecl GhcRn -> RnM (TyFamDefltDecl DocNameI)
renameTyFamDefltD = TyFamDefltDecl GhcRn -> RnM (TyFamDefltDecl DocNameI)
renameTyFamInstD

renameDataFamInstD :: DataFamInstDecl GhcRn -> RnM (DataFamInstDecl DocNameI)
renameDataFamInstD :: DataFamInstDecl GhcRn -> RnM (DataFamInstDecl DocNameI)
renameDataFamInstD (DataFamInstDecl{dfid_eqn :: forall pass. DataFamInstDecl pass -> FamEqn pass (HsDataDefn pass)
dfid_eqn = FamEqn GhcRn (HsDataDefn GhcRn)
eqn}) =
  do
    eqn' <- FamEqn GhcRn (HsDataDefn GhcRn)
-> RnM (FamEqn DocNameI (HsDataDefn DocNameI))
rename_data_fam_eqn FamEqn GhcRn (HsDataDefn GhcRn)
eqn
    return (DataFamInstDecl{dfid_eqn = eqn'})
  where
    rename_data_fam_eqn
      :: FamEqn GhcRn (HsDataDefn GhcRn)
      -> RnM (FamEqn DocNameI (HsDataDefn DocNameI))
    rename_data_fam_eqn :: FamEqn GhcRn (HsDataDefn GhcRn)
-> RnM (FamEqn DocNameI (HsDataDefn DocNameI))
rename_data_fam_eqn
      ( FamEqn
          { feqn_tycon :: forall pass rhs. FamEqn pass rhs -> LIdP pass
feqn_tycon = LIdP GhcRn
tc
          , feqn_bndrs :: forall pass rhs. FamEqn pass rhs -> HsOuterFamEqnTyVarBndrs pass
feqn_bndrs = HsOuterFamEqnTyVarBndrs GhcRn
bndrs
          , feqn_pats :: forall pass rhs. FamEqn pass rhs -> HsFamEqnPats pass
feqn_pats = HsFamEqnPats GhcRn
pats
          , feqn_fixity :: forall pass rhs. FamEqn pass rhs -> LexicalFixity
feqn_fixity = LexicalFixity
fixity
          , feqn_rhs :: forall pass rhs. FamEqn pass rhs -> rhs
feqn_rhs = HsDataDefn GhcRn
defn
          }
        ) =
        do
          tc' <- GenLocated SrcSpanAnnN Name -> RnM (GenLocated SrcSpanAnnN DocName)
forall l. GenLocated l Name -> RnM (GenLocated l DocName)
renameNameL LIdP GhcRn
GenLocated SrcSpanAnnN Name
tc
          bndrs' <- renameOuterTyVarBndrs bndrs
          pats' <- mapM renameLTypeArg pats
          defn' <- renameDataDefn defn
          return
            ( FamEqn
                { feqn_ext = noExtField
                , feqn_tycon = tc'
                , feqn_bndrs = bndrs'
                , feqn_pats = pats'
                , feqn_fixity = fixity
                , feqn_rhs = defn'
                }
            )

renameOuterTyVarBndrs
  :: HsOuterTyVarBndrs flag GhcRn
  -> RnM (HsOuterTyVarBndrs flag DocNameI)
renameOuterTyVarBndrs :: forall flag.
HsOuterTyVarBndrs flag GhcRn
-> RnM (HsOuterTyVarBndrs flag DocNameI)
renameOuterTyVarBndrs (HsOuterImplicit{}) =
  HsOuterTyVarBndrs flag DocNameI
-> RnM (HsOuterTyVarBndrs flag DocNameI)
forall a. a -> RnM a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (HsOuterTyVarBndrs flag DocNameI
 -> RnM (HsOuterTyVarBndrs flag DocNameI))
-> HsOuterTyVarBndrs flag DocNameI
-> RnM (HsOuterTyVarBndrs flag DocNameI)
forall a b. (a -> b) -> a -> b
$ HsOuterImplicit{hso_ximplicit :: XHsOuterImplicit DocNameI
hso_ximplicit = XHsOuterImplicit DocNameI
NoExtField
noExtField}
renameOuterTyVarBndrs (HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr flag (NoGhcTc GhcRn)]
exp_bndrs}) =
  XHsOuterExplicit DocNameI flag
-> [LHsTyVarBndr flag (NoGhcTc DocNameI)]
-> HsOuterTyVarBndrs flag DocNameI
forall flag pass.
XHsOuterExplicit pass flag
-> [LHsTyVarBndr flag (NoGhcTc pass)]
-> HsOuterTyVarBndrs flag pass
HsOuterExplicit XHsOuterExplicit DocNameI flag
NoExtField
noExtField ([GenLocated SrcSpanAnnA (HsTyVarBndr flag DocNameI)]
 -> HsOuterTyVarBndrs flag DocNameI)
-> RnM [GenLocated SrcSpanAnnA (HsTyVarBndr flag DocNameI)]
-> RnM (HsOuterTyVarBndrs flag DocNameI)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)
 -> RnM (GenLocated SrcSpanAnnA (HsTyVarBndr flag DocNameI)))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
-> RnM [GenLocated SrcSpanAnnA (HsTyVarBndr flag DocNameI)]
forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> [a] -> m [b]
mapM ((flag -> RnM flag)
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag DocNameI)
forall flag flag'.
(flag -> RnM flag')
-> LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag' DocNameI)
renameLTyVarBndr flag -> RnM flag
forall a. a -> RnM a
forall (m :: Type -> Type) a. Monad m => a -> m a
return) [LHsTyVarBndr flag (NoGhcTc GhcRn)]
[GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
exp_bndrs

renameWc
  :: (in_thing -> RnM out_thing)
  -> HsWildCardBndrs GhcRn in_thing
  -> RnM (HsWildCardBndrs DocNameI out_thing)
renameWc :: forall in_thing out_thing.
(in_thing -> RnM out_thing)
-> HsWildCardBndrs GhcRn in_thing
-> RnM (HsWildCardBndrs DocNameI out_thing)
renameWc in_thing -> RnM out_thing
rn_thing (HsWC{hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = in_thing
thing}) =
  do
    thing' <- in_thing -> RnM out_thing
rn_thing in_thing
thing
    return
      ( HsWC
          { hswc_body = thing'
          , hswc_ext = noExtField
          }
      )

renameDocInstance :: DocInstance GhcRn -> RnM (DocInstance DocNameI)
renameDocInstance :: DocInstance GhcRn -> RnM (DocInstance DocNameI)
renameDocInstance (InstHead GhcRn
inst, Maybe (MDoc (IdP GhcRn))
idoc, L SrcSpan
l IdP GhcRn
n, Maybe Module
m) = do
  inst' <- InstHead GhcRn -> RnM (InstHead DocNameI)
renameInstHead InstHead GhcRn
inst
  n' <- renameName n
  idoc' <- mapM renameDoc idoc
  return (inst', idoc', L l n', m)

renameSub :: (Name, DocForDecl Name) -> RnM (DocName, DocForDecl DocName)
renameSub :: (Name, DocForDecl Name) -> RnM (DocName, DocForDecl DocName)
renameSub (Name
n, DocForDecl Name
doc) = do
  n' <- Name -> RnM DocName
renameName Name
n
  doc' <- renameDocForDecl doc
  return (n', doc')