{-# OPTIONS -fno-warn-name-shadowing #-}
{-# LANGUAGE NoImplicitPrelude   #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns        #-}
module Language.Haskell.Names.ModuleSymbols
  ( moduleSymbols
  , moduleTable
  )
  where

import           Fay.Compiler.Prelude

import           Language.Haskell.Exts
import           Language.Haskell.Names.GetBound
import qualified Language.Haskell.Names.GlobalSymbolTable as Global
import           Language.Haskell.Names.ScopeUtils
import           Language.Haskell.Names.SyntaxUtils
import           Language.Haskell.Names.Types

import           Data.Lens.Light
import qualified Data.Map                                 as Map
import qualified Data.Set                                 as Set

-- | Compute module's global table. It contains both the imported entities
-- and the global entities defined in this module.
moduleTable
  :: (Eq l, Data l)
  => Global.Table -- ^ the import table for this module
  -> Module l
  -> Global.Table
moduleTable :: Table -> Module l -> Table
moduleTable impTbl :: Table
impTbl m :: Module l
m =
  Table
impTbl Table -> Table -> Table
forall a. Semigroup a => a -> a -> a
<>
  Bool -> ModuleName l -> Symbols -> Table
forall l. Bool -> ModuleName l -> Symbols -> Table
computeSymbolTable Bool
False (Module l -> ModuleName l
forall l. Module l -> ModuleName l
getModuleName Module l
m) (Table -> Module l -> Symbols
forall l. (Eq l, Data l) => Table -> Module l -> Symbols
moduleSymbols Table
impTbl Module l
m)

-- | Compute the symbols that are defined in the given module.
--
-- The import table is needed to resolve possible top-level record
-- wildcard bindings, such as
--
-- >A {..} = foo
moduleSymbols
  :: (Eq l, Data l)
  => Global.Table -- ^ the import table for this module
  -> Module l
  -> Symbols
moduleSymbols :: Table -> Module l -> Symbols
moduleSymbols impTbl :: Table
impTbl m :: Module l
m =
  let (vs :: [SymValueInfo OrigName]
vs,ts :: [SymTypeInfo OrigName]
ts) =
        [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
-> ([SymValueInfo OrigName], [SymTypeInfo OrigName])
forall a b. [Either a b] -> ([a], [b])
partitionEithers ([Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
 -> ([SymValueInfo OrigName], [SymTypeInfo OrigName]))
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
-> ([SymValueInfo OrigName], [SymTypeInfo OrigName])
forall a b. (a -> b) -> a -> b
$
          (Decl l -> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)])
-> [Decl l]
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap
            (Table
-> ModuleName l
-> Decl l
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
forall l.
(Eq l, Data l) =>
Table
-> ModuleName l
-> Decl l
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
getTopDeclSymbols Table
impTbl (ModuleName l
 -> Decl l
 -> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)])
-> ModuleName l
-> Decl l
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
forall a b. (a -> b) -> a -> b
$ Module l -> ModuleName l
forall l. Module l -> ModuleName l
getModuleName Module l
m)
            (Module l -> [Decl l]
forall l. Module l -> [Decl l]
getModuleDecls Module l
m)
  in
    Lens Symbols (Set (SymValueInfo OrigName))
-> Set (SymValueInfo OrigName) -> Symbols -> Symbols
forall a b. Lens a b -> b -> a -> a
setL Lens Symbols (Set (SymValueInfo OrigName))
valSyms ([SymValueInfo OrigName] -> Set (SymValueInfo OrigName)
forall a. Ord a => [a] -> Set a
Set.fromList [SymValueInfo OrigName]
vs) (Symbols -> Symbols) -> Symbols -> Symbols
forall a b. (a -> b) -> a -> b
$
    Lens Symbols (Set (SymTypeInfo OrigName))
-> Set (SymTypeInfo OrigName) -> Symbols -> Symbols
forall a b. Lens a b -> b -> a -> a
setL Lens Symbols (Set (SymTypeInfo OrigName))
tySyms  ([SymTypeInfo OrigName] -> Set (SymTypeInfo OrigName)
forall a. Ord a => [a] -> Set a
Set.fromList [SymTypeInfo OrigName]
ts) Symbols
forall a. Monoid a => a
mempty

type TypeName = GName
type ConName = Name ()
type SelectorName = Name ()
type Constructors = [(ConName, [SelectorName])]

-- Extract names that get bound by a top level declaration.
getTopDeclSymbols
  :: forall l . (Eq l, Data l)
  => Global.Table -- ^ the import table for this module
  -> ModuleName l
  -> Decl l
  -> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
