{-# LANGUAGE AllowAmbiguousTypes     #-}
{-# LANGUAGE CPP                     #-}
{-# LANGUAGE ConstraintKinds         #-}
{-# LANGUAGE DataKinds               #-}
{-# LANGUAGE DeriveDataTypeable      #-}
{-# LANGUAGE FlexibleContexts        #-}
{-# LANGUAGE FlexibleInstances       #-}
{-# LANGUAGE GADTs                   #-}
{-# LANGUAGE OverloadedStrings       #-}
{-# LANGUAGE ScopedTypeVariables     #-}
{-# LANGUAGE TypeApplications        #-}
{-# LANGUAGE TypeFamilies            #-}
{-# LANGUAGE UndecidableInstances    #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# LANGUAGE RankNTypes #-}

{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-orphans #-} -- For the HasLoc instances

{-
Main functions for .hie file generation
-}

module GHC.Iface.Ext.Ast ( mkHieFile, mkHieFileWithSource, getCompressedAsts, enrichHie) where

import GHC.Utils.Outputable(ppr)

import GHC.Prelude hiding ( head, init, last, tail )

import GHC.Types.Avail            ( Avails )
import GHC.Data.Bag               ( Bag, bagToList )
import GHC.Types.Basic
import GHC.Data.BooleanFormula
import GHC.Core.Class             ( className, classSCSelIds )
import GHC.Core.ConLike           ( conLikeName )
import GHC.Core.FVs
import GHC.Core.DataCon           ( dataConNonlinearType )
import GHC.Types.FieldLabel
import GHC.Hs
import GHC.Hs.Syn.Type
import GHC.Utils.Monad            ( concatMapM, MonadIO(liftIO) )
import GHC.Types.Id               ( isDataConId_maybe )
import GHC.Types.Name             ( Name, nameSrcSpan, nameUnique, wiredInNameTyThing_maybe )
import GHC.Types.Name.Env         ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
import GHC.Types.Name.Reader      ( RecFieldInfo(..) )
import GHC.Types.SrcLoc
import GHC.Core.Type              ( Type )
import GHC.Core.TyCon             ( TyCon, tyConClass_maybe )
import GHC.Core.Predicate
import GHC.Core.InstEnv
import GHC.Tc.Types
import GHC.Tc.Types.Evidence
import GHC.Types.Var              ( Id, Var, EvId, varName, varType, varUnique )
import GHC.Types.Var.Env
import GHC.Builtin.Uniques
import GHC.Iface.Make             ( mkIfaceExports )
import GHC.Utils.Panic
import GHC.Utils.Misc
import GHC.Data.Maybe
import GHC.Data.FastString
import qualified GHC.Data.Strict as Strict

import GHC.Iface.Ext.Types
import GHC.Iface.Ext.Utils

import GHC.Unit.Module            ( ml_hs_file )
import GHC.Unit.Module.ModSummary

import qualified Data.Array as A
import qualified Data.ByteString as BS
import qualified Data.Map as M
import qualified Data.Set as S
import Data.Data                  ( Data, Typeable )
import Data.Foldable              ( toList )
import Data.Functor.Identity      ( Identity(..) )
import Data.List.NonEmpty         ( NonEmpty(..), nonEmpty )
import qualified Data.List.NonEmpty as NE
import Data.Void                  ( Void, absurd )
import Control.Monad              ( forM_ )
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Class  ( lift )
import Control.Applicative        ( (<|>) )
import GHC.Types.TypeEnv          ( TypeEnv )
import Control.Arrow              ( second )

{- Note [Updating HieAst for changes in the GHC AST]
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When updating the code in this file for changes in the GHC AST, you
need to pay attention to the following things:

1) Symbols (Names/Vars/Modules) in the following categories:

   a) Symbols that appear in the source file that directly correspond to
   something the user typed
   b) Symbols that don't appear in the source, but should be in some sense
   "visible" to a user, particularly via IDE tooling or the like. This
   includes things like the names introduced by RecordWildcards (We record
   all the names introduced by a (..) in HIE files), and will include implicit
   parameters and evidence variables after one of my pending MRs lands.

2) Subtrees that may contain such symbols, or correspond to a SrcSpan in
   the file. This includes all `Located` things

For 1), you need to call `toHie` for one of the following instances

instance ToHie (Context (Located Name)) where ...
instance ToHie (Context (Located Var)) where ...
instance ToHie (IEContext (Located ModuleName)) where ...

`Context` is a data type that looks like:

data Context a = C ContextInfo a -- Used for names and bindings

`ContextInfo` is defined in `GHC.Iface.Ext.Types`, and looks like

data ContextInfo
  = Use                -- ^ regular variable
  | MatchBind
  | IEThing IEType     -- ^ import/export
  | TyDecl
  -- | Value binding
  | ValBind
      BindType     -- ^ whether or not the binding is in an instance
      Scope        -- ^ scope over which the value is bound
      (Maybe Span) -- ^ span of entire binding
  ...

It is used to annotate symbols in the .hie files with some extra information on
the context in which they occur and should be fairly self explanatory. You need
to select one that looks appropriate for the symbol usage. In very rare cases,
you might need to extend this sum type if none of the cases seem appropriate.

So, given a `Located Name` that is just being "used", and not defined at a
particular location, you would do the following:

   toHie $ C Use located_name

If you select one that corresponds to a binding site, you will need to
provide a `Scope` and a `Span` for your binding. Both of these are basically
`SrcSpans`.

The `SrcSpan` in the `Scope` is supposed to span over the part of the source
where the symbol can be legally allowed to occur. For more details on how to
calculate this, see Note [Capturing Scopes and other non local information]
in GHC.Iface.Ext.Ast.

The binding `Span` is supposed to be the span of the entire binding for
the name.

For a function definition `foo`:

foo x = x + y
  where y = x^2

The binding `Span` is the span of the entire function definition from `foo x`
to `x^2`.  For a class definition, this is the span of the entire class, and
so on.  If this isn't well defined for your bit of syntax (like a variable
bound by a lambda), then you can just supply a `Nothing`

There is a test that checks that all symbols in the resulting HIE file
occur inside their stated `Scope`. This can be turned on by passing the
-fvalidate-ide-info flag to ghc along with -fwrite-ide-info to generate the
.hie file.

You may also want to provide a test in testsuite/test/hiefile that includes
a file containing your new construction, and tests that the calculated scope
is valid (by using -fvalidate-ide-info)

For subtrees in the AST that may contain symbols, the procedure is fairly
straightforward.  If you are extending the GHC AST, you will need to provide a
`ToHie` instance for any new types you may have introduced in the AST.

Here is an extract from the `ToHie` instance for (LHsExpr (GhcPass p)):

  toHie e@(L mspan oexpr) = concatM $ getTypeNode e : case oexpr of
      HsVar _ (L _ var) ->
        [ toHie $ C Use (L mspan var)
             -- Patch up var location since typechecker removes it
        ]
      ...
      HsApp _ a b ->
        [ toHie a
        , toHie b
        ]

If your subtree is `Located` or has a `SrcSpan` available, the output list
should contain a HieAst `Node` corresponding to the subtree. You can use
either `makeNode` or `getTypeNode` for this purpose, depending on whether it
makes sense to assign a `Type` to the subtree. After this, you just need
to concatenate the result of calling `toHie` on all subexpressions and
appropriately annotated symbols contained in the subtree.

The code above from the ToHie instance of `LhsExpr (GhcPass p)` is supposed
to work for both the renamed and typechecked source. `getTypeNode` is from
the `HasType` class defined in this file, and it has different instances
for `GhcTc` and `GhcRn` that allow it to access the type of the expression
when given a typechecked AST:

class Data a => HasType a where
  getTypeNode :: a -> HieM [HieAST Type]
instance HasType (LHsExpr GhcTc) where
  getTypeNode e@(L spn e') = ... -- Actually get the type for this expression
instance HasType (LHsExpr GhcRn) where
  getTypeNode (L spn e) = makeNode e spn -- Fallback to a regular `makeNode` without recording the type

If your subtree doesn't have a span available, you can omit the `makeNode`
call and just recurse directly in to the subexpressions.

-}

-- These synonyms match those defined in compiler/GHC.hs
type RenamedSource     = ( HsGroup GhcRn, [LImportDecl GhcRn]
                         , Maybe [(LIE GhcRn, Avails)]
                         , Maybe (LHsDoc GhcRn)
                         , Maybe (XRec GhcRn ModuleName) )
type TypecheckedSource = LHsBinds GhcTc


{- Note [Name Remapping]
   ~~~~~~~~~~~~~~~~~~~~~
The Typechecker introduces new names for mono names in AbsBinds.
We don't care about the distinction between mono and poly bindings,
so we replace all occurrences of the mono name with the poly name.
-}
type VarMap a = DVarEnv (Var,a)
data HieState = HieState
  { HieState -> NameEnv Id
name_remapping :: NameEnv Id
  , HieState -> VarMap (Set ContextInfo)
unlocated_ev_binds :: VarMap (S.Set ContextInfo)
  -- These contain evidence bindings that we don't have a location for
  -- These are placed at the top level Node in the HieAST after everything
  -- else has been generated
  -- This includes things like top level evidence bindings.
  , HieState -> TypeEnv
type_env :: TypeEnv
  -- tcg_type_env from TcGblEnv contains the type environment for the module
  , HieState -> NameEntityInfo
entity_infos :: NameEntityInfo
  -- ^ Information about entities in the module
  }

addUnlocatedEvBind :: Var -> ContextInfo -> HieM ()
addUnlocatedEvBind :: Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
var ContextInfo
ci = do
  let go :: (a, Set a) -> (a, Set a) -> (a, Set a)
go (a
a,Set a
b) (a
_,Set a
c) = (a
a,Set a -> Set a -> Set a
forall a. Ord a => Set a -> Set a -> Set a
S.union Set a
b Set a
c)
  State HieState () -> HieM ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState () -> HieM ()) -> State HieState () -> HieM ()
forall a b. (a -> b) -> a -> b
$ (HieState -> HieState) -> State HieState ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' ((HieState -> HieState) -> State HieState ())
-> (HieState -> HieState) -> State HieState ()
forall a b. (a -> b) -> a -> b
$ \HieState
s ->
    HieState
s { unlocated_ev_binds =
          extendDVarEnv_C go (unlocated_ev_binds s)
                          var (var,S.singleton ci)
      }

getUnlocatedEvBinds :: FastString -> HieM (NodeIdentifiers Type,[HieAST Type])
getUnlocatedEvBinds :: FastString -> HieM (NodeIdentifiers Type, [HieAST Type])
getUnlocatedEvBinds FastString
file = do
  binds <- State HieState (VarMap (Set ContextInfo))
-> ReaderT NodeOrigin (State HieState) (VarMap (Set ContextInfo))
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState (VarMap (Set ContextInfo))
 -> ReaderT NodeOrigin (State HieState) (VarMap (Set ContextInfo)))
-> State HieState (VarMap (Set ContextInfo))
-> ReaderT NodeOrigin (State HieState) (VarMap (Set ContextInfo))
forall a b. (a -> b) -> a -> b
$ (HieState -> VarMap (Set ContextInfo))
-> State HieState (VarMap (Set ContextInfo))
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> VarMap (Set ContextInfo)
unlocated_ev_binds
  org <- ask
  let elts = VarMap (Set ContextInfo) -> [(Id, Set ContextInfo)]
forall a. DVarEnv a -> [a]
dVarEnvElts VarMap (Set ContextInfo)
binds

      mkNodeInfo (Id
n,Set ContextInfo
ci) = (Name -> Either a Name
forall a b. b -> Either a b
Right (Id -> Name
varName Id
n), Maybe Type -> Set ContextInfo -> IdentifierDetails Type
forall a. Maybe a -> Set ContextInfo -> IdentifierDetails a
IdentifierDetails (Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Maybe Type) -> Type -> Maybe Type
forall a b. (a -> b) -> a -> b
$ Id -> Type
varType Id
n) Set ContextInfo
ci)

      go e :: (Id, Set ContextInfo)
e@(Id
v,Set ContextInfo
_) ([(Identifier, IdentifierDetails Type)]
xs,[HieAST Type]
ys) = case Name -> SrcSpan
nameSrcSpan (Name -> SrcSpan) -> Name -> SrcSpan
forall a b. (a -> b) -> a -> b
$ Id -> Name
varName Id
v of
        RealSrcSpan Span
spn Maybe BufSpan
_
          | Span -> FastString
srcSpanFile Span
spn FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
== FastString
file ->
            let node :: HieAST Type
node = SourcedNodeInfo Type -> Span -> [HieAST Type] -> HieAST Type
forall a. SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
Node (NodeOrigin -> NodeInfo Type -> SourcedNodeInfo Type
forall a. NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
mkSourcedNodeInfo NodeOrigin
org NodeInfo Type
ni) Span
spn []
                ni :: NodeInfo Type
ni = Set NodeAnnotation
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Monoid a => a
mempty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$ [(Identifier, IdentifierDetails Type)] -> NodeIdentifiers Type
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(Id, Set ContextInfo) -> (Identifier, IdentifierDetails Type)
forall {a}.
(Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
mkNodeInfo (Id, Set ContextInfo)
e]
              in ([(Identifier, IdentifierDetails Type)]
xs,HieAST Type
nodeHieAST Type -> [HieAST Type] -> [HieAST Type]
forall a. a -> [a] -> [a]
:[HieAST Type]
ys)
        SrcSpan
_ -> ((Id, Set ContextInfo) -> (Identifier, IdentifierDetails Type)
forall {a}.
(Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
mkNodeInfo (Id, Set ContextInfo)
e (Identifier, IdentifierDetails Type)
-> [(Identifier, IdentifierDetails Type)]
-> [(Identifier, IdentifierDetails Type)]
forall a. a -> [a] -> [a]
: [(Identifier, IdentifierDetails Type)]
xs,[HieAST Type]
ys)

      (nis,asts) = foldr go ([],[]) elts

  pure $ (M.fromList nis, asts)

lookupAndInsertEntityName :: Name -> HieM ()
lookupAndInsertEntityName :: Name -> HieM ()
lookupAndInsertEntityName Name
name = do
  m <- State HieState TypeEnv
-> ReaderT NodeOrigin (State HieState) TypeEnv
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState TypeEnv
 -> ReaderT NodeOrigin (State HieState) TypeEnv)
-> State HieState TypeEnv
-> ReaderT NodeOrigin (State HieState) TypeEnv
forall a b. (a -> b) -> a -> b
$ (HieState -> TypeEnv) -> State HieState TypeEnv
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> TypeEnv
type_env
  let tyThing = TypeEnv -> Name -> Maybe TyThing
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv TypeEnv
m Name
name Maybe TyThing -> Maybe TyThing -> Maybe TyThing
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Name -> Maybe TyThing
wiredInNameTyThing_maybe Name
name
  insertEntityInfo name $ maybe (nameEntityInfo name) tyThingEntityInfo tyThing

-- | Insert entity information for an identifier
insertEntityInfo :: Name -> S.Set EntityInfo -> HieM ()
insertEntityInfo :: Name -> Set EntityInfo -> HieM ()
insertEntityInfo Name
ident Set EntityInfo
info = do
  State HieState () -> HieM ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState () -> HieM ()) -> State HieState () -> HieM ()
forall a b. (a -> b) -> a -> b
$ (HieState -> HieState) -> State HieState ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' ((HieState -> HieState) -> State HieState ())
-> (HieState -> HieState) -> State HieState ()
forall a b. (a -> b) -> a -> b
$ \HieState
s ->
    HieState
s { entity_infos = M.insertWith S.union ident info (entity_infos s) }

initState :: HieState
initState :: HieState
initState = NameEnv Id
-> VarMap (Set ContextInfo)
-> TypeEnv
-> NameEntityInfo
-> HieState
HieState NameEnv Id
forall a. NameEnv a
emptyNameEnv VarMap (Set ContextInfo)
forall a. DVarEnv a
emptyDVarEnv TypeEnv
forall a. Monoid a => a
mempty NameEntityInfo
forall a. Monoid a => a
mempty

class ModifyState a where -- See Note [Name Remapping]
  addSubstitution :: a -> a -> HieState -> HieState

instance ModifyState Name where
  addSubstitution :: Name -> Name -> HieState -> HieState
addSubstitution Name
_ Name
_ HieState
hs = HieState
hs

instance ModifyState Id where
  addSubstitution :: Id -> Id -> HieState -> HieState
addSubstitution Id
mono Id
poly HieState
hs =
    HieState
hs{name_remapping = extendNameEnv (name_remapping hs) (varName mono) poly}

modifyState :: [ABExport] -> HieState -> HieState
modifyState :: [ABExport] -> HieState -> HieState
modifyState = (ABExport -> (HieState -> HieState) -> HieState -> HieState)
-> (HieState -> HieState) -> [ABExport] -> HieState -> HieState
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ABExport -> (HieState -> HieState) -> HieState -> HieState
forall {a}. ABExport -> (a -> HieState) -> a -> HieState
go HieState -> HieState
forall a. a -> a
id
  where
    go :: ABExport -> (a -> HieState) -> a -> HieState
go ABE{abe_poly :: ABExport -> Id
abe_poly=Id
poly,abe_mono :: ABExport -> Id
abe_mono=Id
mono} a -> HieState
f
      = Id -> Id -> HieState -> HieState
forall a. ModifyState a => a -> a -> HieState -> HieState
addSubstitution Id
mono Id
poly (HieState -> HieState) -> (a -> HieState) -> a -> HieState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> HieState
f

type HieM = ReaderT NodeOrigin (State HieState)

-- | Construct an 'HieFile' from the outputs of the typechecker.
mkHieFile :: MonadIO m
          => ModSummary
          -> TcGblEnv
          -> RenamedSource -> m HieFile
mkHieFile :: forall (m :: * -> *).
MonadIO m =>
ModSummary -> TcGblEnv -> RenamedSource -> m HieFile
mkHieFile ModSummary
ms TcGblEnv
ts RenamedSource
rs = do
  let src_file :: FilePath
src_file = FilePath -> Maybe FilePath -> FilePath
forall a. HasDebugCallStack => FilePath -> Maybe a -> a
expectJust FilePath
"mkHieFile" (ModLocation -> Maybe FilePath
ml_hs_file (ModLocation -> Maybe FilePath) -> ModLocation -> Maybe FilePath
forall a b. (a -> b) -> a -> b
$ ModSummary -> ModLocation
ms_location ModSummary
ms)
  src <- IO ByteString -> m ByteString
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString) -> IO ByteString -> m ByteString
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ByteString
BS.readFile FilePath
src_file
  pure $ mkHieFileWithSource src_file src ms ts rs

-- | Construct an 'HieFile' from the outputs of the typechecker but don't
-- read the source file again from disk.
mkHieFileWithSource :: FilePath
                    -> BS.ByteString
                    -> ModSummary
                    -> TcGblEnv
                    -> RenamedSource -> HieFile
mkHieFileWithSource :: FilePath
-> ByteString -> ModSummary -> TcGblEnv -> RenamedSource -> HieFile
mkHieFileWithSource FilePath
src_file ByteString
src ModSummary
ms TcGblEnv
ts RenamedSource
rs =
  let tc_binds :: LHsBinds GhcTc
tc_binds = TcGblEnv -> LHsBinds GhcTc
tcg_binds TcGblEnv
ts
      top_ev_binds :: Bag EvBind
top_ev_binds = TcGblEnv -> Bag EvBind
tcg_ev_binds TcGblEnv
ts
      insts :: [ClsInst]
insts = TcGblEnv -> [ClsInst]
tcg_insts TcGblEnv
ts
      tte :: TypeEnv
tte = TcGblEnv -> TypeEnv
tcg_type_env TcGblEnv
ts
      tcs :: [TyCon]
tcs = TcGblEnv -> [TyCon]
tcg_tcs TcGblEnv
ts
      (HieASTs TypeIndex
asts',Array TypeIndex HieTypeFlat
arr,NameEntityInfo
entityInfos) = LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> TypeEnv
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat, NameEntityInfo)
getCompressedAsts LHsBinds GhcTc
tc_binds RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs TypeEnv
tte in
  HieFile
      { hie_hs_file :: FilePath
hie_hs_file = FilePath
src_file
      , hie_module :: Module
hie_module = ModSummary -> Module
ms_mod ModSummary
ms
      , hie_types :: Array TypeIndex HieTypeFlat
hie_types = Array TypeIndex HieTypeFlat
arr
      , hie_asts :: HieASTs TypeIndex
hie_asts = HieASTs TypeIndex
asts'
      -- mkIfaceExports sorts the AvailInfos for stability
      , hie_exports :: [AvailInfo]
hie_exports = [AvailInfo] -> [AvailInfo]
mkIfaceExports (TcGblEnv -> [AvailInfo]
tcg_exports TcGblEnv
ts)
      , hie_hs_src :: ByteString
hie_hs_src = ByteString
src
      , hie_entity_infos :: NameEntityInfo
hie_entity_infos = NameEntityInfo
entityInfos
      }

getCompressedAsts :: TypecheckedSource -> RenamedSource -> Bag EvBind -> [ClsInst] -> [TyCon] -> TypeEnv
  -> (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat, NameEntityInfo)
getCompressedAsts :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> TypeEnv
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat, NameEntityInfo)
getCompressedAsts LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs TypeEnv
tte =
  let (HieASTs Type
asts, NameEntityInfo
infos) = LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> TypeEnv
-> (HieASTs Type, NameEntityInfo)
enrichHie LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs TypeEnv
tte
      add :: c -> (a, b) -> (a, b, c)
add c
c (a
a, b
b) = (a
a,b
b,c
c)
  in NameEntityInfo
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat, NameEntityInfo)
forall {c} {a} {b}. c -> (a, b) -> (a, b, c)
add NameEntityInfo
infos ((HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
 -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat,
     NameEntityInfo))
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat, NameEntityInfo)
forall a b. (a -> b) -> a -> b
$ HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
compressTypes HieASTs Type
asts

enrichHie :: TypecheckedSource -> RenamedSource -> Bag EvBind -> [ClsInst] -> [TyCon] -> TypeEnv
  -> (HieASTs Type, NameEntityInfo)
