{-# 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 Table
impTbl 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 Table
impTbl Module l
m =
  let ([SymValueInfo OrigName]
vs,[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 Table
impTbl ModuleName l
mdl 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 l
_ DeclHead l
dh Type l
_ ->
      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 l
_loc DeclHead l
dh Maybe (ResultSig l)
_mrs 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 l
_ DataOrNew l
dataOrNew Maybe (Context l)
_ DeclHead l
dh [QualConDecl l]
qualConDecls [Deriving l]
_ ->
      let
        cons :: Constructors
        cons :: Constructors
cons = do -- list monad
          QualConDecl l
_ Maybe [TyVarBind l]
_ Maybe (Context l)
_ ConDecl l
conDecl <- [QualConDecl l]
qualConDecls
          case ConDecl l
conDecl of
            ConDecl l
_ Name l
n [Type l]
_ -> (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 l
_ Type l
_ Name l
n Type l
_ -> (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 l
_ Name l
n [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 l
_ [Name l]
fNames Type l
_ <- [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 l
_ DataOrNew l
dataOrNew Maybe (Context l)
_ DeclHead l
dh Maybe (Type l)
_ [GadtDecl l]
gadtDecls [Deriving l]
_ ->
      -- 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 l
_ Name l
cn Maybe [TyVarBind l]
_tyvarBinds Maybe (Context l)
_context ([FieldDecl l] -> Maybe [FieldDecl l] -> [FieldDecl l]
forall a. a -> Maybe a -> a
fromMaybe [] -> [FieldDecl l]
fields) 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 l
_ [Name l]
fNames Type l
_ <- [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 l
_ Maybe (Context l)
_ DeclHead l
dh Maybe (ResultSig l)
_ ->
      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 l
_ Maybe (Context l)
_ DeclHead l
dh [FunDep l]
_ 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   l
_   DeclHead l
dh Maybe (ResultSig l)
_ Maybe (InjectivityInfo l)
_ <- [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 l
_ Maybe (Context l)
_ DeclHead l
dh Maybe (ResultSig l)
_ <- [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 l
_ [Match l]
ms ->
      let Name l
vn : [Name l]
_ = 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 l
_ Pat l
p Rhs l
_ Maybe (Binds l)
_ ->
      [ 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 l
_ CallConv l
_ Maybe (Safety l)
_ Maybe String
_ Name l
fn Type l
_ ->
      [ 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 }) ]

    Decl l
_ -> []
  where
    ModuleName l
_ 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 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 GName
ty 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 }
          | (Name ()
con, [Name ()]
_) <- 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
$ \(Name ()
c, [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
$ \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 })
          | (Name ()
f, [Name ()]
fCons) <- Map (Name ()) [Name ()] -> Constructors
forall k a. Map k a -> [(k, a)]
Map.toList Map (Name ()) [Name ()]
selectorsMap
          ]