getTopDeclSymbols :: Table
-> ModuleName l
-> Decl l
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
getTopDeclSymbols impTbl :: Table
impTbl mdl :: ModuleName l
mdl d :: Decl l
d =
  (Either (SymValueInfo GName) (SymTypeInfo GName)
 -> Either (SymValueInfo OrigName) (SymTypeInfo OrigName))
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
forall a b. (a -> b) -> [a] -> [b]
map ((SymValueInfo GName
 -> Either (SymValueInfo OrigName) (SymTypeInfo OrigName))
-> (SymTypeInfo GName
    -> Either (SymValueInfo OrigName) (SymTypeInfo OrigName))
-> Either (SymValueInfo GName) (SymTypeInfo GName)
-> Either (SymValueInfo OrigName) (SymTypeInfo OrigName)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (SymValueInfo OrigName
-> Either (SymValueInfo OrigName) (SymTypeInfo OrigName)
forall a b. a -> Either a b
Left (SymValueInfo OrigName
 -> Either (SymValueInfo OrigName) (SymTypeInfo OrigName))
-> (SymValueInfo GName -> SymValueInfo OrigName)
-> SymValueInfo GName
-> Either (SymValueInfo OrigName) (SymTypeInfo OrigName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GName -> OrigName) -> SymValueInfo GName -> SymValueInfo OrigName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GName -> OrigName
OrigName) (SymTypeInfo OrigName
-> Either (SymValueInfo OrigName) (SymTypeInfo OrigName)
forall a b. b -> Either a b
Right (SymTypeInfo OrigName
 -> Either (SymValueInfo OrigName) (SymTypeInfo OrigName))
-> (SymTypeInfo GName -> SymTypeInfo OrigName)
-> SymTypeInfo GName
-> Either (SymValueInfo OrigName) (SymTypeInfo OrigName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GName -> OrigName) -> SymTypeInfo GName -> SymTypeInfo OrigName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GName -> OrigName
OrigName)) ([Either (SymValueInfo GName) (SymTypeInfo GName)]
 -> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)])
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo OrigName) (SymTypeInfo OrigName)]
forall a b. (a -> b) -> a -> b
$
  case Decl l
d of
    TypeDecl _ dh :: DeclHead l
dh _ ->
      let tn :: GName
tn = DeclHead l -> GName
hname DeclHead l
dh
      in  [ SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (SymType :: forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymType        { st_origName :: GName
st_origName = GName
tn, st_fixity :: Maybe SymFixity
st_fixity = Maybe SymFixity
forall a. Maybe a
Nothing })]

    TypeFamDecl _loc :: l
_loc dh :: DeclHead l
dh _mrs :: Maybe (ResultSig l)
_mrs _mk :: Maybe (InjectivityInfo l)
_mk ->
      let tn :: GName
tn = DeclHead l -> GName
hname DeclHead l
dh
      in  [ SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (SymTypeFam :: forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymTypeFam     { st_origName :: GName
st_origName = GName
tn, st_fixity :: Maybe SymFixity
st_fixity = Maybe SymFixity
forall a. Maybe a
Nothing })]

    DataDecl _ dataOrNew :: DataOrNew l
dataOrNew _ dh :: DeclHead l
dh qualConDecls :: [QualConDecl l]
qualConDecls _ ->
      let
        cons :: Constructors
        cons :: Constructors
cons = do -- list monad
          QualConDecl _ _ _ conDecl :: ConDecl l
conDecl <- [QualConDecl l]
qualConDecls
          case ConDecl l
conDecl of
            ConDecl _ n :: Name l
n _ -> (Name (), [Name ()]) -> Constructors
forall (m :: * -> *) a. Monad m => a -> m a
return (Name l -> Name ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Name l
n, [])
            InfixConDecl _ _ n :: Name l
n _ -> (Name (), [Name ()]) -> Constructors
forall (m :: * -> *) a. Monad m => a -> m a
return (Name l -> Name ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Name l
n, [])
            RecDecl _ n :: Name l
n fields :: [FieldDecl l]
fields ->
              (Name (), [Name ()]) -> Constructors
forall (m :: * -> *) a. Monad m => a -> m a
return (Name l -> Name ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Name l
n , [Name l -> Name ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Name l
f | FieldDecl _ fNames :: [Name l]
fNames _ <- [FieldDecl l]
fields, Name l
f <- [Name l]
fNames])

        dq :: GName
dq = DeclHead l -> GName
hname DeclHead l
dh

        infos :: [SymValueInfo GName]