enrichHie :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> TypeEnv
-> (HieASTs Type, NameEntityInfo)
enrichHie LHsBinds GhcTc
ts (HsGroup (GhcPass 'Renamed)
hsGrp, [LImportDecl (GhcPass 'Renamed)]
imports, Maybe [(LIE (GhcPass 'Renamed), [AvailInfo])]
exports, Maybe (LHsDoc (GhcPass 'Renamed))
docs, Maybe (XRec (GhcPass 'Renamed) ModuleName)
modName) Bag EvBind
ev_bs [ClsInst]
insts [TyCon]
tcs TypeEnv
tte =
  (HieState -> NameEntityInfo)
-> (HieASTs Type, HieState) -> (HieASTs Type, NameEntityInfo)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second HieState -> NameEntityInfo
entity_infos ((HieASTs Type, HieState) -> (HieASTs Type, NameEntityInfo))
-> (HieASTs Type, HieState) -> (HieASTs Type, NameEntityInfo)
forall a b. (a -> b) -> a -> b
$ Identity (HieASTs Type, HieState) -> (HieASTs Type, HieState)
forall a. Identity a -> a
runIdentity (Identity (HieASTs Type, HieState) -> (HieASTs Type, HieState))
-> Identity (HieASTs Type, HieState) -> (HieASTs Type, HieState)
forall a b. (a -> b) -> a -> b
$ (StateT HieState Identity (HieASTs Type)
 -> HieState -> Identity (HieASTs Type, HieState))
-> HieState
-> StateT HieState Identity (HieASTs Type)
-> Identity (HieASTs Type, HieState)
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT HieState Identity (HieASTs Type)
-> HieState -> Identity (HieASTs Type, HieState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT HieState
initState{type_env=tte} (StateT HieState Identity (HieASTs Type)
 -> Identity (HieASTs Type, HieState))
-> StateT HieState Identity (HieASTs Type)
-> Identity (HieASTs Type, HieState)
forall a b. (a -> b) -> a -> b
$ (ReaderT NodeOrigin (State HieState) (HieASTs Type)
 -> NodeOrigin -> StateT HieState Identity (HieASTs Type))
-> NodeOrigin
-> ReaderT NodeOrigin (State HieState) (HieASTs Type)
-> StateT HieState Identity (HieASTs Type)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT NodeOrigin (State HieState) (HieASTs Type)
-> NodeOrigin -> StateT HieState Identity (HieASTs Type)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT NodeOrigin
SourceInfo (ReaderT NodeOrigin (State HieState) (HieASTs Type)
 -> StateT HieState Identity (HieASTs Type))
-> ReaderT NodeOrigin (State HieState) (HieASTs Type)
-> StateT HieState Identity (HieASTs Type)
forall a b. (a -> b) -> a -> b
$ do
    modName <- Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
Export (GenLocated SrcSpanAnnA ModuleName
 -> IEContext (GenLocated SrcSpanAnnA ModuleName))
-> Maybe (GenLocated SrcSpanAnnA ModuleName)
-> Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (XRec (GhcPass 'Renamed) ModuleName)
Maybe (GenLocated SrcSpanAnnA ModuleName)
modName)
    tasts <- toHie $ fmap (BC RegularBind ModuleScope) ts
    rasts <- processGrp hsGrp
    imps <- toHie $ filter (not . ideclImplicit . ideclExt . unLoc) imports
    exps <- toHie $ fmap (map $ IEC Export . fst) exports
    docs <- toHie docs
    -- Add Instance bindings
    forM_ insts $ \ClsInst
i ->
      Id -> ContextInfo -> HieM ()
addUnlocatedEvBind (ClsInst -> Id
is_dfun ClsInst
i) (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind (Bool -> Name -> EvVarSource
EvInstBind Bool
False (ClsInst -> Name
is_cls_nm ClsInst
i)) Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing)
    -- Add class parent bindings
    forM_ tcs $ \TyCon
tc ->
      case TyCon -> Maybe Class
tyConClass_maybe TyCon
tc of
        Maybe Class
Nothing -> () -> HieM ()
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
        Just Class
c -> [Id] -> (Id -> HieM ()) -> HieM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Class -> [Id]
classSCSelIds Class
c) ((Id -> HieM ()) -> HieM ()) -> (Id -> HieM ()) -> HieM ()
forall a b. (a -> b) -> a -> b
$ \Id
v ->
          Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
v (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind (Bool -> Name -> EvVarSource
EvInstBind Bool
True (Class -> Name
className Class
c)) Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing)
    let spanFile FastString
file [HieAST a]
children = case [HieAST a] -> Maybe (NonEmpty (HieAST a))
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [HieAST a]
children of
          Maybe (NonEmpty (HieAST a))
Nothing -> RealSrcLoc -> Span
realSrcLocSpan (FastString -> TypeIndex -> TypeIndex -> RealSrcLoc
mkRealSrcLoc FastString
file TypeIndex
1 TypeIndex
1)
          Just NonEmpty (HieAST a)
children -> RealSrcLoc -> RealSrcLoc -> Span
mkRealSrcSpan
              (Span -> RealSrcLoc
realSrcSpanStart (Span -> RealSrcLoc) -> Span -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> Span
forall a. HieAST a -> Span
nodeSpan (NonEmpty (HieAST a) -> HieAST a
forall a. NonEmpty a -> a
NE.head NonEmpty (HieAST a)
children))
              (Span -> RealSrcLoc
realSrcSpanEnd   (Span -> RealSrcLoc) -> Span -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> Span
forall a. HieAST a -> Span
nodeSpan (NonEmpty (HieAST a) -> HieAST a
forall a. NonEmpty a -> a
NE.last NonEmpty (HieAST a)
children))

        flat_asts = [[HieAST Type]] -> [HieAST Type]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
          [ [HieAST Type]
modName
          , [HieAST Type]
tasts
          , [HieAST Type]
rasts
          , [HieAST Type]
imps
          , [HieAST Type]
exps
          , [HieAST Type]
docs
          ]

        modulify (HiePath FastString
file) [HieAST Type]
xs' = do

          top_ev_asts :: [HieAST Type] <- do
            let
              l :: SrcSpanAnnA
              l :: SrcSpanAnnA
l = SrcSpan -> SrcSpanAnnA
forall e. HasAnnotation e => SrcSpan -> e
noAnnSrcSpan (Span -> Maybe BufSpan -> SrcSpan
RealSrcSpan (RealSrcLoc -> Span
realSrcLocSpan (RealSrcLoc -> Span) -> RealSrcLoc -> Span
forall a b. (a -> b) -> a -> b
$ FastString -> TypeIndex -> TypeIndex -> RealSrcLoc
mkRealSrcLoc FastString
file TypeIndex
1 TypeIndex
1) Maybe BufSpan
forall a. Maybe a
Strict.Nothing)
            EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing
                  (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (Bag EvBind -> TcEvBinds
EvBinds Bag EvBind
ev_bs)

          (uloc_evs,more_ev_asts) <- getUnlocatedEvBinds file

          let xs = [HieAST Type] -> [HieAST Type]
mergeSortAsts ([HieAST Type] -> [HieAST Type]) -> [HieAST Type] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [HieAST Type]
xs' [HieAST Type] -> [HieAST Type] -> [HieAST Type]
forall a. [a] -> [a] -> [a]
++ [HieAST Type]
top_ev_asts [HieAST Type] -> [HieAST Type] -> [HieAST Type]
forall a. [a] -> [a] -> [a]
++ [HieAST Type]
more_ev_asts
              span = FastString -> [HieAST Type] -> Span
forall {a}. FastString -> [HieAST a] -> Span
spanFile FastString
file [HieAST Type]
xs

              moduleInfo = Map NodeOrigin (NodeInfo Type) -> SourcedNodeInfo Type
forall a. Map NodeOrigin (NodeInfo a) -> SourcedNodeInfo a
SourcedNodeInfo
                             (Map NodeOrigin (NodeInfo Type) -> SourcedNodeInfo Type)
-> Map NodeOrigin (NodeInfo Type) -> SourcedNodeInfo Type
forall a b. (a -> b) -> a -> b
$ NodeOrigin -> NodeInfo Type -> Map NodeOrigin (NodeInfo Type)
forall k a. k -> a -> Map k a
M.singleton NodeOrigin
SourceInfo
                               (NodeInfo Type -> Map NodeOrigin (NodeInfo Type))
-> NodeInfo Type -> Map NodeOrigin (NodeInfo Type)
forall a b. (a -> b) -> a -> b
$ (FastString -> FastString -> NodeInfo Type
forall a. FastString -> FastString -> NodeInfo a
simpleNodeInfo FastString
"Module" FastString
"Module")
                                  {nodeIdentifiers = uloc_evs}

              moduleNode = SourcedNodeInfo Type -> Span -> [HieAST Type] -> HieAST Type
forall a. SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
Node SourcedNodeInfo Type
moduleInfo Span
span []

          case mergeSortAsts $ moduleNode : xs of
            [HieAST Type
x] -> HieAST Type -> ReaderT NodeOrigin (State HieState) (HieAST Type)
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (m :: * -> *) a. Monad m => a -> m a
return HieAST Type
x
            [HieAST Type]
xs -> FilePath
-> SDoc -> ReaderT NodeOrigin (State HieState) (HieAST Type)
forall a. FilePath -> SDoc -> a
panicDoc FilePath
"enrichHie: mergeSortAsts retur:ed more than one result" ([Span] -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([Span] -> SDoc) -> [Span] -> SDoc
forall a b. (a -> b) -> a -> b
$ (HieAST Type -> Span) -> [HieAST Type] -> [Span]
forall a b. (a -> b) -> [a] -> [b]
map HieAST Type -> Span
forall a. HieAST a -> Span
nodeSpan [HieAST Type]
xs)

    asts' <- sequence
          $ M.mapWithKey modulify
          $ M.fromListWith (++)
          $ map (\HieAST Type
x -> (FastString -> HiePath
HiePath (Span -> FastString
srcSpanFile (HieAST Type -> Span
forall a. HieAST a -> Span
nodeSpan HieAST Type
x)),[HieAST Type
x])) flat_asts

    let asts = Map HiePath (HieAST Type) -> HieASTs Type
forall a. Map HiePath (HieAST a) -> HieASTs a
HieASTs (Map HiePath (HieAST Type) -> HieASTs Type)
-> Map HiePath (HieAST Type) -> HieASTs Type
forall a b. (a -> b) -> a -> b
$ Map HiePath (HieAST Type) -> Map HiePath (HieAST Type)
forall a. Map HiePath (HieAST a) -> Map HiePath (HieAST a)
resolveTyVarScopes Map HiePath (HieAST Type)
asts'
    return asts

processGrp :: HsGroup GhcRn -> HieM [HieAST Type]
processGrp :: HsGroup (GhcPass 'Renamed) -> HieM [HieAST Type]
processGrp HsGroup (GhcPass 'Renamed)
grp = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ RScoped (HsValBinds (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBinds (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> RScoped (HsValBinds (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HsValBinds (GhcPass 'Renamed)
 -> RScoped (HsValBinds (GhcPass 'Renamed)))
-> (HsGroup (GhcPass 'Renamed) -> HsValBinds (GhcPass 'Renamed))
-> HsGroup (GhcPass 'Renamed)
-> RScoped (HsValBinds (GhcPass 'Renamed))
forall a b.
(a -> b)
-> (HsGroup (GhcPass 'Renamed) -> a)
-> HsGroup (GhcPass 'Renamed)
-> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Scope
-> HsValBinds (GhcPass 'Renamed)
-> RScoped (HsValBinds (GhcPass 'Renamed))
forall a. Scope -> a -> RScoped a
RS Scope
ModuleScope ) HsGroup (GhcPass 'Renamed) -> HsValBinds (GhcPass 'Renamed)
forall p. HsGroup p -> HsValBinds p
hs_valds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (SpliceDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (SpliceDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (SpliceDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LSpliceDecl (GhcPass 'Renamed)]
forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds HsGroup (GhcPass 'Renamed)
grp
      , [TyClGroup (GhcPass 'Renamed)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TyClGroup (GhcPass 'Renamed)] -> HieM [HieAST Type])
-> [TyClGroup (GhcPass 'Renamed)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [TyClGroup (GhcPass 'Renamed)]
forall p. HsGroup p -> [TyClGroup p]
hs_tyclds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (DerivDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DerivDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DerivDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LDerivDecl (GhcPass 'Renamed)]
forall p. HsGroup p -> [LDerivDecl p]
hs_derivds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (FixitySig (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (FixitySig (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (FixitySig (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LFixitySig (GhcPass 'Renamed)]
forall p. HsGroup p -> [LFixitySig p]
hs_fixds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (DefaultDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DefaultDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DefaultDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LDefaultDecl (GhcPass 'Renamed)]
forall p. HsGroup p -> [LDefaultDecl p]
hs_defds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (ForeignDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (ForeignDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (ForeignDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LForeignDecl (GhcPass 'Renamed)]
forall p. HsGroup p -> [LForeignDecl p]
hs_fords HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (WarnDecls (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (WarnDecls (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (WarnDecls (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LWarnDecls (GhcPass 'Renamed)]
forall p. HsGroup p -> [LWarnDecls p]
hs_warnds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (AnnDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (AnnDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (AnnDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LAnnDecl (GhcPass 'Renamed)]
forall p. HsGroup p -> [LAnnDecl p]
hs_annds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (RuleDecls (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (RuleDecls (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (RuleDecls (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LRuleDecls (GhcPass 'Renamed)]
forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds HsGroup (GhcPass 'Renamed)
grp
      , [GenLocated SrcSpanAnnA (DocDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DocDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DocDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup (GhcPass 'Renamed) -> [LDocDecl (GhcPass 'Renamed)]
forall p. HsGroup p -> [LDocDecl p]
hs_docs HsGroup (GhcPass 'Renamed)
grp
      ]

getRealSpanA :: EpAnn ann -> Maybe Span
getRealSpanA :: forall ann. EpAnn ann -> Maybe Span
getRealSpanA EpAnn ann
la = SrcSpan -> Maybe Span
getRealSpan (EpAnn ann -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA EpAnn ann
la)

getRealSpan :: SrcSpan -> Maybe Span
getRealSpan :: SrcSpan -> Maybe Span
getRealSpan (RealSrcSpan Span
sp Maybe BufSpan
_) = Span -> Maybe Span
forall a. a -> Maybe a
Just Span
sp
getRealSpan SrcSpan
_ = Maybe Span
forall a. Maybe a
Nothing

grhss_span :: (Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p)))) ~ EpAnn NoEpAnns)
           => GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span :: forall (p :: Pass) (body :: * -> *).
(Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 ~ EpAnn NoEpAnns) =>
GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span (GRHSs XCGRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
_ [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
xs HsLocalBinds (GhcPass p)
bs) = (SrcSpan -> SrcSpan -> SrcSpan) -> SrcSpan -> [SrcSpan] -> SrcSpan
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans (HsLocalBinds (GhcPass p) -> SrcSpan
forall (p :: Pass). HsLocalBinds (GhcPass p) -> SrcSpan
spanHsLocaLBinds HsLocalBinds (GhcPass p)
bs) ((GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 -> SrcSpan)
-> [GenLocated
      (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
-> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated
  (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
[GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
xs)

bindingsOnly :: [Context Name] -> HieM [HieAST a]
bindingsOnly :: forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [] = [HieAST a] -> ReaderT NodeOrigin (State HieState) [HieAST a]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
bindingsOnly (C ContextInfo
c Name
n : [Context Name]
xs) = do
  org <- ReaderT NodeOrigin (State HieState) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
  rest <- bindingsOnly xs
  lookupAndInsertEntityName n
  pure $ case nameSrcSpan n of
    RealSrcSpan Span
span Maybe BufSpan
_ -> SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
forall a. SourcedNodeInfo a -> Span -> [HieAST a] -> HieAST a
Node (NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
forall a. NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
mkSourcedNodeInfo NodeOrigin
org NodeInfo a
nodeinfo) Span
span [] HieAST a -> [HieAST a] -> [HieAST a]
forall a. a -> [a] -> [a]
: [HieAST a]
rest
      where nodeinfo :: NodeInfo a
nodeinfo = Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Set a
S.empty [] (Identifier -> IdentifierDetails a -> NodeIdentifiers a
forall k a. k -> a -> Map k a
M.singleton (Name -> Identifier
forall a b. b -> Either a b
Right Name
n) IdentifierDetails a
info)
            info :: IdentifierDetails a
info = IdentifierDetails a
forall a. Monoid a => a
mempty{identInfo = S.singleton c}
    SrcSpan
_ -> [HieAST a]
rest

concatM :: Monad m => [m [a]] -> m [a]
concatM :: forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [m [a]]
xs = [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[a]] -> [a]) -> m [[a]] -> m [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [m [a]] -> m [[a]]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [m [a]]
xs

{- Note [Capturing Scopes and other non local information]
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toHie is a local transformation, but scopes of bindings cannot be known locally,
hence we have to push the relevant info down into the binding nodes.
We use the following types (*Context and *Scoped) to wrap things and
carry the required info
(Maybe Span) always carries the span of the entire binding, including rhs
-}
data Context a = C ContextInfo a -- Used for names and bindings

data RContext a = RC RecFieldContext a
data RFContext a = RFC RecFieldContext (Maybe Span) a
-- ^ context for record fields

data IEContext a = IEC IEType a
-- ^ context for imports/exports

data BindContext a = BC BindType Scope a
-- ^ context for imports/exports

data PatSynFieldContext a = PSC (Maybe Span) a
-- ^ context for pattern synonym fields.

data SigContext a = SC SigInfo a
-- ^ context for type signatures

data SigInfo = SI SigType (Maybe Span)

data SigType = BindSig | ClassSig | InstSig

data EvBindContext a = EvBindContext Scope (Maybe Span) a

data RScoped a = RS Scope a
-- ^ Scope spans over everything to the right of a, (mostly) not
-- including a itself
-- (Includes a in a few special cases like recursive do bindings) or
-- let/where bindings

-- | Pattern scope
data PScoped a = PS (Maybe Span)
                    Scope       -- ^ use site of the pattern
                    Scope       -- ^ pattern to the right of a, not including a
                    a
  deriving (Typeable (PScoped a)
Typeable (PScoped a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PScoped a -> c (PScoped a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PScoped a))
-> (PScoped a -> Constr)
-> (PScoped a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PScoped a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PScoped a)))
-> ((forall b. Data b => b -> b) -> PScoped a -> PScoped a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PScoped a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PScoped a -> r)
-> (forall u. (forall d. Data d => d -> u) -> PScoped a -> [u])
-> (forall u.
    TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a))
-> Data (PScoped a)
PScoped a -> Constr
PScoped a -> DataType
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
forall a. Data a => Typeable (PScoped a)
forall a. Data a => PScoped a -> Constr
forall a. Data a => PScoped a -> DataType
forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
forall a u.
Data a =>
TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
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. TypeIndex -> (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.
TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u
forall u. (forall d. Data d => d -> u) -> PScoped a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PScoped a)
$ctoConstr :: forall a. Data a => PScoped a -> Constr
toConstr :: PScoped a -> Constr
$cdataTypeOf :: forall a. Data a => PScoped a -> DataType
dataTypeOf :: PScoped a -> DataType
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PScoped a))
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
gmapT :: (forall b. Data b => b -> b) -> PScoped a -> PScoped a
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PScoped a -> [u]
$cgmapQi :: forall a u.
Data a =>
TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u
gmapQi :: forall u.
TypeIndex -> (forall d. Data d => d -> u) -> PScoped a -> u
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
Data) -- Pattern Scope

{- Note [TyVar Scopes]
   ~~~~~~~~~~~~~~~~~~~
Due to -XScopedTypeVariables, type variables can be in scope quite far from
their original binding. We resolve the scope of these type variables
in a separate pass
-}
data TScoped a = TS TyVarScope a -- TyVarScope

data TVScoped a = TVS TyVarScope Scope a -- TyVarScope
-- ^ First scope remains constant
-- Second scope is used to build up the scope of a tyvar over
-- things to its right, ala RScoped

-- | Each element scopes over the elements to the right
listScopes :: Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes :: forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
_ [] = []
listScopes Scope
rhsScope [LocatedA a
pat] = [Scope -> LocatedA a -> RScoped (LocatedA a)
forall a. Scope -> a -> RScoped a
RS Scope
rhsScope LocatedA a
pat]
listScopes Scope
rhsScope (LocatedA a
pat : [LocatedA a]
pats) = Scope -> LocatedA a -> RScoped (LocatedA a)
forall a. Scope -> a -> RScoped a
RS Scope
sc LocatedA a
pat RScoped (LocatedA a)
-> [RScoped (LocatedA a)] -> [RScoped (LocatedA a)]
forall a. a -> [a] -> [a]
: [RScoped (LocatedA a)]
pats'
  where
    pats' :: [RScoped (LocatedA a)]
pats'@((RS Scope
scope LocatedA a
p):[RScoped (LocatedA a)]
_) = Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
rhsScope [LocatedA a]
pats
    sc :: Scope
sc = Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ LocatedA a -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LocatedA a
p

-- | 'listScopes' specialised to 'PScoped' things
patScopes
  :: Maybe Span
  -> Scope
  -> Scope
  -> [LPat (GhcPass p)]
  -> [PScoped (LPat (GhcPass p))]
patScopes :: forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
useScope Scope
patScope [LPat (GhcPass p)]
xs =
  (RScoped (LocatedA (Pat (GhcPass p)))
 -> PScoped (LPat (GhcPass p)))
-> [RScoped (LocatedA (Pat (GhcPass p)))]
-> [PScoped (LPat (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc LocatedA (Pat (GhcPass p))
a) -> Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
useScope Scope
sc LocatedA (Pat (GhcPass p))
a) ([RScoped (LocatedA (Pat (GhcPass p)))]
 -> [PScoped (LPat (GhcPass p))])
-> [RScoped (LocatedA (Pat (GhcPass p)))]
-> [PScoped (LPat (GhcPass p))]
forall a b. (a -> b) -> a -> b
$
    Scope
-> [LocatedA (Pat (GhcPass p))]
-> [RScoped (LocatedA (Pat (GhcPass p)))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
patScope [LPat (GhcPass p)]
[LocatedA (Pat (GhcPass p))]
xs

-- | 'listScopes' specialised to 'HsConPatTyArg'
taScopes
  :: Scope
  -> Scope
  -> [HsConPatTyArg (GhcPass a)]
  -> [TScoped (HsTyPat (GhcPass a))]
taScopes :: forall (a :: Pass).
Scope
-> Scope
-> [HsConPatTyArg (GhcPass a)]
-> [TScoped (HsTyPat (GhcPass a))]
taScopes Scope
scope Scope
rhsScope [HsConPatTyArg (GhcPass a)]
xs =
  (RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))
 -> TScoped (HsTyPat (GhcPass a)))
-> [RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
-> [TScoped (HsTyPat (GhcPass a))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))
a) -> TyVarScope -> HsTyPat (GhcPass a) -> TScoped (HsTyPat (GhcPass a))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
scope, Scope
sc]) (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)) -> HsTyPat (GhcPass a)
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))
a)) ([RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
 -> [TScoped (HsTyPat (GhcPass a))])
-> [RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
-> [TScoped (HsTyPat (GhcPass a))]
forall a b. (a -> b) -> a -> b
$
    Scope
-> [GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))]
-> [RScoped (GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
rhsScope ((HsConPatTyArg (GhcPass a)
 -> GenLocated SrcSpanAnnA (HsTyPat (GhcPass a)))
-> [HsConPatTyArg (GhcPass a)]
-> [GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))]
forall a b. (a -> b) -> [a] -> [b]
map (\(HsConPatTyArg XConPatTyArg (GhcPass a)
_ HsTyPat (GhcPass a)
hstp) -> SrcSpanAnnA
-> HsTyPat (GhcPass a)
-> GenLocated SrcSpanAnnA (HsTyPat (GhcPass a))
forall l e. l -> e -> GenLocated l e
L (GenLocated SrcSpanAnnA (HsType (GhcPass a)) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc (GenLocated SrcSpanAnnA (HsType (GhcPass a)) -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (HsType (GhcPass a)) -> SrcSpanAnnA
forall a b. (a -> b) -> a -> b
$ HsTyPat (GhcPass a) -> LHsType (GhcPass a)
forall pass. HsTyPat pass -> LHsType pass
hstp_body HsTyPat (GhcPass a)
hstp) HsTyPat (GhcPass a)
hstp) [HsConPatTyArg (GhcPass a)]
xs)
  -- We make the HsTyPat into a Located one by using the location of the underlying LHsType.
  -- We then strip off the redundant location information afterward, and take the union of the given scope and those to the right when forming the TS.

-- | 'listScopes' specialised to 'TVScoped' things
tvScopes
  :: TyVarScope
  -> Scope
  -> [LHsTyVarBndr flag (GhcPass a)]
  -> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes :: forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tvScope Scope
rhsScope [LHsTyVarBndr flag (GhcPass a)]
xs =
  (RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))
 -> TVScoped (LHsTyVarBndr flag (GhcPass a)))
-> [RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc LocatedA (HsTyVarBndr flag (GhcPass a))
a)-> TyVarScope
-> Scope
-> LocatedA (HsTyVarBndr flag (GhcPass a))
-> TVScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tvScope Scope
sc LocatedA (HsTyVarBndr flag (GhcPass a))
a) ([RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
 -> [TVScoped (LHsTyVarBndr flag (GhcPass a))])
-> [RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA (HsTyVarBndr flag (GhcPass a))]
-> [RScoped (LocatedA (HsTyVarBndr flag (GhcPass a)))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
rhsScope [LHsTyVarBndr flag (GhcPass a)]
[LocatedA (HsTyVarBndr flag (GhcPass a))]
xs

{- Note [Scoping Rules for SigPat]
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explicitly quantified variables in pattern type signatures are not
brought into scope in the rhs, but implicitly quantified variables
are (HsWC and HsIB).
This is unlike other signatures, where explicitly quantified variables
are brought into the RHS Scope
For example
foo :: forall a. ...;
foo = ... -- a is in scope here

bar (x :: forall a. a -> a) = ... -- a is not in scope here
--   ^ a is in scope here (pattern body)

bax (x :: a) = ... -- a is in scope here

This case in handled in the instance for HsPatSigType
-}

instance HasLoc thing => HasLoc (PScoped thing) where
  getHasLoc :: PScoped thing -> SrcSpan
getHasLoc (PS Maybe Span
_ Scope
_ Scope
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc thing
a

instance HasLoc a => HasLoc (DataDefnCons a) where
  getHasLoc :: DataDefnCons a -> SrcSpan
getHasLoc = [a] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList ([a] -> SrcSpan)
-> (DataDefnCons a -> [a]) -> DataDefnCons a -> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDefnCons a -> [a]
forall a. DataDefnCons a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

instance (HasLoc a, HiePass p) => HasLoc (FamEqn (GhcPass p) a) where
  getHasLoc :: FamEqn (GhcPass p) a -> SrcSpan
getHasLoc (FamEqn XCFamEqn (GhcPass p) a
_ LIdP (GhcPass p)
a HsOuterFamEqnTyVarBndrs (GhcPass p)
outer_bndrs HsFamEqnPats (GhcPass p)
b LexicalFixity
_ a
c) = case HsOuterFamEqnTyVarBndrs (GhcPass p)
outer_bndrs of
    HsOuterImplicit{} ->
      (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [GenLocated SrcSpanAnnN (IdGhcP p) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
a, [HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList HsFamEqnPats (GhcPass p)
[HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc a
c]
    HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
tvs} ->
      (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [GenLocated SrcSpanAnnN (IdGhcP p) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
a, [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
[GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))]
tvs, [HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList HsFamEqnPats (GhcPass p)
[HsArg
   (GhcPass p)
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc a
c]

instance (HasLoc tm, HasLoc ty) => HasLoc (HsArg (GhcPass p) tm ty) where
  getHasLoc :: HsArg (GhcPass p) tm ty -> SrcSpan
getHasLoc (HsValArg XValArg (GhcPass p)
_ tm
tm) = tm -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc tm
tm
  getHasLoc (HsTypeArg XTypeArg (GhcPass p)
_ ty
ty) = ty -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc ty
ty
  getHasLoc (HsArgPar XArgPar (GhcPass p)
sp)  = SrcSpan
XArgPar (GhcPass p)
sp

instance HasLoc (HsDataDefn GhcRn) where
  getHasLoc :: HsDataDefn (GhcPass 'Renamed) -> SrcSpan
getHasLoc def :: HsDataDefn (GhcPass 'Renamed)
def@(HsDataDefn{}) = DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)))
-> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc (DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)))
 -> SrcSpan)
-> DataDefnCons
     (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)))
-> SrcSpan
forall a b. (a -> b) -> a -> b
$ HsDataDefn (GhcPass 'Renamed)
-> DataDefnCons (LConDecl (GhcPass 'Renamed))
forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons HsDataDefn (GhcPass 'Renamed)
def
    -- Only used for data family instances, so we only need rhs
    -- Most probably the rest will be unhelpful anyway

-- | The main worker class
-- See Note [Updating HieAst for changes in the GHC AST] for more information
-- on how to add/modify instances for this.
class ToHie a where
  toHie :: a -> HieM [HieAST Type]

-- | Used to collect type info
class HasType a where
  getTypeNode :: a -> HieM [HieAST Type]

instance ToHie Void where
  toHie :: Void -> HieM [HieAST Type]
toHie Void
v = Void -> HieM [HieAST Type]
forall a. Void -> a
absurd Void
v

instance (ToHie a) => ToHie [a] where
  toHie :: [a] -> HieM [HieAST Type]
toHie = (a -> HieM [HieAST Type]) -> [a] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance (ToHie a) => ToHie (NonEmpty a) where
  toHie :: NonEmpty a -> HieM [HieAST Type]
toHie = (a -> HieM [HieAST Type]) -> NonEmpty a -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance (ToHie a) => ToHie (DataDefnCons a) where
  toHie :: DataDefnCons a -> HieM [HieAST Type]
toHie = (a -> HieM [HieAST Type]) -> DataDefnCons a -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance (ToHie a) => ToHie (Bag a) where
  toHie :: Bag a -> HieM [HieAST Type]
toHie = [a] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([a] -> HieM [HieAST Type])
-> (Bag a -> [a]) -> Bag a -> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bag a -> [a]
forall a. Bag a -> [a]
bagToList

instance (ToHie a) => ToHie (Maybe a) where
  toHie :: Maybe a -> HieM [HieAST Type]
toHie = HieM [HieAST Type]
-> (a -> HieM [HieAST Type]) -> Maybe a -> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance ToHie (IEContext (LocatedA ModuleName)) where
  toHie :: IEContext (GenLocated SrcSpanAnnA ModuleName) -> HieM [HieAST Type]
toHie (IEC IEType
c (L (EpAnn (EpaSpan (RealSrcSpan Span
span Maybe BufSpan
_)) AnnListItem
_ EpAnnComments
_) ModuleName
mname)) = do
      org <- ReaderT NodeOrigin (State HieState) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
      pure [Node (mkSourcedNodeInfo org $ NodeInfo S.empty [] idents) span []]
    where details :: IdentifierDetails Type
details = IdentifierDetails Type
forall a. Monoid a => a
mempty{identInfo = S.singleton (IEThing c)}
          idents :: NodeIdentifiers Type
idents = Identifier -> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (ModuleName -> Identifier
forall a b. a -> Either a b
Left ModuleName
mname) IdentifierDetails Type
details
  toHie IEContext (GenLocated SrcSpanAnnA ModuleName)
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Context (Located a)) => ToHie (Context (LocatedN a)) where
  toHie :: Context (LocatedN a) -> HieM [HieAST Type]
toHie (C ContextInfo
c (L SrcSpanAnnN
l a
a)) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
c (SrcSpan -> a -> Located a
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnN -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnN
l) a
a))

instance ToHie (Context (Located a)) => ToHie (Context (LocatedA a)) where
  toHie :: Context (LocatedA a) -> HieM [HieAST Type]
toHie (C ContextInfo
c (L SrcSpanAnnA
l a
a)) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
c (SrcSpan -> a -> Located a
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
l) a
a))

instance ToHie (Context (Located Var)) where
  toHie :: Context (Located Id) -> HieM [HieAST Type]
toHie Context (Located Id)
c = case Context (Located Id)
c of
      C ContextInfo
context (L (RealSrcSpan Span
span Maybe BufSpan
_) Id
name')
        | Id -> Unique
varUnique Id
name' Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== TypeIndex -> Unique
mkBuiltinUnique TypeIndex
1 -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
        | Bool
otherwise -> do
          m <- State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState (NameEnv Id)
 -> ReaderT NodeOrigin (State HieState) (NameEnv Id))
-> State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall a b. (a -> b) -> a -> b
$ (HieState -> NameEnv Id) -> State HieState (NameEnv Id)
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> NameEnv Id
name_remapping
          org <- ask
          let name = case NameEnv Id -> Name -> Maybe Id
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv Id
m (Id -> Name
varName Id
name') of
                Just Id
var -> Id
var
                Maybe Id
Nothing-> Id
name'
              ty = case Id -> Maybe DataCon
isDataConId_maybe Id
name' of
                      Maybe DataCon
Nothing -> Id -> Type
varType Id
name'
                      Just DataCon
dc -> DataCon -> Type
dataConNonlinearType DataCon
dc
          -- insert the entity info for the name into the entity_infos map
          insertEntityInfo (varName name) $ idEntityInfo name
          insertEntityInfo (varName name') $ idEntityInfo name'
          pure
            [Node
              (mkSourcedNodeInfo org $ NodeInfo S.empty [] $
                M.singleton (Right $ varName name)
                            (IdentifierDetails (Just ty)
                                               (S.singleton context)))
              span
              []]
      C (EvidenceVarBind EvVarSource
i Scope
_ Maybe Span
sp)  (L SrcSpan
_ Id
name) -> do
        Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
name (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
i Scope
ModuleScope Maybe Span
sp)
        [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
      Context (Located Id)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Context (Located Name)) where
  toHie :: Context (Located Name) -> HieM [HieAST Type]
toHie Context (Located Name)
c = case Context (Located Name)
c of
      C ContextInfo
context (L (RealSrcSpan Span
span Maybe BufSpan
_) Name
name')
        | Name -> Unique
nameUnique Name
name' Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== TypeIndex -> Unique
mkBuiltinUnique TypeIndex
1 -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
        | Bool
otherwise -> do
          m <- State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State HieState (NameEnv Id)
 -> ReaderT NodeOrigin (State HieState) (NameEnv Id))
-> State HieState (NameEnv Id)
-> ReaderT NodeOrigin (State HieState) (NameEnv Id)
forall a b. (a -> b) -> a -> b
$ (HieState -> NameEnv Id) -> State HieState (NameEnv Id)
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> NameEnv Id
name_remapping
          org <- ask
          let name = case NameEnv Id -> Name -> Maybe Id
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv Id
m Name
name' of
                Just Id
var -> Id -> Name
varName Id
var
                Maybe Id
Nothing -> Name
name'
          -- insert the entity info for the name into the entity_infos map
          lookupAndInsertEntityName name
          lookupAndInsertEntityName name'
          pure
            [Node
              (mkSourcedNodeInfo org $ NodeInfo S.empty [] $
                M.singleton (Right name)
                            (IdentifierDetails Nothing
                                               (S.singleton context)))
              span
              []]
      Context (Located Name)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

evVarsOfTermList :: EvTerm -> [EvId]
evVarsOfTermList :: EvTerm -> [Id]
evVarsOfTermList (EvExpr EvExpr
e)         = InterestingVarFun -> EvExpr -> [Id]
exprSomeFreeVarsList InterestingVarFun
isEvVar EvExpr
e
evVarsOfTermList (EvTypeable Type
_ EvTypeable
ev)  =
  case EvTypeable
ev of
    EvTypeableTyCon TyCon
_ [EvTerm]
e   -> (EvTerm -> [Id]) -> [EvTerm] -> [Id]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap EvTerm -> [Id]
evVarsOfTermList [EvTerm]
e
    EvTypeableTyApp EvTerm
e1 EvTerm
e2 -> (EvTerm -> [Id]) -> [EvTerm] -> [Id]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap EvTerm -> [Id]
evVarsOfTermList [EvTerm
e1,EvTerm
e2]
    EvTypeableTrFun EvTerm
e1 EvTerm
e2 EvTerm
e3 -> (EvTerm -> [Id]) -> [EvTerm] -> [Id]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap EvTerm -> [Id]
evVarsOfTermList [EvTerm
e1,EvTerm
e2,EvTerm
e3]
    EvTypeableTyLit EvTerm
e     -> EvTerm -> [Id]
evVarsOfTermList EvTerm
e
evVarsOfTermList (EvFun{}) = []

instance ToHie (EvBindContext (LocatedA TcEvBinds)) where
  toHie :: EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
toHie (EvBindContext Scope
sc Maybe Span
sp (L SrcSpanAnnA
span (EvBinds Bag EvBind
bs)))
    = (EvBind -> HieM [HieAST Type]) -> [EvBind] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM EvBind -> HieM [HieAST Type]
go ([EvBind] -> HieM [HieAST Type]) -> [EvBind] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Bag EvBind -> [EvBind]
forall a. Bag a -> [a]
bagToList Bag EvBind
bs
    where
      go :: EvBind -> HieM [HieAST Type]
go EvBind
evbind = do
          let evDeps :: [Id]
evDeps = EvTerm -> [Id]
evVarsOfTermList (EvTerm -> [Id]) -> EvTerm -> [Id]
forall a b. (a -> b) -> a -> b
$ EvBind -> EvTerm
eb_rhs EvBind
evbind
              depNames :: EvBindDeps
depNames = [Name] -> EvBindDeps
EvBindDeps ([Name] -> EvBindDeps) -> [Name] -> EvBindDeps
forall a b. (a -> b) -> a -> b
$ (Id -> Name) -> [Id] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Id -> Name
varName [Id]
evDeps
          [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            [ Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind (EvBindDeps -> EvVarSource
EvLetBind EvBindDeps
depNames) (Scope -> Scope -> Scope
combineScopes Scope
sc (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span)) Maybe Span
sp)
                                        (SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span (Id -> GenLocated SrcSpanAnnA Id)
-> Id -> GenLocated SrcSpanAnnA Id
forall a b. (a -> b) -> a -> b
$ EvBind -> Id
eb_lhs EvBind
evbind))
            , [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Id -> Context (GenLocated SrcSpanAnnA Id))
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
EvidenceVarUse (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) ([Id] -> [Context (GenLocated SrcSpanAnnA Id)])
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> a -> b
$ [Id]
evDeps
            ]
  toHie EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LocatedA HsWrapper) where
  toHie :: LocatedA HsWrapper -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
osp HsWrapper
wrap)
    = case HsWrapper
wrap of
        (WpLet TcEvBinds
bs)      -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
osp) (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
osp) (SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp TcEvBinds
bs)
        (WpCompose HsWrapper
a HsWrapper
b) -> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
          [LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
a), LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
b)]
        (WpFun HsWrapper
a HsWrapper
b Scaled Type
_)   -> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
          [LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
a), LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp HsWrapper
b)]
        (WpEvLam Id
a) ->
          Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvWrapperBind (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
osp) (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
osp))
                (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp Id
a
        (WpEvApp EvTerm
a) ->
          (Id -> HieM [HieAST Type]) -> [Id] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type])
-> (Id -> Context (GenLocated SrcSpanAnnA Id))
-> Id
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
EvidenceVarUse (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
osp) ([Id] -> HieM [HieAST Type]) -> [Id] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ EvTerm -> [Id]
evVarsOfTermList EvTerm
a
        HsWrapper
_               -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => HasType (LocatedA (HsBind (GhcPass p))) where
  getTypeNode :: LocatedA (HsBind (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpanAnnA
spn HsBind (GhcPass p)
bind) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> HsBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsBind (GhcPass p)
bind (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
spn)
      HiePassEv p
HieTc ->  case HsBind (GhcPass p)
bind of
        FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP (GhcPass p)
name} -> HsBind (GhcPass p) -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNode HsBind (GhcPass p)
bind (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
spn) (Id -> Type
varType (Id -> Type) -> Id -> Type
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnN Id -> Id
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN Id
name)
        HsBind (GhcPass p)
_ -> HsBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsBind (GhcPass p)
bind (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
spn)

instance HiePass p => HasType (LocatedA (Pat (GhcPass p))) where
  getTypeNode :: LocatedA (Pat (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpanAnnA
spn Pat (GhcPass p)
pat) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> Pat (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Pat (GhcPass p)
pat SrcSpanAnnA
spn
      HiePassEv p
HieTc -> Pat (GhcPass p) -> SrcSpanAnnA -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpanAnnA -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNodeA Pat (GhcPass p)
pat SrcSpanAnnA
spn (Pat GhcTc -> Type
hsPatType Pat (GhcPass p)
Pat GhcTc
pat)

-- | This instance tries to construct 'HieAST' nodes which include the type of
-- the expression. It is not yet possible to do this efficiently for all
-- expression forms, so we skip filling in the type for those inputs.
--
-- See Note [Computing the type of every node in the tree]
instance HiePass p => HasType (LocatedA (HsExpr (GhcPass p))) where
  getTypeNode :: LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpanAnnA
spn HsExpr (GhcPass p)
e) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> HieM [HieAST Type]
fallback
      HiePassEv p
HieTc -> case HsExpr GhcTc -> Maybe Type
computeType HsExpr (GhcPass p)
HsExpr GhcTc
e of
          Just Type
ty -> HsExpr (GhcPass p) -> SrcSpanAnnA -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpanAnnA -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNodeA HsExpr (GhcPass p)
e SrcSpanAnnA
spn Type
ty
          Maybe Type
Nothing -> HieM [HieAST Type]
fallback
    where
      fallback :: HieM [HieAST Type]
      fallback :: HieM [HieAST Type]
fallback = HsExpr (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsExpr (GhcPass p)
e SrcSpanAnnA
spn

      -- Skip computing the type of some expressions for performance reasons.
      --
      -- See impact on Haddock output (esp. missing type annotations or links)
      -- before skipping more kinds of expressions. See impact on Haddock
      -- performance before computing the types of more expressions.
      --
      -- See Note [Computing the type of every node in the tree]
      computeType :: HsExpr GhcTc -> Maybe Type
      computeType :: HsExpr GhcTc -> Maybe Type
computeType HsExpr GhcTc
e = case HsExpr GhcTc
e of
        HsApp{} -> Maybe Type
forall a. Maybe a
Nothing
        HsAppType{} -> Maybe Type
forall a. Maybe a
Nothing
        NegApp{} -> Maybe Type
forall a. Maybe a
Nothing
        HsPar XPar GhcTc
_ LHsExpr GhcTc
e -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        ExplicitTuple{} -> Maybe Type
forall a. Maybe a
Nothing
        HsIf XIf GhcTc
_ LHsExpr GhcTc
_ LHsExpr GhcTc
t LHsExpr GhcTc
f -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
t Maybe Type -> Maybe Type -> Maybe Type
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
f
        HsLet XLet GhcTc
_ HsLocalBinds GhcTc
_ LHsExpr GhcTc
body -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
body
        RecordCon XRecordCon GhcTc
con_expr XRec GhcTc (ConLikeP GhcTc)
_ HsRecordBinds GhcTc
_ -> HsExpr GhcTc -> Maybe Type
computeType XRecordCon GhcTc
HsExpr GhcTc
con_expr
        ExprWithTySig XExprWithTySig GhcTc
_ LHsExpr GhcTc
e LHsSigWcType (NoGhcTc GhcTc)
_ -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        HsPragE XPragE GhcTc
_ HsPragE GhcTc
_ LHsExpr GhcTc
e -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        XExpr (ExpandedThingTc HsThingRn
thing HsExpr GhcTc
e)
          | OrigExpr (HsGetField{}) <- HsThingRn
thing -- for record-dot-syntax
          -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsExpr GhcTc -> Type
hsExprType HsExpr GhcTc
e)
          | Bool
otherwise -> HsExpr GhcTc -> Maybe Type
computeType HsExpr GhcTc
e
        XExpr (HsTick CoreTickish
_ LHsExpr GhcTc
e) -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        XExpr (HsBinTick TypeIndex
_ TypeIndex
_ LHsExpr GhcTc
e) -> LHsExpr GhcTc -> Maybe Type
computeLType LHsExpr GhcTc
e
        HsExpr GhcTc
e -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsExpr GhcTc -> Type
hsExprType HsExpr GhcTc
e)

      computeLType :: LHsExpr GhcTc -> Maybe Type
      computeLType :: LHsExpr GhcTc -> Maybe Type
computeLType (L SrcSpanAnnA
_ HsExpr GhcTc
e) = HsExpr GhcTc -> Maybe Type
computeType HsExpr GhcTc
e

{- Note [Computing the type of every node in the tree]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In GHC.Iface.Ext.Ast we decorate every node in the AST with its
type, computed by `hsExprType` applied to that node.  So it's
important that `hsExprType` takes roughly constant time per node.
There are three cases to consider:

1. For many nodes (e.g. HsVar, HsDo, HsCase) it is easy to get their
   type -- e.g. it is stored in the node, or in sub-node thereof.

2. For some nodes (e.g. HsPar, HsTick, HsIf) the type of the node is
   the type of a child, so we can recurse, fast.  We don't expect the
   nesting to be very deep, so while this is theoretically non-linear,
   we don't expect it to be a problem in practice.

3. A very few nodes (e.g. HsApp) are more troublesome because we need to
   take the type of a child, and then do some non-trivial processing.
   To be conservative on computation, we decline to decorate these
   nodes, using `fallback` instead.

The function `computeType e` returns `Just t` if we can find the type
of `e` cheaply, and `Nothing` otherwise.  The base `Nothing` cases
are the troublesome ones in (3) above. Hopefully we can ultimately
get rid of them all.

See #16233

-}

data HiePassEv p where
  HieRn :: HiePassEv 'Renamed
  HieTc :: HiePassEv 'Typechecked

class ( HiePass (NoGhcTcPass p)
      , NoGhcTcPass p ~ 'Renamed
      , ModifyState (IdGhcP p)
      , Data (GRHS  (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
      , Data (Match (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
      , Data (Match (GhcPass p) (LocatedA (HsCmd  (GhcPass p))))
      , Data (Stmt  (GhcPass p) (LocatedA (HsExpr (GhcPass p))))
      , Data (Stmt  (GhcPass p) (LocatedA (HsCmd  (GhcPass p))))
      , Data (HsExpr (GhcPass p))
      , Data (HsCmd  (GhcPass p))
      , Data (HsCmdTop (GhcPass p))
      , Data (GRHS (GhcPass p) (LocatedA (HsCmd (GhcPass p))))
      , Data (HsUntypedSplice (GhcPass p))
      , Data (HsLocalBinds (GhcPass p))
      , Data (FieldOcc (GhcPass p))
      , Data (HsTupArg (GhcPass p))
      , Data (IPBind (GhcPass p))
      , ToHie (Context (Located (IdGhcP p)))
      , Anno (IdGhcP p) ~ SrcSpanAnnN
      , Typeable p
      )
      => HiePass p where
  hiePass :: HiePassEv p

instance HiePass 'Renamed where
  hiePass :: HiePassEv 'Renamed
hiePass = HiePassEv 'Renamed
HieRn
instance HiePass 'Typechecked where
  hiePass :: HiePassEv 'Typechecked
hiePass = HiePassEv 'Typechecked
HieTc

instance ToHie (Context (Located NoExtField)) where
  toHie :: Context (Located NoExtField) -> HieM [HieAST Type]
toHie Context (Located NoExtField)
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

type AnnoBody p body
  = ( Anno (Match (GhcPass p) (LocatedA (body (GhcPass p))))
                   ~ SrcSpanAnnA
    , Anno [LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
                   ~ SrcSpanAnnLW
    , Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
                   ~ EpAnn NoEpAnns
    , Anno (StmtLR (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))) ~ SrcSpanAnnA

    , Data (body (GhcPass p))
    , Data (Match (GhcPass p) (LocatedA (body (GhcPass p))))
    , Data (GRHS  (GhcPass p) (LocatedA (body (GhcPass p))))
    , Data (Stmt  (GhcPass p) (LocatedA (body (GhcPass p))))
    )

instance HiePass p => ToHie (BindContext (LocatedA (HsBind (GhcPass p)))) where
  toHie :: BindContext (LocatedA (HsBind (GhcPass p))) -> HieM [HieAST Type]
toHie (BC BindType
context Scope
scope b :: LocatedA (HsBind (GhcPass p))
b@(L SrcSpanAnnA
span HsBind (GhcPass p)
bind)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ LocatedA (HsBind (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LocatedA (HsBind (GhcPass p))
b HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsBind (GhcPass p)
bind of
      FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP (GhcPass p)
name, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches, fun_ext :: forall idL idR. HsBindLR idL idR -> XFunBind idL idR
fun_ext = XFunBind (GhcPass p) (GhcPass p)
ext} ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
context Scope
scope (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
name
        , MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
matches
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
            HiePassEv p
HieTc | (HsWrapper
wrap, [CoreTickish]
_) <- XFunBind (GhcPass p) (GhcPass p)
ext -> LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> LocatedA HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span HsWrapper
wrap
            HiePassEv p
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
      PatBind{pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat (GhcPass p)
lhs, pat_rhs :: forall idL idR. HsBindLR idL idR -> GRHSs idR (LHsExpr idR)
pat_rhs = GRHSs (GhcPass p) (LHsExpr (GhcPass p))
rhs} ->
        [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe Span
getRealSpan (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)) Scope
scope Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
lhs
        , GRHSs (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LHsExpr (GhcPass p))
GRHSs (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
rhs
        ]
      VarBind{var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr (GhcPass p)
expr} ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        ]
      XHsBindsLR XXHsBindsLR (GhcPass p) (GhcPass p)
ext -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc
          | AbsBinds{ abs_exports :: AbsBinds -> [ABExport]
abs_exports = [ABExport]
xs, abs_binds :: AbsBinds -> LHsBinds GhcTc
abs_binds = LHsBinds GhcTc
binds
                    , abs_ev_binds :: AbsBinds -> [TcEvBinds]
abs_ev_binds = [TcEvBinds]
ev_binds
                    , abs_ev_vars :: AbsBinds -> [Id]
abs_ev_vars = [Id]
ev_vars } <- XXHsBindsLR (GhcPass p) (GhcPass p)
ext
          ->
            [  State HieState () -> HieM ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT NodeOrigin m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((HieState -> HieState) -> State HieState ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify ([ABExport] -> HieState -> HieState
modifyState [ABExport]
xs)) HieM () -> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b.
ReaderT NodeOrigin (State HieState) a
-> ReaderT NodeOrigin (State HieState) b
-> ReaderT NodeOrigin (State HieState) b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> -- Note [Name Remapping]
                    ([BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))]
 -> HieM [HieAST Type])
-> [BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)
 -> BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)))
-> [GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)]
-> [BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)
-> BindContext (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
context Scope
scope) LHsBinds GhcTc
[GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc)]
binds)
            , [LocatedA HsWrapper] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([LocatedA HsWrapper] -> HieM [HieAST Type])
-> [LocatedA HsWrapper] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ABExport -> LocatedA HsWrapper)
-> [ABExport] -> [LocatedA HsWrapper]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span (HsWrapper -> LocatedA HsWrapper)
-> (ABExport -> HsWrapper) -> ABExport -> LocatedA HsWrapper
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ABExport -> HsWrapper
abe_wrap) [ABExport]
xs
            , [EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
 -> HieM [HieAST Type])
-> [EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
                (TcEvBinds -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> [TcEvBinds]
-> [EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span)
                    (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> (TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds)
-> TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [TcEvBinds]
ev_binds
            , [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
                (Id -> Context (GenLocated SrcSpanAnnA Id))
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvSigBind
                                        (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span)
                                        (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span))
                    (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [Id]
ev_vars
            ]
      PatSynBind XPatSynBind (GhcPass p) (GhcPass p)
_ PatSynBind (GhcPass p) (GhcPass p)
psb ->
        [ GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> PatSynBind (GhcPass p) (GhcPass p)
-> GenLocated SrcSpan (PatSynBind (GhcPass p) (GhcPass p))
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) PatSynBind (GhcPass p) (GhcPass p)
psb -- PatSynBinds only occur at the top level
        ]

instance ( HiePass p
         , AnnoBody p body
         , ToHie (LocatedA (body (GhcPass p)))
         ) => ToHie (MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))) where
  toHie :: MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
-> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg = case MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg of
    MG{ mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = (L SrcSpanAnnLW
span [GenLocated
   SrcSpanAnnA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
alts) } ->
      (NodeOrigin -> NodeOrigin)
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (Origin -> NodeOrigin -> NodeOrigin
setOrigin Origin
origin) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnLW -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnLW
span)
        , [GenLocated
   SrcSpanAnnA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated
   SrcSpanAnnA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
alts
        ]
    where origin :: Origin
origin = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
             HiePassEv p
HieRn -> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
-> XMG (GhcPass p) (LocatedA (body (GhcPass p)))
forall p body. MatchGroup p body -> XMG p body
mg_ext MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg
             HiePassEv p
HieTc -> MatchGroupTc -> Origin
mg_origin (MatchGroupTc -> Origin) -> MatchGroupTc -> Origin
forall a b. (a -> b) -> a -> b
$ MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
-> XMG (GhcPass p) (LocatedA (body (GhcPass p)))
forall p body. MatchGroup p body -> XMG p body
mg_ext MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mg

setOrigin :: Origin -> NodeOrigin -> NodeOrigin
setOrigin :: Origin -> NodeOrigin -> NodeOrigin
setOrigin Origin
FromSource NodeOrigin
_ = NodeOrigin
SourceInfo
setOrigin (Generated {}) NodeOrigin
_ = NodeOrigin
GeneratedInfo

instance HiePass p => ToHie (Located (PatSynBind (GhcPass p) (GhcPass p))) where
    toHie :: Located (PatSynBind (GhcPass p) (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpan
sp PatSynBind (GhcPass p) (GhcPass p)
psb) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case PatSynBind (GhcPass p) (GhcPass p)
psb of
      PSB{psb_id :: forall idL idR. PatSynBind idL idR -> LIdP idL
psb_id=LIdP (GhcPass p)
var, psb_args :: forall idL idR. PatSynBind idL idR -> HsPatSynDetails idR
psb_args=HsPatSynDetails (GhcPass p)
dets, psb_def :: forall idL idR. PatSynBind idL idR -> LPat idR
psb_def=LPat (GhcPass p)
pat, psb_dir :: forall idL idR. PatSynBind idL idR -> HsPatSynDir idR
psb_dir=HsPatSynDir (GhcPass p)
dir} ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
PatSynDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
sp) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
var
        , HsConDetails
  Void
  (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
  [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   Void
   (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
   [PatSynFieldContext (RecordPatSynField (GhcPass p))]
 -> HieM [HieAST Type])
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  Void
  (GenLocated SrcSpanAnnN (IdGhcP p))
  [RecordPatSynField (GhcPass p)]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
toBind HsPatSynDetails (GhcPass p)
HsConDetails
  Void
  (GenLocated SrcSpanAnnN (IdGhcP p))
  [RecordPatSynField (GhcPass p)]
dets
        , PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
lhsScope Scope
patScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
        , HsPatSynDir (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsPatSynDir (GhcPass p)
dir
        ]
        where
          lhsScope :: Scope
lhsScope = Scope -> Scope -> Scope
combineScopes Scope
varScope Scope
detScope
          varScope :: Scope
varScope = GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
var
          patScope :: Scope
patScope = SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope) -> SrcSpanAnnA -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (Pat (GhcPass p)) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
          detScope :: Scope
detScope = case HsPatSynDetails (GhcPass p)
dets of
            (PrefixCon [Void]
_ [LIdP (GhcPass p)]
args) -> (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope)
-> [GenLocated SrcSpanAnnN (IdGhcP p)] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope [LIdP (GhcPass p)]
[GenLocated SrcSpanAnnN (IdGhcP p)]
args
            (InfixCon LIdP (GhcPass p)
a LIdP (GhcPass p)
b) -> Scope -> Scope -> Scope
combineScopes (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
a) (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
b)
            (RecCon [RecordPatSynField (GhcPass p)]
r) -> (RecordPatSynField (GhcPass p) -> Scope -> Scope)
-> Scope -> [RecordPatSynField (GhcPass p)] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RecordPatSynField (GhcPass p) -> Scope -> Scope
go Scope
NoScope [RecordPatSynField (GhcPass p)]
r
          go :: RecordPatSynField (GhcPass p) -> Scope -> Scope
go (RecordPatSynField (FieldOcc (GhcPass p)
a :: FieldOcc (GhcPass p)) LIdP (GhcPass p)
b) Scope
c = Scope -> Scope -> Scope
combineScopes Scope
c
            (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (FieldOcc (GhcPass p) -> LIdP (GhcPass p)
forall pass. FieldOcc pass -> LIdP pass
foLabel FieldOcc (GhcPass p)
a)) (GenLocated SrcSpanAnnN (IdGhcP p) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
b)
          detSpan :: Maybe Span
detSpan = case Scope
detScope of
            LocalScope Span
a -> Span -> Maybe Span
forall a. a -> Maybe a
Just Span
a
            Scope
_ -> Maybe Span
forall a. Maybe a
Nothing
          toBind :: HsConDetails
  Void
  (GenLocated SrcSpanAnnN (IdGhcP p))
  [RecordPatSynField (GhcPass p)]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
toBind (PrefixCon [Void]
ts [GenLocated SrcSpanAnnN (IdGhcP p)]
args) = Bool
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a. HasCallStack => Bool -> a -> a
assert ([Void] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Void]
ts) (HsConDetails
   Void
   (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
   [PatSynFieldContext (RecordPatSynField (GhcPass p))]
 -> HsConDetails
      Void
      (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (GhcPass p))])
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> a -> b
$ [Void]
-> [Context (GenLocated SrcSpanAnnN (IdGhcP p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [Void]
ts ([Context (GenLocated SrcSpanAnnN (IdGhcP p))]
 -> HsConDetails
      Void
      (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (GhcPass p))])
-> [Context (GenLocated SrcSpanAnnN (IdGhcP p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnN (IdGhcP p)
 -> Context (GenLocated SrcSpanAnnN (IdGhcP p)))
-> [GenLocated SrcSpanAnnN (IdGhcP p)]
-> [Context (GenLocated SrcSpanAnnN (IdGhcP p))]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [GenLocated SrcSpanAnnN (IdGhcP p)]
args
          toBind (InfixCon GenLocated SrcSpanAnnN (IdGhcP p)
a GenLocated SrcSpanAnnN (IdGhcP p)
b) = Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use GenLocated SrcSpanAnnN (IdGhcP p)
a) (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use GenLocated SrcSpanAnnN (IdGhcP p)
b)
          toBind (RecCon [RecordPatSynField (GhcPass p)]
r) = [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon ([PatSynFieldContext (RecordPatSynField (GhcPass p))]
 -> HsConDetails
      Void
      (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (GhcPass p))])
-> [PatSynFieldContext (RecordPatSynField (GhcPass p))]
-> HsConDetails
     Void
     (Context (GenLocated SrcSpanAnnN (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> a -> b
$ (RecordPatSynField (GhcPass p)
 -> PatSynFieldContext (RecordPatSynField (GhcPass p)))
-> [RecordPatSynField (GhcPass p)]
-> [PatSynFieldContext (RecordPatSynField (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Span
-> RecordPatSynField (GhcPass p)
-> PatSynFieldContext (RecordPatSynField (GhcPass p))
forall a. Maybe Span -> a -> PatSynFieldContext a
PSC Maybe Span
detSpan) [RecordPatSynField (GhcPass p)]
r

instance HiePass p => ToHie (HsPatSynDir (GhcPass p)) where
  toHie :: HsPatSynDir (GhcPass p) -> HieM [HieAST Type]
toHie HsPatSynDir (GhcPass p)
dir = case HsPatSynDir (GhcPass p)
dir of
    ExplicitBidirectional MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg -> MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup
  (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
mg
    HsPatSynDir (GhcPass p)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( HiePass p
         , Data (body (GhcPass p))
         , AnnoBody p body
         , ToHie (LocatedA (body (GhcPass p)))
         ) => ToHie (LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))) where
  toHie :: LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span Match (GhcPass p) (LocatedA (body (GhcPass p)))
m ) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Match (GhcPass p) (LocatedA (body (GhcPass p)))
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Match (GhcPass p) (LocatedA (body (GhcPass p)))
m SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Match (GhcPass p) (LocatedA (body (GhcPass p)))
m of
    Match{m_ctxt :: forall p body. Match p body -> HsMatchContext (LIdP (NoGhcTc p))
m_ctxt=HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
mctx, m_pats :: forall p body. Match p body -> XRec p [LPat p]
m_pats = L EpaLocation' [LEpaComment]
_ [GenLocated SrcSpanAnnA (Pat (GhcPass p))]
pats, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhss } ->
      [ forall (p :: Pass).
HiePass p =>
HsMatchContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsMatchContext @p HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
mctx
      , let rhsScope :: Scope
rhsScope = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
forall (p :: Pass) (body :: * -> *).
(Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 ~ EpAnn NoEpAnns) =>
GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhss
          in [PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))]
 -> HieM [HieAST Type])
-> [PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
forall a. Maybe a
Nothing Scope
rhsScope Scope
NoScope [LPat (GhcPass p)]
[GenLocated SrcSpanAnnA (Pat (GhcPass p))]
pats
      , GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhss
      ]

toHieHsMatchContext :: forall p. HiePass p => HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
                                           -> HieM [HieAST Type]
toHieHsMatchContext :: forall (p :: Pass).
HiePass p =>
HsMatchContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsMatchContext HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
ctxt
  = case HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
ctxt of
      FunRhs{mc_fun :: forall fn. HsMatchContext fn -> fn
mc_fun=LIdP (NoGhcTc (GhcPass p))
name} -> Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
MatchBind (LIdP (NoGhcTc (GhcPass p)) -> LocatedN Name
get_name LIdP (NoGhcTc (GhcPass p))
name)
      StmtCtxt HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a          -> forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext @p HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a
      HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
_                   -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  where
      -- See a paragraph about Haddock in #20415.
    get_name :: LIdP (NoGhcTc (GhcPass p)) -> LocatedN Name
    get_name :: LIdP (NoGhcTc (GhcPass p)) -> LocatedN Name
get_name LIdP (NoGhcTc (GhcPass p))
name = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
                      HiePassEv p
HieRn -> LIdP (NoGhcTc (GhcPass p))
LocatedN Name
name
                      HiePassEv p
HieTc -> LIdP (NoGhcTc (GhcPass p))
LocatedN Name
name

toHieHsStmtContext :: forall p. HiePass p => HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
                                          -> HieM [HieAST Type]
toHieHsStmtContext :: forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
ctxt
  = case HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
ctxt of
      PatGuard HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
a      -> forall (p :: Pass).
HiePass p =>
HsMatchContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsMatchContext @p HsMatchContext (LIdP (NoGhcTc (GhcPass p)))
a
      ParStmtCtxt HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a   -> forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext  @p HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a
      TransStmtCtxt HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a -> forall (p :: Pass).
HiePass p =>
HsStmtContext (LIdP (NoGhcTc (GhcPass p))) -> HieM [HieAST Type]
toHieHsStmtContext  @p HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
a
      HsStmtContext (LIdP (NoGhcTc (GhcPass p)))
_               -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => ToHie (PScoped (LocatedA (Pat (GhcPass p)))) where
  toHie :: PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
toHie (PS Maybe Span
rsp Scope
scope Scope
pscope lpat :: LocatedA (Pat (GhcPass p))
lpat@(L SrcSpanAnnA
ospan Pat (GhcPass p)
opat)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ LocatedA (Pat (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LocatedA (Pat (GhcPass p))
lpat HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Pat (GhcPass p)
opat of
      OrPat XOrPat (GhcPass p)
_ NonEmpty (LPat (GhcPass p))
pats ->
        (LocatedA (Pat (GhcPass p)) -> HieM [HieAST Type])
-> [LocatedA (Pat (GhcPass p))] -> [HieM [HieAST Type]]
forall a b. (a -> b) -> [a] -> [b]
map (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> (LocatedA (Pat (GhcPass p))
    -> PScoped (LocatedA (Pat (GhcPass p))))
-> LocatedA (Pat (GhcPass p))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope) (NonEmpty (LocatedA (Pat (GhcPass p)))
-> [LocatedA (Pat (GhcPass p))]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (LPat (GhcPass p))
NonEmpty (LocatedA (Pat (GhcPass p)))
pats)
      WildPat XWildPat (GhcPass p)
_ ->
        []
      VarPat XVarPat (GhcPass p)
_ LIdP (GhcPass p)
lname ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe Span
rsp) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
lname
        ]
      LazyPat XLazyPat (GhcPass p)
_ LPat (GhcPass p)
p ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
p
        ]
      AsPat XAsPat (GhcPass p)
_ LIdP (GhcPass p)
lname LPat (GhcPass p)
pat ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope
                                 (Scope -> Scope -> Scope
combineScopes (LocatedA (Pat (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat) Scope
pscope)
                                 Maybe Span
rsp)
                    LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
lname
        , PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      ParPat XParPat (GhcPass p)
_ LPat (GhcPass p)
pat ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      BangPat XBangPat (GhcPass p)
_ LPat (GhcPass p)
pat ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      ListPat XListPat (GhcPass p)
_ [LPat (GhcPass p)]
pats ->
        [ [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
pats
        ]
      TuplePat XTuplePat (GhcPass p)
_ [LPat (GhcPass p)]
pats Boxity
_ ->
        [ [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (LocatedA (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [LPat (GhcPass p)]
pats
        ]
      SumPat XSumPat (GhcPass p)
_ LPat (GhcPass p)
pat TypeIndex
_ TypeIndex
_ ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      ConPat {pat_con :: forall p. Pat p -> XRec p (ConLikeP p)
pat_con = XRec (GhcPass p) (ConLikeP (GhcPass p))
con, pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = HsConPatDetails (GhcPass p)
dets, pat_con_ext :: forall p. Pat p -> XConPat p
pat_con_ext = XConPat (GhcPass p)
ext} ->
        case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieTc ->
            [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (LocatedN Name -> Context (LocatedN Name))
-> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ (ConLike -> Name)
-> GenLocated SrcSpanAnnN ConLike -> LocatedN Name
forall a b.
(a -> b) -> GenLocated SrcSpanAnnN a -> GenLocated SrcSpanAnnN b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConLike -> Name
conLikeName XRec (GhcPass p) (ConLikeP (GhcPass p))
GenLocated SrcSpanAnnN ConLike
con
            , HsConDetails
  (TScoped (HsTyPat (GhcPass 'Renamed)))
  (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
  (RContext
     (HsRecFields
        (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (TScoped (HsTyPat (GhcPass 'Renamed)))
   (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
   (RContext
      (HsRecFields
         (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
 -> HieM [HieAST Type])
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
     (RContext
        (HsRecFields
           (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed))
  (GenLocated SrcSpanAnnA (Pat GhcTc))
  (HsRecFields (GhcPass p) (GenLocated SrcSpanAnnA (Pat GhcTc)))
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
     (RContext
        (HsRecFields
           (GhcPass p) (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))))
forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed)) a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify HsConPatDetails (GhcPass p)
HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed))
  (GenLocated SrcSpanAnnA (Pat GhcTc))
  (HsRecFields (GhcPass p) (GenLocated SrcSpanAnnA (Pat GhcTc)))
dets
            , let ev_binds :: TcEvBinds
ev_binds = ConPatTc -> TcEvBinds
cpt_binds XConPat (GhcPass p)
ConPatTc
ext
                  ev_vars :: [Id]
ev_vars = ConPatTc -> [Id]
cpt_dicts XConPat (GhcPass p)
ConPatTc
ext
                  wrap :: HsWrapper
wrap = ConPatTc -> HsWrapper
cpt_wrap XConPat (GhcPass p)
ConPatTc
ext
                  evscope :: Scope
evscope = SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
ospan Scope -> Scope -> Scope
`combineScopes` Scope
scope Scope -> Scope -> Scope
`combineScopes` Scope
pscope
                 in [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [ EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
scope Maybe Span
rsp (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan TcEvBinds
ev_binds
                            , LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> LocatedA HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan HsWrapper
wrap
                            , [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpanAnnA Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Id -> Context (GenLocated SrcSpanAnnA Id))
-> [Id] -> [Context (GenLocated SrcSpanAnnA Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvPatternBind Scope
evscope Maybe Span
rsp)
                                          (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> (Id -> GenLocated SrcSpanAnnA Id)
-> Id
-> Context (GenLocated SrcSpanAnnA Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan) [Id]
ev_vars
                            ]
            ]
          HiePassEv p
HieRn ->
            [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use XRec (GhcPass p) (ConLikeP (GhcPass p))
LocatedN Name
con
            , HsConDetails
  (TScoped (HsTyPat (GhcPass 'Renamed)))
  (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))
  (RContext
     (HsRecFields
        (GhcPass p)
        (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (TScoped (HsTyPat (GhcPass 'Renamed)))
   (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))
   (RContext
      (HsRecFields
         (GhcPass p)
         (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))))
 -> HieM [HieAST Type])
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))
     (RContext
        (HsRecFields
           (GhcPass p)
           (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed))
  (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
  (HsRecFields
     (GhcPass p) (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))
     (RContext
        (HsRecFields
           (GhcPass p)
           (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))))
forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed)) a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify HsConPatDetails (GhcPass p)
HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed))
  (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
  (HsRecFields
     (GhcPass p) (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))))
dets
            ]
      ViewPat XViewPat (GhcPass p)
_ LHsExpr (GhcPass p)
expr LPat (GhcPass p)
pat ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        , PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        ]
      SplicePat XSplicePat (GhcPass p)
_ HsUntypedSplice (GhcPass p)
sp ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsUntypedSplice (GhcPass p)
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan HsUntypedSplice (GhcPass p)
sp
        ]
      LitPat XLitPat (GhcPass p)
_ HsLit (GhcPass p)
_ ->
        []
      NPat XNPat (GhcPass p)
_ (L EpAnn NoEpAnns
loc HsOverLit (GhcPass p)
lit) Maybe (SyntaxExpr (GhcPass p))
_ SyntaxExpr (GhcPass p)
eq ->
        [ GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsOverLit (GhcPass p)
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
forall l e. l -> e -> GenLocated l e
L (EpAnn NoEpAnns -> SrcSpanAnnA
forall a b. (HasLoc a, HasAnnotation b) => a -> b
l2l EpAnn NoEpAnns
loc :: SrcSpanAnnA) HsOverLit (GhcPass p)
lit
        , LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (SrcSpanAnnA
-> SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan SyntaxExpr (GhcPass p)
SyntaxExprGhc p
eq)
        ]
      NPlusKPat XNPlusKPat (GhcPass p)
_ LIdP (GhcPass p)
n (L EpAnn NoEpAnns
loc HsOverLit (GhcPass p)
lit) HsOverLit (GhcPass p)
_ SyntaxExpr (GhcPass p)
ord SyntaxExpr (GhcPass p)
_ ->
        [ Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe Span
rsp) LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
n
        , GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsOverLit (GhcPass p)
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
forall l e. l -> e -> GenLocated l e
L (EpAnn NoEpAnns -> SrcSpanAnnA
forall a b. (HasLoc a, HasAnnotation b) => a -> b
l2l EpAnn NoEpAnns
loc :: SrcSpanAnnA) HsOverLit (GhcPass p)
lit
        , LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (SrcSpanAnnA
-> SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan SyntaxExpr (GhcPass p)
SyntaxExprGhc p
ord)
        ]
      SigPat XSigPat (GhcPass p)
_ LPat (GhcPass p)
pat HsPatSigType (NoGhcTc (GhcPass p))
sig ->
        [ PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (LocatedA (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> LocatedA (Pat (GhcPass p))
-> PScoped (LocatedA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope LPat (GhcPass p)
LocatedA (Pat (GhcPass p))
pat
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
            HiePassEv p
HieTc ->
              let cscope :: Scope
cscope = GenLocated SrcSpanAnnA (Pat GhcTc) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat GhcTc)
pat in
                TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsPatSigType (GhcPass 'Renamed)
-> TScoped (HsPatSigType (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
cscope, Scope
scope, Scope
pscope])
                           HsPatSigType (NoGhcTc (GhcPass p))
HsPatSigType (GhcPass 'Renamed)
sig
            HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
      EmbTyPat XEmbTyPat (GhcPass p)
_ HsTyPat (NoGhcTc (GhcPass p))
tp ->
        [ TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsTyPat (GhcPass 'Renamed)
-> TScoped (HsTyPat (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
scope, Scope
pscope]) HsTyPat (NoGhcTc (GhcPass p))
HsTyPat (GhcPass 'Renamed)
tp
        ]
      InvisPat XInvisPat (GhcPass p)
_ HsTyPat (NoGhcTc (GhcPass p))
tp ->
        [ TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsTyPat (GhcPass 'Renamed)
-> TScoped (HsTyPat (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
scope, Scope
pscope]) HsTyPat (NoGhcTc (GhcPass p))
HsTyPat (GhcPass 'Renamed)
tp
        ]
      XPat XXPat (GhcPass p)
e ->
        case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieRn -> case XXPat (GhcPass p)
e of
            HsPatExpanded Pat (GhcPass 'Renamed)
_ Pat (GhcPass 'Renamed)
p -> [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (SrcSpanAnnA
-> Pat (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan Pat (GhcPass 'Renamed)
p) ]
          HiePassEv p
HieTc -> case XXPat (GhcPass p)
e of
            CoPat HsWrapper
wrap Pat GhcTc
pat Type
_ ->
              [ LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> LocatedA HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan HsWrapper
wrap
              , PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (GenLocated SrcSpanAnnA (Pat GhcTc)
 -> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)))
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a b. (a -> b) -> a -> b
$ (SrcSpanAnnA -> Pat GhcTc -> GenLocated SrcSpanAnnA (Pat GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan Pat GhcTc
pat)
              ]
            ExpansionPat Pat (GhcPass 'Renamed)
_ Pat GhcTc
p -> [ PScoped (GenLocated SrcSpanAnnA (Pat GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat GhcTc)
-> PScoped (GenLocated SrcSpanAnnA (Pat GhcTc))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (SrcSpanAnnA -> Pat GhcTc -> GenLocated SrcSpanAnnA (Pat GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
ospan Pat GhcTc
p) ]
    where
      contextify :: a ~ LPat (GhcPass p) => HsConDetails (HsConPatTyArg GhcRn) a (HsRecFields (GhcPass p) a)
                 -> HsConDetails (TScoped (HsTyPat GhcRn)) (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
      contextify :: forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails
  (HsConPatTyArg (GhcPass 'Renamed)) a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify (PrefixCon [HsConPatTyArg (GhcPass 'Renamed)]
tyargs [a]
args) =
        [TScoped (HsTyPat (GhcPass 'Renamed))]
-> [PScoped a]
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon (Scope
-> Scope
-> [HsConPatTyArg (GhcPass 'Renamed)]
-> [TScoped (HsTyPat (GhcPass 'Renamed))]
forall (a :: Pass).
Scope
-> Scope
-> [HsConPatTyArg (GhcPass a)]
-> [TScoped (HsTyPat (GhcPass a))]
taScopes Scope
scope Scope
argscope [HsConPatTyArg (GhcPass 'Renamed)]
tyargs)
                  (Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [a]
[LPat (GhcPass p)]
args)
        where argscope :: Scope
argscope = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (a -> Scope) -> [a] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map a -> Scope
forall a. HasLoc a => a -> Scope
mkScope [a]
args
      contextify (InfixCon a
a a
b) = PScoped a
-> PScoped a
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon PScoped a
PScoped (LPat (GhcPass p))
a' PScoped a
PScoped (LPat (GhcPass p))
b'
        where [PScoped (LPat (GhcPass p))
a', PScoped (LPat (GhcPass p))
b'] = Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe Span
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe Span
rsp Scope
scope Scope
pscope [a
LPat (GhcPass p)
a,a
LPat (GhcPass p)
b]
      contextify (RecCon HsRecFields (GhcPass p) a
r) = RContext
  (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext
        (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))))
forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon (RContext
   (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
 -> HsConDetails
      (TScoped (HsTyPat (GhcPass 'Renamed)))
      (PScoped a)
      (RContext
         (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
-> HsConDetails
     (TScoped (HsTyPat (GhcPass 'Renamed)))
     (PScoped a)
     (RContext
        (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))))
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldMatch (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
 -> RContext
      (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))))
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p)))))
forall a b. (a -> b) -> a -> b
$ HsRecFields (GhcPass p) (LocatedA (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
contextify_rec HsRecFields (GhcPass p) a
HsRecFields (GhcPass p) (LocatedA (Pat (GhcPass p)))
r
      contextify_rec :: HsRecFields (GhcPass p) (LocatedA (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
contextify_rec (HsRecFields XHsRecFields (GhcPass p)
x [LHsRecField (GhcPass p) (LocatedA (Pat (GhcPass p)))]
fds Maybe (XRec (GhcPass p) RecFieldsDotDot)
a) = XHsRecFields (GhcPass p)
-> [LHsRecField (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))]
-> Maybe (XRec (GhcPass p) RecFieldsDotDot)
-> HsRecFields (GhcPass p) (PScoped (LocatedA (Pat (GhcPass p))))
forall p arg.
XHsRecFields p
-> [LHsRecField p arg]
-> Maybe (XRec p RecFieldsDotDot)
-> HsRecFields p arg
HsRecFields XHsRecFields (GhcPass p)
x ((RScoped
   (LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p)))))
 -> LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (PScoped (LocatedA (Pat (GhcPass p))))))
-> [RScoped
      (LocatedA
         (HsFieldBind
            (XRec (GhcPass p) (FieldOcc (GhcPass p)))
            (LocatedA (Pat (GhcPass p)))))]
-> [LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (PScoped (LocatedA (Pat (GhcPass p)))))]
forall a b. (a -> b) -> [a] -> [b]
map RScoped
  (LocatedA
     (HsFieldBind
        (XRec (GhcPass p) (FieldOcc (GhcPass p)))
        (LocatedA (Pat (GhcPass p)))))
-> LocatedA
     (HsFieldBind
        (XRec (GhcPass p) (FieldOcc (GhcPass p)))
        (PScoped (LocatedA (Pat (GhcPass p)))))
forall id a1.
RScoped (LocatedA (HsFieldBind id a1))
-> LocatedA (HsFieldBind id (PScoped a1))
go [RScoped
   (LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p)))))]
scoped_fds) Maybe (XRec (GhcPass p) RecFieldsDotDot)
a
        where
          go :: RScoped (LocatedA (HsFieldBind id a1))
                      -> LocatedA (HsFieldBind id (PScoped a1)) -- AZ
          go :: forall id a1.
RScoped (LocatedA (HsFieldBind id a1))
-> LocatedA (HsFieldBind id (PScoped a1))
go (RS Scope
fscope (L SrcSpanAnnA
spn (HsFieldBind XHsFieldBind id
x id
lbl a1
pat Bool
pun))) =
            SrcSpanAnnA
-> HsFieldBind id (PScoped a1)
-> GenLocated SrcSpanAnnA (HsFieldBind id (PScoped a1))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
spn (HsFieldBind id (PScoped a1)
 -> GenLocated SrcSpanAnnA (HsFieldBind id (PScoped a1)))
-> HsFieldBind id (PScoped a1)
-> GenLocated SrcSpanAnnA (HsFieldBind id (PScoped a1))
forall a b. (a -> b) -> a -> b
$ XHsFieldBind id
-> id -> PScoped a1 -> Bool -> HsFieldBind id (PScoped a1)
forall lhs rhs.
XHsFieldBind lhs -> lhs -> rhs -> Bool -> HsFieldBind lhs rhs
HsFieldBind XHsFieldBind id
x id
lbl (Maybe Span -> Scope -> Scope -> a1 -> PScoped a1
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
fscope a1
pat) Bool
pun
          scoped_fds :: [RScoped
   (LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p)))))]
scoped_fds = Scope
-> [LocatedA
      (HsFieldBind
         (XRec (GhcPass p) (FieldOcc (GhcPass p)))
         (LocatedA (Pat (GhcPass p))))]
-> [RScoped
      (LocatedA
         (HsFieldBind
            (XRec (GhcPass p) (FieldOcc (GhcPass p)))
            (LocatedA (Pat (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
pscope [LHsRecField (GhcPass p) (LocatedA (Pat (GhcPass p)))]
[LocatedA
   (HsFieldBind
      (XRec (GhcPass p) (FieldOcc (GhcPass p)))
      (LocatedA (Pat (GhcPass p))))]
fds

toHieSyntax :: forall p. HiePass p => LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax :: forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax LocatedA (SyntaxExpr (GhcPass p))
s = (NodeOrigin -> NodeOrigin)
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (NodeOrigin -> NodeOrigin -> NodeOrigin
forall a b. a -> b -> a
const NodeOrigin
GeneratedInfo) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
  HiePassEv p
HieRn -> LocatedA SyntaxExprRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (SyntaxExpr (GhcPass p))
LocatedA SyntaxExprRn
s
  HiePassEv p
HieTc -> LocatedA SyntaxExprTc -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (SyntaxExpr (GhcPass p))
LocatedA SyntaxExprTc
s

instance ToHie (LocatedA SyntaxExprRn) where
  toHie :: LocatedA SyntaxExprRn -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
mspan (SyntaxExprRn HsExpr (GhcPass 'Renamed)
expr)) = LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr (GhcPass 'Renamed)
-> LocatedA (HsExpr (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr (GhcPass 'Renamed)
expr)
  toHie (L SrcSpanAnnA
_ SyntaxExprRn
NoSyntaxExprRn) = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LocatedA SyntaxExprTc) where
  toHie :: LocatedA SyntaxExprTc -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
mspan (SyntaxExprTc HsExpr GhcTc
expr [HsWrapper]
w1 HsWrapper
w2)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcTc
expr)
      , (HsWrapper -> HieM [HieAST Type])
-> [HsWrapper] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LocatedA HsWrapper -> HieM [HieAST Type])
-> (HsWrapper -> LocatedA HsWrapper)
-> HsWrapper
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan) [HsWrapper]
w1
      , LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsWrapper
w2)
      ]
  toHie (L SrcSpanAnnA
_ SyntaxExprTc
NoSyntaxExprTc) = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (TScoped (HsPatSigType GhcRn)) where
  toHie :: TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsPS (HsPSRn [Name]
wcs [Name]
tvs) body :: LHsType (GhcPass 'Renamed)
body@(L SrcSpanAnnA
span HsType (GhcPass 'Renamed)
_))) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) TyVarScope
sc) ([Name]
wcs[Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++[Name]
tvs)
      , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body
      ]
  -- See Note [Scoping Rules for SigPat]

instance ToHie (TScoped (HsTyPat GhcRn)) where
  toHie :: TScoped (HsTyPat (GhcPass 'Renamed)) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsTP (HsTPRn [Name]
wcs [Name]
imp_tvs [Name]
exp_tvs) body :: LHsType (GhcPass 'Renamed)
body@(L SrcSpanAnnA
span HsType (GhcPass 'Renamed)
_))) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) TyVarScope
sc) ([Name]
wcs [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name]
imp_tvs [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name]
exp_tvs)
      , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body
      ]

instance ( ToHie (LocatedA (body (GhcPass p)))
         , HiePass p
         , AnnoBody p body
         ) => ToHie (GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))) where
  toHie :: GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
-> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhs = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhs of
    GRHSs XCGRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
_ [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
grhss HsLocalBinds (GhcPass p)
binds ->
     [ [GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (LocatedA (body (GhcPass p)))]
[GenLocated
   (EpAnn NoEpAnns) (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))]
grhss
     , RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBinds (GhcPass p) -> RScoped (HsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
forall (p :: Pass) (body :: * -> *).
(Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
 ~ EpAnn NoEpAnns) =>
GRHSs (GhcPass p) (LocatedA (body (GhcPass p))) -> SrcSpan
grhss_span GRHSs (GhcPass p) (LocatedA (body (GhcPass p)))
grhs) HsLocalBinds (GhcPass p)
binds
     ]

instance ( ToHie (LocatedA (body (GhcPass p)))
         , HiePass p
         , AnnoBody p body
         ) => ToHie (LocatedAn NoEpAnns (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))) where
  toHie :: LocatedAn NoEpAnns (GRHS (GhcPass p) (LocatedA (body (GhcPass p))))
-> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
g) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
-> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
g EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case GRHS (GhcPass p) (LocatedA (body (GhcPass p)))
g of
    GRHS XCGRHS (GhcPass p) (LocatedA (body (GhcPass p)))
_ [GuardLStmt (GhcPass p)]
guards LocatedA (body (GhcPass p))
body ->
      [ [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes (LocatedA (body (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LocatedA (body (GhcPass p))
body) [GuardLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
guards
      , LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
      ]

{-
Note [Source locations for implicit function calls]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While calls to e.g. 'fromString' with -XOverloadedStrings do not actually
appear in the source code, giving their HsWrapper the location of the
overloaded bit of syntax that triggered them is useful for assigning
their type class evidence uses to the right location in the HIE AST.
Without this, we only get type class instance information under the
expected top-level node if the type had to be inferred. (#23540)

We currently handle the following constructors with this in mind,
all largely in the renamer as their locations are normally inherited by
the typechecker:

  * HsOverLit, where we assign the SrcSpan of the overloaded literal
    to ol_from_fun.
  * HsDo, where we give the SrcSpan of the entire do block to each
    ApplicativeStmt.
  * Expanded (via ExpandedThingRn) ExplicitList{}, where we give the SrcSpan of the original
    list expression to the 'fromListN' call.

In order for the implicit function calls to not be confused for actual
occurrences of functions in the source code, most of this extra information
is put under 'GeneratedInfo'.
-}

whenPostTc :: forall p t m. (HiePass p, Applicative t, Monoid m) => ((p ~ 'Typechecked) => t m) -> t m
whenPostTc :: forall (p :: Pass) (t :: * -> *) m.
(HiePass p, Applicative t, Monoid m) =>
((p ~ 'Typechecked) => t m) -> t m
whenPostTc (p ~ 'Typechecked) => t m
a = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
  HiePassEv p
HieTc -> t m
(p ~ 'Typechecked) => t m
a
  HiePassEv p
HieRn -> m -> t m
forall a. a -> t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure m
forall a. Monoid a => a
mempty

-- | Helper function for a common pattern where we are only interested in
-- implicit evidence information: runs only post-typecheck and marks the
-- current 'NodeOrigin' as generated.
whenPostTcGen :: forall p. HiePass p => ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen :: forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen (p ~ 'Typechecked) => HieM [HieAST Type]
a = (NodeOrigin -> NodeOrigin)
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local (NodeOrigin -> NodeOrigin -> NodeOrigin
forall a b. a -> b -> a
const NodeOrigin
GeneratedInfo) (HieM [HieAST Type] -> HieM [HieAST Type])
-> HieM [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ forall (p :: Pass) (t :: * -> *) m.
(HiePass p, Applicative t, Monoid m) =>
((p ~ 'Typechecked) => t m) -> t m
whenPostTc @p HieM [HieAST Type]
(p ~ 'Typechecked) => HieM [HieAST Type]
a

instance HiePass p => ToHie (LocatedA (HsOverLit (GhcPass p))) where
  toHie :: LocatedA (HsOverLit (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span (OverLit XOverLit (GhcPass p)
x OverLitVal
_)) = forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case XOverLit (GhcPass p)
x of
      OverLitTc Bool
_ HsExpr GhcTc
witness Type
_ ->
        [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span HsExpr GhcTc
witness)
        ]
      -- See Note [Source locations for implicit function calls]

instance HiePass p => ToHie (LocatedA (HsExpr (GhcPass p))) where
  toHie :: LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
toHie e :: LocatedA (HsExpr (GhcPass p))
e@(L SrcSpanAnnA
mspan HsExpr (GhcPass p)
oexpr) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LocatedA (HsExpr (GhcPass p))
e HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsExpr (GhcPass p)
oexpr of
      HsVar XVar (GhcPass p)
_ (L SrcSpanAnnN
_ IdGhcP p
var) ->
        [ Context (GenLocated SrcSpanAnnA (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA (IdGhcP p)
-> Context (GenLocated SrcSpanAnnA (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (SrcSpanAnnA -> IdGhcP p -> GenLocated SrcSpanAnnA (IdGhcP p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan IdGhcP p
var)
             -- Patch up var location since typechecker removes it
        ]
      HsUnboundVar XUnboundVar (GhcPass p)
_ RdrName
_ -> []  -- there is an unbound name here, but that causes trouble
      HsOverLabel {} -> []
      HsIPVar XIPVar (GhcPass p)
_ HsIPName
_ -> []
      HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
o ->
        [ GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsOverLit (GhcPass p)
-> GenLocated SrcSpanAnnA (HsOverLit (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsOverLit (GhcPass p)
o)
        ]
      HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
_ -> []
      HsLam XLam (GhcPass p)
_ HsLamVariant
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
mg
        ]
      HsApp XApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        ]
      HsAppType XAppTypeE (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsWcType (NoGhcTc (GhcPass p))
sig ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsWcType (NoGhcTc (GhcPass p))
HsWildCardBndrs
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
sig
        ]
      OpApp XOpApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
c
        ]
      NegApp XNegApp (GhcPass p)
_ LHsExpr (GhcPass p)
a SyntaxExpr (GhcPass p)
_ ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        ]
      HsPar XPar (GhcPass p)
_ LHsExpr (GhcPass p)
a ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        ]
      SectionL XSectionL (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        ]
      SectionR XSectionR (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        ]
      ExplicitTuple XExplicitTuple (GhcPass p)
_ [HsTupArg (GhcPass p)]
args Boxity
_ ->
        [ [HsTupArg (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [HsTupArg (GhcPass p)]
args
        ]
      ExplicitSum XExplicitSum (GhcPass p)
_ TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
expr ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsCase XCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsExpr (GhcPass p)))
matches
        ]
      HsIf XIf (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
a
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
b
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
c
        ]
      HsMultiIf XMultiIf (GhcPass p)
_ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss ->
        [ [GenLocated
   (EpAnn NoEpAnns)
   (GRHS (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
[GenLocated
   (EpAnn NoEpAnns)
   (GRHS (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
grhss
        ]
      HsLet XLet (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsExpr (GhcPass p)
expr ->
        [ RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBinds (GhcPass p) -> RScoped (HsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LocatedA (HsExpr (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr) HsLocalBinds (GhcPass p)
binds
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsDo XDo (GhcPass p)
_ HsDoFlavour
_ (L SrcSpanAnnLW
ispan [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
stmts) ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnLW -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnLW
ispan)
        , [RScoped
   (LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsExpr (GhcPass p))))]
stmts
        ]
      ExplicitList XExplicitList (GhcPass p)
_ [LHsExpr (GhcPass p)]
exprs ->
        [ [LocatedA (HsExpr (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsExpr (GhcPass p)]
[LocatedA (HsExpr (GhcPass p))]
exprs
        ]
      RecordCon { rcon_con :: forall p. HsExpr p -> XRec p (ConLikeP p)
rcon_con = XRec (GhcPass p) (ConLikeP (GhcPass p))
con, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds (GhcPass p)
binds} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (LocatedN Name -> Context (LocatedN Name))
-> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ LocatedN Name
con_name
        , RContext (HsRecordBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RContext (HsRecordBinds (GhcPass p)) -> HieM [HieAST Type])
-> RContext (HsRecordBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecordBinds (GhcPass p)
-> RContext (HsRecordBinds (GhcPass p))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign (HsRecordBinds (GhcPass p) -> RContext (HsRecordBinds (GhcPass p)))
-> HsRecordBinds (GhcPass p)
-> RContext (HsRecordBinds (GhcPass p))
forall a b. (a -> b) -> a -> b
$ HsRecordBinds (GhcPass p)
binds
        ]
        where
          con_name :: LocatedN Name
          con_name :: LocatedN Name
con_name = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of       -- Like ConPat
                       HiePassEv p
HieRn -> XRec (GhcPass p) (ConLikeP (GhcPass p))
LocatedN Name
con
                       HiePassEv p
HieTc -> (ConLike -> Name)
-> GenLocated SrcSpanAnnN ConLike -> LocatedN Name
forall a b.
(a -> b) -> GenLocated SrcSpanAnnN a -> GenLocated SrcSpanAnnN b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConLike -> Name
conLikeName XRec (GhcPass p) (ConLikeP (GhcPass p))
GenLocated SrcSpanAnnN ConLike
con
      RecordUpd { rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr (GhcPass p)
expr
                , rupd_flds :: forall p. HsExpr p -> LHsRecUpdFields p
rupd_flds = RegularRecUpdFields { recUpdFields :: forall p. LHsRecUpdFields p -> [LHsRecUpdField p p]
recUpdFields = [LHsRecUpdField (GhcPass p) (GhcPass p)]
upds } }->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieRn -> [RContext
   (GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
         (LocatedA (HsExpr (GhcPass 'Renamed)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext
    (GenLocated
       SrcSpanAnnA
       (HsFieldBind
          (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
          (LocatedA (HsExpr (GhcPass 'Renamed)))))]
 -> HieM [HieAST Type])
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
            (LocatedA (HsExpr (GhcPass 'Renamed)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
      (LocatedA (HsExpr (GhcPass 'Renamed))))
 -> RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
            (LocatedA (HsExpr (GhcPass 'Renamed))))))
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
         (LocatedA (HsExpr (GhcPass 'Renamed))))]
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
            (LocatedA (HsExpr (GhcPass 'Renamed)))))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> GenLocated
     SrcSpanAnnA
     (HsFieldBind
        (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
        (LocatedA (HsExpr (GhcPass 'Renamed))))
-> RContext
     (GenLocated
        SrcSpanAnnA
        (HsFieldBind
           (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
           (LocatedA (HsExpr (GhcPass 'Renamed)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign) [LHsRecUpdField (GhcPass p) (GhcPass p)]
[GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
      (LocatedA (HsExpr (GhcPass 'Renamed))))]
upds
          HiePassEv p
HieTc -> [RContext
   (GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
         (GenLocated SrcSpanAnnA (HsExpr GhcTc))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext
    (GenLocated
       SrcSpanAnnA
       (HsFieldBind
          (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
          (GenLocated SrcSpanAnnA (HsExpr GhcTc))))]
 -> HieM [HieAST Type])
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
            (GenLocated SrcSpanAnnA (HsExpr GhcTc))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
      (GenLocated SrcSpanAnnA (HsExpr GhcTc)))
 -> RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
            (GenLocated SrcSpanAnnA (HsExpr GhcTc)))))
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind
         (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
         (GenLocated SrcSpanAnnA (HsExpr GhcTc)))]
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind
            (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
            (GenLocated SrcSpanAnnA (HsExpr GhcTc))))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> GenLocated
     SrcSpanAnnA
     (HsFieldBind
        (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
        (GenLocated SrcSpanAnnA (HsExpr GhcTc)))
-> RContext
     (GenLocated
        SrcSpanAnnA
        (HsFieldBind
           (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
           (GenLocated SrcSpanAnnA (HsExpr GhcTc))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign) [LHsRecUpdField (GhcPass p) (GhcPass p)]
[GenLocated
   SrcSpanAnnA
   (HsFieldBind
      (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
      (GenLocated SrcSpanAnnA (HsExpr GhcTc)))]
upds
        ]
      RecordUpd { rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr (GhcPass p)
expr
                , rupd_flds :: forall p. HsExpr p -> LHsRecUpdFields p
rupd_flds = OverloadedRecUpdFields {} }->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      ExprWithTySig XExprWithTySig (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsSigWcType (NoGhcTc (GhcPass p))
sig ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        , TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [LocatedA (HsExpr (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr]) LHsSigWcType (NoGhcTc (GhcPass p))
HsWildCardBndrs
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
sig
        ]
      ArithSeq XArithSeq (GhcPass p)
enum Maybe (SyntaxExpr (GhcPass p))
_ ArithSeqInfo (GhcPass p)
info ->
        [ ArithSeqInfo (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ArithSeqInfo (GhcPass p)
info
        , forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan XArithSeq (GhcPass p)
HsExpr GhcTc
enum)
        ]
      HsPragE XPragE (GhcPass p)
_ HsPragE (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsProc XProc (GhcPass p)
_ LPat (GhcPass p)
pat LHsCmdTop (GhcPass p)
cmdtop ->
        [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing (GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsCmdTop (GhcPass p)
GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))
cmdtop) Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
        , GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmdTop (GhcPass p)
GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))
cmdtop
        ]
      HsStatic XStatic (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
expr
        ]
      HsEmbTy XEmbTy (GhcPass p)
_ LHsWcType (NoGhcTc (GhcPass p))
ty ->
        [ TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsWcType (NoGhcTc (GhcPass p))
HsWildCardBndrs
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
ty
        ]
      HsQual XQual (GhcPass p)
_ XRec (GhcPass p) [LHsExpr (GhcPass p)]
ctx LHsExpr (GhcPass p)
body ->
        [ GenLocated SrcSpanAnnC [LocatedA (HsExpr (GhcPass p))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec (GhcPass p) [LHsExpr (GhcPass p)]
GenLocated SrcSpanAnnC [LocatedA (HsExpr (GhcPass p))]
ctx
        , LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
body
        ]
      HsForAll XForAll (GhcPass p)
x HsForAllTelescope (GhcPass p)
tele LHsExpr (GhcPass p)
body -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn ->
          [ HsForAllTelescope (GhcPass 'Renamed)
-> SrcSpan -> HieM [HieAST Type]
toHieForAllTele HsForAllTelescope (GhcPass p)
HsForAllTelescope (GhcPass 'Renamed)
tele (LocatedA (HsExpr (GhcPass 'Renamed)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass 'Renamed))
body)
          ]
        HiePassEv p
HieTc -> DataConCantHappen -> [HieM [HieAST Type]]
forall a. DataConCantHappen -> a
dataConCantHappen XForAll (GhcPass p)
DataConCantHappen
x
      HsFunArr XFunArr (GhcPass p)
x HsArrowOf (LHsExpr (GhcPass p)) (GhcPass p)
mult LHsExpr (GhcPass p)
arg LHsExpr (GhcPass p)
res -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn ->
          [ LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsArrowOf (LocatedA (HsExpr (GhcPass 'Renamed))) (GhcPass 'Renamed)
-> LocatedA (HsExpr (GhcPass 'Renamed))
arrowToHsExpr HsArrowOf (LHsExpr (GhcPass p)) (GhcPass p)
HsArrowOf (LocatedA (HsExpr (GhcPass 'Renamed))) (GhcPass 'Renamed)
mult)
          , LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass 'Renamed))
arg
          , LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass 'Renamed))
res
          ]
        HiePassEv p
HieTc -> DataConCantHappen -> [HieM [HieAST Type]]
forall a. DataConCantHappen -> a
dataConCantHappen XFunArr (GhcPass p)
DataConCantHappen
x
      HsTypedBracket XTypedBracket (GhcPass p)
xbracket LHsExpr (GhcPass p)
b -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn ->
          [ LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass 'Renamed))
b
          ]
        HiePassEv p
HieTc | HsBracketTc HsQuote (GhcPass 'Renamed)
_ Type
_ Maybe QuoteWrapper
_ [PendingTcSplice]
p <- XTypedBracket (GhcPass p)
xbracket ->
          [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr GhcTc)
b
          , [PendingTcSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingTcSplice]
p
          ]
      HsUntypedBracket XUntypedBracket (GhcPass p)
xbracket HsQuote (GhcPass p)
b -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn ->
            [ HsQuote (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsQuote (GhcPass p)
b
            , [PendingRnSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingRnSplice]
XUntypedBracket (GhcPass p)
xbracket
            ]
        HiePassEv p
HieTc | HsBracketTc HsQuote (GhcPass 'Renamed)
q Type
_ Maybe QuoteWrapper
_ [PendingTcSplice]
p <- XUntypedBracket (GhcPass p)
xbracket ->
          [ HsQuote (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsQuote (GhcPass 'Renamed)
q
          , [PendingTcSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingTcSplice]
p
          ]
      HsTypedSplice XTypedSplice (GhcPass p)
_ LHsExpr (GhcPass p)
x ->
        [ LocatedA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass p))
x
        ]
      HsUntypedSplice XUntypedSplice (GhcPass p)
_ HsUntypedSplice (GhcPass p)
x ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsUntypedSplice (GhcPass p)
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsUntypedSplice (GhcPass p)
x
        ]
      HsGetField {} -> []
      HsProjection {} -> []
      XExpr XXExpr (GhcPass p)
x -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc -> case XXExpr (GhcPass p)
x of
          WrapExpr HsWrapper
w HsExpr GhcTc
a
            -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcTc
a
               , LocatedA HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA -> HsWrapper -> LocatedA HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsWrapper
w) ]
          ExpandedThingTc HsThingRn
_ HsExpr GhcTc
e
            -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpanAnnA
-> HsExpr GhcTc -> GenLocated SrcSpanAnnA (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan HsExpr GhcTc
e) ]
          ConLikeTc ConLike
con [Id]
_ [Scaled Type]
_
            -> [ Context (GenLocated SrcSpanAnnA Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Name) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA Name
-> Context (GenLocated SrcSpanAnnA Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (GenLocated SrcSpanAnnA Name
 -> Context (GenLocated SrcSpanAnnA Name))
-> GenLocated SrcSpanAnnA Name
-> Context (GenLocated SrcSpanAnnA Name)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Name -> GenLocated SrcSpanAnnA Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan (Name -> GenLocated SrcSpanAnnA Name)
-> Name -> GenLocated SrcSpanAnnA Name
forall a b. (a -> b) -> a -> b
$ ConLike -> Name
conLikeName ConLike
con ]
          HsTick CoreTickish
_ LHsExpr GhcTc
expr
            -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr
               ]
          HsBinTick TypeIndex
_ TypeIndex
_ LHsExpr GhcTc
expr
            -> [ GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr
               ]
          HsRecSelTc FieldOcc GhcTc
fld
            -> [ RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
 -> HieM [HieAST Type])
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe Span
-> GenLocated SrcSpanAnnA (FieldOcc GhcTc)
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc GhcTc))
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
RecFieldOcc Maybe Span
forall a. Maybe a
Nothing (SrcSpanAnnA
-> FieldOcc GhcTc -> GenLocated SrcSpanAnnA (FieldOcc GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan FieldOcc GhcTc
fld)
               ]
        HiePassEv p
HieRn -> case XXExpr (GhcPass p)
x of
          HsRecSelRn FieldOcc (GhcPass 'Renamed)
fld
            -> [ RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe Span
-> GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
RecFieldOcc Maybe Span
forall a. Maybe a
Nothing (SrcSpanAnnA
-> FieldOcc (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
mspan FieldOcc (GhcPass 'Renamed)
fld)
               ]
          XXExpr (GhcPass p)
_ -> []

-- NOTE: no longer have the location
instance HiePass p => ToHie (HsTupArg (GhcPass p)) where
  toHie :: HsTupArg (GhcPass p) -> HieM [HieAST Type]
toHie HsTupArg (GhcPass p)
arg = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case HsTupArg (GhcPass p)
arg of
    Present XPresent (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
      [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
      ]
    Missing XMissing (GhcPass p)
_ -> []

instance ( ToHie (LocatedA (body (GhcPass p)))
         , AnnoBody p body
         , HiePass p
         ) => ToHie (RScoped (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))) where
  toHie :: RScoped (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))
-> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpanAnnA
span Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HieM [HieAST Type]
node HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt of
      LastStmt XLastStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ LocatedA (body (GhcPass p))
body Maybe Bool
_ SyntaxExpr (GhcPass p)
_ ->
        [ LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
        ]
      BindStmt XBindStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
monad LPat (GhcPass p)
pat LocatedA (body (GhcPass p))
body ->
        [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ LocatedA (body (GhcPass p)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LocatedA (body (GhcPass p))
body) Scope
scope Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
        , LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
        , forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type])
-> LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> SyntaxExpr GhcTc -> LocatedA (SyntaxExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span (XBindStmtTc -> SyntaxExpr GhcTc
xbstc_bindOp XBindStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
XBindStmtTc
monad)
        ]
      BodyStmt XBodyStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ LocatedA (body (GhcPass p))
body SyntaxExpr (GhcPass p)
monad SyntaxExpr (GhcPass p)
alternative ->
        [ LocatedA (body (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LocatedA (body (GhcPass p))
body
        , forall (p :: Pass) (t :: * -> *) m.
(HiePass p, Applicative t, Monoid m) =>
((p ~ 'Typechecked) => t m) -> t m
whenPostTc @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            (SyntaxExprGhc 'Typechecked -> HieM [HieAST Type])
-> [SyntaxExprGhc 'Typechecked] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
-> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
 -> HieM [HieAST Type])
-> (SyntaxExprGhc 'Typechecked
    -> GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked))
-> SyntaxExprGhc 'Typechecked
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA
-> SyntaxExprGhc 'Typechecked
-> GenLocated SrcSpanAnnA (SyntaxExprGhc 'Typechecked)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [SyntaxExpr (GhcPass p)
SyntaxExprGhc 'Typechecked
monad, SyntaxExpr (GhcPass p)
SyntaxExprGhc 'Typechecked
alternative]
        ]
      LetStmt XLetStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ HsLocalBindsLR (GhcPass p) (GhcPass p)
binds ->
        [ RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBindsLR (GhcPass p) (GhcPass p)
-> RScoped (HsLocalBindsLR (GhcPass p) (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
scope HsLocalBindsLR (GhcPass p) (GhcPass p)
binds
        ]
      ParStmt XParStmt (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
_ [ParStmtBlock (GhcPass p) (GhcPass p)]
parstmts HsExpr (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ ->
        [ (ParStmtBlock (GhcPass p) (GhcPass p) -> HieM [HieAST Type])
-> [ParStmtBlock (GhcPass p) (GhcPass p)] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (\(ParStmtBlock XParStmtBlock (GhcPass p) (GhcPass p)
_ [ExprLStmt (GhcPass p)]
stmts [IdP (GhcPass p)]
_ SyntaxExpr (GhcPass p)
_) ->
                          [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts)
                     [ParStmtBlock (GhcPass p) (GhcPass p)]
parstmts
        ]
      TransStmt {trS_stmts :: forall idL idR body. StmtLR idL idR body -> [ExprLStmt idL]
trS_stmts = [ExprLStmt (GhcPass p)]
stmts, trS_using :: forall idL idR body. StmtLR idL idR body -> LHsExpr idR
trS_using = LHsExpr (GhcPass p)
using, trS_by :: forall idL idR body. StmtLR idL idR body -> Maybe (LHsExpr idR)
trS_by = Maybe (LHsExpr (GhcPass p))
by} ->
        [ [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
scope [ExprLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts
        , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
using
        , Maybe (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsExpr (GhcPass p))
Maybe (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))
by
        ]
      RecStmt {recS_stmts :: forall idL idR body.
StmtLR idL idR body -> XRec idR [LStmtLR idL idR body]
recS_stmts = L SrcSpanAnnLW
_ [LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))]
stmts} ->
        [ [RScoped
   (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
 -> RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))))
-> [LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))]
-> [RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
-> RScoped
     (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
 -> RScoped
      (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))))
-> Scope
-> LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))
-> RScoped
     (LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p)))))
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes Scope
scope (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span))) [LocatedA (Stmt (GhcPass p) (LocatedA (body (GhcPass p))))]
stmts
        ]
      XStmtLR XXStmtLR (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
x -> case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieRn -> ApplicativeStmt (GhcPass p) (GhcPass p) -> [HieM [HieAST Type]]
extApplicativeStmt XXStmtLR (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
ApplicativeStmt (GhcPass p) (GhcPass p)
x
        HiePassEv p
HieTc -> ApplicativeStmt (GhcPass p) (GhcPass p) -> [HieM [HieAST Type]]
extApplicativeStmt XXStmtLR (GhcPass p) (GhcPass p) (LocatedA (body (GhcPass p)))
ApplicativeStmt (GhcPass p) (GhcPass p)
x
    where
      node :: HieM [HieAST Type]
node = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc -> Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt SrcSpanAnnA
span
        HiePassEv p
HieRn -> Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Stmt (GhcPass p) (LocatedA (body (GhcPass p)))
stmt SrcSpanAnnA
span
      extApplicativeStmt :: ApplicativeStmt (GhcPass p) (GhcPass p) -> [ReaderT NodeOrigin (State HieState) [HieAST Type]]
      extApplicativeStmt :: ApplicativeStmt (GhcPass p) (GhcPass p) -> [HieM [HieAST Type]]
extApplicativeStmt (ApplicativeStmt XApplicativeStmt (GhcPass p) (GhcPass p)
_ [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
stmts Maybe (SyntaxExpr (GhcPass p))
_) =
        [ ((SyntaxExprGhc p, ApplicativeArg (GhcPass p))
 -> HieM [HieAST Type])
-> [(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (RScoped (ApplicativeArg (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (ApplicativeArg (GhcPass p)) -> HieM [HieAST Type])
-> ((SyntaxExprGhc p, ApplicativeArg (GhcPass p))
    -> RScoped (ApplicativeArg (GhcPass p)))
-> (SyntaxExprGhc p, ApplicativeArg (GhcPass p))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Scope
-> ApplicativeArg (GhcPass p)
-> RScoped (ApplicativeArg (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
scope (ApplicativeArg (GhcPass p)
 -> RScoped (ApplicativeArg (GhcPass p)))
-> ((SyntaxExprGhc p, ApplicativeArg (GhcPass p))
    -> ApplicativeArg (GhcPass p))
-> (SyntaxExprGhc p, ApplicativeArg (GhcPass p))
-> RScoped (ApplicativeArg (GhcPass p))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SyntaxExprGhc p, ApplicativeArg (GhcPass p))
-> ApplicativeArg (GhcPass p)
forall a b. (a, b) -> b
snd) [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
[(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
stmts
        , let applicative_or_functor :: [SyntaxExprGhc p]
applicative_or_functor = ((SyntaxExprGhc p, ApplicativeArg (GhcPass p)) -> SyntaxExprGhc p)
-> [(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
-> [SyntaxExprGhc p]
forall a b. (a -> b) -> [a] -> [b]
map (SyntaxExprGhc p, ApplicativeArg (GhcPass p)) -> SyntaxExprGhc p
forall a b. (a, b) -> a
fst [(SyntaxExpr (GhcPass p), ApplicativeArg (GhcPass p))]
[(SyntaxExprGhc p, ApplicativeArg (GhcPass p))]
stmts
           in forall (p :: Pass).
HiePass p =>
((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
whenPostTcGen @p (((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type])
-> ((p ~ 'Typechecked) => HieM [HieAST Type]) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
                (SyntaxExprGhc p -> HieM [HieAST Type])
-> [SyntaxExprGhc p] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (LocatedA (SyntaxExpr GhcTc) -> HieM [HieAST Type]
GenLocated SrcSpanAnnA (SyntaxExprGhc p) -> HieM [HieAST Type]
forall (p :: Pass).
HiePass p =>
LocatedA (SyntaxExpr (GhcPass p)) -> HieM [HieAST Type]
toHieSyntax (GenLocated SrcSpanAnnA (SyntaxExprGhc p) -> HieM [HieAST Type])
-> (SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p))
-> SyntaxExprGhc p
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnA
-> SyntaxExprGhc p -> GenLocated SrcSpanAnnA (SyntaxExprGhc p)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span) [SyntaxExprGhc p]
applicative_or_functor
        ]

instance HiePass p => ToHie (RScoped (HsLocalBinds (GhcPass p))) where
  toHie :: RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
scope HsLocalBinds (GhcPass p)
binds) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsLocalBinds (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsLocalBinds (GhcPass p)
binds (HsLocalBinds (GhcPass p) -> SrcSpan
forall (p :: Pass). HsLocalBinds (GhcPass p) -> SrcSpan
spanHsLocaLBinds HsLocalBinds (GhcPass p)
binds) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsLocalBinds (GhcPass p)
binds of
      EmptyLocalBinds XEmptyLocalBinds (GhcPass p) (GhcPass p)
_ -> []
      HsIPBinds XHsIPBinds (GhcPass p) (GhcPass p)
_ HsIPBinds (GhcPass p)
ipbinds -> case HsIPBinds (GhcPass p)
ipbinds of
        IPBinds XIPBinds (GhcPass p)
evbinds [LIPBind (GhcPass p)]
xs -> let sc :: Scope
sc = Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ HsLocalBinds (GhcPass p) -> Scope
forall (p :: Pass). HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds HsLocalBinds (GhcPass p)
binds
                                  sp :: SrcSpanAnnA
                                  sp :: SrcSpanAnnA
sp = SrcSpan -> SrcSpanAnnA
forall e. HasAnnotation e => SrcSpan -> e
noAnnSrcSpan (SrcSpan -> SrcSpanAnnA) -> SrcSpan -> SrcSpanAnnA
forall a b. (a -> b) -> a -> b
$ HsLocalBinds (GhcPass p) -> SrcSpan
forall (p :: Pass). HsLocalBinds (GhcPass p) -> SrcSpan
spanHsLocaLBinds HsLocalBinds (GhcPass p)
binds in
          [
            case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
              HiePassEv p
HieTc -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
sc (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
sp) (GenLocated SrcSpanAnnA TcEvBinds
 -> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds))
-> GenLocated SrcSpanAnnA TcEvBinds
-> EvBindContext (GenLocated SrcSpanAnnA TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> TcEvBinds -> GenLocated SrcSpanAnnA TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
sp XIPBinds (GhcPass p)
TcEvBinds
evbinds
              HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          , [RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
 -> HieM [HieAST Type])
-> [RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (IPBind (GhcPass p))
 -> RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p))))
-> [GenLocated SrcSpanAnnA (IPBind (GhcPass p))]
-> [RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> GenLocated SrcSpanAnnA (IPBind (GhcPass p))
-> RScoped (GenLocated SrcSpanAnnA (IPBind (GhcPass p)))
forall a. Scope -> a -> RScoped a
RS Scope
sc) [LIPBind (GhcPass p)]
[GenLocated SrcSpanAnnA (IPBind (GhcPass p))]
xs
          ]
      HsValBinds XHsValBinds (GhcPass p) (GhcPass p)
_ HsValBindsLR (GhcPass p) (GhcPass p)
valBinds ->
        [
          RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsValBindsLR (GhcPass p) (GhcPass p)
-> RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (Scope -> Scope -> Scope
combineScopes Scope
scope (HsLocalBinds (GhcPass p) -> Scope
forall (p :: Pass). HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds HsLocalBinds (GhcPass p)
binds))
                      HsValBindsLR (GhcPass p) (GhcPass p)
valBinds
        ]

scopeHsLocaLBinds :: HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds :: forall (p :: Pass). HsLocalBinds (GhcPass p) -> Scope
scopeHsLocaLBinds (HsValBinds XHsValBinds (GhcPass p) (GhcPass p)
_ (ValBinds XValBinds (GhcPass p) (GhcPass p)
_ LHsBindsLR (GhcPass p) (GhcPass p)
bs [LSig (GhcPass p)]
sigs))
  = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope]
bsScope [Scope] -> [Scope] -> [Scope]
forall a. [a] -> [a] -> [a]
++ [Scope]
sigsScope)
  where
    bsScope :: [Scope]
    bsScope :: [Scope]
bsScope = (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> Scope)
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope)
-> (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
    -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc) LHsBindsLR (GhcPass p) (GhcPass p)
[GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
bs
    sigsScope :: [Scope]
    sigsScope :: [Scope]
sigsScope = (GenLocated SrcSpanAnnA (Sig (GhcPass p)) -> Scope)
-> [GenLocated SrcSpanAnnA (Sig (GhcPass p))] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope)
-> (GenLocated SrcSpanAnnA (Sig (GhcPass p)) -> SrcSpan)
-> GenLocated SrcSpanAnnA (Sig (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Sig (GhcPass p)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LSig (GhcPass p)]
[GenLocated SrcSpanAnnA (Sig (GhcPass p))]
sigs
scopeHsLocaLBinds (HsValBinds XHsValBinds (GhcPass p) (GhcPass p)
_ (XValBindsLR (NValBinds [(RecFlag, LHsBindsLR (GhcPass p) (GhcPass p))]
bs [LSig (GhcPass 'Renamed)]
sigs)))
  = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope]
bsScope [Scope] -> [Scope] -> [Scope]
forall a. [a] -> [a] -> [a]
++ [Scope]
sigsScope)
  where
    bsScope :: [Scope]
    bsScope :: [Scope]
bsScope = (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> Scope)
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope)
-> (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
    -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc) ([GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
 -> [Scope])
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [Scope]
forall a b. (a -> b) -> a -> b
$ ((RecFlag,
  [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
 -> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> [(RecFlag,
     [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])]
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (RecFlag,
 [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall a b. (a, b) -> b
snd [(RecFlag, LHsBindsLR (GhcPass p) (GhcPass p))]
[(RecFlag,
  [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])]
bs
    sigsScope :: [Scope]
    sigsScope :: [Scope]
sigsScope = (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)) -> Scope)
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope)
-> (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)) -> SrcSpan)
-> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs

scopeHsLocaLBinds (HsIPBinds XHsIPBinds (GhcPass p) (GhcPass p)
_ (IPBinds XIPBinds (GhcPass p)
_ [LIPBind (GhcPass p)]
bs))
  = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ((GenLocated SrcSpanAnnA (IPBind (GhcPass p)) -> Scope)
-> [GenLocated SrcSpanAnnA (IPBind (GhcPass p))] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> Scope)
-> (GenLocated SrcSpanAnnA (IPBind (GhcPass p)) -> SrcSpanAnnA)
-> GenLocated SrcSpanAnnA (IPBind (GhcPass p))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (IPBind (GhcPass p)) -> SrcSpanAnnA
forall l e. GenLocated l e -> l
getLoc) [LIPBind (GhcPass p)]
[GenLocated SrcSpanAnnA (IPBind (GhcPass p))]
bs)
scopeHsLocaLBinds (EmptyLocalBinds XEmptyLocalBinds (GhcPass p) (GhcPass p)
_) = Scope
NoScope

instance HiePass p => ToHie (RScoped (LocatedA (IPBind (GhcPass p)))) where
  toHie :: RScoped (LocatedA (IPBind (GhcPass p))) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpanAnnA
sp bind :: IPBind (GhcPass p)
bind@(IPBind XCIPBind (GhcPass p)
v XRec (GhcPass p) HsIPName
_ LHsExpr (GhcPass p)
expr))) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IPBind (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA IPBind (GhcPass p)
bind SrcSpanAnnA
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
    HiePassEv p
HieRn -> [LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
LocatedA (HsExpr (GhcPass 'Renamed))
expr]
    HiePassEv p
HieTc -> [ Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnA Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvImplicitBind Scope
scope (SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
sp))
                       (GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id))
-> GenLocated SrcSpanAnnA Id -> Context (GenLocated SrcSpanAnnA Id)
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Id -> GenLocated SrcSpanAnnA Id
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
sp XCIPBind (GhcPass p)
Id
v
             , GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr GhcTc)
expr
             ]

instance HiePass p => ToHie (RScoped (HsValBindsLR (GhcPass p) (GhcPass p))) where
  toHie :: RScoped (HsValBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
toHie (RS Scope
sc HsValBindsLR (GhcPass p) (GhcPass p)
v) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case HsValBindsLR (GhcPass p) (GhcPass p)
v of
    ValBinds XValBinds (GhcPass p) (GhcPass p)
_ LHsBindsLR (GhcPass p) (GhcPass p)
binds [LSig (GhcPass p)]
sigs ->
      [ [BindContext
   (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([BindContext
    (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
 -> HieM [HieAST Type])
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> BindContext
     (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) LHsBindsLR (GhcPass p) (GhcPass p)
[GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
binds
      , [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig (GhcPass p))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p))))
-> [GenLocated SrcSpanAnnA (Sig (GhcPass p))]
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass p))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass p)))
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe Span -> SigInfo
SI SigType
BindSig Maybe Span
forall a. Maybe a
Nothing)) [LSig (GhcPass p)]
[GenLocated SrcSpanAnnA (Sig (GhcPass p))]
sigs
      ]
    XValBindsLR XXValBindsLR (GhcPass p) (GhcPass p)
x -> [ RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> NHsValBindsLR (GhcPass p) -> RScoped (NHsValBindsLR (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
sc XXValBindsLR (GhcPass p) (GhcPass p)
NHsValBindsLR (GhcPass p)
x ]

instance HiePass p => ToHie (RScoped (NHsValBindsLR (GhcPass p))) where
  toHie :: RScoped (NHsValBindsLR (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
sc (NValBinds [(RecFlag, LHsBinds (GhcPass p))]
binds [LSig (GhcPass 'Renamed)]
sigs)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ [BindContext
   (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (((RecFlag,
  [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
 -> [BindContext
       (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))])
-> [(RecFlag,
     [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
 -> BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))))
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))
-> BindContext
     (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) ([GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
 -> [BindContext
       (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))])
-> ((RecFlag,
     [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
    -> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> (RecFlag,
    [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag,
 [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])
-> [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))]
forall a b. (a, b) -> b
snd) [(RecFlag, LHsBinds (GhcPass p))]
[(RecFlag,
  [GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p))])]
binds)
    , [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe Span -> SigInfo
SI SigType
BindSig Maybe Span
forall a. Maybe a
Nothing)) [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs
    ]

instance ( ToHie arg , HasLoc arg , Data arg
         , HiePass p ) => ToHie (RContext (HsRecFields (GhcPass p) arg)) where
  toHie :: RContext (HsRecFields (GhcPass p) arg) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (HsRecFields XHsRecFields (GhcPass p)
_ [LHsRecField (GhcPass p) arg]
fields Maybe (XRec (GhcPass p) RecFieldsDotDot)
_)) = [RContext
   (GenLocated
      SrcSpanAnnA
      (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext
    (GenLocated
       SrcSpanAnnA
       (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
 -> HieM [HieAST Type])
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA
   (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)
 -> RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)))
-> [GenLocated
      SrcSpanAnnA
      (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)]
-> [RContext
      (GenLocated
         SrcSpanAnnA
         (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> GenLocated
     SrcSpanAnnA
     (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)
-> RContext
     (GenLocated
        SrcSpanAnnA
        (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
c) [LHsRecField (GhcPass p) arg]
[GenLocated
   SrcSpanAnnA
   (HsFieldBind (GenLocated SrcSpanAnnA (FieldOcc (GhcPass p))) arg)]
fields

instance ( ToHie (RFContext label)
         , ToHie arg, HasLoc arg, Data arg
         , Data label
         ) => ToHie (RContext (LocatedA (HsFieldBind label arg))) where
  toHie :: RContext (LocatedA (HsFieldBind label arg)) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (L SrcSpanAnnA
span HsFieldBind label arg
recfld)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsFieldBind label arg -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsFieldBind label arg
recfld (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsFieldBind label arg
recfld of
    HsFieldBind XHsFieldBind label
_ label
label arg
expr Bool
_ ->
      [ RFContext label -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext label -> HieM [HieAST Type])
-> RFContext label -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext -> Maybe Span -> label -> RFContext label
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
c (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ arg -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc arg
expr) label
label
      , arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
expr
      ]

instance HiePass p => ToHie (RFContext (LocatedA (FieldOcc (GhcPass p)))) where
  toHie :: RFContext (LocatedA (FieldOcc (GhcPass p))) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpanAnnA
nspan FieldOcc (GhcPass p)
f)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn ->
        case FieldOcc (GhcPass p)
f of
          FieldOcc XCFieldOcc (GhcPass p)
_ LIdP (GhcPass p)
fld ->
            [Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) (Name -> Located Name) -> Name -> Located Name
forall a b. (a -> b) -> a -> b
$ LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
LocatedN Name
fld)]
      HiePassEv p
HieTc ->
        case FieldOcc (GhcPass p)
f of
          FieldOcc XCFieldOcc (GhcPass p)
_ LIdP (GhcPass p)
fld ->
            [Context (Located Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Id) -> HieM [HieAST Type])
-> Context (Located Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Id -> Context (Located Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Id -> Located Id
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
nspan) (Id -> Located Id) -> Id -> Located Id
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnN Id -> Id
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
GenLocated SrcSpanAnnN Id
fld)]


instance HiePass p => ToHie (RScoped (ApplicativeArg (GhcPass p))) where
  toHie :: RScoped (ApplicativeArg (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
sc (ApplicativeArgOne XApplicativeArgOne (GhcPass p)
_ LPat (GhcPass p)
pat LHsExpr (GhcPass p)
expr Bool
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
sc Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
    , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
    ]
  toHie (RS Scope
sc (ApplicativeArgMany XApplicativeArgMany (GhcPass p)
_ [ExprLStmt (GhcPass p)]
stmts HsExpr (GhcPass p)
_ LPat (GhcPass p)
pat HsDoFlavour
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [RScoped
   (LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR
          (GhcPass p)
          (GhcPass p)
          (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR
         (GhcPass p)
         (GhcPass p)
         (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR
            (GhcPass p)
            (GhcPass p)
            (GenLocated SrcSpanAnnA (HsExpr (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [ExprLStmt (GhcPass p)]
[LocatedA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts
    , PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
 -> HieM [HieAST Type])
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass p))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
sc Scope
NoScope LPat (GhcPass p)
GenLocated SrcSpanAnnA (Pat (GhcPass p))
pat
    ]

instance (ToHie tyarg, ToHie arg, ToHie rec) => ToHie (HsConDetails tyarg arg rec) where
  toHie :: HsConDetails tyarg arg rec -> HieM [HieAST Type]
toHie (PrefixCon [tyarg]
tyargs [arg]
args) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [ [tyarg] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [tyarg]
tyargs, [arg] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [arg]
args ]
  toHie (RecCon rec
rec) = rec -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie rec
rec
  toHie (InfixCon arg
a arg
b) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [ arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
a, arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
b]

instance ToHie (HsConDeclGADTDetails GhcRn) where
  toHie :: HsConDeclGADTDetails (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (PrefixConGADT XPrefixConGADT (GhcPass 'Renamed)
_ [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))]
args) = [HsScaled
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))]
[HsScaled
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
args
  toHie (RecConGADT XRecConGADT (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) [LConDeclField (GhcPass 'Renamed)]
rec) = GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec (GhcPass 'Renamed) [LConDeclField (GhcPass 'Renamed)]
GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
rec

instance HiePass p => ToHie (LocatedAn NoEpAnns (HsCmdTop (GhcPass p))) where
  toHie :: LocatedAn NoEpAnns (HsCmdTop (GhcPass p)) -> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span HsCmdTop (GhcPass p)
top) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsCmdTop (GhcPass p) -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsCmdTop (GhcPass p)
top EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsCmdTop (GhcPass p)
top of
    HsCmdTop XCmdTop (GhcPass p)
_ LHsCmd (GhcPass p)
cmd ->
      [ GenLocated SrcSpanAnnA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
GenLocated SrcSpanAnnA (HsCmd (GhcPass p))
cmd
      ]

instance HiePass p => ToHie (LocatedA (HsCmd (GhcPass p))) where
  toHie :: LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span HsCmd (GhcPass p)
cmd) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsCmd (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsCmd (GhcPass p)
cmd SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsCmd (GhcPass p)
cmd of
      HsCmdArrApp XCmdArrApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b HsArrAppType
_ Bool
_ ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
a
        , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
b
        ]
      HsCmdArrForm XCmdArrForm (GhcPass p)
_ LHsExpr (GhcPass p)
a LexicalFixity
_ [LHsCmdTop (GhcPass p)]
cmdtops ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
a
        , [GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsCmdTop (GhcPass p)]
[GenLocated (EpAnn NoEpAnns) (HsCmdTop (GhcPass p))]
cmdtops
        ]
      HsCmdApp XCmdApp (GhcPass p)
_ LHsCmd (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
a
        , GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
b
        ]
      HsCmdPar XCmdPar (GhcPass p)
_ LHsCmd (GhcPass p)
a ->
        [ LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
a
        ]
      HsCmdCase XCmdCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        , MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
alts
        ]
      HsCmdLam XCmdLamCase (GhcPass p)
_ HsLamVariant
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
MatchGroup (GhcPass p) (LocatedA (HsCmd (GhcPass p)))
alts
        ]
      HsCmdIf XCmdIf (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsCmd (GhcPass p)
b LHsCmd (GhcPass p)
c ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
a
        , LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
b
        , LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
c
        ]
      HsCmdLet XCmdLet (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsCmd (GhcPass p)
cmd' ->
        [ RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (HsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> HsLocalBinds (GhcPass p) -> RScoped (HsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LocatedA (HsCmd (GhcPass p)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
cmd') HsLocalBinds (GhcPass p)
binds
        , LocatedA (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
LocatedA (HsCmd (GhcPass p))
cmd'
        ]
      HsCmdDo XCmdDo (GhcPass p)
_ (L SrcSpanAnnLW
ispan [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p))))]
stmts) ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnLW -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnLW
ispan)
        , [RScoped
   (LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (LocatedA
       (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [LocatedA
      (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p))))]
-> [RScoped
      (LocatedA
         (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p)))))]
forall a. Scope -> [LocatedA a] -> [RScoped (LocatedA a)]
listScopes Scope
NoScope [LocatedA
   (StmtLR (GhcPass p) (GhcPass p) (LocatedA (HsCmd (GhcPass p))))]
stmts
        ]
      XCmd XXCmd (GhcPass p)
_ -> []

instance ToHie (TyClGroup GhcRn) where
  toHie :: TyClGroup (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie TyClGroup{ group_tyclds :: forall pass. TyClGroup pass -> [LTyClDecl pass]
group_tyclds = [LTyClDecl (GhcPass 'Renamed)]
classes
                 , group_roles :: forall pass. TyClGroup pass -> [LRoleAnnotDecl pass]
group_roles  = [LRoleAnnotDecl (GhcPass 'Renamed)]
roles
                 , group_kisigs :: forall pass. TyClGroup pass -> [LStandaloneKindSig pass]
group_kisigs = [LStandaloneKindSig (GhcPass 'Renamed)]
sigs
                 , group_instds :: forall pass. TyClGroup pass -> [LInstDecl pass]
group_instds = [LInstDecl (GhcPass 'Renamed)]
instances } =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [GenLocated SrcSpanAnnA (TyClDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyClDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (TyClDecl (GhcPass 'Renamed))]
classes
    , [GenLocated SrcSpanAnnA (StandaloneKindSig (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LStandaloneKindSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (StandaloneKindSig (GhcPass 'Renamed))]
sigs
    , [GenLocated SrcSpanAnnA (RoleAnnotDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LRoleAnnotDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (RoleAnnotDecl (GhcPass 'Renamed))]
roles
    , [GenLocated SrcSpanAnnA (InstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LInstDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (InstDecl (GhcPass 'Renamed))]
instances
    ]

instance ToHie (LocatedA (TyClDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (TyClDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span TyClDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyClDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA TyClDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case TyClDecl (GhcPass 'Renamed)
decl of
      FamDecl {tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl (GhcPass 'Renamed)
fdecl} ->
        [ GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ((SrcSpanAnnA
-> FamilyDecl (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span FamilyDecl (GhcPass 'Renamed)
fdecl) :: LFamilyDecl GhcRn)
        ]
      SynDecl {tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass 'Renamed)
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars (GhcPass 'Renamed)
vars, tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LHsType (GhcPass 'Renamed)
typ} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
SynDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsQTyVars (GhcPass 'Renamed)
-> TScoped (LHsQTyVars (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
typ]) LHsQTyVars (GhcPass 'Renamed)
vars
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
typ
        ]
      DataDecl {tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass 'Renamed)
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars (GhcPass 'Renamed)
vars, tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn (GhcPass 'Renamed)
defn} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
DataDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsQTyVars (GhcPass 'Renamed)
-> TScoped (LHsQTyVars (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
quant_scope, Scope
rhs_scope]) LHsQTyVars (GhcPass 'Renamed)
vars
        , HsDataDefn (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsDataDefn (GhcPass 'Renamed)
defn
        ]
        where
          quant_scope :: Scope
quant_scope = GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated
   SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
 -> Scope)
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Maybe
     (GenLocated
        SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall a. a -> Maybe a -> a
fromMaybe ([GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA []) (Maybe
   (GenLocated
      SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
 -> GenLocated
      SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> Maybe
     (GenLocated
        SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall a b. (a -> b) -> a -> b
$ HsDataDefn (GhcPass 'Renamed)
-> Maybe (LHsContext (GhcPass 'Renamed))
forall pass. HsDataDefn pass -> Maybe (LHsContext pass)
dd_ctxt HsDataDefn (GhcPass 'Renamed)
defn
          rhs_scope :: Scope
rhs_scope = Scope
sig_sc Scope -> Scope -> Scope
`combineScopes` Scope
con_sc Scope -> Scope -> Scope
`combineScopes` Scope
deriv_sc
          sig_sc :: Scope
sig_sc = Scope
-> (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> Scope)
-> Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
 -> Scope)
-> Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn (GhcPass 'Renamed) -> Maybe (LHsType (GhcPass 'Renamed))
forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_kindSig HsDataDefn (GhcPass 'Renamed)
defn
          con_sc :: Scope
con_sc = (Scope -> Scope -> Scope) -> Scope -> DataDefnCons Scope -> Scope
forall a b. (a -> b -> b) -> b -> DataDefnCons a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope (DataDefnCons Scope -> Scope) -> DataDefnCons Scope -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)) -> Scope)
-> DataDefnCons
     (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)))
-> DataDefnCons Scope
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsDataDefn (GhcPass 'Renamed)
-> DataDefnCons (LConDecl (GhcPass 'Renamed))
forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons HsDataDefn (GhcPass 'Renamed)
defn
          deriv_sc :: Scope
deriv_sc = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))
-> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))
 -> Scope)
-> [GenLocated
      (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
-> [Scope]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsDataDefn (GhcPass 'Renamed) -> HsDeriving (GhcPass 'Renamed)
forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs HsDataDefn (GhcPass 'Renamed)
defn
      ClassDecl { tcdCtxt :: forall pass. TyClDecl pass -> Maybe (LHsContext pass)
tcdCtxt = Maybe (LHsContext (GhcPass 'Renamed))
context
                , tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass 'Renamed)
name
                , tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars (GhcPass 'Renamed)
vars
                , tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdFDs = [LHsFunDep (GhcPass 'Renamed)]
deps
                , tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdSigs = [LSig (GhcPass 'Renamed)]
sigs
                , tcdMeths :: forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths = LHsBinds (GhcPass 'Renamed)
meths
                , tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATs = [XRec (GhcPass 'Renamed) (FamilyDecl (GhcPass 'Renamed))]
typs
                , tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATDefs = [LTyFamDefltDecl (GhcPass 'Renamed)]
deftyps
                } ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ClassDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
context
        , TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsQTyVars (GhcPass 'Renamed)
-> TScoped (LHsQTyVars (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
context_scope, Scope
rhs_scope]) LHsQTyVars (GhcPass 'Renamed)
vars
        , [GenLocated SrcSpanAnnA (FunDep (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsFunDep (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (FunDep (GhcPass 'Renamed))]
deps
        , [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))
forall a. SigInfo -> a -> SigContext a
SC (SigInfo
 -> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))))
-> SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe Span -> SigInfo
SI SigType
ClassSig (Maybe Span -> SigInfo) -> Maybe Span -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs
        , [BindContext (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([BindContext (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))
 -> BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))
-> BindContext (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) LHsBinds (GhcPass 'Renamed)
[GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))]
meths
        , [GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [XRec (GhcPass 'Renamed) (FamilyDecl (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))]
typs
        , (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
    -> SrcSpan)
-> GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LTyFamDefltDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
deftyps
        , [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyFamDefltDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
deftyps
        ]
        where
          context_scope :: Scope
context_scope = GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated
   SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
 -> Scope)
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Maybe
     (GenLocated
        SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall a. a -> Maybe a -> a
fromMaybe ([GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA []) Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
context
          rhs_scope :: Scope
rhs_scope = (Scope -> Scope -> Scope) -> [Scope] -> Scope
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1' Scope -> Scope -> Scope
combineScopes ([Scope] -> Scope) -> [Scope] -> Scope
forall a b. (a -> b) -> a -> b
$ (SrcSpan -> Scope) -> [SrcSpan] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope
            [ [GenLocated SrcSpanAnnA (FunDep (GhcPass 'Renamed))] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LHsFunDep (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (FunDep (GhcPass 'Renamed))]
deps, [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LSig (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
sigs, [GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList LHsBinds (GhcPass 'Renamed)
[GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))]
meths, [GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))] -> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [XRec (GhcPass 'Renamed) (FamilyDecl (GhcPass 'Renamed))]
[GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))]
typs, [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LTyFamDefltDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
deftyps]

instance ToHie (LocatedA (FamilyDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (FamilyDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span FamilyDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FamilyDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA FamilyDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FamilyDecl (GhcPass 'Renamed)
decl of
      FamilyDecl XCFamilyDecl (GhcPass 'Renamed)
_ FamilyInfo (GhcPass 'Renamed)
info TopLevelFlag
_ LIdP (GhcPass 'Renamed)
name LHsQTyVars (GhcPass 'Renamed)
vars LexicalFixity
_ LFamilyResultSig (GhcPass 'Renamed)
sig Maybe (LInjectivityAnn (GhcPass 'Renamed))
inj ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
FamDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsQTyVars (GhcPass 'Renamed)
-> TScoped (LHsQTyVars (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
rhsSpan]) LHsQTyVars (GhcPass 'Renamed)
vars
        , FamilyInfo (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamilyInfo (GhcPass 'Renamed)
info
        , RScoped
  (GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped
   (GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> RScoped
     (GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed))
-> RScoped
     (GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed)))
forall a. Scope -> a -> RScoped a
RS Scope
injSpan LFamilyResultSig (GhcPass 'Renamed)
GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed))
sig
        , Maybe
  (GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LInjectivityAnn (GhcPass 'Renamed))
Maybe
  (GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed)))
inj
        ]
        where
          rhsSpan :: Scope
rhsSpan = Scope
sigSpan Scope -> Scope -> Scope
`combineScopes` Scope
injSpan
          sigSpan :: Scope
sigSpan = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LFamilyResultSig (GhcPass 'Renamed)
GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed))
sig
          injSpan :: Scope
injSpan = Scope
-> (GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed))
    -> Scope)
-> Maybe
     (GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed)))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpan -> Scope)
-> (GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed))
    -> SrcSpan)
-> GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) Maybe (LInjectivityAnn (GhcPass 'Renamed))
Maybe
  (GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed)))
inj

instance ToHie (FamilyInfo GhcRn) where
  toHie :: FamilyInfo (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (ClosedTypeFamily (Just [LTyFamInstEqn (GhcPass 'Renamed)]
eqns)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ (GenLocated
   SrcSpanAnnA
   (FamEqn
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> [GenLocated
      SrcSpanAnnA
      (FamEqn
         (GhcPass 'Renamed)
         (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated
      SrcSpanAnnA
      (FamEqn
         (GhcPass 'Renamed)
         (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
    -> SrcSpan)
-> GenLocated
     SrcSpanAnnA
     (FamEqn
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated
  SrcSpanAnnA
  (FamEqn
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [LTyFamInstEqn (GhcPass 'Renamed)]
[GenLocated
   SrcSpanAnnA
   (FamEqn
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
eqns
    , [TScoped
   (FamEqn
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped
    (FamEqn
       (GhcPass 'Renamed)
       (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
 -> HieM [HieAST Type])
-> [TScoped
      (FamEqn
         (GhcPass 'Renamed)
         (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpanAnnA
   (FamEqn
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
 -> TScoped
      (FamEqn
         (GhcPass 'Renamed)
         (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))))
-> [GenLocated
      SrcSpanAnnA
      (FamEqn
         (GhcPass 'Renamed)
         (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
-> [TScoped
      (FamEqn
         (GhcPass 'Renamed)
         (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated
  SrcSpanAnnA
  (FamEqn
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> TScoped
     (FamEqn
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
forall {a} {a}. HasLoc a => GenLocated a a -> TScoped a
go [LTyFamInstEqn (GhcPass 'Renamed)]
[GenLocated
   SrcSpanAnnA
   (FamEqn
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))]
eqns
    ]
    where
      go :: GenLocated a a -> TScoped a
go (L a
l a
ib) = TyVarScope -> a -> TScoped a
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [a -> Scope
forall a. HasLoc a => a -> Scope
mkScope a
l]) a
ib
  toHie FamilyInfo (GhcPass 'Renamed)
_ = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (RScoped (LocatedAn NoEpAnns (FamilyResultSig GhcRn))) where
  toHie :: RScoped
  (GenLocated (EpAnn NoEpAnns) (FamilyResultSig (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (RS Scope
sc (L EpAnn NoEpAnns
span FamilyResultSig (GhcPass 'Renamed)
sig)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FamilyResultSig (GhcPass 'Renamed)
-> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA FamilyResultSig (GhcPass 'Renamed)
sig EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FamilyResultSig (GhcPass 'Renamed)
sig of
      NoSig XNoSig (GhcPass 'Renamed)
_ ->
        []
      KindSig XCKindSig (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
k ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
k
        ]
      TyVarSig XTyVarSig (GhcPass 'Renamed)
_ LHsTyVarBndr () (GhcPass 'Renamed)
bndr ->
        [ TVScoped
  (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TVScoped
   (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TVScoped
     (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))
-> TVScoped
     (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) Scope
NoScope LHsTyVarBndr () (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))
bndr
        ]

instance ToHie (LocatedA (FunDep GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (FunDep (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span fd :: FunDep (GhcPass 'Renamed)
fd@(FunDep XCFunDep (GhcPass 'Renamed)
_ [LIdP (GhcPass 'Renamed)]
lhs [LIdP (GhcPass 'Renamed)]
rhs)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ FunDep (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode FunDep (GhcPass 'Renamed)
fd (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)
    , [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass 'Renamed)]
[LocatedN Name]
lhs
    , [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass 'Renamed)]
[LocatedN Name]
rhs
    ]


instance ToHie (TScoped (FamEqn GhcRn (HsDataDefn GhcRn))) where
  toHie :: TScoped (FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (TS TyVarScope
_ FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed))
f) = FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed))
f

instance ToHie (TScoped (FamEqn GhcRn (LocatedA (HsType GhcRn)))) where
  toHie :: TScoped
  (FamEqn
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
toHie (TS TyVarScope
_ FamEqn
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
f) = FamEqn
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamEqn
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
f

instance (ToHie rhs, HasLoc rhs)
    => ToHie (FamEqn GhcRn rhs) where
  toHie :: FamEqn (GhcPass 'Renamed) rhs -> HieM [HieAST Type]
toHie fe :: FamEqn (GhcPass 'Renamed) rhs
fe@(FamEqn XCFamEqn (GhcPass 'Renamed) rhs
_ LIdP (GhcPass 'Renamed)
var HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed)
outer_bndrs HsFamEqnPats (GhcPass 'Renamed)
pats LexicalFixity
_ rhs
rhs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
InstDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ FamEqn (GhcPass 'Renamed) rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc FamEqn (GhcPass 'Renamed) rhs
fe) LIdP (GhcPass 'Renamed)
LocatedN Name
var
    , TVScoped (HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TVScoped (HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> TVScoped (HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed)
-> TVScoped (HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope HsOuterFamEqnTyVarBndrs (GhcPass 'Renamed)
outer_bndrs
    , [HsArg
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsFamEqnPats (GhcPass 'Renamed)
[HsArg
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
pats
    , rhs -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie rhs
rhs
    ]
    where scope :: Scope
scope = Scope -> Scope -> Scope
combineScopes Scope
patsScope Scope
rhsScope
          patsScope :: Scope
patsScope = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope ([HsArg
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList HsFamEqnPats (GhcPass 'Renamed)
[HsArg
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
pats)
          rhsScope :: Scope
rhsScope = SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc rhs
rhs)

instance ToHie (LocatedAn NoEpAnns (InjectivityAnn GhcRn)) where
  toHie :: GenLocated (EpAnn NoEpAnns) (InjectivityAnn (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span InjectivityAnn (GhcPass 'Renamed)
ann) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ InjectivityAnn (GhcPass 'Renamed)
-> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA InjectivityAnn (GhcPass 'Renamed)
ann EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InjectivityAnn (GhcPass 'Renamed)
ann of
      InjectivityAnn XCInjectivityAnn (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
lhs [LIdP (GhcPass 'Renamed)]
rhs ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
lhs
        , [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass 'Renamed)]
[LocatedN Name]
rhs
        ]

instance ToHie (HsDataDefn GhcRn) where
  toHie :: HsDataDefn (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (HsDataDefn XCHsDataDefn (GhcPass 'Renamed)
_ Maybe (LHsContext (GhcPass 'Renamed))
ctx Maybe (XRec (GhcPass 'Renamed) CType)
_ Maybe (LHsType (GhcPass 'Renamed))
mkind DataDefnCons (LConDecl (GhcPass 'Renamed))
cons HsDeriving (GhcPass 'Renamed)
derivs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
ctx
    , Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsType (GhcPass 'Renamed))
Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
mkind
    , DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie DataDefnCons (LConDecl (GhcPass 'Renamed))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed)))
cons
    , [GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsDeriving (GhcPass 'Renamed)
[GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
derivs
    ]

instance ToHie (Located [LocatedAn NoEpAnns (HsDerivingClause GhcRn)]) where
  toHie :: Located
  [GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
-> HieM [HieAST Type]
toHie (L SrcSpan
span [GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
clauses) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
span
    , [GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))]
clauses
    ]

instance ToHie (LocatedAn NoEpAnns (HsDerivingClause GhcRn)) where
  toHie :: GenLocated (EpAnn NoEpAnns) (HsDerivingClause (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span HsDerivingClause (GhcPass 'Renamed)
cl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsDerivingClause (GhcPass 'Renamed)
-> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsDerivingClause (GhcPass 'Renamed)
cl EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsDerivingClause (GhcPass 'Renamed)
cl of
      HsDerivingClause XCHsDerivingClause (GhcPass 'Renamed)
_ Maybe (LDerivStrategy (GhcPass 'Renamed))
strat LDerivClauseTys (GhcPass 'Renamed)
dct ->
        [ Maybe
  (RScoped
     (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Scope
-> GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))
-> RScoped
     (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
forall a. Scope -> a -> RScoped a
RS (GenLocated SrcSpanAnnC (DerivClauseTys (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LDerivClauseTys (GhcPass 'Renamed)
GenLocated SrcSpanAnnC (DerivClauseTys (GhcPass 'Renamed))
dct) (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))
 -> RScoped
      (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
-> Maybe
     (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
-> Maybe
     (RScoped
        (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LDerivStrategy (GhcPass 'Renamed))
Maybe
  (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
strat)
        , GenLocated SrcSpanAnnC (DerivClauseTys (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LDerivClauseTys (GhcPass 'Renamed)
GenLocated SrcSpanAnnC (DerivClauseTys (GhcPass 'Renamed))
dct
        ]

instance ToHie (LocatedC (DerivClauseTys GhcRn)) where
  toHie :: GenLocated SrcSpanAnnC (DerivClauseTys (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnC
span DerivClauseTys (GhcPass 'Renamed)
dct) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivClauseTys (GhcPass 'Renamed)
-> SrcSpanAnnC -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DerivClauseTys (GhcPass 'Renamed)
dct SrcSpanAnnC
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivClauseTys (GhcPass 'Renamed)
dct of
      DctSingle XDctSingle (GhcPass 'Renamed)
_ LHsSigType (GhcPass 'Renamed)
ty -> [ TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
ty ]
      DctMulti XDctMulti (GhcPass 'Renamed)
_ [LHsSigType (GhcPass 'Renamed)]
tys -> [ [TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TScoped
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
 -> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
-> [TScoped
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
tys ]

instance ToHie (RScoped (LocatedAn NoEpAnns (DerivStrategy GhcRn))) where
  toHie :: RScoped
  (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (RS Scope
sc (L EpAnn NoEpAnns
span DerivStrategy (GhcPass 'Renamed)
strat)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivStrategy (GhcPass 'Renamed)
-> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DerivStrategy (GhcPass 'Renamed)
strat EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivStrategy (GhcPass 'Renamed)
strat of
      StockStrategy XStockStrategy (GhcPass 'Renamed)
_ -> []
      AnyclassStrategy XAnyClassStrategy (GhcPass 'Renamed)
_ -> []
      NewtypeStrategy XNewtypeStrategy (GhcPass 'Renamed)
_ -> []
      ViaStrategy XViaStrategy (GhcPass 'Renamed)
s -> [ TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) XViaStrategy (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
s) ]

instance ToHie (LocatedP OverlapMode) where
  toHie :: LocatedP OverlapMode -> HieM [HieAST Type]
toHie (L SrcSpanAnnP
span OverlapMode
_) = SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnP -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnP
span)

instance ToHie a => ToHie (HsScaled GhcRn a) where
  toHie :: HsScaled (GhcPass 'Renamed) a -> HieM [HieAST Type]
toHie (HsScaled HsArrow (GhcPass 'Renamed)
w a
t) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsArrow (GhcPass 'Renamed) -> LHsType (GhcPass 'Renamed)
arrowToHsType HsArrow (GhcPass 'Renamed)
w), a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie a
t]

instance ToHie (LocatedA (ConDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ConDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span ConDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ConDecl (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ConDecl (GhcPass 'Renamed)
decl (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ConDecl (GhcPass 'Renamed)
decl of
      ConDeclGADT { con_names :: forall pass. ConDecl pass -> NonEmpty (LIdP pass)
con_names = NonEmpty (LIdP (GhcPass 'Renamed))
names, con_bndrs :: forall pass. ConDecl pass -> XRec pass (HsOuterSigTyVarBndrs pass)
con_bndrs = L SrcSpanAnnA
outer_bndrs_loc HsOuterSigTyVarBndrs (GhcPass 'Renamed)
outer_bndrs
                  , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext (GhcPass 'Renamed))
ctx, con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_g_args = HsConDeclGADTDetails (GhcPass 'Renamed)
args, con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LHsType (GhcPass 'Renamed)
typ
                  , con_doc :: forall pass. ConDecl pass -> Maybe (LHsDoc pass)
con_doc = Maybe (LHsDoc (GhcPass 'Renamed))
doc} ->
        [ NonEmpty (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (NonEmpty (Context (LocatedN Name)) -> HieM [HieAST Type])
-> NonEmpty (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ConDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) (LocatedN Name -> Context (LocatedN Name))
-> NonEmpty (LocatedN Name) -> NonEmpty (Context (LocatedN Name))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty (LIdP (GhcPass 'Renamed))
NonEmpty (LocatedN Name)
names
        , case HsOuterSigTyVarBndrs (GhcPass 'Renamed)
outer_bndrs of
            HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit (GhcPass 'Renamed)
imp_vars} ->
              [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
outer_bndrs_loc) TyVarScope
resScope)
                             [Name]
XHsOuterImplicit (GhcPass 'Renamed)
imp_vars
            HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr Specificity (NoGhcTc (GhcPass 'Renamed))]
exp_bndrs} ->
              [TVScoped
   (GenLocated
      SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated
       SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated
         SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
-> [TVScoped (LHsTyVarBndr Specificity (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
resScope Scope
NoScope [LHsTyVarBndr Specificity (NoGhcTc (GhcPass 'Renamed))]
[LHsTyVarBndr Specificity (GhcPass 'Renamed)]
exp_bndrs
        , Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
ctx
        , HsConDeclGADTDetails (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclGADTDetails (GhcPass 'Renamed)
args
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
typ
        , Maybe (LHsDoc (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsDoc (GhcPass 'Renamed))
doc
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
argsScope Scope
tyScope
          ctxScope :: Scope
ctxScope = Scope
-> (GenLocated
      SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
    -> Scope)
-> Maybe
     (GenLocated
        SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
ctx
          argsScope :: Scope
argsScope = case HsConDeclGADTDetails (GhcPass 'Renamed)
args of
            PrefixConGADT XPrefixConGADT (GhcPass 'Renamed)
_ [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))]
xs -> [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))] -> Scope
scaled_args_scope [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))]
xs
            RecConGADT XRecConGADT (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) [LConDeclField (GhcPass 'Renamed)]
x     -> GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec (GhcPass 'Renamed) [LConDeclField (GhcPass 'Renamed)]
GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
x
          tyScope :: Scope
tyScope = GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
typ
          resScope :: TyVarScope
resScope = [Scope] -> TyVarScope
ResolvedScopes [Scope
ctxScope, Scope
rhsScope]
      ConDeclH98 { con_name :: forall pass. ConDecl pass -> LIdP pass
con_name = LIdP (GhcPass 'Renamed)
name, con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_ex_tvs = [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
qvars
                 , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext (GhcPass 'Renamed))
ctx, con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_args = HsConDeclH98Details (GhcPass 'Renamed)
dets
                 , con_doc :: forall pass. ConDecl pass -> Maybe (LHsDoc pass)
con_doc = Maybe (LHsDoc (GhcPass 'Renamed))
doc} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ConDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)) LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , [TVScoped
   (GenLocated
      SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated
       SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated
         SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
-> [TVScoped (LHsTyVarBndr Specificity (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
rhsScope [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
qvars
        , Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
ctx
        , HsConDetails
  Void
  (HsScaled
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
  (GenLocated
     SrcSpanAnnL
     [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclH98Details (GhcPass 'Renamed)
HsConDetails
  Void
  (HsScaled
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
  (GenLocated
     SrcSpanAnnL
     [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))])
dets
        , Maybe (LHsDoc (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsDoc (GhcPass 'Renamed))
doc
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
ctxScope Scope
argsScope
          ctxScope :: Scope
ctxScope = Scope
-> (GenLocated
      SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
    -> Scope)
-> Maybe
     (GenLocated
        SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope Maybe (LHsContext (GhcPass 'Renamed))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))])
ctx
          argsScope :: Scope
argsScope = case HsConDeclH98Details (GhcPass 'Renamed)
dets of
            PrefixCon [Void]
_ [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))]
xs -> [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))] -> Scope
scaled_args_scope [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))]
xs
            InfixCon HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))
a HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))
b   -> [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))] -> Scope
scaled_args_scope [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))
a, HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))
b]
            RecCon XRec (GhcPass 'Renamed) [LConDeclField (GhcPass 'Renamed)]
x       -> GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
-> Scope
forall a. HasLoc a => a -> Scope
mkScope XRec (GhcPass 'Renamed) [LConDeclField (GhcPass 'Renamed)]
GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
x
    where scaled_args_scope :: [HsScaled GhcRn (LHsType GhcRn)] -> Scope
          scaled_args_scope :: [HsScaled (GhcPass 'Renamed) (LHsType (GhcPass 'Renamed))] -> Scope
scaled_args_scope = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Scope -> Scope -> Scope
combineScopes Scope
NoScope ([Scope] -> Scope)
-> ([HsScaled
       (GhcPass 'Renamed)
       (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
    -> [Scope])
-> [HsScaled
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HsScaled
   (GhcPass 'Renamed)
   (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
 -> Scope)
-> [HsScaled
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))]
-> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> Scope)
-> (HsScaled
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
    -> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> HsScaled
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsScaled
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
forall pass a. HsScaled pass a -> a
hsScaledThing)

instance ToHie (LocatedL [LocatedA (ConDeclField GhcRn)]) where
  toHie :: GenLocated
  SrcSpanAnnL
  [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
-> HieM [HieAST Type]
toHie (L SrcSpanAnnL
span [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
decls) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
span)
    , [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
decls
    ]

instance ToHie (TScoped (HsWildCardBndrs GhcRn (LocatedA (HsSigType GhcRn)))) where
  toHie :: TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsWC XHsWC
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
names GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
a)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsWC
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
names
      , TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS TyVarScope
sc GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
a
      ]
    where span :: SrcSpan
span = GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
a

instance ToHie (TScoped (HsWildCardBndrs GhcRn (LocatedA (HsType GhcRn)))) where
  toHie :: TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsWC XHsWC
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
names GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsWC
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
names
      , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
      ]
    where span :: SrcSpan
span = GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a

instance ToHie (LocatedA (StandaloneKindSig GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (StandaloneKindSig (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
sp StandaloneKindSig (GhcPass 'Renamed)
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [StandaloneKindSig (GhcPass 'Renamed)
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA StandaloneKindSig (GhcPass 'Renamed)
sig SrcSpanAnnA
sp, StandaloneKindSig (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie StandaloneKindSig (GhcPass 'Renamed)
sig]

instance ToHie (StandaloneKindSig GhcRn) where
  toHie :: StandaloneKindSig (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie StandaloneKindSig (GhcPass 'Renamed)
sig = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case StandaloneKindSig (GhcPass 'Renamed)
sig of
    StandaloneKindSig XStandaloneKindSig (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
name LHsSigType (GhcPass 'Renamed)
typ ->
      [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl LIdP (GhcPass 'Renamed)
LocatedN Name
name
      , TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
typ
      ]

instance HiePass p => ToHie (SigContext (LocatedA (Sig (GhcPass p)))) where
  toHie :: SigContext (LocatedA (Sig (GhcPass p))) -> HieM [HieAST Type]
toHie (SC (SI SigType
styp Maybe Span
msp) (L SrcSpanAnnA
sp Sig (GhcPass p)
sig)) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieTc -> [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
      HiePassEv p
HieRn -> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Sig (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA Sig (GhcPass p)
sig SrcSpanAnnA
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Sig (GhcPass p)
sig of
        TypeSig XTypeSig (GhcPass p)
_ [LIdP (GhcPass p)]
names LHsSigWcType (GhcPass p)
typ ->
          [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe Span -> TyVarScope
UnresolvedScope ((LocatedN Name -> Name) -> [LocatedN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP (GhcPass p)]
[LocatedN Name]
names) Maybe Span
forall a. Maybe a
Nothing) LHsSigWcType (GhcPass p)
HsWildCardBndrs
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
typ
          ]
        PatSynSig XPatSynSig (GhcPass p)
_ [LIdP (GhcPass p)]
names LHsSigType (GhcPass p)
typ ->
          [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe Span -> TyVarScope
UnresolvedScope ((LocatedN Name -> Name) -> [LocatedN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP (GhcPass p)]
[LocatedN Name]
names) Maybe Span
forall a. Maybe a
Nothing) LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
typ
          ]
        ClassOpSig XClassOpSig (GhcPass p)
_ Bool
_ [LIdP (GhcPass p)]
names LHsSigType (GhcPass p)
typ ->
          [ case SigType
styp of
              SigType
ClassSig -> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> LocatedN Name -> Context (LocatedN Name))
-> ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ Maybe Span -> ContextInfo
ClassTyDecl (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
sp) [LIdP (GhcPass p)]
[LocatedN Name]
names
              SigType
_  -> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> LocatedN Name -> Context (LocatedN Name))
-> ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a b. (a -> b) -> a -> b
$ ContextInfo
TyDecl) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe Span -> TyVarScope
UnresolvedScope ((LocatedN Name -> Name) -> [LocatedN Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocatedN Name -> Name
forall l e. GenLocated l e -> e
unLoc [LIdP (GhcPass p)]
[LocatedN Name]
names) Maybe Span
msp) LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
typ
          ]
        FixSig XFixSig (GhcPass p)
_ FixitySig (GhcPass p)
fsig ->
          [ GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> FixitySig (GhcPass p)
-> GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
sp FixitySig (GhcPass p)
fsig
          ]
        InlineSig XInlineSig (GhcPass p)
_ LIdP (GhcPass p)
name InlinePragma
_ ->
          [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) LIdP (GhcPass p)
LocatedN Name
name
          ]
        SpecSig XSpecSig (GhcPass p)
_ LIdP (GhcPass p)
name [LHsSigType (GhcPass p)]
typs InlinePragma
_ ->
          [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) LIdP (GhcPass p)
LocatedN Name
name
          , [TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TScoped
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
 -> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
-> [TScoped
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType (GhcPass p)]
[GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))]
typs
          ]
        SpecInstSig XSpecInstSig (GhcPass p)
_ LHsSigType (GhcPass p)
typ ->
          [ TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
typ
          ]
        MinimalSig XMinimalSig (GhcPass p)
_ LBooleanFormula (LIdP (GhcPass p))
form ->
          [ LBooleanFormula (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (LIdP (GhcPass p))
LBooleanFormula (LocatedN Name)
form
          ]
        SCCFunSig XSCCFunSig (GhcPass p)
_ LIdP (GhcPass p)
name Maybe (XRec (GhcPass p) StringLiteral)
mtxt ->
          [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) LIdP (GhcPass p)
LocatedN Name
name
          , HieM [HieAST Type]
-> (GenLocated (EpAnn NoEpAnns) StringLiteral
    -> HieM [HieAST Type])
-> Maybe (GenLocated (EpAnn NoEpAnns) StringLiteral)
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated (EpAnn NoEpAnns) StringLiteral -> SrcSpan)
-> GenLocated (EpAnn NoEpAnns) StringLiteral
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (EpAnn NoEpAnns) StringLiteral -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) Maybe (XRec (GhcPass p) StringLiteral)
Maybe (GenLocated (EpAnn NoEpAnns) StringLiteral)
mtxt
          ]
        CompleteMatchSig XCompleteMatchSig (GhcPass p)
_ [LIdP (GhcPass p)]
names Maybe (LIdP (GhcPass p))
typ ->
          [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass p)]
[LocatedN Name]
names
          , Maybe (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (Context (LocatedN Name)) -> HieM [HieAST Type])
-> Maybe (Context (LocatedN Name)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> Maybe (LocatedN Name) -> Maybe (Context (LocatedN Name))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Maybe (LIdP (GhcPass p))
Maybe (LocatedN Name)
typ
          ]
        XSig XXSig (GhcPass p)
_ -> []

instance ToHie (TScoped (LocatedA (HsSigType GhcRn))) where
  toHie :: TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (TS TyVarScope
tsc (L SrcSpanAnnA
span t :: HsSigType (GhcPass 'Renamed)
t@HsSig{sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs=HsOuterSigTyVarBndrs (GhcPass 'Renamed)
bndrs,sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body=LHsType (GhcPass 'Renamed)
body})) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsSigType (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsSigType (GhcPass 'Renamed)
t SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
:
      [ TVScoped (HsOuterSigTyVarBndrs (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TyVarScope
-> Scope
-> HsOuterSigTyVarBndrs (GhcPass 'Renamed)
-> TVScoped (HsOuterSigTyVarBndrs (GhcPass 'Renamed))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tsc (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) HsOuterSigTyVarBndrs (GhcPass 'Renamed)
bndrs)
      , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body
      ]

-- Check this
instance Data flag => ToHie (TVScoped (HsOuterTyVarBndrs flag GhcRn)) where
  toHie :: TVScoped (HsOuterTyVarBndrs flag (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (TVS TyVarScope
tsc Scope
sc HsOuterTyVarBndrs flag (GhcPass 'Renamed)
bndrs) = case HsOuterTyVarBndrs flag (GhcPass 'Renamed)
bndrs of
    HsOuterImplicit XHsOuterImplicit (GhcPass 'Renamed)
xs -> [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) [Name]
XHsOuterImplicit (GhcPass 'Renamed)
xs
    HsOuterExplicit XHsOuterExplicit (GhcPass 'Renamed) flag
_ [LHsTyVarBndr flag (NoGhcTc (GhcPass 'Renamed))]
xs -> [TVScoped
   (GenLocated SrcSpanAnnA (HsTyVarBndr flag (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated SrcSpanAnnA (HsTyVarBndr flag (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr flag (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass 'Renamed)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tsc Scope
sc [LHsTyVarBndr flag (NoGhcTc (GhcPass 'Renamed))]
[LHsTyVarBndr flag (GhcPass 'Renamed)]
xs

toHieForAllTele ::  HsForAllTelescope GhcRn -> SrcSpan -> HieM [HieAST Type]
toHieForAllTele :: HsForAllTelescope (GhcPass 'Renamed)
-> SrcSpan -> HieM [HieAST Type]
toHieForAllTele (HsForAllVis { hsf_vis_bndrs :: forall pass. HsForAllTelescope pass -> [LHsTyVarBndr () pass]
hsf_vis_bndrs = [LHsTyVarBndr () (GhcPass 'Renamed)]
bndrs }) SrcSpan
loc =
  [TVScoped
   (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr () (GhcPass 'Renamed)]
-> [TVScoped (LHsTyVarBndr () (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
loc) [LHsTyVarBndr () (GhcPass 'Renamed)]
bndrs
toHieForAllTele (HsForAllInvis { hsf_invis_bndrs :: forall pass.
HsForAllTelescope pass -> [LHsTyVarBndr Specificity pass]
hsf_invis_bndrs = [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
bndrs }) SrcSpan
loc =
  [TVScoped
   (GenLocated
      SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated
       SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated
         SrcSpanAnnA (HsTyVarBndr Specificity (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
-> [TVScoped (LHsTyVarBndr Specificity (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
loc) [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
bndrs

instance ToHie (LocatedA (HsType GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span HsType (GhcPass 'Renamed)
t) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsType (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsType (GhcPass 'Renamed)
t (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsType (GhcPass 'Renamed)
t of
      HsForAllTy XForAllTy (GhcPass 'Renamed)
_ HsForAllTelescope (GhcPass 'Renamed)
tele LHsType (GhcPass 'Renamed)
body ->
        [ HsForAllTelescope (GhcPass 'Renamed)
-> SrcSpan -> HieM [HieAST Type]
toHieForAllTele HsForAllTelescope (GhcPass 'Renamed)
tele (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body)
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body
        ]
      HsQualTy XQualTy (GhcPass 'Renamed)
_ LHsContext (GhcPass 'Renamed)
ctx LHsType (GhcPass 'Renamed)
body ->
        [ GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsContext (GhcPass 'Renamed)
GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
ctx
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body
        ]
      HsTyVar XTyVar (GhcPass 'Renamed)
_ PromotionFlag
_ LIdP (GhcPass 'Renamed)
var ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
var
        ]
      HsAppTy XAppTy (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
a LHsType (GhcPass 'Renamed)
b ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
b
        ]
      HsAppKindTy XAppKindTy (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
ty LHsType (GhcPass 'Renamed)
ki ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
ty
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
ki
        ]
      HsFunTy XFunTy (GhcPass 'Renamed)
_ HsArrow (GhcPass 'Renamed)
w LHsType (GhcPass 'Renamed)
a LHsType (GhcPass 'Renamed)
b ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsArrow (GhcPass 'Renamed) -> LHsType (GhcPass 'Renamed)
arrowToHsType HsArrow (GhcPass 'Renamed)
w)
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
b
        ]
      HsListTy XListTy (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
a ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        ]
      HsTupleTy XTupleTy (GhcPass 'Renamed)
_ HsTupleSort
_ [LHsType (GhcPass 'Renamed)]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
tys
        ]
      HsSumTy XSumTy (GhcPass 'Renamed)
_ [LHsType (GhcPass 'Renamed)]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
tys
        ]
      HsOpTy XOpTy (GhcPass 'Renamed)
_ PromotionFlag
_prom LHsType (GhcPass 'Renamed)
a LIdP (GhcPass 'Renamed)
op LHsType (GhcPass 'Renamed)
b ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        , Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
op
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
b
        ]
      HsParTy XParTy (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
a ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        ]
      HsIParamTy XIParamTy (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) HsIPName
ip LHsType (GhcPass 'Renamed)
ty ->
        [ GenLocated (EpAnn NoEpAnns) HsIPName -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec (GhcPass 'Renamed) HsIPName
GenLocated (EpAnn NoEpAnns) HsIPName
ip
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
ty
        ]
      HsKindSig XKindSig (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
a LHsType (GhcPass 'Renamed)
b ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
b
        ]
      HsSpliceTy XSpliceTy (GhcPass 'Renamed)
_ HsUntypedSplice (GhcPass 'Renamed)
a ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsUntypedSplice (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span HsUntypedSplice (GhcPass 'Renamed)
a
        ]
      HsDocTy XDocTy (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
a LHsDoc (GhcPass 'Renamed)
doc ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
a
        , LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
doc
        ]
      HsBangTy XBangTy (GhcPass 'Renamed)
_ HsBang
_ LHsType (GhcPass 'Renamed)
ty ->
        [ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
ty
        ]
      HsRecTy XRecTy (GhcPass 'Renamed)
_ [LConDeclField (GhcPass 'Renamed)]
fields ->
        [ [GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LConDeclField (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))]
fields
        ]
      HsExplicitListTy XExplicitListTy (GhcPass 'Renamed)
_ PromotionFlag
_ [LHsType (GhcPass 'Renamed)]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
tys
        ]
      HsExplicitTupleTy XExplicitTupleTy (GhcPass 'Renamed)
_ [LHsType (GhcPass 'Renamed)]
tys ->
        [ [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
tys
        ]
      HsTyLit XTyLit (GhcPass 'Renamed)
_ HsTyLit (GhcPass 'Renamed)
_ -> []
      HsWildCardTy XWildCardTy (GhcPass 'Renamed)
_ -> []
      HsStarTy XStarTy (GhcPass 'Renamed)
_ Bool
_ -> []
      XHsType XXType (GhcPass 'Renamed)
_ -> []

instance (ToHie tm, ToHie ty) => ToHie (HsArg (GhcPass p) tm ty) where
  toHie :: HsArg (GhcPass p) tm ty -> HieM [HieAST Type]
toHie (HsValArg XValArg (GhcPass p)
_ tm
tm) = tm -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie tm
tm
  toHie (HsTypeArg XTypeArg (GhcPass p)
_ ty
ty) = ty -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ty
ty
  toHie (HsArgPar XArgPar (GhcPass p)
sp) = SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
XArgPar (GhcPass p)
sp

instance Data flag => ToHie (TVScoped (LocatedA (HsTyVarBndr flag GhcRn))) where
  toHie :: TVScoped (LocatedA (HsTyVarBndr flag (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (TVS TyVarScope
tsc Scope
sc (L SrcSpanAnnA
span HsTyVarBndr flag (GhcPass 'Renamed)
bndr)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsTyVarBndr flag (GhcPass 'Renamed)
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsTyVarBndr flag (GhcPass 'Renamed)
bndr SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: ([HieM [HieAST Type]]
name' [HieM [HieAST Type]]
-> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. [a] -> [a] -> [a]
++ [HieM [HieAST Type]]
kind')
    where
      name' :: [HieM [HieAST Type]]
name' = case HsTyVarBndr flag (GhcPass 'Renamed) -> HsBndrVar (GhcPass 'Renamed)
forall flag (pass :: Pass).
HsTyVarBndr flag (GhcPass pass) -> HsBndrVar (GhcPass pass)
hsBndrVar HsTyVarBndr flag (GhcPass 'Renamed)
bndr of
        HsBndrWildCard XBndrWildCard (GhcPass 'Renamed)
_ -> []
        HsBndrVar XBndrVar (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
tv   -> [Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) LIdP (GhcPass 'Renamed)
LocatedN Name
tv]
      kind' :: [HieM [HieAST Type]]
kind' = case HsTyVarBndr flag (GhcPass 'Renamed)
-> HsBndrKind (GhcPass 'Renamed)
forall flag (pass :: Pass).
HsTyVarBndr flag (GhcPass pass) -> HsBndrKind (GhcPass pass)
hsBndrKind HsTyVarBndr flag (GhcPass 'Renamed)
bndr of
        HsBndrNoKind XBndrNoKind (GhcPass 'Renamed)
_ -> []
        HsBndrKind XBndrKind (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
k -> [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
k]

instance ToHie (TScoped (LHsQTyVars GhcRn)) where
  toHie :: TScoped (LHsQTyVars (GhcPass 'Renamed)) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsQTvs XHsQTvs (GhcPass 'Renamed)
implicits [LHsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)]
vars)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [Context Name]
bindings
    , [TVScoped
   (GenLocated
      SrcSpanAnnA
      (HsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped
    (GenLocated
       SrcSpanAnnA
       (HsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [TVScoped
      (GenLocated
         SrcSpanAnnA
         (HsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)]
-> [TVScoped
      (LHsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
sc Scope
NoScope [LHsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)]
vars
    ]
    where
      varLoc :: SrcSpan
varLoc = [GenLocated
   SrcSpanAnnA
   (HsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed))]
-> SrcSpan
forall a. HasLoc a => [a] -> SrcSpan
getHasLocList [LHsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed)]
[GenLocated
   SrcSpanAnnA
   (HsTyVarBndr (HsBndrVis (GhcPass 'Renamed)) (GhcPass 'Renamed))]
vars
      bindings :: [Context Name]
bindings = (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpan
varLoc) TyVarScope
sc) [Name]
XHsQTvs (GhcPass 'Renamed)
implicits

instance ToHie (LocatedC [LocatedA (HsType GhcRn)]) where
  toHie :: GenLocated
  SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
toHie (L SrcSpanAnnC
span [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
tys) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnC -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnC
span)
      , [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
tys
      ]

instance HiePass p => ToHie (LocatedC [LocatedA (HsExpr (GhcPass p))]) where
  toHie :: LocatedC [LocatedA (HsExpr (GhcPass p))] -> HieM [HieAST Type]
toHie (L SrcSpanAnnC
span [LocatedA (HsExpr (GhcPass p))]
exprs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpanAnnC -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnC
span)
    , [LocatedA (HsExpr (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LocatedA (HsExpr (GhcPass p))]
exprs
    ]

instance ToHie (LocatedA (ConDeclField GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ConDeclField (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span ConDeclField (GhcPass 'Renamed)
field) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ConDeclField (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ConDeclField (GhcPass 'Renamed)
field (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ConDeclField (GhcPass 'Renamed)
field of
      ConDeclField XConDeclField (GhcPass 'Renamed)
_ [LFieldOcc (GhcPass 'Renamed)]
fields LHsType (GhcPass 'Renamed)
typ Maybe (LHsDoc (GhcPass 'Renamed))
doc ->
        [ [RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [RFContext
      (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))
 -> RFContext
      (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))]
-> [RFContext
      (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> Maybe Span
-> GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))
-> RFContext (GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed)))
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
RecFieldDecl (SrcSpan -> Maybe Span
getRealSpan (SrcSpan -> Maybe Span) -> SrcSpan -> Maybe Span
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
getHasLoc LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
typ)) [LFieldOcc (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (FieldOcc (GhcPass 'Renamed))]
fields
        , GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
typ
        , Maybe (LHsDoc (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsDoc (GhcPass 'Renamed))
doc
        ]

instance ToHie (LHsExpr a) => ToHie (ArithSeqInfo a) where
  toHie :: ArithSeqInfo a -> HieM [HieAST Type]
toHie (From LHsExpr a
expr) = LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
expr
  toHie (FromThen LHsExpr a
a LHsExpr a
b) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
a
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
b
    ]
  toHie (FromTo LHsExpr a
a LHsExpr a
b) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
a
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
b
    ]
  toHie (FromThenTo LHsExpr a
a LHsExpr a
b LHsExpr a
c) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
a
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
b
    , LHsExpr a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr a
c
    ]

instance ToHie (LocatedA (SpliceDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (SpliceDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span SpliceDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SpliceDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA SpliceDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case SpliceDecl (GhcPass 'Renamed)
decl of
      SpliceDecl XSpliceDecl (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) (HsUntypedSplice (GhcPass 'Renamed))
splice SpliceDecoration
_ ->
        [ GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie XRec (GhcPass 'Renamed) (HsUntypedSplice (GhcPass 'Renamed))
GenLocated SrcSpanAnnA (HsUntypedSplice (GhcPass 'Renamed))
splice
        ]

instance ToHie (HsQuote GhcRn) where
  toHie :: HsQuote (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (ExpBr XExpBr (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
e)  = LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
e
  toHie (PatBr XPatBr (GhcPass 'Renamed)
_ LPat (GhcPass 'Renamed)
b)  = PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe Span
-> Scope
-> Scope
-> GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
-> PScoped (GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
NoScope Scope
NoScope LPat (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (Pat (GhcPass 'Renamed))
b)
  toHie (DecBrL {} ) = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  toHie (DecBrG XDecBrG (GhcPass 'Renamed)
_ HsGroup (GhcPass 'Renamed)
decls) = HsGroup (GhcPass 'Renamed) -> HieM [HieAST Type]
processGrp HsGroup (GhcPass 'Renamed)
decls
  toHie (TypBr XTypBr (GhcPass 'Renamed)
_ LHsType (GhcPass 'Renamed)
ty) = GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
ty
  toHie (VarBr {} )  = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie PendingRnSplice where
  toHie :: PendingRnSplice -> HieM [HieAST Type]
toHie (PendingRnSplice UntypedSpliceFlavour
_ Name
_ LHsExpr (GhcPass 'Renamed)
e) = LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
e

instance ToHie PendingTcSplice where
  toHie :: PendingTcSplice -> HieM [HieAST Type]
toHie (PendingTcSplice Name
_ LHsExpr GhcTc
e) = GenLocated SrcSpanAnnA (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
e

instance ToHie (LBooleanFormula (LocatedN Name)) where
  toHie :: LBooleanFormula (LocatedN Name) -> HieM [HieAST Type]
toHie (L SrcSpanAnnL
span BooleanFormula (LocatedN Name)
form) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ BooleanFormula (LocatedN Name) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode BooleanFormula (LocatedN Name)
form (SrcSpanAnnL -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnL
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case BooleanFormula (LocatedN Name)
form of
      Var LocatedN Name
a ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LocatedN Name
a
        ]
      And [LBooleanFormula (LocatedN Name)]
forms ->
        [ [LBooleanFormula (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LBooleanFormula (LocatedN Name)]
forms
        ]
      Or [LBooleanFormula (LocatedN Name)]
forms ->
        [ [LBooleanFormula (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LBooleanFormula (LocatedN Name)]
forms
        ]
      Parens LBooleanFormula (LocatedN Name)
f ->
        [ LBooleanFormula (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (LocatedN Name)
f
        ]

instance ToHie (LocatedAn NoEpAnns HsIPName) where
  toHie :: GenLocated (EpAnn NoEpAnns) HsIPName -> HieM [HieAST Type]
toHie (L EpAnn NoEpAnns
span HsIPName
e) = HsIPName -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsIPName
e EpAnn NoEpAnns
span

instance HiePass p => ToHie (LocatedA (HsUntypedSplice (GhcPass p))) where
  toHie :: LocatedA (HsUntypedSplice (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span HsUntypedSplice (GhcPass p)
sp) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsUntypedSplice (GhcPass p) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA HsUntypedSplice (GhcPass p)
sp SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsUntypedSplice (GhcPass p)
sp of
      HsUntypedSpliceExpr XUntypedSpliceExpr (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ GenLocated SrcSpanAnnA (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
GenLocated SrcSpanAnnA (HsExpr (GhcPass p))
expr
        ]
      HsQuasiQuote XQuasiQuote (GhcPass p)
_ IdP (GhcPass p)
_ XRec (GhcPass p) FastString
ispanFs ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (GenLocated (EpAnn NoEpAnns) FastString -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA XRec (GhcPass p) FastString
GenLocated (EpAnn NoEpAnns) FastString
ispanFs)
        ]

instance ToHie (LocatedA (RoleAnnotDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (RoleAnnotDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span RoleAnnotDecl (GhcPass 'Renamed)
annot) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RoleAnnotDecl (GhcPass 'Renamed)
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RoleAnnotDecl (GhcPass 'Renamed)
annot SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RoleAnnotDecl (GhcPass 'Renamed)
annot of
      RoleAnnotDecl XCRoleAnnotDecl (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
var [XRec (GhcPass 'Renamed) (Maybe Role)]
roles ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
var
        , (GenLocated (EpAnn NoEpAnns) (Maybe Role) -> HieM [HieAST Type])
-> [GenLocated (EpAnn NoEpAnns) (Maybe Role)] -> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated (EpAnn NoEpAnns) (Maybe Role) -> SrcSpan)
-> GenLocated (EpAnn NoEpAnns) (Maybe Role)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (EpAnn NoEpAnns) (Maybe Role) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) [XRec (GhcPass 'Renamed) (Maybe Role)]
[GenLocated (EpAnn NoEpAnns) (Maybe Role)]
roles
        ]

instance ToHie (LocatedA (InstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (InstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span InstDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ InstDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA InstDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InstDecl (GhcPass 'Renamed)
decl of
      ClsInstD XClsInstD (GhcPass 'Renamed)
_ ClsInstDecl (GhcPass 'Renamed)
d ->
        [ GenLocated SrcSpanAnnA (ClsInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (ClsInstDecl (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (ClsInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> ClsInstDecl (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (ClsInstDecl (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span ClsInstDecl (GhcPass 'Renamed)
d
        ]
      DataFamInstD XDataFamInstD (GhcPass 'Renamed)
_ DataFamInstDecl (GhcPass 'Renamed)
d ->
        [ GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> DataFamInstDecl (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span DataFamInstDecl (GhcPass 'Renamed)
d
        ]
      TyFamInstD XTyFamInstD (GhcPass 'Renamed)
_ TyFamInstDecl (GhcPass 'Renamed)
d ->
        [ GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> TyFamInstDecl (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
span TyFamInstDecl (GhcPass 'Renamed)
d
        ]

instance ToHie (LocatedA (ClsInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ClsInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span ClsInstDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span]) (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
 -> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed) -> LHsSigType (GhcPass 'Renamed)
forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty ClsInstDecl (GhcPass 'Renamed)
decl
    , [BindContext (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([BindContext (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))
 -> BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))
-> BindContext (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) ([GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))]
 -> [BindContext
       (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))])
-> [GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed))]
-> [BindContext
      (GenLocated SrcSpanAnnA (HsBind (GhcPass 'Renamed)))]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed) -> LHsBinds (GhcPass 'Renamed)
forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds ClsInstDecl (GhcPass 'Renamed)
decl
    , [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))
forall a. SigInfo -> a -> SigContext a
SC (SigInfo
 -> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
 -> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))))
-> SigInfo
-> GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))
-> SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe Span -> SigInfo
SI SigType
InstSig (Maybe Span -> SigInfo) -> Maybe Span -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) ([GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
 -> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))])
-> [GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed))]
-> [SigContext (GenLocated SrcSpanAnnA (Sig (GhcPass 'Renamed)))]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed) -> [LSig (GhcPass 'Renamed)]
forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs ClsInstDecl (GhcPass 'Renamed)
decl
    , (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
    -> SrcSpan)
-> GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) ([GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed)
-> [LTyFamDefltDecl (GhcPass 'Renamed)]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl (GhcPass 'Renamed)
decl
    , [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed)
-> [LTyFamDefltDecl (GhcPass 'Renamed)]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl (GhcPass 'Renamed)
decl
    , (GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Traversable f) =>
(a -> m [b]) -> f a -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
    -> SrcSpan)
-> GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
-> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA) ([GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed)
-> [LDataFamInstDecl (GhcPass 'Renamed)]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl (GhcPass 'Renamed)
decl
    , [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed)
-> [LDataFamInstDecl (GhcPass 'Renamed)]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl (GhcPass 'Renamed)
decl
    , Maybe (LocatedP OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (LocatedP OverlapMode) -> HieM [HieAST Type])
-> Maybe (LocatedP OverlapMode) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl (GhcPass 'Renamed)
-> Maybe (XRec (GhcPass 'Renamed) OverlapMode)
forall pass. ClsInstDecl pass -> Maybe (XRec pass OverlapMode)
cid_overlap_mode ClsInstDecl (GhcPass 'Renamed)
decl
    ]

instance ToHie (LocatedA (DataFamInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
sp (DataFamInstDecl FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed))
d)) = TScoped (FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped
     (FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed))
-> TScoped
     (FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
sp]) FamEqn (GhcPass 'Renamed) (HsDataDefn (GhcPass 'Renamed))
d

instance ToHie (LocatedA (TyFamInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
sp (TyFamInstDecl XCTyFamInstDecl (GhcPass 'Renamed)
_ TyFamInstEqn (GhcPass 'Renamed)
d)) = TScoped
  (FamEqn
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (FamEqn
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> TScoped
     (FamEqn
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> FamEqn
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> TScoped
     (FamEqn
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
sp]) TyFamInstEqn (GhcPass 'Renamed)
FamEqn
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
d


instance HiePass p => ToHie (Context (FieldOcc (GhcPass p))) where
  toHie :: Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type]
toHie (C ContextInfo
c (FieldOcc XCFieldOcc (GhcPass p)
_ LIdP (GhcPass p)
l)) = Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
c LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
l)

instance HiePass p => ToHie (PatSynFieldContext (RecordPatSynField (GhcPass p))) where
  toHie :: PatSynFieldContext (RecordPatSynField (GhcPass p))
-> HieM [HieAST Type]
toHie (PSC Maybe Span
sp (RecordPatSynField FieldOcc (GhcPass p)
a LIdP (GhcPass p)
b)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type])
-> Context (FieldOcc (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> FieldOcc (GhcPass p) -> Context (FieldOcc (GhcPass p))
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
RecFieldDecl Maybe Span
sp) FieldOcc (GhcPass p)
a
    , Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpanAnnN (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpanAnnN (IdGhcP p)
-> Context (GenLocated SrcSpanAnnN (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass p)
GenLocated SrcSpanAnnN (IdGhcP p)
b
    ]

instance ToHie (LocatedA (DerivDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DerivDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span DerivDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DerivDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivDecl (GhcPass 'Renamed)
decl of
      DerivDecl XCDerivDecl (GhcPass 'Renamed)
_ LHsSigWcType (GhcPass 'Renamed)
typ Maybe (LDerivStrategy (GhcPass 'Renamed))
strat Maybe (XRec (GhcPass 'Renamed) OverlapMode)
overlap ->
        [ TScoped
  (HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass 'Renamed)
      (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass 'Renamed)
     (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> TScoped
     (HsWildCardBndrs
        (GhcPass 'Renamed)
        (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigWcType (GhcPass 'Renamed)
HsWildCardBndrs
  (GhcPass 'Renamed)
  (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
typ
        , Maybe
  (RScoped
     (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe
   (RScoped
      (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
 -> HieM [HieAST Type])
-> Maybe
     (RScoped
        (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Scope
-> GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))
-> RScoped
     (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
forall a. Scope -> a -> RScoped a
RS (SrcSpanAnnA -> Scope
forall a. HasLoc a => a -> Scope
mkScope SrcSpanAnnA
span) (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))
 -> RScoped
      (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
-> Maybe
     (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
-> Maybe
     (RScoped
        (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (LDerivStrategy (GhcPass 'Renamed))
Maybe
  (GenLocated (EpAnn NoEpAnns) (DerivStrategy (GhcPass 'Renamed)))
strat)
        , Maybe (LocatedP OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (XRec (GhcPass 'Renamed) OverlapMode)
Maybe (LocatedP OverlapMode)
overlap
        ]

instance ToHie (LocatedA (FixitySig GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (FixitySig (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span FixitySig (GhcPass 'Renamed)
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FixitySig (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA FixitySig (GhcPass 'Renamed)
sig SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FixitySig (GhcPass 'Renamed)
sig of
      FixitySig XFixitySig (GhcPass 'Renamed)
_ [LIdP (GhcPass 'Renamed)]
vars Fixity
_ ->
        [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass 'Renamed)]
[LocatedN Name]
vars
        ]

instance ToHie (LocatedA (DefaultDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DefaultDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span DefaultDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DefaultDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DefaultDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DefaultDecl (GhcPass 'Renamed)
decl of
      DefaultDecl XCDefaultDecl (GhcPass 'Renamed)
_ Maybe (LIdP (GhcPass 'Renamed))
cl [LHsType (GhcPass 'Renamed)]
typs ->
        [ HieM [HieAST Type]
-> (LocatedN Name -> HieM [HieAST Type])
-> Maybe (LocatedN Name)
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) (Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> (LocatedN Name -> Context (LocatedN Name))
-> LocatedN Name
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Maybe (LIdP (GhcPass 'Renamed))
Maybe (LocatedN Name)
cl
        , [GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsType (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
typs
        ]

instance ToHie (LocatedA (ForeignDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ForeignDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span ForeignDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ForeignDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA ForeignDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ForeignDecl (GhcPass 'Renamed)
decl of
      ForeignImport {fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP (GhcPass 'Renamed)
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType (GhcPass 'Renamed)
sig, fd_fi :: forall pass. ForeignDecl pass -> ForeignImport pass
fd_fi = ForeignImport (GhcPass 'Renamed)
fi} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
RegularBind Scope
ModuleScope (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA -> Maybe Span
forall ann. EpAnn ann -> Maybe Span
getRealSpanA SrcSpanAnnA
span) LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
sig
        , ForeignImport (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignImport (GhcPass 'Renamed)
fi
        ]
      ForeignExport {fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP (GhcPass 'Renamed)
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType (GhcPass 'Renamed)
sig, fd_fe :: forall pass. ForeignDecl pass -> ForeignExport pass
fd_fe = ForeignExport (GhcPass 'Renamed)
fe} ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
name
        , TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
-> TScoped (GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsSigType (GhcPass 'Renamed))
sig
        , ForeignExport (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignExport (GhcPass 'Renamed)
fe
        ]

instance ToHie (ForeignImport GhcRn) where
  toHie :: ForeignImport (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (CImport (L EpaLocation' [LEpaComment]
c SourceText
_) (L EpaLocation' [LEpaComment]
a CCallConv
_) (L EpaLocation' [LEpaComment]
b Safety
_) Maybe Header
_ CImportSpec
_) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
a
    , EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
b
    , EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
c
    ]

instance ToHie (ForeignExport GhcRn) where
  toHie :: ForeignExport (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (CExport (L EpaLocation' [LEpaComment]
b SourceText
_) (L EpaLocation' [LEpaComment]
a CExportSpec
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
a
    , EpaLocation' [LEpaComment] -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
EpaLocation' [LEpaComment] -> ReaderT NodeOrigin m [HieAST a]
locOnlyE EpaLocation' [LEpaComment]
b
    ]

instance ToHie (LocatedA (WarnDecls GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (WarnDecls (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span WarnDecls (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ WarnDecls (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA WarnDecls (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecls (GhcPass 'Renamed)
decl of
      Warnings XWarnings (GhcPass 'Renamed)
_ [LWarnDecl (GhcPass 'Renamed)]
warnings ->
        [ [GenLocated SrcSpanAnnA (WarnDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LWarnDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (WarnDecl (GhcPass 'Renamed))]
warnings
        ]

instance ToHie (LocatedA (WarnDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (WarnDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span WarnDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ WarnDecl (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode WarnDecl (GhcPass 'Renamed)
decl (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecl (GhcPass 'Renamed)
decl of
      Warning XWarning (GhcPass 'Renamed)
_ [LIdP (GhcPass 'Renamed)]
vars WarningTxt (GhcPass 'Renamed)
_ ->
        [ [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (LocatedN Name)] -> HieM [HieAST Type])
-> [Context (LocatedN Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LocatedN Name -> Context (LocatedN Name))
-> [LocatedN Name] -> [Context (LocatedN Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [LIdP (GhcPass 'Renamed)]
[LocatedN Name]
vars
        ]

instance ToHie (LocatedA (AnnDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (AnnDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span AnnDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ AnnDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA AnnDecl (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case AnnDecl (GhcPass 'Renamed)
decl of
      HsAnnotation XHsAnnotation (GhcPass 'Renamed)
_ AnnProvenance (GhcPass 'Renamed)
prov LHsExpr (GhcPass 'Renamed)
expr ->
        [ AnnProvenance (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie AnnProvenance (GhcPass 'Renamed)
prov
        , LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
expr
        ]

instance ToHie (AnnProvenance GhcRn) where
  toHie :: AnnProvenance (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (ValueAnnProvenance LIdP (GhcPass 'Renamed)
a) = Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
a
  toHie (TypeAnnProvenance LIdP (GhcPass 'Renamed)
a) = Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use LIdP (GhcPass 'Renamed)
LocatedN Name
a
  toHie AnnProvenance (GhcPass 'Renamed)
ModuleAnnProvenance = [HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (LocatedA (RuleDecls GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (RuleDecls (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span RuleDecls (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RuleDecls (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RuleDecls (GhcPass 'Renamed)
decl SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleDecls (GhcPass 'Renamed)
decl of
      HsRules XCRuleDecls (GhcPass 'Renamed)
_ [LRuleDecl (GhcPass 'Renamed)]
rules ->
        [ [GenLocated SrcSpanAnnA (RuleDecl (GhcPass 'Renamed))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LRuleDecl (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (RuleDecl (GhcPass 'Renamed))]
rules
        ]

instance ToHie (LocatedA (RuleDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (RuleDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span r :: RuleDecl (GhcPass 'Renamed)
r@(HsRule XHsRule (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) FastString
rname Activation
_ Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass 'Renamed))]
tybndrs [LRuleBndr (GhcPass 'Renamed)]
bndrs LHsExpr (GhcPass 'Renamed)
exprA LHsExpr (GhcPass 'Renamed)
exprB)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
        [ RuleDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RuleDecl (GhcPass 'Renamed)
r SrcSpanAnnA
span
        , SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type]) -> SrcSpan -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ GenLocated (EpAnn NoEpAnns) FastString -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA XRec (GhcPass 'Renamed) FastString
GenLocated (EpAnn NoEpAnns) FastString
rname
        , Maybe
  [TVScoped
     (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe
   [TVScoped
      (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> Maybe
     [TVScoped
        (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))]
 -> [TVScoped
       (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))])
-> Maybe
     [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))]
-> Maybe
     [TVScoped
        (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed)))]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TyVarScope
-> Scope
-> [LHsTyVarBndr () (GhcPass 'Renamed)]
-> [TVScoped (LHsTyVarBndr () (GhcPass 'Renamed))]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope) Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass 'Renamed))]
Maybe [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass 'Renamed))]
tybndrs
        , [RScoped
   (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [RScoped
      (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))
 -> RScoped
      (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))))
-> [GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))]
-> [RScoped
      (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))
-> RScoped
     (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))
 -> RScoped
      (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))))
-> Scope
-> GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))
-> RScoped
     (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
forall a. HasLoc a => a -> Scope
mkScope (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span)) [LRuleBndr (GhcPass 'Renamed)]
[GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))]
bndrs
        , LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
exprA
        , LocatedA (HsExpr (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
exprB
        ]
    where scope :: Scope
scope = Scope
bndrs_sc Scope -> Scope -> Scope
`combineScopes` Scope
exprA_sc Scope -> Scope -> Scope
`combineScopes` Scope
exprB_sc
          bndrs_sc :: Scope
bndrs_sc = Scope
-> (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))
    -> Scope)
-> Maybe
     (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope ([GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))]
-> Maybe
     (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))
forall a. [a] -> Maybe a
listToMaybe [LRuleBndr (GhcPass 'Renamed)]
[GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed))]
bndrs)
          exprA_sc :: Scope
exprA_sc = LocatedA (HsExpr (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
exprA
          exprB_sc :: Scope
exprB_sc = LocatedA (HsExpr (GhcPass 'Renamed)) -> Scope
forall a. HasLoc a => a -> Scope
mkScope LHsExpr (GhcPass 'Renamed)
LocatedA (HsExpr (GhcPass 'Renamed))
exprB

instance ToHie (RScoped (LocatedAn NoEpAnns (RuleBndr GhcRn))) where
  toHie :: RScoped (GenLocated (EpAnn NoEpAnns) (RuleBndr (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (RS Scope
sc (L EpAnn NoEpAnns
span RuleBndr (GhcPass 'Renamed)
bndr)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RuleBndr (GhcPass 'Renamed) -> EpAnn NoEpAnns -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA RuleBndr (GhcPass 'Renamed)
bndr EpAnn NoEpAnns
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleBndr (GhcPass 'Renamed)
bndr of
      RuleBndr XCRuleBndr (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
var ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe Span
forall a. Maybe a
Nothing) LIdP (GhcPass 'Renamed)
LocatedN Name
var
        ]
      RuleBndrSig XRuleBndrSig (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
var HsPatSigType (GhcPass 'Renamed)
typ ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (BindType -> Scope -> Maybe Span -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe Span
forall a. Maybe a
Nothing) LIdP (GhcPass 'Renamed)
LocatedN Name
var
        , TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type])
-> TScoped (HsPatSigType (GhcPass 'Renamed)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsPatSigType (GhcPass 'Renamed)
-> TScoped (HsPatSigType (GhcPass 'Renamed))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
sc]) HsPatSigType (GhcPass 'Renamed)
typ
        ]

instance ToHie (LocatedA (ImportDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (ImportDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span ImportDecl (GhcPass 'Renamed)
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ImportDecl (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ImportDecl (GhcPass 'Renamed)
decl (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ImportDecl (GhcPass 'Renamed)
decl of
      ImportDecl { ideclName :: forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName = XRec (GhcPass 'Renamed) ModuleName
name, ideclAs :: forall pass. ImportDecl pass -> Maybe (XRec pass ModuleName)
ideclAs = Maybe (XRec (GhcPass 'Renamed) ModuleName)
as, ideclImportList :: forall pass.
ImportDecl pass
-> Maybe (ImportListInterpretation, XRec pass [LIE pass])
ideclImportList = Maybe
  (ImportListInterpretation,
   XRec (GhcPass 'Renamed) [LIE (GhcPass 'Renamed)])
hidden } ->
        [ IEContext (GenLocated SrcSpanAnnA ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA ModuleName)
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
Import XRec (GhcPass 'Renamed) ModuleName
GenLocated SrcSpanAnnA ModuleName
name
        , Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
 -> HieM [HieAST Type])
-> Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA ModuleName
 -> IEContext (GenLocated SrcSpanAnnA ModuleName))
-> Maybe (GenLocated SrcSpanAnnA ModuleName)
-> Maybe (IEContext (GenLocated SrcSpanAnnA ModuleName))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
ImportAs) Maybe (XRec (GhcPass 'Renamed) ModuleName)
Maybe (GenLocated SrcSpanAnnA ModuleName)
as
        , HieM [HieAST Type]
-> ((ImportListInterpretation,
     GenLocated
       SrcSpanAnnLI [GenLocated SrcSpanAnnA (IE (GhcPass 'Renamed))])
    -> HieM [HieAST Type])
-> Maybe
     (ImportListInterpretation,
      GenLocated
        SrcSpanAnnLI [GenLocated SrcSpanAnnA (IE (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([HieAST Type] -> HieM [HieAST Type]
forall a. a -> ReaderT NodeOrigin (State HieState) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []) (ImportListInterpretation,
 GenLocated
   SrcSpanAnnLI [GenLocated SrcSpanAnnA (IE (GhcPass 'Renamed))])
-> HieM [HieAST Type]
forall {a} {a}.
(HasLoc a, ToHie (IEContext a)) =>
(ImportListInterpretation, GenLocated a [a]) -> HieM [HieAST Type]
goIE Maybe
  (ImportListInterpretation,
   XRec (GhcPass 'Renamed) [LIE (GhcPass 'Renamed)])
Maybe
  (ImportListInterpretation,
   GenLocated
     SrcSpanAnnLI [GenLocated SrcSpanAnnA (IE (GhcPass 'Renamed))])
hidden
        ]
    where
      goIE :: (ImportListInterpretation, GenLocated a [a]) -> HieM [HieAST Type]
goIE (ImportListInterpretation
hiding, (L a
sp [a]
liens)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA a
sp)
        , [IEContext a] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext a] -> HieM [HieAST Type])
-> [IEContext a] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (a -> IEContext a) -> [a] -> [IEContext a]
forall a b. (a -> b) -> [a] -> [b]
map (IEType -> a -> IEContext a
forall a. IEType -> a -> IEContext a
IEC IEType
c) [a]
liens
        ]
        where
         -- ROMES:TODO: I notice some overlap here with Iface types, eventually
         -- we could join these
         c :: IEType
c = case ImportListInterpretation
hiding of
               ImportListInterpretation
Exactly -> IEType
Import
               ImportListInterpretation
EverythingBut -> IEType
ImportHiding


instance ToHie (IEContext (LocatedA (IE GhcRn))) where
  toHie :: IEContext (GenLocated SrcSpanAnnA (IE (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpanAnnA
span IE (GhcPass 'Renamed)
ie)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IE (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode IE (GhcPass 'Renamed)
ie (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
span) HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IE (GhcPass 'Renamed)
ie of
      IEVar XIEVar (GhcPass 'Renamed)
_ LIEWrappedName (GhcPass 'Renamed)
n Maybe (LHsDoc (GhcPass 'Renamed))
_ ->
        [ IEContext
  (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext
   (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
n
        ]
      IEThingAbs XIEThingAbs (GhcPass 'Renamed)
_ LIEWrappedName (GhcPass 'Renamed)
n Maybe (LHsDoc (GhcPass 'Renamed))
_ ->
        [ IEContext
  (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext
   (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
n
        ]
      IEThingAll XIEThingAll (GhcPass 'Renamed)
_ LIEWrappedName (GhcPass 'Renamed)
n Maybe (LHsDoc (GhcPass 'Renamed))
_ ->
        [ IEContext
  (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext
   (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
n
        ]
      IEThingWith XIEThingWith (GhcPass 'Renamed)
_ LIEWrappedName (GhcPass 'Renamed)
n IEWildcard
_ [LIEWrappedName (GhcPass 'Renamed)]
ns Maybe (LHsDoc (GhcPass 'Renamed))
_ ->
        [ IEContext
  (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext
   (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
 -> HieM [HieAST Type])
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
n
        , [IEContext
   (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext
    (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))]
 -> HieM [HieAST Type])
-> [IEContext
      (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
 -> IEContext
      (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))]
-> [IEContext
      (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))]
forall a b. (a -> b) -> [a] -> [b]
map (IEType
-> GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))
-> IEContext
     (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
forall a. IEType -> a -> IEContext a
IEC IEType
c) [LIEWrappedName (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed))]
ns
        ]
      IEModuleContents XIEModuleContents (GhcPass 'Renamed)
_ XRec (GhcPass 'Renamed) ModuleName
n ->
        [ IEContext (GenLocated SrcSpanAnnA ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (GenLocated SrcSpanAnnA ModuleName)
 -> HieM [HieAST Type])
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType
-> GenLocated SrcSpanAnnA ModuleName
-> IEContext (GenLocated SrcSpanAnnA ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
c XRec (GhcPass 'Renamed) ModuleName
GenLocated SrcSpanAnnA ModuleName
n
        ]
      IEGroup XIEGroup (GhcPass 'Renamed)
_ TypeIndex
_ LHsDoc (GhcPass 'Renamed)
d -> [LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
d]
      IEDoc XIEDoc (GhcPass 'Renamed)
_ LHsDoc (GhcPass 'Renamed)
d -> [LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
d]
      IEDocNamed XIEDocNamed (GhcPass 'Renamed)
_ FilePath
_ -> []

instance ToHie (IEContext (LocatedA (IEWrappedName GhcRn))) where
  toHie :: IEContext
  (GenLocated SrcSpanAnnA (IEWrappedName (GhcPass 'Renamed)))
-> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpanAnnA
span IEWrappedName (GhcPass 'Renamed)
iewn)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEWrappedName (GhcPass 'Renamed)
-> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA IEWrappedName (GhcPass 'Renamed)
iewn SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IEWrappedName (GhcPass 'Renamed)
iewn of
      IEDefault XIEDefault (GhcPass 'Renamed)
_ (L SrcSpanAnnN
l Name
p) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
p)
        ]
      IEName XIEName (GhcPass 'Renamed)
_ (L SrcSpanAnnN
l Name
n) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
n)
        ]
      IEPattern XIEPattern (GhcPass 'Renamed)
_ (L SrcSpanAnnN
l Name
p) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
p)
        ]
      IEType XIEType (GhcPass 'Renamed)
_ (L SrcSpanAnnN
l Name
n) ->
        [ Context (LocatedN Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (LocatedN Name) -> HieM [HieAST Type])
-> Context (LocatedN Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> LocatedN Name -> Context (LocatedN Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (SrcSpanAnnN -> Name -> LocatedN Name
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l Name
n)
        ]

instance ToHie (IEContext (Located RecFieldInfo)) where
  toHie :: IEContext (Located RecFieldInfo) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span RecFieldInfo
info)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ RecFieldInfo -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode RecFieldInfo
info SrcSpan
span
      , Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
span (FieldLabel -> Name
flSelector (FieldLabel -> Name) -> FieldLabel -> Name
forall a b. (a -> b) -> a -> b
$ RecFieldInfo -> FieldLabel
recFieldLabel RecFieldInfo
info)
      ]

instance ToHie (LocatedA (DocDecl GhcRn)) where
  toHie :: GenLocated SrcSpanAnnA (DocDecl (GhcPass 'Renamed))
-> HieM [HieAST Type]
toHie (L SrcSpanAnnA
span DocDecl (GhcPass 'Renamed)
d) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DocDecl (GhcPass 'Renamed) -> SrcSpanAnnA -> HieM [HieAST Type]
forall (m :: * -> *) a ann b.
(Monad m, Data a) =>
a -> EpAnn ann -> ReaderT NodeOrigin m [HieAST b]
makeNodeA DocDecl (GhcPass 'Renamed)
d SrcSpanAnnA
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DocDecl (GhcPass 'Renamed)
d of
    DocCommentNext LHsDoc (GhcPass 'Renamed)
d -> [ LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
d ]
    DocCommentPrev LHsDoc (GhcPass 'Renamed)
d -> [ LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
d ]
    DocCommentNamed FilePath
_ LHsDoc (GhcPass 'Renamed)
d -> [ LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
d ]
    DocGroup TypeIndex
_ LHsDoc (GhcPass 'Renamed)
d -> [ LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsDoc (GhcPass 'Renamed)
d ]

instance ToHie (LHsDoc GhcRn) where
  toHie :: LHsDoc (GhcPass 'Renamed) -> HieM [HieAST Type]
toHie (L SrcSpan
span d :: HsDoc (GhcPass 'Renamed)
d@(WithHsDocIdentifiers HsDocString
_ [Located (IdP (GhcPass 'Renamed))]
ids)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsDoc (GhcPass 'Renamed) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsDoc (GhcPass 'Renamed)
d SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: [[Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdP (GhcPass 'Renamed))]
[Located Name]
ids]