{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module Haddock.Interface.RenameType
( rename
) where
import Control.Monad.Trans.State
import qualified Data.List as List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as Set
import GHC
import GHC.Data.FastString
import GHC.Types.Name
import Haddock.Types
newtype NameRep
= NameRep FastString
deriving (NameRep -> NameRep -> Bool
(NameRep -> NameRep -> Bool)
-> (NameRep -> NameRep -> Bool) -> Eq NameRep
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameRep -> NameRep -> Bool
== :: NameRep -> NameRep -> Bool
$c/= :: NameRep -> NameRep -> Bool
/= :: NameRep -> NameRep -> Bool
Eq)
instance Ord NameRep where
compare :: NameRep -> NameRep -> Ordering
compare (NameRep FastString
fs1) (NameRep FastString
fs2) = FastString -> FastString -> Ordering
uniqCompareFS FastString
fs1 FastString
fs2
getNameRep :: NamedThing name => name -> NameRep
getNameRep :: forall name. NamedThing name => name -> NameRep
getNameRep = FastString -> NameRep
NameRep (FastString -> NameRep) -> (name -> FastString) -> name -> NameRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. name -> FastString
forall a. NamedThing a => a -> FastString
getOccFS
nameRepString :: NameRep -> String
nameRepString :: NameRep -> String
nameRepString (NameRep FastString
fs) = FastString -> String
unpackFS FastString
fs
stringNameRep :: String -> NameRep
stringNameRep :: String -> NameRep
stringNameRep = FastString -> NameRep
NameRep (FastString -> NameRep)
-> (String -> FastString) -> String -> NameRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> FastString
mkFastString
setInternalNameRep :: SetName name => NameRep -> name -> name
setInternalNameRep :: forall name. SetName name => NameRep -> name -> name
setInternalNameRep (NameRep FastString
fs) = OccName -> name -> name
forall name. SetName name => OccName -> name -> name
setInternalOccName (FastString -> OccName
mkVarOccFS FastString
fs)
setInternalOccName :: SetName name => OccName -> name -> name
setInternalOccName :: forall name. SetName name => OccName -> name -> name
setInternalOccName OccName
occ name
name =
Name -> name -> name
forall name. SetName name => Name -> name -> name
setName Name
nname' name
name
where
nname :: Name
nname = name -> Name
forall a. NamedThing a => a -> Name
getName name
name
nname' :: Name
nname' = Unique -> OccName -> SrcSpan -> Name
mkInternalName (Name -> Unique
nameUnique Name
nname) OccName
occ (Name -> SrcSpan
nameSrcSpan Name
nname)
rename :: [Name] -> LHsType GhcRn -> LHsType GhcRn
rename :: [Name] -> LHsType GhcRn -> LHsType GhcRn
rename [] LHsType GhcRn
typ = LHsType GhcRn
typ
rename [Name]
fv LHsType GhcRn
typ = State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> RenameEnv Name -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall s a. State s a -> s -> a
evalState ((HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
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 SrcSpanAnnA a -> f (GenLocated SrcSpanAnnA b)
traverse HsType GhcRn -> Rename (IdP GhcRn) (HsType GhcRn)
HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
renameType LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
typ) RenameEnv Name
env
where
env :: RenameEnv Name
env =
RenameEnv
{ rneHeadFVs :: Map NameRep Name
rneHeadFVs = [(NameRep, Name)] -> Map NameRep Name
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(NameRep, Name)] -> Map NameRep Name)
-> [(NameRep, Name)] -> Map NameRep Name
forall a b. (a -> b) -> a -> b
$ (Name -> (NameRep, Name)) -> [Name] -> [(NameRep, Name)]
forall a b. (a -> b) -> [a] -> [b]
map Name -> (NameRep, Name)
forall {b}. NamedThing b => b -> (NameRep, b)
mkPair [Name]
fv
, rneCtx :: Map Name Name
rneCtx = Map Name Name
forall k a. Map k a
Map.empty
}
mkPair :: b -> (NameRep, b)
mkPair b
name = (b -> NameRep
forall name. NamedThing name => name -> NameRep
getNameRep b
name, b
name)
type Rename name = State (RenameEnv name)
data RenameEnv name = RenameEnv
{ forall name. RenameEnv name -> Map NameRep Name
rneHeadFVs :: Map NameRep Name
, forall name. RenameEnv name -> Map Name name
rneCtx :: Map Name name
}
renameType :: HsType GhcRn -> Rename (IdP GhcRn) (HsType GhcRn)
renameType :: HsType GhcRn -> Rename (IdP GhcRn) (HsType GhcRn)
renameType (HsForAllTy XForAllTy GhcRn
x HsForAllTelescope GhcRn
tele LHsType GhcRn
lt) =
XForAllTy GhcRn
-> HsForAllTelescope GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XForAllTy pass
-> HsForAllTelescope pass -> LHsType pass -> HsType pass
HsForAllTy XForAllTy GhcRn
x
(HsForAllTelescope GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> StateT (RenameEnv Name) Identity (HsForAllTelescope GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> HsForAllTelescope GhcRn
-> Rename (IdP GhcRn) (HsForAllTelescope GhcRn)
renameForAllTelescope HsForAllTelescope GhcRn
tele
StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt
renameType (HsQualTy XQualTy GhcRn
x LHsContext GhcRn
lctxt LHsType GhcRn
lt) =
XQualTy GhcRn -> LHsContext GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XQualTy pass -> LHsContext pass -> LHsType pass -> HsType pass
HsQualTy XQualTy GhcRn
x
(GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)])
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsContext GhcRn -> Rename (IdP GhcRn) (LHsContext GhcRn)
renameLContext LHsContext GhcRn
lctxt
StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt
renameType (HsTyVar XTyVar GhcRn
x PromotionFlag
ip LIdP GhcRn
name) = XTyVar GhcRn -> PromotionFlag -> LIdP GhcRn -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcRn
x PromotionFlag
ip (GenLocated SrcSpanAnnN Name -> HsType GhcRn)
-> StateT (RenameEnv Name) Identity (GenLocated SrcSpanAnnN Name)
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> StateT (RenameEnv Name) Identity Name)
-> GenLocated SrcSpanAnnN Name
-> StateT (RenameEnv Name) Identity (GenLocated SrcSpanAnnN Name)
forall (f :: Type -> Type) a b.
Functor f =>
(a -> f b) -> LocatedN a -> f (LocatedN b)
locatedN Name -> StateT (RenameEnv Name) Identity Name
forall name. SetName name => name -> Rename name name
renameName LIdP GhcRn
GenLocated SrcSpanAnnN Name
name
renameType t :: HsType GhcRn
t@(HsStarTy XStarTy GhcRn
_ Bool
_) = HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure HsType GhcRn
t
renameType (HsAppTy XAppTy GhcRn
x LHsType GhcRn
lf LHsType GhcRn
la) = XAppTy GhcRn -> LHsType GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XAppTy pass -> LHsType pass -> LHsType pass -> HsType pass
HsAppTy XAppTy GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lf StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
la
renameType (HsAppKindTy XAppKindTy GhcRn
x LHsType GhcRn
lt LHsType GhcRn
lk) = XAppKindTy GhcRn -> LHsType GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XAppKindTy pass -> LHsType pass -> LHsType pass -> HsType pass
HsAppKindTy XAppKindTy GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLKind LHsType GhcRn
lk
renameType (HsFunTy XFunTy GhcRn
x HsArrow GhcRn
w LHsType GhcRn
la LHsType GhcRn
lr) = XFunTy GhcRn
-> HsArrow GhcRn -> LHsType GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XFunTy pass
-> HsArrow pass -> LHsType pass -> LHsType pass -> HsType pass
HsFunTy XFunTy GhcRn
x (HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsType GhcRn)
-> StateT
(RenameEnv Name)
Identity
(HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> HsArrow GhcRn -> Rename (IdP GhcRn) (HsArrow GhcRn)
renameHsArrow HsArrow GhcRn
w StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
la StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lr
renameType (HsListTy XListTy GhcRn
x LHsType GhcRn
lt) = XListTy GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass. XListTy pass -> LHsType pass -> HsType pass
HsListTy XListTy GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt
renameType (HsTupleTy XTupleTy GhcRn
x HsTupleSort
srt [LHsType GhcRn]
lt) = XTupleTy GhcRn -> HsTupleSort -> [LHsType GhcRn] -> HsType GhcRn
forall pass.
XTupleTy pass -> HsTupleSort -> [LHsType pass] -> HsType pass
HsTupleTy XTupleTy GhcRn
x HsTupleSort
srt ([GenLocated SrcSpanAnnA (HsType GhcRn)] -> HsType GhcRn)
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
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 -> Rename (IdP GhcRn) (LHsType GhcRn)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
lt
renameType (HsSumTy XSumTy GhcRn
x [LHsType GhcRn]
lt) = XSumTy GhcRn -> [LHsType GhcRn] -> HsType GhcRn
forall pass. XSumTy pass -> [LHsType pass] -> HsType pass
HsSumTy XSumTy GhcRn
x ([GenLocated SrcSpanAnnA (HsType GhcRn)] -> HsType GhcRn)
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
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 -> Rename (IdP GhcRn) (LHsType GhcRn)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
renameLType [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
lt
renameType (HsOpTy XOpTy GhcRn
x PromotionFlag
f LHsType GhcRn
la LIdP GhcRn
lop LHsType GhcRn
lb) =
XOpTy GhcRn
-> PromotionFlag
-> LHsType GhcRn
-> LIdP GhcRn
-> LHsType GhcRn
-> HsType GhcRn
forall pass.
XOpTy pass
-> PromotionFlag
-> LHsType pass
-> LIdP pass
-> LHsType pass
-> HsType pass
HsOpTy XOpTy GhcRn
x (PromotionFlag
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnN Name
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsType GhcRn)
-> StateT (RenameEnv Name) Identity PromotionFlag
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnN Name
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> PromotionFlag -> StateT (RenameEnv Name) Identity PromotionFlag
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure PromotionFlag
f StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnN Name
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnN Name
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
la StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnN Name
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> StateT (RenameEnv Name) Identity (GenLocated SrcSpanAnnN Name)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> (Name -> StateT (RenameEnv Name) Identity Name)
-> GenLocated SrcSpanAnnN Name
-> StateT (RenameEnv Name) Identity (GenLocated SrcSpanAnnN Name)
forall (f :: Type -> Type) a b.
Functor f =>
(a -> f b) -> LocatedN a -> f (LocatedN b)
locatedN Name -> StateT (RenameEnv Name) Identity Name
forall name. SetName name => name -> Rename name name
renameName LIdP GhcRn
GenLocated SrcSpanAnnN Name
lop StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lb
renameType (HsParTy XParTy GhcRn
x LHsType GhcRn
lt) = XParTy GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass. XParTy pass -> LHsType pass -> HsType pass
HsParTy XParTy GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt
renameType (HsIParamTy XIParamTy GhcRn
x XRec GhcRn HsIPName
ip LHsType GhcRn
lt) = XIParamTy GhcRn
-> XRec GhcRn HsIPName -> LHsType GhcRn -> HsType GhcRn
forall pass.
XIParamTy pass -> XRec pass HsIPName -> LHsType pass -> HsType pass
HsIParamTy XIParamTy GhcRn
x XRec GhcRn HsIPName
ip (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt
renameType (HsKindSig XKindSig GhcRn
x LHsType GhcRn
lt LHsType GhcRn
lk) = XKindSig GhcRn -> LHsType GhcRn -> LHsType GhcRn -> HsType GhcRn
forall pass.
XKindSig pass -> LHsType pass -> LHsType pass -> HsType pass
HsKindSig XKindSig GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
lk
renameType t :: HsType GhcRn
t@(HsSpliceTy XSpliceTy GhcRn
_ HsUntypedSplice GhcRn
_) = HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure HsType GhcRn
t
renameType (HsDocTy XDocTy GhcRn
x LHsType GhcRn
lt LHsDoc GhcRn
doc) = XDocTy GhcRn -> LHsType GhcRn -> LHsDoc GhcRn -> HsType GhcRn
forall pass.
XDocTy pass -> LHsType pass -> LHsDoc pass -> HsType pass
HsDocTy XDocTy GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn)
-> LHsDoc GhcRn -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (LHsDoc GhcRn -> HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt StateT (RenameEnv Name) Identity (LHsDoc GhcRn -> HsType GhcRn)
-> StateT (RenameEnv Name) Identity (LHsDoc GhcRn)
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> LHsDoc GhcRn -> StateT (RenameEnv Name) Identity (LHsDoc GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure LHsDoc GhcRn
doc
renameType (HsBangTy XBangTy GhcRn
x HsBang
bang LHsType GhcRn
lt) = XBangTy GhcRn -> HsBang -> LHsType GhcRn -> HsType GhcRn
forall pass. XBangTy pass -> HsBang -> LHsType pass -> HsType pass
HsBangTy XBangTy GhcRn
x HsBang
bang (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
lt
renameType t :: HsType GhcRn
t@(HsRecTy XRecTy GhcRn
_ [LConDeclField GhcRn]
_) = HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure HsType GhcRn
t
renameType t :: HsType GhcRn
t@(XHsType XXType GhcRn
_) = HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure HsType GhcRn
t
renameType (HsExplicitListTy XExplicitListTy GhcRn
x PromotionFlag
ip [LHsType GhcRn]
ltys) =
XExplicitListTy GhcRn
-> PromotionFlag -> [LHsType GhcRn] -> HsType GhcRn
forall pass.
XExplicitListTy pass
-> PromotionFlag -> [LHsType pass] -> HsType pass
HsExplicitListTy XExplicitListTy GhcRn
x PromotionFlag
ip ([GenLocated SrcSpanAnnA (HsType GhcRn)] -> HsType GhcRn)
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameLTypes [LHsType GhcRn]
ltys
renameType (HsExplicitTupleTy XExplicitTupleTy GhcRn
x PromotionFlag
ip [LHsType GhcRn]
ltys) =
XExplicitTupleTy GhcRn
-> PromotionFlag -> [LHsType GhcRn] -> HsType GhcRn
forall pass.
XExplicitTupleTy pass
-> PromotionFlag -> [LHsType pass] -> HsType pass
HsExplicitTupleTy XExplicitTupleTy GhcRn
x PromotionFlag
ip ([GenLocated SrcSpanAnnA (HsType GhcRn)] -> HsType GhcRn)
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameLTypes [LHsType GhcRn]
ltys
renameType t :: HsType GhcRn
t@(HsTyLit XTyLit GhcRn
_ HsTyLit GhcRn
_) = HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure HsType GhcRn
t
renameType (HsWildCardTy XWildCardTy GhcRn
wc) = HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (XWildCardTy GhcRn -> HsType GhcRn
forall pass. XWildCardTy pass -> HsType pass
HsWildCardTy XWildCardTy GhcRn
wc)
renameHsArrow :: HsArrow GhcRn -> Rename (IdP GhcRn) (HsArrow GhcRn)
renameHsArrow :: HsArrow GhcRn -> Rename (IdP GhcRn) (HsArrow GhcRn)
renameHsArrow (HsExplicitMult XExplicitMult (LHsType GhcRn) GhcRn
x LHsType GhcRn
p) = XExplicitMult (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
forall mult pass.
XExplicitMult mult pass -> mult -> HsArrowOf mult pass
HsExplicitMult XExplicitMult (LHsType GhcRn) GhcRn
XExplicitMult (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT
(RenameEnv Name)
Identity
(HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType LHsType GhcRn
p
renameHsArrow HsArrow GhcRn
mult = HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
-> StateT
(RenameEnv Name)
Identity
(HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure HsArrow GhcRn
HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
mult
renameLType :: LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType :: LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType = (HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
forall (f :: Type -> Type) a b l.
Functor f =>
(a -> f b) -> GenLocated l a -> f (GenLocated l b)
located HsType GhcRn -> Rename (IdP GhcRn) (HsType GhcRn)
HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
renameType
renameLKind :: LHsKind GhcRn -> Rename (IdP GhcRn) (LHsKind GhcRn)
renameLKind :: LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLKind = LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
renameLType
renameLTypes :: [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameLTypes :: [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameLTypes = (GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn)))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> StateT
(RenameEnv Name) Identity [GenLocated SrcSpanAnnA (HsType GhcRn)]
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 -> Rename (IdP GhcRn) (LHsType GhcRn)
GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
renameLType
renameLContext :: LHsContext GhcRn -> Rename (IdP GhcRn) (LHsContext GhcRn)
renameLContext :: LHsContext GhcRn -> Rename (IdP GhcRn) (LHsContext GhcRn)
renameLContext (L SrcSpanAnnC
l [GenLocated SrcSpanAnnA (HsType GhcRn)]
ctxt) = do
ctxt' <- [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameContext [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
ctxt
return (L l ctxt')
renameContext :: HsContext GhcRn -> Rename (IdP GhcRn) (HsContext GhcRn)
renameContext :: [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameContext = [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
renameLTypes
renameForAllTelescope
:: HsForAllTelescope GhcRn
-> Rename (IdP GhcRn) (HsForAllTelescope GhcRn)
renameForAllTelescope :: HsForAllTelescope GhcRn
-> Rename (IdP GhcRn) (HsForAllTelescope GhcRn)
renameForAllTelescope (HsForAllVis XHsForAllVis GhcRn
x [LHsTyVarBndr () GhcRn]
bndrs) =
XHsForAllVis GhcRn
-> [LHsTyVarBndr () GhcRn] -> HsForAllTelescope GhcRn
forall pass.
XHsForAllVis pass
-> [LHsTyVarBndr () pass] -> HsForAllTelescope pass
HsForAllVis XHsForAllVis GhcRn
x ([GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
-> HsForAllTelescope GhcRn)
-> StateT
(RenameEnv Name)
Identity
[GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
-> StateT (RenameEnv Name) Identity (HsForAllTelescope GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
-> StateT
(RenameEnv Name)
Identity
[GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
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 LHsTyVarBndr () GhcRn -> Rename (IdP GhcRn) (LHsTyVarBndr () GhcRn)
GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn))
forall flag.
LHsTyVarBndr flag GhcRn
-> Rename (IdP GhcRn) (LHsTyVarBndr flag GhcRn)
renameLBinder [LHsTyVarBndr () GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
bndrs
renameForAllTelescope (HsForAllInvis XHsForAllInvis GhcRn
x [LHsTyVarBndr Specificity GhcRn]
bndrs) =
XHsForAllInvis GhcRn
-> [LHsTyVarBndr Specificity GhcRn] -> HsForAllTelescope GhcRn
forall pass.
XHsForAllInvis pass
-> [LHsTyVarBndr Specificity pass] -> HsForAllTelescope pass
HsForAllInvis XHsForAllInvis GhcRn
x ([GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
-> HsForAllTelescope GhcRn)
-> StateT
(RenameEnv Name)
Identity
[GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
-> StateT (RenameEnv Name) Identity (HsForAllTelescope GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
-> StateT
(RenameEnv Name)
Identity
[GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
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 LHsTyVarBndr Specificity GhcRn
-> Rename (IdP GhcRn) (LHsTyVarBndr Specificity GhcRn)
GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn))
forall flag.
LHsTyVarBndr flag GhcRn
-> Rename (IdP GhcRn) (LHsTyVarBndr flag GhcRn)
renameLBinder [LHsTyVarBndr Specificity GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
bndrs
renameBinder :: HsTyVarBndr flag GhcRn -> Rename (IdP GhcRn) (HsTyVarBndr flag GhcRn)
renameBinder :: forall flag.
HsTyVarBndr flag GhcRn
-> Rename (IdP GhcRn) (HsTyVarBndr flag GhcRn)
renameBinder (HsTvb XTyVarBndr GhcRn
x flag
fl HsBndrVar GhcRn
bvar HsBndrKind GhcRn
lkind) =
XTyVarBndr GhcRn
-> flag
-> HsBndrVar GhcRn
-> HsBndrKind GhcRn
-> HsTyVarBndr flag GhcRn
forall flag pass.
XTyVarBndr pass
-> flag
-> HsBndrVar pass
-> HsBndrKind pass
-> HsTyVarBndr flag pass
HsTvb XTyVarBndr GhcRn
x flag
fl (HsBndrVar GhcRn -> HsBndrKind GhcRn -> HsTyVarBndr flag GhcRn)
-> StateT (RenameEnv Name) Identity (HsBndrVar GhcRn)
-> StateT
(RenameEnv Name)
Identity
(HsBndrKind GhcRn -> HsTyVarBndr flag GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> HsBndrVar GhcRn -> Rename (IdP GhcRn) (HsBndrVar GhcRn)
renameBinderVar HsBndrVar GhcRn
bvar StateT
(RenameEnv Name)
Identity
(HsBndrKind GhcRn -> HsTyVarBndr flag GhcRn)
-> StateT (RenameEnv Name) Identity (HsBndrKind GhcRn)
-> StateT (RenameEnv Name) Identity (HsTyVarBndr flag GhcRn)
forall a b.
StateT (RenameEnv Name) Identity (a -> b)
-> StateT (RenameEnv Name) Identity a
-> StateT (RenameEnv Name) Identity b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> HsBndrKind GhcRn -> Rename (IdP GhcRn) (HsBndrKind GhcRn)
renameBinderKind HsBndrKind GhcRn
lkind
renameBinderVar :: HsBndrVar GhcRn -> Rename (IdP GhcRn) (HsBndrVar GhcRn)
renameBinderVar :: HsBndrVar GhcRn -> Rename (IdP GhcRn) (HsBndrVar GhcRn)
renameBinderVar (HsBndrVar XBndrVar GhcRn
x LIdP GhcRn
lname) = XBndrVar GhcRn -> LIdP GhcRn -> HsBndrVar GhcRn
forall pass. XBndrVar pass -> LIdP pass -> HsBndrVar pass
HsBndrVar XBndrVar GhcRn
x (GenLocated SrcSpanAnnN Name -> HsBndrVar GhcRn)
-> StateT (RenameEnv Name) Identity (GenLocated SrcSpanAnnN Name)
-> StateT (RenameEnv Name) Identity (HsBndrVar GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> StateT (RenameEnv Name) Identity Name)
-> GenLocated SrcSpanAnnN Name
-> StateT (RenameEnv Name) Identity (GenLocated SrcSpanAnnN Name)
forall (f :: Type -> Type) a b.
Functor f =>
(a -> f b) -> LocatedN a -> f (LocatedN b)
locatedN Name -> StateT (RenameEnv Name) Identity Name
forall name. SetName name => name -> Rename name name
renameName LIdP GhcRn
GenLocated SrcSpanAnnN Name
lname
renameBinderVar (HsBndrWildCard XBndrWildCard GhcRn
x) = HsBndrVar GhcRn
-> StateT (RenameEnv Name) Identity (HsBndrVar GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XBndrWildCard GhcRn -> HsBndrVar GhcRn
forall pass. XBndrWildCard pass -> HsBndrVar pass
HsBndrWildCard XBndrWildCard GhcRn
x)
renameBinderKind :: HsBndrKind GhcRn -> Rename (IdP GhcRn) (HsBndrKind GhcRn)
renameBinderKind :: HsBndrKind GhcRn -> Rename (IdP GhcRn) (HsBndrKind GhcRn)
renameBinderKind (HsBndrNoKind XBndrNoKind GhcRn
x) = HsBndrKind GhcRn
-> StateT (RenameEnv Name) Identity (HsBndrKind GhcRn)
forall a. a -> StateT (RenameEnv Name) Identity a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (XBndrNoKind GhcRn -> HsBndrKind GhcRn
forall pass. XBndrNoKind pass -> HsBndrKind pass
HsBndrNoKind XBndrNoKind GhcRn
x)
renameBinderKind (HsBndrKind XBndrKind GhcRn
x LHsType GhcRn
k) = XBndrKind GhcRn -> LHsType GhcRn -> HsBndrKind GhcRn
forall pass. XBndrKind pass -> LHsKind pass -> HsBndrKind pass
HsBndrKind XBndrKind GhcRn
x (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsBndrKind GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
-> StateT (RenameEnv Name) Identity (HsBndrKind GhcRn)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn))
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> State (RenameEnv Name) (GenLocated SrcSpanAnnA (HsType GhcRn))
forall (f :: Type -> Type) a b l.
Functor f =>
(a -> f b) -> GenLocated l a -> f (GenLocated l b)
located HsType GhcRn -> Rename (IdP GhcRn) (HsType GhcRn)
HsType GhcRn -> StateT (RenameEnv Name) Identity (HsType GhcRn)
renameType LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
k
renameLBinder :: LHsTyVarBndr flag GhcRn -> Rename (IdP GhcRn) (LHsTyVarBndr flag GhcRn)
renameLBinder :: forall flag.
LHsTyVarBndr flag GhcRn
-> Rename (IdP GhcRn) (LHsTyVarBndr flag GhcRn)
renameLBinder = (HsTyVarBndr flag GhcRn
-> StateT (RenameEnv Name) Identity (HsTyVarBndr flag GhcRn))
-> GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)
-> StateT
(RenameEnv Name)
Identity
(GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))
forall (f :: Type -> Type) a b l.
Functor f =>
(a -> f b) -> GenLocated l a -> f (GenLocated l b)
located HsTyVarBndr flag GhcRn
-> Rename (IdP GhcRn) (HsTyVarBndr flag GhcRn)
HsTyVarBndr flag GhcRn
-> StateT (RenameEnv Name) Identity (HsTyVarBndr flag GhcRn)
forall flag.
HsTyVarBndr flag GhcRn
-> Rename (IdP GhcRn) (HsTyVarBndr flag GhcRn)
renameBinder
renameName :: SetName name => name -> Rename name name
renameName :: forall name. SetName name => name -> Rename name name
renameName name
name = do
RenameEnv{..} <- StateT (RenameEnv name) Identity (RenameEnv name)
forall (m :: Type -> Type) s. Monad m => StateT s m s
get
case Map.lookup (getName name) rneCtx of
Maybe name
Nothing
| Just Name
headTv <- NameRep -> Map NameRep Name -> Maybe Name
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (name -> NameRep
forall name. NamedThing name => name -> NameRep
getNameRep name
name) Map NameRep Name
rneHeadFVs
, Name
headTv Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
/= name -> Name
forall a. NamedThing a => a -> Name
getName name
name ->
name -> StateT (RenameEnv name) Identity name
forall name. SetName name => name -> Rename name name
freshName name
name
Just name
name' -> name -> StateT (RenameEnv name) Identity name
forall a. a -> StateT (RenameEnv name) Identity a
forall (m :: Type -> Type) a. Monad m => a -> m a
return name
name'
Maybe name
_ -> name -> StateT (RenameEnv name) Identity name
forall a. a -> StateT (RenameEnv name) Identity a
forall (m :: Type -> Type) a. Monad m => a -> m a
return name
name
freshName :: SetName name => name -> Rename name name
freshName :: forall name. SetName name => name -> Rename name name
freshName name
name = do
taken <- Rename name (Set NameRep)
forall name. NamedThing name => Rename name (Set NameRep)
takenNames
let name' = NameRep -> name -> name
forall name. SetName name => NameRep -> name -> name
setInternalNameRep (Set NameRep -> NameRep -> NameRep
findFreshName Set NameRep
taken NameRep
rep) name
name
modify $ \RenameEnv name
rne ->
RenameEnv name
rne
{ rneCtx = Map.insert (getName name) name' (rneCtx rne)
}
return name'
where
nname :: Name
nname = name -> Name
forall a. NamedThing a => a -> Name
getName name
name
rep :: NameRep
rep = Name -> NameRep
forall name. NamedThing name => name -> NameRep
getNameRep Name
nname
takenNames :: NamedThing name => Rename name (Set NameRep)
takenNames :: forall name. NamedThing name => Rename name (Set NameRep)
takenNames = do
RenameEnv{..} <- StateT (RenameEnv name) Identity (RenameEnv name)
forall (m :: Type -> Type) s. Monad m => StateT s m s
get
return $ Set.unions [headReps rneHeadFVs, ctxElems rneCtx]
where
headReps :: Map NameRep a -> Set NameRep
headReps = [NameRep] -> Set NameRep
forall a. Ord a => [a] -> Set a
Set.fromList ([NameRep] -> Set NameRep)
-> (Map NameRep a -> [NameRep]) -> Map NameRep a -> Set NameRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map NameRep a -> [NameRep]
forall k a. Map k a -> [k]
Map.keys
ctxElems :: Map k name -> Set NameRep
ctxElems = [NameRep] -> Set NameRep
forall a. Ord a => [a] -> Set a
Set.fromList ([NameRep] -> Set NameRep)
-> (Map k name -> [NameRep]) -> Map k name -> Set NameRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (name -> NameRep) -> [name] -> [NameRep]
forall a b. (a -> b) -> [a] -> [b]
map name -> NameRep
forall name. NamedThing name => name -> NameRep
getNameRep ([name] -> [NameRep])
-> (Map k name -> [name]) -> Map k name -> [NameRep]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k name -> [name]
forall k a. Map k a -> [a]
Map.elems
findFreshName :: Set NameRep -> NameRep -> NameRep
findFreshName :: Set NameRep -> NameRep -> NameRep
findFreshName Set NameRep
taken =
Maybe NameRep -> NameRep
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe NameRep -> NameRep)
-> (NameRep -> Maybe NameRep) -> NameRep -> NameRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NameRep -> Bool) -> [NameRep] -> Maybe NameRep
forall (t :: Type -> Type) a.
Foldable t =>
(a -> Bool) -> t a -> Maybe a
List.find NameRep -> Bool
isFresh ([NameRep] -> Maybe NameRep)
-> (NameRep -> [NameRep]) -> NameRep -> Maybe NameRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NameRep -> [NameRep]
alternativeNames
where
isFresh :: NameRep -> Bool
isFresh = Bool -> Bool
not (Bool -> Bool) -> (NameRep -> Bool) -> NameRep -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NameRep -> Set NameRep -> Bool) -> Set NameRep -> NameRep -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip NameRep -> Set NameRep -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member Set NameRep
taken
alternativeNames :: NameRep -> [NameRep]
alternativeNames :: NameRep -> [NameRep]
alternativeNames NameRep
name =
[String -> NameRep
stringNameRep (String -> NameRep) -> String -> NameRep
forall a b. (a -> b) -> a -> b
$ String
str String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i | Int
i :: Int <- [Int
0 ..]]
where
str :: String
str = NameRep -> String
nameRepString NameRep
name
located :: Functor f => (a -> f b) -> GenLocated l a -> f (GenLocated l b)
located :: forall (f :: Type -> Type) a b l.
Functor f =>
(a -> f b) -> GenLocated l a -> f (GenLocated l b)
located a -> f b
f (L l
loc a
e) = l -> b -> GenLocated l b
forall l e. l -> e -> GenLocated l e
L l
loc (b -> GenLocated l b) -> f b -> f (GenLocated l b)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
e
locatedN :: Functor f => (a -> f b) -> LocatedN a -> f (LocatedN b)
locatedN :: forall (f :: Type -> Type) a b.
Functor f =>
(a -> f b) -> LocatedN a -> f (LocatedN b)
locatedN a -> f b
f (L SrcSpanAnnN
loc a
e) = SrcSpanAnnN -> b -> GenLocated SrcSpanAnnN b
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc (b -> GenLocated SrcSpanAnnN b)
-> f b -> f (GenLocated SrcSpanAnnN b)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
e