infos = GName -> Constructors -> [SymValueInfo GName]
constructorsToInfos GName
dq Constructors
cons

      in
        SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (DataOrNew l -> GName -> Maybe SymFixity -> SymTypeInfo GName
forall l name.
DataOrNew l -> name -> Maybe SymFixity -> SymTypeInfo name
dataOrNewCon DataOrNew l
dataOrNew GName
dq Maybe SymFixity
forall a. Maybe a
Nothing) Either (SymValueInfo GName) (SymTypeInfo GName)
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a. a -> [a] -> [a]
: (SymValueInfo GName
 -> Either (SymValueInfo GName) (SymTypeInfo GName))
-> [SymValueInfo GName]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a b. (a -> b) -> [a] -> [b]
map SymValueInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. a -> Either a b
Left [SymValueInfo GName]
infos

    GDataDecl _ dataOrNew :: DataOrNew l
dataOrNew _ dh :: DeclHead l
dh _ gadtDecls :: [GadtDecl l]
gadtDecls _ ->
      -- FIXME: We shouldn't create selectors for fields with existential type variables!
      let
        dq :: GName
dq = DeclHead l -> GName
hname DeclHead l
dh

        cons :: Constructors
        cons :: Constructors
cons = do -- list monad
          GadtDecl _ cn :: Name l
cn _tyvarBinds :: Maybe [TyVarBind l]
_tyvarBinds _context :: Maybe (Context l)
_context ([FieldDecl l] -> Maybe [FieldDecl l] -> [FieldDecl l]
forall a. a -> Maybe a -> a
fromMaybe [] -> [FieldDecl l]
fields) _ty :: Type l
_ty <- [GadtDecl l]
gadtDecls
          (Name (), [Name ()]) -> Constructors
forall (m :: * -> *) a. Monad m => a -> m a
return (Name l -> Name ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Name l
cn , [Name l -> Name ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Name l
f | FieldDecl _ fNames :: [Name l]
fNames _ <- [FieldDecl l]
fields, Name l
f <- [Name l]
fNames])

        infos :: [SymValueInfo GName]
infos = GName -> Constructors -> [SymValueInfo GName]
constructorsToInfos GName
dq Constructors
cons
      in
          SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (DataOrNew l -> GName -> Maybe SymFixity -> SymTypeInfo GName
forall l name.
DataOrNew l -> name -> Maybe SymFixity -> SymTypeInfo name
dataOrNewCon DataOrNew l
dataOrNew GName
dq Maybe SymFixity
forall a. Maybe a
Nothing) Either (SymValueInfo GName) (SymTypeInfo GName)
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a. a -> [a] -> [a]
: (SymValueInfo GName
 -> Either (SymValueInfo GName) (SymTypeInfo GName))
-> [SymValueInfo GName]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a b. (a -> b) -> [a] -> [b]
map SymValueInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. a -> Either a b
Left [SymValueInfo GName]
infos

    DataFamDecl _ _ dh :: DeclHead l
dh _ ->
      let tn :: GName
tn = DeclHead l -> GName
hname DeclHead l
dh
      in [SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (SymDataFam :: forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymDataFam { st_origName :: GName
st_origName = GName
tn, st_fixity :: Maybe SymFixity
st_fixity = Maybe SymFixity
forall a. Maybe a
Nothing })]

    ClassDecl _ _ dh :: DeclHead l
dh _ mds :: Maybe [ClassDecl l]
mds ->
      let
        ms :: [Name l]
ms = Table -> Decl l -> [Name l]
forall a l. GetBound a l => Table -> a -> [Name l]
getBound Table
impTbl Decl l
d
        cq :: GName
cq = DeclHead l -> GName
hname DeclHead l
dh
        cdecls :: [ClassDecl l]
