{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
#include "HsVersions.h"
module GHC.Types.Avail (
Avails,
AvailInfo(..),
avail,
availField,
availTC,
availsToNameSet,
availsToNameSetWithSelectors,
availsToNameEnv,
availExportsDecl,
availName, availGreName,
availNames, availNonFldNames,
availNamesWithSelectors,
availFlds,
availGreNames,
availSubordinateGreNames,
stableAvailCmp,
plusAvail,
trimAvail,
filterAvail,
filterAvails,
nubAvails,
GreName(..),
greNameMangledName,
greNamePrintableName,
greNameSrcSpan,
greNameFieldLabel,
partitionGreNames,
stableGreNameCmp,
) where
import GHC.Prelude
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Name.Set
import GHC.Types.SrcLoc
import GHC.Types.FieldLabel
import GHC.Utils.Binary
import GHC.Data.List.SetOps
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Utils.Misc
import Data.Data ( Data )
import Data.Either ( partitionEithers )
import Data.List ( find )
import Data.Maybe
data AvailInfo
= Avail GreName
| AvailTC
Name
[GreName]
deriving ( AvailInfo -> AvailInfo -> Bool
(AvailInfo -> AvailInfo -> Bool)
-> (AvailInfo -> AvailInfo -> Bool) -> Eq AvailInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AvailInfo -> AvailInfo -> Bool
$c/= :: AvailInfo -> AvailInfo -> Bool
== :: AvailInfo -> AvailInfo -> Bool
$c== :: AvailInfo -> AvailInfo -> Bool
Eq
, Typeable AvailInfo
Typeable AvailInfo
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AvailInfo -> c AvailInfo)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AvailInfo)
-> (AvailInfo -> Constr)
-> (AvailInfo -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AvailInfo))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AvailInfo))
-> ((forall b. Data b => b -> b) -> AvailInfo -> AvailInfo)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r)
-> (forall u. (forall d. Data d => d -> u) -> AvailInfo -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> AvailInfo -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo)
-> Data AvailInfo
AvailInfo -> DataType
AvailInfo -> Constr
(forall b. Data b => b -> b) -> AvailInfo -> AvailInfo
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> AvailInfo -> u
forall u. (forall d. Data d => d -> u) -> AvailInfo -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AvailInfo
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AvailInfo -> c AvailInfo
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AvailInfo)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AvailInfo)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AvailInfo -> m AvailInfo
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> AvailInfo -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> AvailInfo -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> AvailInfo -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> AvailInfo -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AvailInfo -> r
gmapT :: (forall b. Data b => b -> b) -> AvailInfo -> AvailInfo
$cgmapT :: (forall b. Data b => b -> b) -> AvailInfo -> AvailInfo
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AvailInfo)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AvailInfo)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AvailInfo)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AvailInfo)
dataTypeOf :: AvailInfo -> DataType
$cdataTypeOf :: AvailInfo -> DataType
toConstr :: AvailInfo -> Constr
$ctoConstr :: AvailInfo -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AvailInfo
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AvailInfo
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AvailInfo -> c AvailInfo
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AvailInfo -> c AvailInfo
Data )
type Avails = [AvailInfo]
stableAvailCmp :: AvailInfo -> AvailInfo -> Ordering
stableAvailCmp :: AvailInfo -> AvailInfo -> Ordering
stableAvailCmp (Avail GreName
c1) (Avail GreName
c2) = GreName
c1 GreName -> GreName -> Ordering
`stableGreNameCmp` GreName
c2
stableAvailCmp (Avail {}) (AvailTC {}) = Ordering
LT
stableAvailCmp (AvailTC Name
n [GreName]
ns) (AvailTC Name
m [GreName]
ms) = (Name
n Name -> Name -> Ordering
`stableNameCmp` Name
m) Ordering -> Ordering -> Ordering
`thenCmp`
((GreName -> GreName -> Ordering)
-> [GreName] -> [GreName] -> Ordering
forall a. (a -> a -> Ordering) -> [a] -> [a] -> Ordering
cmpList GreName -> GreName -> Ordering
stableGreNameCmp [GreName]
ns [GreName]
ms)
stableAvailCmp (AvailTC {}) (Avail {}) = Ordering
GT
stableGreNameCmp :: GreName -> GreName -> Ordering
stableGreNameCmp :: GreName -> GreName -> Ordering
stableGreNameCmp (NormalGreName Name
n1) (NormalGreName Name
n2) = Name
n1 Name -> Name -> Ordering
`stableNameCmp` Name
n2
stableGreNameCmp (NormalGreName {}) (FieldGreName {}) = Ordering
LT
stableGreNameCmp (FieldGreName FieldLabel
f1) (FieldGreName FieldLabel
f2) = FieldLabel -> Name
flSelector FieldLabel
f1 Name -> Name -> Ordering
`stableNameCmp` FieldLabel -> Name
flSelector FieldLabel
f2
stableGreNameCmp (FieldGreName {}) (NormalGreName {}) = Ordering
GT
avail :: Name -> AvailInfo
avail :: Name -> AvailInfo
avail Name
n = GreName -> AvailInfo
Avail (Name -> GreName
NormalGreName Name
n)
availField :: FieldLabel -> AvailInfo
availField :: FieldLabel -> AvailInfo
availField FieldLabel
fl = GreName -> AvailInfo
Avail (FieldLabel -> GreName
FieldGreName FieldLabel
fl)
availTC :: Name -> [Name] -> [FieldLabel] -> AvailInfo
availTC :: Name -> [Name] -> [FieldLabel] -> AvailInfo
availTC Name
n [Name]
ns [FieldLabel]
fls = Name -> [GreName] -> AvailInfo
AvailTC Name
n ((Name -> GreName) -> [Name] -> [GreName]
forall a b. (a -> b) -> [a] -> [b]
map Name -> GreName
NormalGreName [Name]
ns [GreName] -> [GreName] -> [GreName]
forall a. [a] -> [a] -> [a]
++ (FieldLabel -> GreName) -> [FieldLabel] -> [GreName]
forall a b. (a -> b) -> [a] -> [b]
map FieldLabel -> GreName
FieldGreName [FieldLabel]
fls)
availsToNameSet :: [AvailInfo] -> NameSet
availsToNameSet :: [AvailInfo] -> NameSet
availsToNameSet [AvailInfo]
avails = (AvailInfo -> NameSet -> NameSet)
-> NameSet -> [AvailInfo] -> NameSet
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr AvailInfo -> NameSet -> NameSet
add NameSet
emptyNameSet [AvailInfo]
avails
where add :: AvailInfo -> NameSet -> NameSet
add AvailInfo
avail NameSet
set = NameSet -> [Name] -> NameSet
extendNameSetList NameSet
set (AvailInfo -> [Name]
availNames AvailInfo
avail)
availsToNameSetWithSelectors :: [AvailInfo] -> NameSet
availsToNameSetWithSelectors :: [AvailInfo] -> NameSet
availsToNameSetWithSelectors [AvailInfo]
avails = (AvailInfo -> NameSet -> NameSet)
-> NameSet -> [AvailInfo] -> NameSet
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr AvailInfo -> NameSet -> NameSet
add NameSet
emptyNameSet [AvailInfo]
avails
where add :: AvailInfo -> NameSet -> NameSet
add AvailInfo
avail NameSet
set = NameSet -> [Name] -> NameSet
extendNameSetList NameSet
set (AvailInfo -> [Name]
availNamesWithSelectors AvailInfo
avail)
availsToNameEnv :: [AvailInfo] -> NameEnv AvailInfo
availsToNameEnv :: [AvailInfo] -> NameEnv AvailInfo
availsToNameEnv [AvailInfo]
avails = (AvailInfo -> NameEnv AvailInfo -> NameEnv AvailInfo)
-> NameEnv AvailInfo -> [AvailInfo] -> NameEnv AvailInfo
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr AvailInfo -> NameEnv AvailInfo -> NameEnv AvailInfo
add NameEnv AvailInfo
forall a. NameEnv a
emptyNameEnv [AvailInfo]
avails
where add :: AvailInfo -> NameEnv AvailInfo -> NameEnv AvailInfo
add AvailInfo
avail NameEnv AvailInfo
env = NameEnv AvailInfo -> [(Name, AvailInfo)] -> NameEnv AvailInfo
forall a. NameEnv a -> [(Name, a)] -> NameEnv a
extendNameEnvList NameEnv AvailInfo
env
([Name] -> [AvailInfo] -> [(Name, AvailInfo)]
forall a b. [a] -> [b] -> [(a, b)]
zip (AvailInfo -> [Name]
availNames AvailInfo
avail) (AvailInfo -> [AvailInfo]
forall a. a -> [a]
repeat AvailInfo
avail))
availExportsDecl :: AvailInfo -> Bool
availExportsDecl :: AvailInfo -> Bool
availExportsDecl (AvailTC Name
ty_name [GreName]
names)
| GreName
n : [GreName]
_ <- [GreName]
names = Name -> GreName
NormalGreName Name
ty_name GreName -> GreName -> Bool
forall a. Eq a => a -> a -> Bool
== GreName
n
| Bool
otherwise = Bool
False
availExportsDecl AvailInfo
_ = Bool
True
availName :: AvailInfo -> Name
availName :: AvailInfo -> Name
availName (Avail GreName
n) = GreName -> Name
greNameMangledName GreName
n
availName (AvailTC Name
n [GreName]
_) = Name
n
availGreName :: AvailInfo -> GreName
availGreName :: AvailInfo -> GreName
availGreName (Avail GreName
c) = GreName
c
availGreName (AvailTC Name
n [GreName]
_) = Name -> GreName
NormalGreName Name
n
availNames :: AvailInfo -> [Name]
availNames :: AvailInfo -> [Name]
availNames (Avail GreName
c) = GreName -> [Name]
childNonOverloadedNames GreName
c
availNames (AvailTC Name
_ [GreName]
cs) = (GreName -> [Name]) -> [GreName] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap GreName -> [Name]
childNonOverloadedNames [GreName]
cs
childNonOverloadedNames :: GreName -> [Name]
childNonOverloadedNames :: GreName -> [Name]
childNonOverloadedNames (NormalGreName Name
n) = [Name
n]
childNonOverloadedNames (FieldGreName FieldLabel
fl) = [ FieldLabel -> Name
flSelector FieldLabel
fl | Bool -> Bool
not (FieldLabel -> Bool
flIsOverloaded FieldLabel
fl) ]
availNamesWithSelectors :: AvailInfo -> [Name]
availNamesWithSelectors :: AvailInfo -> [Name]
availNamesWithSelectors (Avail GreName
c) = [GreName -> Name
greNameMangledName GreName
c]
availNamesWithSelectors (AvailTC Name
_ [GreName]
cs) = (GreName -> Name) -> [GreName] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map GreName -> Name
greNameMangledName [GreName]
cs
availNonFldNames :: AvailInfo -> [Name]
availNonFldNames :: AvailInfo -> [Name]
availNonFldNames (Avail (NormalGreName Name
n)) = [Name
n]
availNonFldNames (Avail (FieldGreName {})) = []
availNonFldNames (AvailTC Name
_ [GreName]
ns) = (GreName -> Maybe Name) -> [GreName] -> [Name]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe GreName -> Maybe Name
f [GreName]
ns
where
f :: GreName -> Maybe Name
f (NormalGreName Name
n) = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n
f (FieldGreName {}) = Maybe Name
forall a. Maybe a
Nothing
availFlds :: AvailInfo -> [FieldLabel]
availFlds :: AvailInfo -> [FieldLabel]
availFlds (Avail GreName
c) = Maybe FieldLabel -> [FieldLabel]
forall a. Maybe a -> [a]
maybeToList (GreName -> Maybe FieldLabel
greNameFieldLabel GreName
c)
availFlds (AvailTC Name
_ [GreName]
cs) = (GreName -> Maybe FieldLabel) -> [GreName] -> [FieldLabel]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe GreName -> Maybe FieldLabel
greNameFieldLabel [GreName]
cs
availGreNames :: AvailInfo -> [GreName]
availGreNames :: AvailInfo -> [GreName]
availGreNames (Avail GreName
c) = [GreName
c]
availGreNames (AvailTC Name
_ [GreName]
cs) = [GreName]
cs
availSubordinateGreNames :: AvailInfo -> [GreName]
availSubordinateGreNames :: AvailInfo -> [GreName]
availSubordinateGreNames (Avail {}) = []
availSubordinateGreNames avail :: AvailInfo
avail@(AvailTC Name
_ [GreName]
ns)
| AvailInfo -> Bool
availExportsDecl AvailInfo
avail = [GreName] -> [GreName]
forall a. [a] -> [a]
tail [GreName]
ns
| Bool
otherwise = [GreName]
ns
data GreName = NormalGreName Name
| FieldGreName FieldLabel
deriving (Typeable GreName
Typeable GreName
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GreName -> c GreName)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GreName)
-> (GreName -> Constr)
-> (GreName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GreName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GreName))
-> ((forall b. Data b => b -> b) -> GreName -> GreName)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r)
-> (forall u. (forall d. Data d => d -> u) -> GreName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> GreName -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName)
-> Data GreName
GreName -> DataType
GreName -> Constr
(forall b. Data b => b -> b) -> GreName -> GreName
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> GreName -> u
forall u. (forall d. Data d => d -> u) -> GreName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GreName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GreName -> c GreName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GreName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GreName)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GreName -> m GreName
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> GreName -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> GreName -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> GreName -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> GreName -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GreName -> r
gmapT :: (forall b. Data b => b -> b) -> GreName -> GreName
$cgmapT :: (forall b. Data b => b -> b) -> GreName -> GreName
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GreName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GreName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GreName)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GreName)
dataTypeOf :: GreName -> DataType
$cdataTypeOf :: GreName -> DataType
toConstr :: GreName -> Constr
$ctoConstr :: GreName -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GreName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GreName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GreName -> c GreName
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GreName -> c GreName
Data, GreName -> GreName -> Bool
(GreName -> GreName -> Bool)
-> (GreName -> GreName -> Bool) -> Eq GreName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GreName -> GreName -> Bool
$c/= :: GreName -> GreName -> Bool
== :: GreName -> GreName -> Bool
$c== :: GreName -> GreName -> Bool
Eq)
instance Outputable GreName where
ppr :: GreName -> SDoc
ppr (NormalGreName Name
n) = Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n
ppr (FieldGreName FieldLabel
fl) = FieldLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr FieldLabel
fl
instance HasOccName GreName where
occName :: GreName -> OccName
occName (NormalGreName Name
n) = Name -> OccName
forall name. HasOccName name => name -> OccName
occName Name
n
occName (FieldGreName FieldLabel
fl) = FieldLabel -> OccName
forall name. HasOccName name => name -> OccName
occName FieldLabel
fl
greNameMangledName :: GreName -> Name
greNameMangledName :: GreName -> Name
greNameMangledName (NormalGreName Name
n) = Name
n
greNameMangledName (FieldGreName FieldLabel
fl) = FieldLabel -> Name
flSelector FieldLabel
fl
greNamePrintableName :: GreName -> Name
greNamePrintableName :: GreName -> Name
greNamePrintableName (NormalGreName Name
n) = Name
n
greNamePrintableName (FieldGreName FieldLabel
fl) = FieldLabel -> Name
fieldLabelPrintableName FieldLabel
fl
greNameSrcSpan :: GreName -> SrcSpan
greNameSrcSpan :: GreName -> SrcSpan
greNameSrcSpan (NormalGreName Name
n) = Name -> SrcSpan
nameSrcSpan Name
n
greNameSrcSpan (FieldGreName FieldLabel
fl) = Name -> SrcSpan
nameSrcSpan (FieldLabel -> Name
flSelector FieldLabel
fl)
greNameFieldLabel :: GreName -> Maybe FieldLabel
greNameFieldLabel :: GreName -> Maybe FieldLabel
greNameFieldLabel (NormalGreName {}) = Maybe FieldLabel
forall a. Maybe a
Nothing
greNameFieldLabel (FieldGreName FieldLabel
fl) = FieldLabel -> Maybe FieldLabel
forall a. a -> Maybe a
Just FieldLabel
fl
partitionGreNames :: [GreName] -> ([Name], [FieldLabel])
partitionGreNames :: [GreName] -> ([Name], [FieldLabel])
partitionGreNames = [Either Name FieldLabel] -> ([Name], [FieldLabel])
forall a b. [Either a b] -> ([a], [b])
partitionEithers ([Either Name FieldLabel] -> ([Name], [FieldLabel]))
-> ([GreName] -> [Either Name FieldLabel])
-> [GreName]
-> ([Name], [FieldLabel])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GreName -> Either Name FieldLabel)
-> [GreName] -> [Either Name FieldLabel]
forall a b. (a -> b) -> [a] -> [b]
map GreName -> Either Name FieldLabel
to_either
where
to_either :: GreName -> Either Name FieldLabel
to_either (NormalGreName Name
n) = Name -> Either Name FieldLabel
forall a b. a -> Either a b
Left Name
n
to_either (FieldGreName FieldLabel
fl) = FieldLabel -> Either Name FieldLabel
forall a b. b -> Either a b
Right FieldLabel
fl
plusAvail :: AvailInfo -> AvailInfo -> AvailInfo
plusAvail :: AvailInfo -> AvailInfo -> AvailInfo
plusAvail AvailInfo
a1 AvailInfo
a2
| Bool
debugIsOn Bool -> Bool -> Bool
&& AvailInfo -> Name
availName AvailInfo
a1 Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
/= AvailInfo -> Name
availName AvailInfo
a2
= String -> SDoc -> AvailInfo
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"GHC.Rename.Env.plusAvail names differ" ([SDoc] -> SDoc
hsep [AvailInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr AvailInfo
a1,AvailInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr AvailInfo
a2])
plusAvail a1 :: AvailInfo
a1@(Avail {}) (Avail {}) = AvailInfo
a1
plusAvail (AvailTC Name
_ []) a2 :: AvailInfo
a2@(AvailTC {}) = AvailInfo
a2
plusAvail a1 :: AvailInfo
a1@(AvailTC {}) (AvailTC Name
_ []) = AvailInfo
a1
plusAvail (AvailTC Name
n1 (GreName
s1:[GreName]
ss1)) (AvailTC Name
n2 (GreName
s2:[GreName]
ss2))
= case (Name -> GreName
NormalGreName Name
n1GreName -> GreName -> Bool
forall a. Eq a => a -> a -> Bool
==GreName
s1, Name -> GreName
NormalGreName Name
n2GreName -> GreName -> Bool
forall a. Eq a => a -> a -> Bool
==GreName
s2) of
(Bool
True,Bool
True) -> Name -> [GreName] -> AvailInfo
AvailTC Name
n1 (GreName
s1 GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
: ([GreName]
ss1 [GreName] -> [GreName] -> [GreName]
forall a.
(HasDebugCallStack, Outputable a, Eq a) =>
[a] -> [a] -> [a]
`unionLists` [GreName]
ss2))
(Bool
True,Bool
False) -> Name -> [GreName] -> AvailInfo
AvailTC Name
n1 (GreName
s1 GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
: ([GreName]
ss1 [GreName] -> [GreName] -> [GreName]
forall a.
(HasDebugCallStack, Outputable a, Eq a) =>
[a] -> [a] -> [a]
`unionLists` (GreName
s2GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
:[GreName]
ss2)))
(Bool
False,Bool
True) -> Name -> [GreName] -> AvailInfo
AvailTC Name
n1 (GreName
s2 GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
: ((GreName
s1GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
:[GreName]
ss1) [GreName] -> [GreName] -> [GreName]
forall a.
(HasDebugCallStack, Outputable a, Eq a) =>
[a] -> [a] -> [a]
`unionLists` [GreName]
ss2))
(Bool
False,Bool
False) -> Name -> [GreName] -> AvailInfo
AvailTC Name
n1 ((GreName
s1GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
:[GreName]
ss1) [GreName] -> [GreName] -> [GreName]
forall a.
(HasDebugCallStack, Outputable a, Eq a) =>
[a] -> [a] -> [a]
`unionLists` (GreName
s2GreName -> [GreName] -> [GreName]
forall a. a -> [a] -> [a]
:[GreName]
ss2))
plusAvail AvailInfo
a1 AvailInfo
a2 = String -> SDoc -> AvailInfo
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"GHC.Rename.Env.plusAvail" ([SDoc] -> SDoc
hsep [AvailInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr AvailInfo
a1,AvailInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr AvailInfo
a2])
trimAvail :: AvailInfo -> Name -> AvailInfo
trimAvail :: AvailInfo -> Name -> AvailInfo
trimAvail avail :: AvailInfo
avail@(Avail {}) Name
_ = AvailInfo
avail
trimAvail avail :: AvailInfo
avail@(AvailTC Name
n [GreName]
ns) Name
m = case (GreName -> Bool) -> [GreName] -> Maybe GreName
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
m) (Name -> Bool) -> (GreName -> Name) -> GreName -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GreName -> Name
greNameMangledName) [GreName]
ns of
Just GreName
c -> Name -> [GreName] -> AvailInfo
AvailTC Name
n [GreName
c]
Maybe GreName
Nothing -> String -> SDoc -> AvailInfo
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"trimAvail" ([SDoc] -> SDoc
hsep [AvailInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr AvailInfo
avail, Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
m])
filterAvails :: (Name -> Bool) -> [AvailInfo] -> [AvailInfo]
filterAvails :: (Name -> Bool) -> [AvailInfo] -> [AvailInfo]
filterAvails Name -> Bool
keep [AvailInfo]
avails = (AvailInfo -> [AvailInfo] -> [AvailInfo])
-> [AvailInfo] -> [AvailInfo] -> [AvailInfo]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((Name -> Bool) -> AvailInfo -> [AvailInfo] -> [AvailInfo]
filterAvail Name -> Bool
keep) [] [AvailInfo]
avails
filterAvail :: (Name -> Bool) -> AvailInfo -> [AvailInfo] -> [AvailInfo]
filterAvail :: (Name -> Bool) -> AvailInfo -> [AvailInfo] -> [AvailInfo]
filterAvail Name -> Bool
keep AvailInfo
ie [AvailInfo]
rest =
case AvailInfo
ie of
Avail GreName
c | Name -> Bool
keep (GreName -> Name
greNameMangledName GreName
c) -> AvailInfo
ie AvailInfo -> [AvailInfo] -> [AvailInfo]
forall a. a -> [a] -> [a]
: [AvailInfo]
rest
| Bool
otherwise -> [AvailInfo]
rest
AvailTC Name
tc [GreName]
cs ->
let cs' :: [GreName]
cs' = (GreName -> Bool) -> [GreName] -> [GreName]
forall a. (a -> Bool) -> [a] -> [a]
filter (Name -> Bool
keep (Name -> Bool) -> (GreName -> Name) -> GreName -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GreName -> Name
greNameMangledName) [GreName]
cs
in if [GreName] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GreName]
cs' then [AvailInfo]
rest else Name -> [GreName] -> AvailInfo
AvailTC Name
tc [GreName]
cs' AvailInfo -> [AvailInfo] -> [AvailInfo]
forall a. a -> [a] -> [a]
: [AvailInfo]
rest
nubAvails :: [AvailInfo] -> [AvailInfo]
nubAvails :: [AvailInfo] -> [AvailInfo]
nubAvails [AvailInfo]
avails = NameEnv AvailInfo -> [AvailInfo]
forall a. NameEnv a -> [a]
nameEnvElts ((NameEnv AvailInfo -> AvailInfo -> NameEnv AvailInfo)
-> NameEnv AvailInfo -> [AvailInfo] -> NameEnv AvailInfo
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' NameEnv AvailInfo -> AvailInfo -> NameEnv AvailInfo
add NameEnv AvailInfo
forall a. NameEnv a
emptyNameEnv [AvailInfo]
avails)
where
add :: NameEnv AvailInfo -> AvailInfo -> NameEnv AvailInfo
add NameEnv AvailInfo
env AvailInfo
avail = (AvailInfo -> AvailInfo -> AvailInfo)
-> NameEnv AvailInfo -> Name -> AvailInfo -> NameEnv AvailInfo
forall a. (a -> a -> a) -> NameEnv a -> Name -> a -> NameEnv a
extendNameEnv_C AvailInfo -> AvailInfo -> AvailInfo
plusAvail NameEnv AvailInfo
env (AvailInfo -> Name
availName AvailInfo
avail) AvailInfo
avail
instance Outputable AvailInfo where
ppr :: AvailInfo -> SDoc
ppr = AvailInfo -> SDoc
pprAvail
pprAvail :: AvailInfo -> SDoc
pprAvail :: AvailInfo -> SDoc
pprAvail (Avail GreName
n)
= GreName -> SDoc
forall a. Outputable a => a -> SDoc
ppr GreName
n
pprAvail (AvailTC Name
n [GreName]
ns)
= Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces ([SDoc] -> SDoc
fsep (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma ((GreName -> SDoc) -> [GreName] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GreName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [GreName]
ns)))
instance Binary AvailInfo where
put_ :: BinHandle -> AvailInfo -> IO ()
put_ BinHandle
bh (Avail GreName
aa) = do
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
BinHandle -> GreName -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh GreName
aa
put_ BinHandle
bh (AvailTC Name
ab [GreName]
ac) = do
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
BinHandle -> Name -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Name
ab
BinHandle -> [GreName] -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [GreName]
ac
get :: BinHandle -> IO AvailInfo
get BinHandle
bh = do
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> do GreName
aa <- BinHandle -> IO GreName
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
AvailInfo -> IO AvailInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (GreName -> AvailInfo
Avail GreName
aa)
Word8
_ -> do Name
ab <- BinHandle -> IO Name
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
[GreName]
ac <- BinHandle -> IO [GreName]
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
AvailInfo -> IO AvailInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> [GreName] -> AvailInfo
AvailTC Name
ab [GreName]
ac)
instance Binary GreName where
put_ :: BinHandle -> GreName -> IO ()
put_ BinHandle
bh (NormalGreName Name
aa) = do
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
BinHandle -> Name -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Name
aa
put_ BinHandle
bh (FieldGreName FieldLabel
ab) = do
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
BinHandle -> FieldLabel -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh FieldLabel
ab
get :: BinHandle -> IO GreName
get BinHandle
bh = do
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> do Name
aa <- BinHandle -> IO Name
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
GreName -> IO GreName
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> GreName
NormalGreName Name
aa)
Word8
_ -> do FieldLabel
ab <- BinHandle -> IO FieldLabel
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
GreName -> IO GreName
forall (m :: * -> *) a. Monad m => a -> m a
return (FieldLabel -> GreName
FieldGreName FieldLabel
ab)