cdecls = [ClassDecl l] -> Maybe [ClassDecl l] -> [ClassDecl l]
forall a. a -> Maybe a -> a
fromMaybe [] Maybe [ClassDecl l]
mds
      in
          SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (SymClass :: forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymClass   { st_origName :: GName
st_origName = GName
cq,       st_fixity :: Maybe SymFixity
st_fixity = Maybe SymFixity
forall a. Maybe a
Nothing }) Either (SymValueInfo GName) (SymTypeInfo GName)
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a. a -> [a] -> [a]
:
        [ SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (SymTypeFam :: forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymTypeFam { st_origName :: GName
st_origName = DeclHead l -> GName
hname DeclHead l
dh, st_fixity :: Maybe SymFixity
st_fixity = Maybe SymFixity
forall a. Maybe a
Nothing }) | ClsTyFam   _   dh :: DeclHead l
dh _ _ <- [ClassDecl l]
cdecls ] [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a. [a] -> [a] -> [a]
++
        [ SymTypeInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. b -> Either a b
Right (SymDataFam :: forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymDataFam { st_origName :: GName
st_origName = DeclHead l -> GName
hname DeclHead l
dh, st_fixity :: Maybe SymFixity
st_fixity = Maybe SymFixity
forall a. Maybe a
Nothing }) | ClsDataFam _ _ dh :: DeclHead l
dh _ <- [ClassDecl l]
cdecls ] [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
-> [Either (SymValueInfo GName) (SymTypeInfo GName)]
forall a. [a] -> [a] -> [a]
++
        [ SymValueInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. a -> Either a b
Left  (SymMethod :: forall name. name -> Maybe SymFixity -> name -> SymValueInfo name
SymMethod  { sv_origName :: GName
sv_origName = Name l -> GName
forall l. Name l -> GName
qname Name l
mn, sv_fixity :: Maybe SymFixity
sv_fixity = Maybe SymFixity
forall a. Maybe a
Nothing, sv_className :: GName
sv_className = GName
cq }) | Name l
mn <- [Name l]
ms ]

    FunBind _ ms :: [Match l]
ms ->
      let vn :: Name l
vn : _ = Table -> [Match l] -> [Name l]
forall a l. GetBound a l => Table -> a -> [Name l]
getBound Table
impTbl [Match l]
ms
      in  [ SymValueInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. a -> Either a b
Left  (SymValue :: forall name. name -> Maybe SymFixity -> SymValueInfo name
SymValue { sv_origName :: GName
sv_origName = Name l -> GName
forall l. Name l -> GName
qname Name l
vn, sv_fixity :: Maybe SymFixity
sv_fixity = Maybe SymFixity
forall a. Maybe a
Nothing }) ]

    PatBind _ p :: Pat l
p _ _ ->
      [ SymValueInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. a -> Either a b
Left  (SymValue :: forall name. name -> Maybe SymFixity -> SymValueInfo name
SymValue { sv_origName :: GName
sv_origName = Name l -> GName
forall l. Name l -> GName
qname Name l
vn, sv_fixity :: Maybe SymFixity
sv_fixity = Maybe SymFixity
forall a. Maybe a
Nothing }) | Name l
vn <- Table -> Pat l -> [Name l]
forall a l. GetBound a l => Table -> a -> [Name l]
getBound Table
impTbl Pat l
p ]

    ForImp _ _ _ _ fn :: Name l
fn _ ->
      [ SymValueInfo GName
-> Either (SymValueInfo GName) (SymTypeInfo GName)
forall a b. a -> Either a b
Left  (SymValue :: forall name. name -> Maybe SymFixity -> SymValueInfo name
SymValue { sv_origName :: GName
sv_origName = Name l -> GName
forall l. Name l -> GName
qname Name l
fn, sv_fixity :: Maybe SymFixity
sv_fixity = Maybe SymFixity
forall a. Maybe a
Nothing }) ]

    _ -> []
  where
    ModuleName _ smdl :: String
smdl = ModuleName l
mdl
    qname :: Name l -> GName
qname = String -> String -> GName
GName String
smdl (String -> GName) -> (Name l -> String) -> Name l -> GName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name l -> String
forall l. Name l -> String
nameToString
    hname :: DeclHead l -> GName
    hname :: DeclHead l -> GName
hname = Name l -> GName
forall l. Name l -> GName
qname (Name l -> GName) -> (DeclHead l -> Name l) -> DeclHead l -> GName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DeclHead l -> Name l
forall l. DeclHead l -> Name l
getDeclHeadName
    dataOrNewCon :: DataOrNew l -> name -> Maybe SymFixity -> SymTypeInfo name
dataOrNewCon dataOrNew :: DataOrNew l
dataOrNew = case DataOrNew l
dataOrNew of DataType {} -> name -> Maybe SymFixity -> SymTypeInfo name
forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymData; NewType {} -> name -> Maybe SymFixity -> SymTypeInfo name
forall name. name -> Maybe SymFixity -> SymTypeInfo name
SymNewType

    constructorsToInfos :: TypeName -> Constructors -> [SymValueInfo GName]
    constructorsToInfos :: GName -> Constructors -> [SymValueInfo GName]
constructorsToInfos ty :: GName
ty cons :: Constructors
cons = [SymValueInfo GName]
conInfos [SymValueInfo GName]
-> [SymValueInfo GName] -> [SymValueInfo GName]
forall a. [a] -> [a] -> [a]
++ [SymValueInfo GName]
selInfos
      where
        conInfos :: [SymValueInfo GName]
conInfos =
          [ SymConstructor :: forall name. name -> Maybe SymFixity -> name -> SymValueInfo name
SymConstructor { sv_origName :: GName
sv_origName = Name () -> GName
forall l. Name l -> GName
qname Name ()
con, sv_fixity :: Maybe SymFixity
sv_fixity = Maybe SymFixity
forall a. Maybe a
Nothing, sv_typeName :: GName
sv_typeName = GName
ty }
          | (con :: Name ()
con, _) <- Constructors
cons
          ]

        selectorsMap :: Map.Map SelectorName [ConName]
        selectorsMap :: Map (Name ()) [Name ()]
selectorsMap =
          ([Name ()] -> [Name ()] -> [Name ()])
-> [Map (Name ()) [Name ()]] -> Map (Name ()) [Name ()]
forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith [Name ()] -> [Name ()] -> [Name ()]
forall a. [a] -> [a] -> [a]
(++) ([Map (Name ()) [Name ()]] -> Map (Name ()) [Name ()])
-> (((Name (), [Name ()]) -> Map (Name ()) [Name ()])
    -> [Map (Name ()) [Name ()]])
-> ((Name (), [Name ()]) -> Map (Name ()) [Name ()])
-> Map (Name ()) [Name ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (((Name (), [Name ()]) -> Map (Name ()) [Name ()])
 -> Constructors -> [Map (Name ()) [Name ()]])
-> Constructors
-> ((Name (), [Name ()]) -> Map (Name ()) [Name ()])
-> [Map (Name ()) [Name ()]]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Name (), [Name ()]) -> Map (Name ()) [Name ()])
-> Constructors -> [Map (Name ()) [Name ()]]
forall a b. (a -> b) -> [a] -> [b]
map Constructors
cons (((Name (), [Name ()]) -> Map (Name ()) [Name ()])
 -> Map (Name ()) [Name ()])
-> ((Name (), [Name ()]) -> Map (Name ()) [Name ()])
-> Map (Name ()) [Name ()]
forall a b. (a -> b) -> a -> b
$ \(c :: Name ()
c, fs :: [Name ()]
fs) ->
            ([Name ()] -> [Name ()] -> [Name ()])
-> [Map (Name ()) [Name ()]] -> Map (Name ()) [Name ()]
forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith [Name ()] -> [Name ()] -> [Name ()]
forall a. [a] -> [a] -> [a]
(++) ([Map (Name ()) [Name ()]] -> Map (Name ()) [Name ()])
-> ((Name () -> Map (Name ()) [Name ()])
    -> [Map (Name ()) [Name ()]])
-> (Name () -> Map (Name ()) [Name ()])
-> Map (Name ()) [Name ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name () -> Map (Name ()) [Name ()])
 -> [Name ()] -> [Map (Name ()) [Name ()]])
-> [Name ()]
-> (Name () -> Map (Name ()) [Name ()])
-> [Map (Name ()) [Name ()]]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Name () -> Map (Name ()) [Name ()])
-> [Name ()] -> [Map (Name ()) [Name ()]]
forall a b. (a -> b) -> [a] -> [b]
map [Name ()]
fs ((Name () -> Map (Name ()) [Name ()]) -> Map (Name ()) [Name ()])
-> (Name () -> Map (Name ()) [Name ()]) -> Map (Name ()) [Name ()]
forall a b. (a -> b) -> a -> b
$ \f :: Name ()
f ->
              Name () -> [Name ()] -> Map (Name ()) [Name ()]
forall k a. k -> a -> Map k a
Map.singleton Name ()
f [Name ()
c]

        selInfos :: [SymValueInfo GName]
selInfos =
          [ (SymSelector :: forall name.
name -> Maybe SymFixity -> name -> [name] -> SymValueInfo name
SymSelector { sv_origName :: GName
sv_origName = Name () -> GName
forall l. Name l -> GName
qname Name ()
f, sv_fixity :: Maybe SymFixity
sv_fixity = Maybe SymFixity
forall a. Maybe a
Nothing, sv_typeName :: GName
sv_typeName = GName
ty, sv_constructors :: [GName]
sv_constructors = (Name () -> GName) -> [Name ()] -> [GName]
forall a b. (a -> b) -> [a] -> [b]
map Name () -> GName
forall l. Name l -> GName
qname [Name ()]
fCons })
          | (f :: Name ()
f, fCons :: [Name ()]
fCons) <- Map (Name ()) [Name ()] -> Constructors
forall k a. Map k a -> [(k, a)]
Map.toList Map (Name ()) [Name ()]
selectorsMap
          ]