{-
Main functions for .hie file generation
-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

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

import GHC.Utils.Outputable(ppr)

import GHC.Prelude

import GHC.Types.Avail            ( Avails )
import GHC.Data.Bag               ( Bag, bagToList )
import GHC.Types.Basic
import GHC.Data.BooleanFormula
import GHC.Core.Class             ( FunDep, className, classSCSelIds )
import GHC.Core.Utils             ( exprType )
import GHC.Core.ConLike           ( conLikeName, ConLike(RealDataCon) )
import GHC.Core.TyCon             ( TyCon, tyConClass_maybe )
import GHC.Core.FVs
import GHC.Core.DataCon           ( dataConNonlinearType )
import GHC.HsToCore               ( deSugarExpr )
import GHC.Types.FieldLabel
import GHC.Hs
import GHC.Driver.Types
import GHC.Unit.Module            ( ModuleName, ml_hs_file )
import GHC.Utils.Monad            ( concatMapM, liftIO )
import GHC.Types.Id               ( isDataConId_maybe )
import GHC.Types.Name             ( Name, nameSrcSpan, nameUnique )
import GHC.Types.Name.Env         ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv )
import GHC.Types.SrcLoc
import GHC.Tc.Utils.Zonk          ( hsLitType, hsPatType )
import GHC.Core.Type              ( mkVisFunTys, Type )
import GHC.Core.Predicate
import GHC.Core.InstEnv
import GHC.Builtin.Types          ( mkListTy, mkSumTy )
import GHC.Tc.Types
import GHC.Tc.Types.Evidence
import GHC.Types.Var              ( Id, Var, EvId, varName, setVarName, varType, varUnique )
import GHC.Types.Var.Env
import GHC.Types.Unique
import GHC.Iface.Make             ( mkIfaceExports )
import GHC.Utils.Panic
import GHC.Data.Maybe
import GHC.Data.FastString

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

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.List                  ( foldl1' )
import Control.Monad              ( forM_ )
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Class  ( lift )

{- 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 are 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
        ]
      HsConLikeOut _ con ->
        [ toHie $ C Use $ L mspan $ conLikeName con
        ]
      ...
      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 LHsDocString )
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.
  }

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)
  StateT HieState Hsc () -> HieM ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateT HieState Hsc () -> HieM ())
-> StateT HieState Hsc () -> HieM ()
forall a b. (a -> b) -> a -> b
$ (HieState -> HieState) -> StateT HieState Hsc ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' ((HieState -> HieState) -> StateT HieState Hsc ())
-> (HieState -> HieState) -> StateT HieState Hsc ()
forall a b. (a -> b) -> a -> b
$ \HieState
s ->
    HieState
s { unlocated_ev_binds :: VarMap (Set ContextInfo)
unlocated_ev_binds =
          ((Id, Set ContextInfo)
 -> (Id, Set ContextInfo) -> (Id, Set ContextInfo))
-> VarMap (Set ContextInfo)
-> Id
-> (Id, Set ContextInfo)
-> VarMap (Set ContextInfo)
forall a. (a -> a -> a) -> DVarEnv a -> Id -> a -> DVarEnv a
extendDVarEnv_C (Id, Set ContextInfo)
-> (Id, Set ContextInfo) -> (Id, Set ContextInfo)
forall {a} {a} {a}. Ord a => (a, Set a) -> (a, Set a) -> (a, Set a)
go (HieState -> VarMap (Set ContextInfo)
unlocated_ev_binds HieState
s)
                          Id
var (Id
var,ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
ci)
      }

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

      mkNodeInfo :: (Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
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 :: (Id, Set ContextInfo)
-> ([(Either ModuleName Name, IdentifierDetails Type)],
    [HieAST Type])
-> ([(Either ModuleName Name, IdentifierDetails Type)],
    [HieAST Type])
go e :: (Id, Set ContextInfo)
e@(Id
v,Set ContextInfo
_) ([(Either ModuleName Name, 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 (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Monoid a => a
mempty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$ [(Either ModuleName Name, IdentifierDetails Type)]
-> NodeIdentifiers Type
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(Id, Set ContextInfo)
-> (Either ModuleName Name, IdentifierDetails Type)
forall {a}.
(Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
mkNodeInfo (Id, Set ContextInfo)
e]
              in ([(Either ModuleName Name, IdentifierDetails Type)]
xs,HieAST Type
nodeHieAST Type -> [HieAST Type] -> [HieAST Type]
forall a. a -> [a] -> [a]
:[HieAST Type]
ys)
        SrcSpan
_ -> ((Id, Set ContextInfo)
-> (Either ModuleName Name, IdentifierDetails Type)
forall {a}.
(Id, Set ContextInfo) -> (Either a Name, IdentifierDetails Type)
mkNodeInfo (Id, Set ContextInfo)
e (Either ModuleName Name, IdentifierDetails Type)
-> [(Either ModuleName Name, IdentifierDetails Type)]
-> [(Either ModuleName Name, IdentifierDetails Type)]
forall a. a -> [a] -> [a]
: [(Either ModuleName Name, IdentifierDetails Type)]
xs,[HieAST Type]
ys)

      ([(Either ModuleName Name, IdentifierDetails Type)]
nis,[HieAST Type]
asts) = ((Id, Set ContextInfo)
 -> ([(Either ModuleName Name, IdentifierDetails Type)],
     [HieAST Type])
 -> ([(Either ModuleName Name, IdentifierDetails Type)],
     [HieAST Type]))
-> ([(Either ModuleName Name, IdentifierDetails Type)],
    [HieAST Type])
-> [(Id, Set ContextInfo)]
-> ([(Either ModuleName Name, IdentifierDetails Type)],
    [HieAST Type])
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Id, Set ContextInfo)
-> ([(Either ModuleName Name, IdentifierDetails Type)],
    [HieAST Type])
-> ([(Either ModuleName Name, IdentifierDetails Type)],
    [HieAST Type])
go ([],[]) [(Id, Set ContextInfo)]
elts

  (NodeIdentifiers Type, [HieAST Type])
-> HieM (NodeIdentifiers Type, [HieAST Type])
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((NodeIdentifiers Type, [HieAST Type])
 -> HieM (NodeIdentifiers Type, [HieAST Type]))
-> (NodeIdentifiers Type, [HieAST Type])
-> HieM (NodeIdentifiers Type, [HieAST Type])
forall a b. (a -> b) -> a -> b
$ ([(Either ModuleName Name, IdentifierDetails Type)]
-> NodeIdentifiers Type
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(Either ModuleName Name, IdentifierDetails Type)]
nis, [HieAST Type]
asts)

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

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 :: NameEnv Id
name_remapping = NameEnv Id -> Name -> Id -> NameEnv Id
forall a. NameEnv a -> Name -> a -> NameEnv a
extendNameEnv (HieState -> NameEnv Id
name_remapping HieState
hs) (Id -> Name
varName Id
mono) Id
poly}

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

type HieM = ReaderT NodeOrigin (StateT HieState Hsc)

-- | Construct an 'HieFile' from the outputs of the typechecker.
mkHieFile :: ModSummary
          -> TcGblEnv
          -> RenamedSource -> Hsc HieFile
mkHieFile :: ModSummary -> TcGblEnv -> RenamedSource -> Hsc HieFile
mkHieFile ModSummary
ms TcGblEnv
ts RenamedSource
rs = do
  let src_file :: FilePath
src_file = FilePath -> Maybe FilePath -> FilePath
forall a. HasCallStack => 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)
  ByteString
src <- IO ByteString -> Hsc ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> Hsc ByteString)
-> IO ByteString -> Hsc ByteString
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ByteString
BS.readFile FilePath
src_file
  FilePath
-> ByteString
-> ModSummary
-> TcGblEnv
-> RenamedSource
-> Hsc HieFile
mkHieFileWithSource FilePath
src_file ByteString
src ModSummary
ms TcGblEnv
ts RenamedSource
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 -> Hsc HieFile
mkHieFileWithSource :: FilePath
-> ByteString
-> ModSummary
-> TcGblEnv
-> RenamedSource
-> Hsc HieFile
mkHieFileWithSource FilePath
src_file ByteString
src ModSummary
ms TcGblEnv
ts RenamedSource
rs = do
  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
      tcs :: [TyCon]
tcs = TcGblEnv -> [TyCon]
tcg_tcs TcGblEnv
ts
  (HieASTs TypeIndex
asts', Array TypeIndex HieTypeFlat
arr) <- LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> Hsc (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
getCompressedAsts LHsBinds GhcTc
tc_binds RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs
  HieFile -> Hsc HieFile
forall (m :: * -> *) a. Monad m => a -> m a
return (HieFile -> Hsc HieFile) -> HieFile -> Hsc HieFile
forall a b. (a -> b) -> a -> b
$ HieFile :: FilePath
-> Module
-> Array TypeIndex HieTypeFlat
-> HieASTs TypeIndex
-> [AvailInfo]
-> ByteString
-> HieFile
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
      }

getCompressedAsts :: TypecheckedSource -> RenamedSource -> Bag EvBind -> [ClsInst] -> [TyCon]
  -> Hsc (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat)
getCompressedAsts :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> Hsc (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
getCompressedAsts LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs = do
  HieASTs Type
asts <- LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> Hsc (HieASTs Type)
enrichHie LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs
  (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
-> Hsc (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
forall (m :: * -> *) a. Monad m => a -> m a
return ((HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
 -> Hsc (HieASTs TypeIndex, Array TypeIndex HieTypeFlat))
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
-> Hsc (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
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]
  -> Hsc (HieASTs Type)
enrichHie :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> Hsc (HieASTs Type)
enrichHie LHsBinds GhcTc
ts (HsGroup GhcRn
hsGrp, [GenLocated SrcSpan (ImportDecl GhcRn)]
imports, Maybe [(LIE GhcRn, [AvailInfo])]
exports, Maybe LHsDocString
_) Bag EvBind
ev_bs [ClsInst]
insts [TyCon]
tcs =
  (StateT HieState Hsc (HieASTs Type)
 -> HieState -> Hsc (HieASTs Type))
-> HieState
-> StateT HieState Hsc (HieASTs Type)
-> Hsc (HieASTs Type)
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT HieState Hsc (HieASTs Type)
-> HieState -> Hsc (HieASTs Type)
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT HieState
initState (StateT HieState Hsc (HieASTs Type) -> Hsc (HieASTs Type))
-> StateT HieState Hsc (HieASTs Type) -> Hsc (HieASTs Type)
forall a b. (a -> b) -> a -> b
$ (ReaderT NodeOrigin (StateT HieState Hsc) (HieASTs Type)
 -> NodeOrigin -> StateT HieState Hsc (HieASTs Type))
-> NodeOrigin
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieASTs Type)
-> StateT HieState Hsc (HieASTs Type)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT NodeOrigin (StateT HieState Hsc) (HieASTs Type)
-> NodeOrigin -> StateT HieState Hsc (HieASTs Type)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT NodeOrigin
SourceInfo (ReaderT NodeOrigin (StateT HieState Hsc) (HieASTs Type)
 -> StateT HieState Hsc (HieASTs Type))
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieASTs Type)
-> StateT HieState Hsc (HieASTs Type)
forall a b. (a -> b) -> a -> b
$ do
    [HieAST Type]
tasts <- Bag (BindContext (LHsBindLR GhcTc GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBindLR GhcTc GhcTc)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBindLR GhcTc GhcTc)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBindLR GhcTc GhcTc -> BindContext (LHsBindLR GhcTc GhcTc))
-> LHsBinds GhcTc -> Bag (BindContext (LHsBindLR GhcTc GhcTc))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> LHsBindLR GhcTc GhcTc
-> BindContext (LHsBindLR GhcTc GhcTc)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
ModuleScope) LHsBinds GhcTc
ts
    [HieAST Type]
rasts <- HsGroup GhcRn -> HieM [HieAST Type]
forall {p}.
(ToHie (GenLocated SrcSpan (SpliceDecl p)),
 ToHie (GenLocated SrcSpan (DerivDecl p)),
 ToHie (GenLocated SrcSpan (FixitySig p)),
 ToHie (GenLocated SrcSpan (DefaultDecl p)),
 ToHie (GenLocated SrcSpan (ForeignDecl p)),
 ToHie (GenLocated SrcSpan (WarnDecls p)),
 ToHie (GenLocated SrcSpan (AnnDecl p)),
 ToHie (GenLocated SrcSpan (RuleDecls p)),
 ToHie (RScoped (HsValBinds p)), ToHie (TyClGroup p)) =>
HsGroup p -> HieM [HieAST Type]
processGrp HsGroup GhcRn
hsGrp
    [HieAST Type]
imps <- [GenLocated SrcSpan (ImportDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (ImportDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (ImportDecl GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpan (ImportDecl GhcRn) -> Bool)
-> [GenLocated SrcSpan (ImportDecl GhcRn)]
-> [GenLocated SrcSpan (ImportDecl GhcRn)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> (GenLocated SrcSpan (ImportDecl GhcRn) -> Bool)
-> GenLocated SrcSpan (ImportDecl GhcRn)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImportDecl GhcRn -> Bool
forall pass. ImportDecl pass -> Bool
ideclImplicit (ImportDecl GhcRn -> Bool)
-> (GenLocated SrcSpan (ImportDecl GhcRn) -> ImportDecl GhcRn)
-> GenLocated SrcSpan (ImportDecl GhcRn)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (ImportDecl GhcRn) -> ImportDecl GhcRn
forall l e. GenLocated l e -> e
unLoc) [GenLocated SrcSpan (ImportDecl GhcRn)]
imports
    [HieAST Type]
exps <- Maybe [IEContext (LIE GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [IEContext (LIE GhcRn)] -> HieM [HieAST Type])
-> Maybe [IEContext (LIE GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([(LIE GhcRn, [AvailInfo])] -> [IEContext (LIE GhcRn)])
-> Maybe [(LIE GhcRn, [AvailInfo])]
-> Maybe [IEContext (LIE GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((LIE GhcRn, [AvailInfo]) -> IEContext (LIE GhcRn))
-> [(LIE GhcRn, [AvailInfo])] -> [IEContext (LIE GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (((LIE GhcRn, [AvailInfo]) -> IEContext (LIE GhcRn))
 -> [(LIE GhcRn, [AvailInfo])] -> [IEContext (LIE GhcRn)])
-> ((LIE GhcRn, [AvailInfo]) -> IEContext (LIE GhcRn))
-> [(LIE GhcRn, [AvailInfo])]
-> [IEContext (LIE GhcRn)]
forall a b. (a -> b) -> a -> b
$ IEType -> LIE GhcRn -> IEContext (LIE GhcRn)
forall a. IEType -> a -> IEContext a
IEC IEType
Export (LIE GhcRn -> IEContext (LIE GhcRn))
-> ((LIE GhcRn, [AvailInfo]) -> LIE GhcRn)
-> (LIE GhcRn, [AvailInfo])
-> IEContext (LIE GhcRn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LIE GhcRn, [AvailInfo]) -> LIE GhcRn
forall a b. (a, b) -> a
fst) Maybe [(LIE GhcRn, [AvailInfo])]
exports
    -- Add Instance bindings
    [ClsInst] -> (ClsInst -> HieM ()) -> HieM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [ClsInst]
insts ((ClsInst -> HieM ()) -> HieM ())
-> (ClsInst -> HieM ()) -> HieM ()
forall a b. (a -> b) -> a -> b
$ \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
    [TyCon] -> (TyCon -> HieM ()) -> HieM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [TyCon]
tcs ((TyCon -> HieM ()) -> HieM ()) -> (TyCon -> HieM ()) -> HieM ()
forall a b. (a -> b) -> a -> b
$ \TyCon
tc ->
      case TyCon -> Maybe Class
tyConClass_maybe TyCon
tc of
        Maybe Class
Nothing -> () -> HieM ()
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 -> [HieAST a] -> Span
spanFile FastString
file [HieAST a]
children = case [HieAST a]
children of
          [] -> RealSrcLoc -> Span
realSrcLocSpan (FastString -> TypeIndex -> TypeIndex -> RealSrcLoc
mkRealSrcLoc FastString
file TypeIndex
1 TypeIndex
1)
          [HieAST a]
_ -> 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 (HieAST a -> Span) -> HieAST a -> Span
forall a b. (a -> b) -> a -> b
$ [HieAST a] -> HieAST a
forall a. [a] -> a
head [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 (HieAST a -> Span) -> HieAST a -> Span
forall a b. (a -> b) -> a -> b
$ [HieAST a] -> HieAST a
forall a. [a] -> a
last [HieAST a]
children)

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

        modulify :: FastString
-> [HieAST Type]
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type)
modulify FastString
file [HieAST Type]
xs' = do

          [HieAST Type]
top_ev_asts <-
            EvBindContext (GenLocated SrcSpan TcEvBinds) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpan TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
ModuleScope Maybe Span
forall a. Maybe a
Nothing
                  (GenLocated SrcSpan TcEvBinds
 -> EvBindContext (GenLocated SrcSpan TcEvBinds))
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> TcEvBinds -> GenLocated SrcSpan TcEvBinds
forall l e. l -> e -> GenLocated l e
L (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
Nothing)
                  (TcEvBinds -> GenLocated SrcSpan TcEvBinds)
-> TcEvBinds -> GenLocated SrcSpan TcEvBinds
forall a b. (a -> b) -> a -> b
$ Bag EvBind -> TcEvBinds
EvBinds Bag EvBind
ev_bs

          (NodeIdentifiers Type
uloc_evs,[HieAST Type]
more_ev_asts) <- FastString -> HieM (NodeIdentifiers Type, [HieAST Type])
getUnlocatedEvBinds FastString
file

          let xs :: [HieAST Type]
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 :: Span
span = FastString -> [HieAST Type] -> Span
forall {a}. FastString -> [HieAST a] -> Span
spanFile FastString
file [HieAST Type]
xs

              moduleInfo :: SourcedNodeInfo Type
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 :: NodeIdentifiers Type
nodeIdentifiers = NodeIdentifiers Type
uloc_evs}

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

          case [HieAST Type] -> [HieAST Type]
mergeSortAsts ([HieAST Type] -> [HieAST Type]) -> [HieAST Type] -> [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HieAST Type
moduleNode HieAST Type -> [HieAST Type] -> [HieAST Type]
forall a. a -> [a] -> [a]
: [HieAST Type]
xs of
            [HieAST Type
x] -> HieAST Type
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type)
forall (m :: * -> *) a. Monad m => a -> m a
return HieAST Type
x
            [HieAST Type]
xs -> FilePath
-> SDoc -> ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type)
forall a. FilePath -> SDoc -> a
panicDoc FilePath
"enrichHie: mergeSortAsts returned 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)

    Map FastString (HieAST Type)
asts' <- Map
  FastString (ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type))
-> ReaderT
     NodeOrigin (StateT HieState Hsc) (Map FastString (HieAST Type))
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
          (Map
   FastString (ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type))
 -> ReaderT
      NodeOrigin (StateT HieState Hsc) (Map FastString (HieAST Type)))
-> Map
     FastString (ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type))
-> ReaderT
     NodeOrigin (StateT HieState Hsc) (Map FastString (HieAST Type))
forall a b. (a -> b) -> a -> b
$ (FastString
 -> [HieAST Type]
 -> ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type))
-> Map FastString [HieAST Type]
-> Map
     FastString (ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type))
forall k a b. (k -> a -> b) -> Map k a -> Map k b
M.mapWithKey FastString
-> [HieAST Type]
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type)
modulify
          (Map FastString [HieAST Type]
 -> Map
      FastString
      (ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type)))
-> Map FastString [HieAST Type]
-> Map
     FastString (ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type))
forall a b. (a -> b) -> a -> b
$ ([HieAST Type] -> [HieAST Type] -> [HieAST Type])
-> [(FastString, [HieAST Type])] -> Map FastString [HieAST Type]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
M.fromListWith [HieAST Type] -> [HieAST Type] -> [HieAST Type]
forall a. [a] -> [a] -> [a]
(++)
          ([(FastString, [HieAST Type])] -> Map FastString [HieAST Type])
-> [(FastString, [HieAST Type])] -> Map FastString [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HieAST Type -> (FastString, [HieAST Type]))
-> [HieAST Type] -> [(FastString, [HieAST Type])]
forall a b. (a -> b) -> [a] -> [b]
map (\HieAST Type
x -> (Span -> FastString
srcSpanFile (HieAST Type -> Span
forall a. HieAST a -> Span
nodeSpan HieAST Type
x),[HieAST Type
x])) [HieAST Type]
flat_asts

    let asts :: HieASTs Type
asts = Map FastString (HieAST Type) -> HieASTs Type
forall a. Map FastString (HieAST a) -> HieASTs a
HieASTs (Map FastString (HieAST Type) -> HieASTs Type)
-> Map FastString (HieAST Type) -> HieASTs Type
forall a b. (a -> b) -> a -> b
$ Map FastString (HieAST Type) -> Map FastString (HieAST Type)
forall a. Map FastString (HieAST a) -> Map FastString (HieAST a)
resolveTyVarScopes Map FastString (HieAST Type)
asts'
    HieASTs Type
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieASTs Type)
forall (m :: * -> *) a. Monad m => a -> m a
return HieASTs Type
asts
  where
    processGrp :: HsGroup p -> HieM [HieAST Type]
processGrp HsGroup p
grp = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
      [ RScoped (HsValBinds p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (HsValBinds p) -> HieM [HieAST Type])
-> RScoped (HsValBinds p) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HsValBinds p -> RScoped (HsValBinds p))
-> (HsGroup p -> HsValBinds p)
-> HsGroup p
-> RScoped (HsValBinds p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Scope -> HsValBinds p -> RScoped (HsValBinds p)
forall a. Scope -> a -> RScoped a
RS Scope
ModuleScope ) HsGroup p -> HsValBinds p
forall p. HsGroup p -> HsValBinds p
hs_valds HsGroup p
grp
      , [GenLocated SrcSpan (SpliceDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (SpliceDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (SpliceDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (SpliceDecl p)]
forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds HsGroup p
grp
      , [TyClGroup p] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TyClGroup p] -> HieM [HieAST Type])
-> [TyClGroup p] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [TyClGroup p]
forall p. HsGroup p -> [TyClGroup p]
hs_tyclds HsGroup p
grp
      , [GenLocated SrcSpan (DerivDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (DerivDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DerivDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (DerivDecl p)]
forall p. HsGroup p -> [LDerivDecl p]
hs_derivds HsGroup p
grp
      , [GenLocated SrcSpan (FixitySig p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (FixitySig p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (FixitySig p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (FixitySig p)]
forall p. HsGroup p -> [LFixitySig p]
hs_fixds HsGroup p
grp
      , [GenLocated SrcSpan (DefaultDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (DefaultDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DefaultDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (DefaultDecl p)]
forall p. HsGroup p -> [LDefaultDecl p]
hs_defds HsGroup p
grp
      , [GenLocated SrcSpan (ForeignDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (ForeignDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (ForeignDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (ForeignDecl p)]
forall p. HsGroup p -> [LForeignDecl p]
hs_fords HsGroup p
grp
      , [GenLocated SrcSpan (WarnDecls p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (WarnDecls p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (WarnDecls p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (WarnDecls p)]
forall p. HsGroup p -> [LWarnDecls p]
hs_warnds HsGroup p
grp
      , [GenLocated SrcSpan (AnnDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (AnnDecl p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (AnnDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (AnnDecl p)]
forall p. HsGroup p -> [LAnnDecl p]
hs_annds HsGroup p
grp
      , [GenLocated SrcSpan (RuleDecls p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (RuleDecls p)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (RuleDecls p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [GenLocated SrcSpan (RuleDecls p)]
forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds HsGroup p
grp
      ]

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 :: GRHSs p body -> SrcSpan
grhss_span :: forall p body. GRHSs p body -> SrcSpan
grhss_span (GRHSs XCGRHSs p body
_ [LGRHS p body]
xs LHsLocalBinds p
bs) = (SrcSpan -> SrcSpan -> SrcSpan) -> SrcSpan -> [SrcSpan] -> SrcSpan
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans (LHsLocalBinds p -> SrcSpan
forall l e. GenLocated l e -> l
getLoc LHsLocalBinds p
bs) ((LGRHS p body -> SrcSpan) -> [LGRHS p body] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map LGRHS p body -> SrcSpan
forall l e. GenLocated l e -> l
getLoc [LGRHS p body]
xs)
grhss_span (XGRHSs XXGRHSs p body
_) = FilePath -> SrcSpan
forall a. FilePath -> a
panic FilePath
"XGRHS has no span"

bindingsOnly :: [Context Name] -> HieM [HieAST a]
bindingsOnly :: forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [] = [HieAST a] -> ReaderT NodeOrigin (StateT HieState Hsc) [HieAST a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
bindingsOnly (C ContextInfo
c Name
n : [Context Name]
xs) = do
  NodeOrigin
org <- ReaderT NodeOrigin (StateT HieState Hsc) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
  [HieAST a]
rest <- [Context Name]
-> ReaderT NodeOrigin (StateT HieState Hsc) [HieAST a]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [Context Name]
xs
  [HieAST a] -> ReaderT NodeOrigin (StateT HieState Hsc) [HieAST a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST a] -> ReaderT NodeOrigin (StateT HieState Hsc) [HieAST a])
-> [HieAST a]
-> ReaderT NodeOrigin (StateT HieState Hsc) [HieAST a]
forall a b. (a -> b) -> a -> b
$ case Name -> SrcSpan
nameSrcSpan Name
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 (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] (Either ModuleName Name -> IdentifierDetails a -> NodeIdentifiers a
forall k a. k -> a -> Map k a
M.singleton (Name -> Either ModuleName Name
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 :: Set ContextInfo
identInfo = ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
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)
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, 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 -> DataType
PScoped a -> Constr
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
forall {a}. Data a => Typeable (PScoped a)
forall a. Data a => PScoped a -> DataType
forall a. Data a => PScoped a -> Constr
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))
gmapMo :: 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)
gmapMp :: forall (m :: * -> *).
MonadPlus 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)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PScoped a -> m (PScoped a)
gmapQi :: forall u.
TypeIndex -> (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
gmapQ :: forall u. (forall d. Data d => d -> u) -> PScoped a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PScoped a -> r
gmapT :: (forall b. Data b => b -> b) -> PScoped a -> PScoped a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> 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))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PScoped a))
dataTypeOf :: PScoped a -> DataType
$cdataTypeOf :: forall a. Data a => PScoped a -> DataType
toConstr :: PScoped a -> Constr
$ctoConstr :: forall a. Data a => PScoped a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> 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)
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 -> [Located a] -> [RScoped (Located a)]
listScopes :: forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
_ [] = []
listScopes Scope
rhsScope [Located a
pat] = [Scope -> Located a -> RScoped (Located a)
forall a. Scope -> a -> RScoped a
RS Scope
rhsScope Located a
pat]
listScopes Scope
rhsScope (Located a
pat : [Located a]
pats) = Scope -> Located a -> RScoped (Located a)
forall a. Scope -> a -> RScoped a
RS Scope
sc Located a
pat RScoped (Located a)
-> [RScoped (Located a)] -> [RScoped (Located a)]
forall a. a -> [a] -> [a]
: [RScoped (Located a)]
pats'
  where
    pats' :: [RScoped (Located a)]
pats'@((RS Scope
scope Located a
p):[RScoped (Located a)]
_) = Scope -> [Located a] -> [RScoped (Located a)]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
rhsScope [Located a]
pats
    sc :: Scope
sc = Scope -> Scope -> Scope
combineScopes Scope
scope (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ Located a -> SrcSpan
forall l e. GenLocated l e -> l
getLoc Located 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 (Located (Pat (GhcPass p)))
 -> PScoped (Located (Pat (GhcPass p))))
-> [RScoped (Located (Pat (GhcPass p)))]
-> [PScoped (Located (Pat (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc Located (Pat (GhcPass p))
a) -> Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
useScope Scope
sc Located (Pat (GhcPass p))
a) ([RScoped (Located (Pat (GhcPass p)))]
 -> [PScoped (Located (Pat (GhcPass p)))])
-> [RScoped (Located (Pat (GhcPass p)))]
-> [PScoped (Located (Pat (GhcPass p)))]
forall a b. (a -> b) -> a -> b
$
    Scope
-> [Located (Pat (GhcPass p))]
-> [RScoped (Located (Pat (GhcPass p)))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
patScope [Located (Pat (GhcPass p))]
[LPat (GhcPass p)]
xs

-- | 'listScopes' specialised to 'TVScoped' things
tvScopes
  :: TyVarScope
  -> Scope
  -> [LHsTyVarBndr flag a]
  -> [TVScoped (LHsTyVarBndr flag a)]
tvScopes :: forall flag a.
TyVarScope
-> Scope
-> [LHsTyVarBndr flag a]
-> [TVScoped (LHsTyVarBndr flag a)]
tvScopes TyVarScope
tvScope Scope
rhsScope [LHsTyVarBndr flag a]
xs =
  (RScoped (LHsTyVarBndr flag a) -> TVScoped (LHsTyVarBndr flag a))
-> [RScoped (LHsTyVarBndr flag a)]
-> [TVScoped (LHsTyVarBndr flag a)]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc LHsTyVarBndr flag a
a)-> TyVarScope
-> Scope -> LHsTyVarBndr flag a -> TVScoped (LHsTyVarBndr flag a)
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tvScope Scope
sc LHsTyVarBndr flag a
a) ([RScoped (LHsTyVarBndr flag a)]
 -> [TVScoped (LHsTyVarBndr flag a)])
-> [RScoped (LHsTyVarBndr flag a)]
-> [TVScoped (LHsTyVarBndr flag a)]
forall a b. (a -> b) -> a -> b
$ Scope -> [LHsTyVarBndr flag a] -> [RScoped (LHsTyVarBndr flag a)]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
rhsScope [LHsTyVarBndr flag 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
-}

class HasLoc a where
  -- ^ defined so that HsImplicitBndrs and HsWildCardBndrs can
  -- know what their implicit bindings are scoping over
  loc :: a -> SrcSpan

instance HasLoc thing => HasLoc (TScoped thing) where
  loc :: TScoped thing -> SrcSpan
loc (TS TyVarScope
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a

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

instance HasLoc (LHsQTyVars GhcRn) where
  loc :: LHsQTyVars GhcRn -> SrcSpan
loc (HsQTvs XHsQTvs GhcRn
_ [LHsTyVarBndr () GhcRn]
vs) = [LHsTyVarBndr () GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LHsTyVarBndr () GhcRn]
vs

instance HasLoc thing => HasLoc (HsImplicitBndrs a thing) where
  loc :: HsImplicitBndrs a thing -> SrcSpan
loc (HsIB XHsIB a thing
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a
  loc HsImplicitBndrs a thing
_ = SrcSpan
noSrcSpan

instance HasLoc thing => HasLoc (HsWildCardBndrs a thing) where
  loc :: HsWildCardBndrs a thing -> SrcSpan
loc (HsWC XHsWC a thing
_ thing
a) = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a
  loc HsWildCardBndrs a thing
_ = SrcSpan
noSrcSpan

instance HasLoc (Located a) where
  loc :: Located a -> SrcSpan
loc (L SrcSpan
l a
_) = SrcSpan
l

instance HasLoc a => HasLoc [a] where
  loc :: [a] -> SrcSpan
loc [] = SrcSpan
noSrcSpan
  loc [a]
xs = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans ([SrcSpan] -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a b. (a -> b) -> a -> b
$ (a -> SrcSpan) -> [a] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [a]
xs

instance HasLoc a => HasLoc (FamEqn s a) where
  loc :: FamEqn s a -> SrcSpan
loc (FamEqn XCFamEqn s a
_ Located (IdP s)
a Maybe [LHsTyVarBndr () s]
Nothing HsTyPats s
b LexicalFixity
_ a
c) = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [Located (IdP s) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (IdP s)
a, HsTyPats s -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc HsTyPats s
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
c]
  loc (FamEqn XCFamEqn s a
_ Located (IdP s)
a (Just [LHsTyVarBndr () s]
tvs) HsTyPats s
b LexicalFixity
_ a
c) = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans
                                              [Located (IdP s) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (IdP s)
a, [LHsTyVarBndr () s] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LHsTyVarBndr () s]
tvs, HsTyPats s -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc HsTyPats s
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
c]
  loc FamEqn s a
_ = SrcSpan
noSrcSpan
instance (HasLoc tm, HasLoc ty) => HasLoc (HsArg tm ty) where
  loc :: HsArg tm ty -> SrcSpan
loc (HsValArg tm
tm) = tm -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc tm
tm
  loc (HsTypeArg SrcSpan
_ ty
ty) = ty -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc ty
ty
  loc (HsArgPar SrcSpan
sp)  = SrcSpan
sp

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

{- Note [Real DataCon Name]
The typechecker substitutes the conLikeWrapId for the name, but we don't want
this showing up in the hieFile, so we replace the name in the Id with the
original datacon name
See also Note [Data Constructor Naming]
-}
class HasRealDataConName p where
  getRealDataCon :: XRecordCon p -> Located (IdP p) -> Located (IdP p)

instance HasRealDataConName GhcRn where
  getRealDataCon :: XRecordCon GhcRn -> Located (IdP GhcRn) -> Located (IdP GhcRn)
getRealDataCon XRecordCon GhcRn
_ Located (IdP GhcRn)
n = Located (IdP GhcRn)
n
instance HasRealDataConName GhcTc where
  getRealDataCon :: XRecordCon GhcTc -> Located (IdP GhcTc) -> Located (IdP GhcTc)
getRealDataCon RecordConTc{rcon_con_like :: RecordConTc -> ConLike
rcon_con_like = ConLike
con} (L SrcSpan
sp IdP GhcTc
var) =
    SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp (Id -> Name -> Id
setVarName Id
IdP GhcTc
var (ConLike -> Name
conLikeName ConLike
con))

-- | 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 a) => ToHie [a] where
  toHie :: [a] -> HieM [HieAST Type]
toHie = (a -> HieM [HieAST Type]) -> [a] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [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 (f :: * -> *) a. Applicative f => a -> f a
pure []) a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie

instance ToHie (IEContext (Located ModuleName)) where
  toHie :: IEContext (Located ModuleName) -> HieM [HieAST Type]
toHie (IEC IEType
c (L (RealSrcSpan Span
span Maybe BufSpan
_) ModuleName
mname)) = do
      NodeOrigin
org <- ReaderT NodeOrigin (StateT HieState Hsc) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
      [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST Type] -> HieM [HieAST Type])
-> [HieAST Type] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [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 -> SourcedNodeInfo Type)
-> NodeInfo Type -> SourcedNodeInfo Type
forall a b. (a -> b) -> a -> b
$ Set (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] NodeIdentifiers Type
idents) Span
span []]
    where details :: IdentifierDetails Type
details = IdentifierDetails Type
forall a. Monoid a => a
mempty{identInfo :: Set ContextInfo
identInfo = ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton (IEType -> ContextInfo
IEThing IEType
c)}
          idents :: NodeIdentifiers Type
idents = Either ModuleName Name
-> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (ModuleName -> Either ModuleName Name
forall a b. a -> Either a b
Left ModuleName
mname) IdentifierDetails Type
details
  toHie IEContext (Located ModuleName)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Context (Located Var)) where
  toHie :: Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
toHie Context (GenLocated SrcSpan Id)
c = case Context (GenLocated SrcSpan 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 (f :: * -> *) a. Applicative f => a -> f a
pure []
          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
        | Bool
otherwise -> do
          NameEnv Id
m <- StateT HieState Hsc (NameEnv Id)
-> ReaderT NodeOrigin (StateT HieState Hsc) (NameEnv Id)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateT HieState Hsc (NameEnv Id)
 -> ReaderT NodeOrigin (StateT HieState Hsc) (NameEnv Id))
-> StateT HieState Hsc (NameEnv Id)
-> ReaderT NodeOrigin (StateT HieState Hsc) (NameEnv Id)
forall a b. (a -> b) -> a -> b
$ (HieState -> NameEnv Id) -> StateT HieState Hsc (NameEnv Id)
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> NameEnv Id
name_remapping
          NodeOrigin
org <- ReaderT NodeOrigin (StateT HieState Hsc) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
          let name :: Id
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 :: Type
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
          [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
            [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 -> SourcedNodeInfo Type)
-> NodeInfo Type -> SourcedNodeInfo Type
forall a b. (a -> b) -> a -> b
$ Set (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$
                Either ModuleName Name
-> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (Name -> Either ModuleName Name
forall a b. b -> Either a b
Right (Name -> Either ModuleName Name) -> Name -> Either ModuleName Name
forall a b. (a -> b) -> a -> b
$ Id -> Name
varName Id
name)
                            (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
ty)
                                               (ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
context)))
              Span
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 (f :: * -> *) a. Applicative f => a -> f a
pure []
      Context (GenLocated SrcSpan Id)
_ -> [HieAST Type] -> HieM [HieAST Type]
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 (f :: * -> *) a. Applicative f => a -> f a
pure []
          -- `mkOneRecordSelector` makes a field var using this unique, which we ignore
        | Bool
otherwise -> do
          NameEnv Id
m <- StateT HieState Hsc (NameEnv Id)
-> ReaderT NodeOrigin (StateT HieState Hsc) (NameEnv Id)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateT HieState Hsc (NameEnv Id)
 -> ReaderT NodeOrigin (StateT HieState Hsc) (NameEnv Id))
-> StateT HieState Hsc (NameEnv Id)
-> ReaderT NodeOrigin (StateT HieState Hsc) (NameEnv Id)
forall a b. (a -> b) -> a -> b
$ (HieState -> NameEnv Id) -> StateT HieState Hsc (NameEnv Id)
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
gets HieState -> NameEnv Id
name_remapping
          NodeOrigin
org <- ReaderT NodeOrigin (StateT HieState Hsc) NodeOrigin
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
          let name :: Name
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'
          [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
            [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 -> SourcedNodeInfo Type)
-> NodeInfo Type -> SourcedNodeInfo Type
forall a b. (a -> b) -> a -> b
$ Set (FastString, FastString)
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set (FastString, FastString)
-> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set (FastString, FastString)
forall a. Set a
S.empty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$
                Either ModuleName Name
-> IdentifierDetails Type -> NodeIdentifiers Type
forall k a. k -> a -> Map k a
M.singleton (Name -> Either ModuleName Name
forall a b. b -> Either a b
Right Name
name)
                            (Maybe Type -> Set ContextInfo -> IdentifierDetails Type
forall a. Maybe a -> Set ContextInfo -> IdentifierDetails a
IdentifierDetails Maybe Type
forall a. Maybe a
Nothing
                                               (ContextInfo -> Set ContextInfo
forall a. a -> Set a
S.singleton ContextInfo
context)))
              Span
span
              []]
      Context (Located Name)
_ -> [HieAST Type] -> HieM [HieAST Type]
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 (Located TcEvBinds)) where
  toHie :: EvBindContext (GenLocated SrcSpan TcEvBinds) -> HieM [HieAST Type]
toHie (EvBindContext Scope
sc Maybe Span
sp (L SrcSpan
span (EvBinds Bag EvBind
bs)))
    = (EvBind -> HieM [HieAST Type]) -> [EvBind] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [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 SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan 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 (SrcSpan -> Scope
mkScope SrcSpan
span)) Maybe Span
sp)
                                        (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
span (Id -> GenLocated SrcSpan Id) -> Id -> GenLocated SrcSpan Id
forall a b. (a -> b) -> a -> b
$ EvBind -> Id
eb_lhs EvBind
evbind))
            , [Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Id -> Context (GenLocated SrcSpan Id))
-> [Id] -> [Context (GenLocated SrcSpan Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
EvidenceVarUse (GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id))
-> (Id -> GenLocated SrcSpan Id)
-> Id
-> Context (GenLocated SrcSpan Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
span) ([Id] -> [Context (GenLocated SrcSpan Id)])
-> [Id] -> [Context (GenLocated SrcSpan Id)]
forall a b. (a -> b) -> a -> b
$ [Id]
evDeps
            ]
  toHie EvBindContext (GenLocated SrcSpan TcEvBinds)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Located HsWrapper) where
  toHie :: Located HsWrapper -> HieM [HieAST Type]
toHie (L SrcSpan
osp HsWrapper
wrap)
    = case HsWrapper
wrap of
        (WpLet TcEvBinds
bs)      -> EvBindContext (GenLocated SrcSpan TcEvBinds) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpan TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext (SrcSpan -> Scope
mkScope SrcSpan
osp) (SrcSpan -> Maybe Span
getRealSpan SrcSpan
osp) (SrcSpan -> TcEvBinds -> GenLocated SrcSpan TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpan
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
$
          [Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
osp HsWrapper
a), Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
osp HsWrapper
b)]
        (WpFun HsWrapper
a HsWrapper
b Scaled Type
_ SDoc
_) -> [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
$
          [Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
osp HsWrapper
a), Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
osp HsWrapper
b)]
        (WpEvLam Id
a) ->
          Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvWrapperBind (SrcSpan -> Scope
mkScope SrcSpan
osp) (SrcSpan -> Maybe Span
getRealSpan SrcSpan
osp))
                (GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id))
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
osp Id
a
        (WpEvApp EvTerm
a) ->
          (Id -> HieM [HieAST Type]) -> [Id] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> (Id -> Context (GenLocated SrcSpan Id))
-> Id
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C ContextInfo
EvidenceVarUse (GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id))
-> (Id -> GenLocated SrcSpan Id)
-> Id
-> Context (GenLocated SrcSpan Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
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 (f :: * -> *) a. Applicative f => a -> f a
pure []

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

instance HiePass p => HasType (Located (Pat (GhcPass p))) where
  getTypeNode :: Located (Pat (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpan
spn Pat (GhcPass p)
pat) =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> Pat (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode Pat (GhcPass p)
pat SrcSpan
spn
      HiePassEv p
HieTc -> Pat (GhcPass p) -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNode Pat (GhcPass p)
pat SrcSpan
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.
--
-- 'HsApp', for example, doesn't have any type information available directly on
-- the node. Our next recourse would be to desugar it into a 'CoreExpr' then
-- query the type of that. Yet both the desugaring call and the type query both
-- involve recursive calls to the function and argument! This is particularly
-- problematic when you realize that the HIE traversal will eventually visit
-- those nodes too and ask for their types again.
--
-- Since the above is quite costly, we just skip cases where computing the
-- expression's type is going to be expensive.
--
-- See #16233
instance HiePass p => HasType (LHsExpr (GhcPass p)) where
  getTypeNode :: LHsExpr (GhcPass p) -> HieM [HieAST Type]
getTypeNode e :: LHsExpr (GhcPass p)
e@(L SrcSpan
spn HsExpr (GhcPass p)
e') =
    case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> HsExpr (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsExpr (GhcPass p)
e' SrcSpan
spn
      HiePassEv p
HieTc ->
        -- Some expression forms have their type immediately available
        let tyOpt :: Maybe Type
tyOpt = case HsExpr (GhcPass p)
e' of
              HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
l -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsLit (GhcPass p) -> Type
forall (p :: Pass). HsLit (GhcPass p) -> Type
hsLitType HsLit (GhcPass p)
l)
              HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
o -> Type -> Maybe Type
forall a. a -> Maybe a
Just (HsOverLit GhcTc -> Type
overLitType HsOverLit (GhcPass p)
HsOverLit GhcTc
o)

              HsConLikeOut XConLikeOut (GhcPass p)
_ (RealDataCon DataCon
con) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (DataCon -> Type
dataConNonlinearType DataCon
con)

              HsLam     XLam (GhcPass p)
_ (MG { mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG (GhcPass p) (LHsExpr (GhcPass p))
groupTy }) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (MatchGroupTc -> Type
matchGroupType XMG (GhcPass p) (LHsExpr (GhcPass p))
MatchGroupTc
groupTy)
              HsLamCase XLamCase (GhcPass p)
_ (MG { mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG (GhcPass p) (LHsExpr (GhcPass p))
groupTy }) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (MatchGroupTc -> Type
matchGroupType XMG (GhcPass p) (LHsExpr (GhcPass p))
MatchGroupTc
groupTy)
              HsCase XCase (GhcPass p)
_  LHsExpr (GhcPass p)
_ (MG { mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = XMG (GhcPass p) (LHsExpr (GhcPass p))
groupTy }) -> Type -> Maybe Type
forall a. a -> Maybe a
Just (MatchGroupTc -> Type
mg_res_ty XMG (GhcPass p) (LHsExpr (GhcPass p))
MatchGroupTc
groupTy)

              ExplicitList  XExplicitList (GhcPass p)
ty Maybe (SyntaxExpr (GhcPass p))
_ [LHsExpr (GhcPass p)]
_   -> Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Type
mkListTy Type
XExplicitList (GhcPass p)
ty)
              ExplicitSum   XExplicitSum (GhcPass p)
ty TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
_ -> Type -> Maybe Type
forall a. a -> Maybe a
Just ([Type] -> Type
mkSumTy [Type]
XExplicitSum (GhcPass p)
ty)
              HsDo          XDo (GhcPass p)
ty HsStmtContext GhcRn
_ Located [ExprLStmt (GhcPass p)]
_   -> Type -> Maybe Type
forall a. a -> Maybe a
Just Type
XDo (GhcPass p)
ty
              HsMultiIf     XMultiIf (GhcPass p)
ty [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
_     -> Type -> Maybe Type
forall a. a -> Maybe a
Just Type
XMultiIf (GhcPass p)
ty

              HsExpr (GhcPass p)
_ -> Maybe Type
forall a. Maybe a
Nothing

        in
        case Maybe Type
tyOpt of
          Just Type
t -> HsExpr (GhcPass p) -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNode HsExpr (GhcPass p)
e' SrcSpan
spn Type
t
          Maybe Type
Nothing
            | HsExpr GhcTc -> Bool
skipDesugaring HsExpr (GhcPass p)
HsExpr GhcTc
e' -> HieM [HieAST Type]
fallback
            | Bool
otherwise -> do
                HscEnv
hs_env <- StateT HieState Hsc HscEnv
-> ReaderT NodeOrigin (StateT HieState Hsc) HscEnv
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateT HieState Hsc HscEnv
 -> ReaderT NodeOrigin (StateT HieState Hsc) HscEnv)
-> StateT HieState Hsc HscEnv
-> ReaderT NodeOrigin (StateT HieState Hsc) HscEnv
forall a b. (a -> b) -> a -> b
$ Hsc HscEnv -> StateT HieState Hsc HscEnv
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Hsc HscEnv -> StateT HieState Hsc HscEnv)
-> Hsc HscEnv -> StateT HieState Hsc HscEnv
forall a b. (a -> b) -> a -> b
$ (HscEnv -> WarningMessages -> IO (HscEnv, WarningMessages))
-> Hsc HscEnv
forall a.
(HscEnv -> WarningMessages -> IO (a, WarningMessages)) -> Hsc a
Hsc ((HscEnv -> WarningMessages -> IO (HscEnv, WarningMessages))
 -> Hsc HscEnv)
-> (HscEnv -> WarningMessages -> IO (HscEnv, WarningMessages))
-> Hsc HscEnv
forall a b. (a -> b) -> a -> b
$ \HscEnv
e WarningMessages
w -> (HscEnv, WarningMessages) -> IO (HscEnv, WarningMessages)
forall (m :: * -> *) a. Monad m => a -> m a
return (HscEnv
e,WarningMessages
w)
                (Messages
_,Maybe EvExpr
mbe) <- IO (Messages, Maybe EvExpr)
-> ReaderT
     NodeOrigin (StateT HieState Hsc) (Messages, Maybe EvExpr)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Messages, Maybe EvExpr)
 -> ReaderT
      NodeOrigin (StateT HieState Hsc) (Messages, Maybe EvExpr))
-> IO (Messages, Maybe EvExpr)
-> ReaderT
     NodeOrigin (StateT HieState Hsc) (Messages, Maybe EvExpr)
forall a b. (a -> b) -> a -> b
$ HscEnv -> LHsExpr GhcTc -> IO (Messages, Maybe EvExpr)
deSugarExpr HscEnv
hs_env LHsExpr (GhcPass p)
LHsExpr GhcTc
e
                HieM [HieAST Type]
-> (EvExpr -> HieM [HieAST Type])
-> Maybe EvExpr
-> HieM [HieAST Type]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe HieM [HieAST Type]
fallback (HsExpr (GhcPass p) -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNode HsExpr (GhcPass p)
e' SrcSpan
spn (Type -> HieM [HieAST Type])
-> (EvExpr -> Type) -> EvExpr -> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EvExpr -> Type
exprType) Maybe EvExpr
mbe
        where
          fallback :: HieM [HieAST Type]
fallback = HsExpr (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsExpr (GhcPass p)
e' SrcSpan
spn

          matchGroupType :: MatchGroupTc -> Type
          matchGroupType :: MatchGroupTc -> Type
matchGroupType (MatchGroupTc [Scaled Type]
args Type
res) = [Scaled Type] -> Type -> Type
mkVisFunTys [Scaled Type]
args Type
res

          -- | Skip desugaring of these expressions for performance reasons.
          --
          -- See impact on Haddock output (esp. missing type annotations or links)
          -- before marking more things here as 'False'. See impact on Haddock
          -- performance before marking more things as 'True'.
          skipDesugaring :: HsExpr GhcTc -> Bool
          skipDesugaring :: HsExpr GhcTc -> Bool
skipDesugaring HsExpr GhcTc
e = case HsExpr GhcTc
e of
            HsVar{}             -> Bool
False
            HsUnboundVar{}      -> Bool
False
            HsConLikeOut{}      -> Bool
False
            HsRecFld{}          -> Bool
False
            HsOverLabel{}       -> Bool
False
            HsIPVar{}           -> Bool
False
            XExpr (WrapExpr {}) -> Bool
False
            HsExpr GhcTc
_                   -> Bool
True

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

class ( IsPass p
      , HiePass (NoGhcTcPass p)
      , ModifyState (IdGhcP p)
      , Data (GRHS (GhcPass p) (Located (HsExpr (GhcPass p))))
      , Data (HsExpr (GhcPass p))
      , Data (HsCmd (GhcPass p))
      , Data (AmbiguousFieldOcc (GhcPass p))
      , Data (HsCmdTop (GhcPass p))
      , Data (GRHS (GhcPass p) (Located (HsCmd (GhcPass p))))
      , Data (HsSplice (GhcPass p))
      , Data (HsLocalBinds (GhcPass p))
      , Data (FieldOcc (GhcPass p))
      , Data (HsTupArg (GhcPass p))
      , Data (IPBind (GhcPass p))
      , ToHie (Context (Located (IdGhcP p)))
      , ToHie (RFContext (Located (AmbiguousFieldOcc (GhcPass p))))
      , ToHie (RFContext (Located (FieldOcc (GhcPass p))))
      , ToHie (TScoped (LHsWcType (GhcPass (NoGhcTcPass p))))
      , ToHie (TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p))))
      , HasRealDataConName (GhcPass 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 HiePass p => ToHie (BindContext (LHsBind (GhcPass p))) where
  toHie :: BindContext (LHsBind (GhcPass p)) -> HieM [HieAST Type]
toHie (BC BindType
context Scope
scope b :: LHsBind (GhcPass p)
b@(L SrcSpan
span HsBindLR (GhcPass p) (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
$ LHsBind (GhcPass p) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LHsBind (GhcPass p)
b HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsBindLR (GhcPass p) (GhcPass p)
bind of
      FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = Located (IdP (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)
wrap} ->
        [ Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdGhcP p)) -> HieM [HieAST Type])
-> Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdGhcP p) -> Context (Located (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
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) Located (IdGhcP p)
Located (IdP (GhcPass p))
name
        , MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
            HiePassEv p
HieTc -> Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Located HsWrapper -> HieM [HieAST Type])
-> Located HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
span XFunBind (GhcPass p) (GhcPass p)
HsWrapper
wrap
            HiePassEv p
_ -> [HieAST Type] -> HieM [HieAST Type]
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 (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) Scope
scope Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
lhs
        , GRHSs (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (LHsExpr (GhcPass p))
rhs
        ]
      VarBind{var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr (GhcPass p)
expr} ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      AbsBinds{ abs_exports :: forall idL idR. HsBindLR idL idR -> [ABExport idL]
abs_exports = [ABExport (GhcPass p)]
xs, abs_binds :: forall idL idR. HsBindLR idL idR -> LHsBinds idL
abs_binds = LHsBinds (GhcPass p)
binds
              , abs_ev_binds :: forall idL idR. HsBindLR idL idR -> [TcEvBinds]
abs_ev_binds = [TcEvBinds]
ev_binds
              , abs_ev_vars :: forall idL idR. HsBindLR idL idR -> [Id]
abs_ev_vars = [Id]
ev_vars } ->
        [  StateT HieState Hsc () -> HieM ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((HieState -> HieState) -> StateT HieState Hsc ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify ([ABExport (GhcPass p)] -> HieState -> HieState
forall p.
ModifyState (IdP p) =>
[ABExport p] -> HieState -> HieState
modifyState [ABExport (GhcPass p)]
xs)) HieM () -> HieM [HieAST Type] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> -- Note [Name Remapping]
                (Bag (BindContext (LHsBind (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBind (GhcPass p))) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBind (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBind (GhcPass p) -> BindContext (LHsBind (GhcPass p)))
-> LHsBinds (GhcPass p) -> Bag (BindContext (LHsBind (GhcPass p)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> LHsBind (GhcPass p)
-> BindContext (LHsBind (GhcPass p))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
context Scope
scope) LHsBinds (GhcPass p)
binds)
        , [Located HsWrapper] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Located HsWrapper] -> HieM [HieAST Type])
-> [Located HsWrapper] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (ABExport (GhcPass p) -> Located HsWrapper)
-> [ABExport (GhcPass p)] -> [Located HsWrapper]
forall a b. (a -> b) -> [a] -> [b]
map (SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
span (HsWrapper -> Located HsWrapper)
-> (ABExport (GhcPass p) -> HsWrapper)
-> ABExport (GhcPass p)
-> Located HsWrapper
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ABExport (GhcPass p) -> HsWrapper
forall p. ABExport p -> HsWrapper
abe_wrap) [ABExport (GhcPass p)]
xs
        , [EvBindContext (GenLocated SrcSpan TcEvBinds)]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([EvBindContext (GenLocated SrcSpan TcEvBinds)]
 -> HieM [HieAST Type])
-> [EvBindContext (GenLocated SrcSpan TcEvBinds)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            (TcEvBinds -> EvBindContext (GenLocated SrcSpan TcEvBinds))
-> [TcEvBinds] -> [EvBindContext (GenLocated SrcSpan TcEvBinds)]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> Maybe Span
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext (SrcSpan -> Scope
mkScope SrcSpan
span) (SrcSpan -> Maybe Span
getRealSpan SrcSpan
span)
                (GenLocated SrcSpan TcEvBinds
 -> EvBindContext (GenLocated SrcSpan TcEvBinds))
-> (TcEvBinds -> GenLocated SrcSpan TcEvBinds)
-> TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> TcEvBinds -> GenLocated SrcSpan TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpan
span) [TcEvBinds]
ev_binds
        , [Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
            (Id -> Context (GenLocated SrcSpan Id))
-> [Id] -> [Context (GenLocated SrcSpan Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvSigBind
                                    (SrcSpan -> Scope
mkScope SrcSpan
span)
                                    (SrcSpan -> Maybe Span
getRealSpan SrcSpan
span))
                (GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id))
-> (Id -> GenLocated SrcSpan Id)
-> Id
-> Context (GenLocated SrcSpan Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
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 SrcSpan
span PatSynBind (GhcPass p) (GhcPass p)
psb -- PatSynBinds only occur at the top level
        ]

instance ( HiePass p
         , ToHie (Located body)
         , Data body
         ) => ToHie (MatchGroup (GhcPass p) (Located body)) where
  toHie :: MatchGroup (GhcPass p) (Located body) -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located body)
mg = case MatchGroup (GhcPass p) (Located body)
mg of
    MG{ mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = (L SrcSpan
span [LMatch (GhcPass p) (Located body)]
alts) , mg_origin :: forall p body. MatchGroup p body -> Origin
mg_origin = Origin
origin} ->
      (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 SrcSpan
span
        , [LMatch (GhcPass p) (Located body)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LMatch (GhcPass p) (Located body)]
alts
        ]

setOrigin :: Origin -> NodeOrigin -> NodeOrigin
setOrigin :: Origin -> NodeOrigin -> NodeOrigin
setOrigin Origin
FromSource NodeOrigin
_ = NodeOrigin
SourceInfo
setOrigin Origin
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 -> Located (IdP idL)
psb_id=Located (IdP (GhcPass p))
var, psb_args :: forall idL idR.
PatSynBind idL idR -> HsPatSynDetails (Located (IdP idR))
psb_args=HsPatSynDetails (Located (IdP (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 (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdGhcP p)) -> HieM [HieAST Type])
-> Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdGhcP p) -> Context (Located (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) Located (IdGhcP p)
Located (IdP (GhcPass p))
var
        , HsConDetails
  (Context (Located (IdGhcP p)))
  [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (Context (Located (IdGhcP p)))
   [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
 -> HieM [HieAST Type])
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (Located (IdGhcP p)) [RecordPatSynField (Located (IdGhcP p))]
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
toBind HsConDetails
  (Located (IdGhcP p)) [RecordPatSynField (Located (IdGhcP p))]
HsPatSynDetails (Located (IdP (GhcPass p)))
dets
        , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
lhsScope Scope
patScope Located (Pat (GhcPass p))
LPat (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 = Located (IdGhcP p) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdGhcP p)
Located (IdP (GhcPass p))
var
          patScope :: Scope
patScope = SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ Located (Pat (GhcPass p)) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
          detScope :: Scope
detScope = case HsPatSynDetails (Located (IdP (GhcPass p)))
dets of
            (PrefixCon [Located (IdP (GhcPass p))]
args) -> (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
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
$ (Located (IdGhcP p) -> Scope) -> [Located (IdGhcP p)] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map Located (IdGhcP p) -> Scope
forall a. Located a -> Scope
mkLScope [Located (IdGhcP p)]
[Located (IdP (GhcPass p))]
args
            (InfixCon Located (IdP (GhcPass p))
a Located (IdP (GhcPass p))
b) -> Scope -> Scope -> Scope
combineScopes (Located (IdGhcP p) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdGhcP p)
Located (IdP (GhcPass p))
a) (Located (IdGhcP p) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdGhcP p)
Located (IdP (GhcPass p))
b)
            (RecCon [RecordPatSynField (Located (IdP (GhcPass p)))]
r) -> (RecordPatSynField (Located (IdGhcP p)) -> Scope -> Scope)
-> Scope -> [RecordPatSynField (Located (IdGhcP p))] -> Scope
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr RecordPatSynField (Located (IdGhcP p)) -> Scope -> Scope
forall {a}. RecordPatSynField (Located a) -> Scope -> Scope
go Scope
NoScope [RecordPatSynField (Located (IdGhcP p))]
[RecordPatSynField (Located (IdP (GhcPass p)))]
r
          go :: RecordPatSynField (Located a) -> Scope -> Scope
go (RecordPatSynField Located a
a Located a
b) Scope
c = Scope -> Scope -> Scope
combineScopes Scope
c
            (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes (Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
a) (Located a -> Scope
forall a. Located a -> Scope
mkLScope Located a
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
  (Located (IdGhcP p)) [RecordPatSynField (Located (IdGhcP p))]
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
toBind (PrefixCon [Located (IdGhcP p)]
args) = [Context (Located (IdGhcP p))]
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon ([Context (Located (IdGhcP p))]
 -> HsConDetails
      (Context (Located (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))])
-> [Context (Located (IdGhcP p))]
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
forall a b. (a -> b) -> a -> b
$ (Located (IdGhcP p) -> Context (Located (IdGhcP p)))
-> [Located (IdGhcP p)] -> [Context (Located (IdGhcP p))]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located (IdGhcP p)]
args
          toBind (InfixCon Located (IdGhcP p)
a Located (IdGhcP p)
b) = Context (Located (IdGhcP p))
-> Context (Located (IdGhcP p))
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon (ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdGhcP p)
a) (ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located (IdGhcP p)
b)
          toBind (RecCon [RecordPatSynField (Located (IdGhcP p))]
r) = [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
forall arg rec. rec -> HsConDetails arg rec
RecCon ([PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
 -> HsConDetails
      (Context (Located (IdGhcP p)))
      [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))])
-> [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
-> HsConDetails
     (Context (Located (IdGhcP p)))
     [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
forall a b. (a -> b) -> a -> b
$ (RecordPatSynField (Located (IdGhcP p))
 -> PatSynFieldContext (RecordPatSynField (Located (IdGhcP p))))
-> [RecordPatSynField (Located (IdGhcP p))]
-> [PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Span
-> RecordPatSynField (Located (IdGhcP p))
-> PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))
forall a. Maybe Span -> a -> PatSynFieldContext a
PSC Maybe Span
detSpan) [RecordPatSynField (Located (IdGhcP 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) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
    HsPatSynDir (GhcPass p)
_ -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ( HiePass p
         , Data body
         , ToHie (Located body)
         ) => ToHie (LMatch (GhcPass p) (Located body)) where
  toHie :: LMatch (GhcPass p) (Located body) -> HieM [HieAST Type]
toHie (L SrcSpan
span Match (GhcPass p) (Located body)
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
$ HieM [HieAST Type]
node HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Match (GhcPass p) (Located body)
m of
    Match{m_ctxt :: forall p body. Match p body -> HsMatchContext (NoGhcTc p)
m_ctxt=HsMatchContext (NoGhcTc (GhcPass p))
mctx, m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat (GhcPass p)]
pats, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss =  GRHSs (GhcPass p) (Located body)
grhss } ->
      [ HsMatchContext (GhcPass (NoGhcTcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsMatchContext (GhcPass (NoGhcTcPass p))
HsMatchContext (NoGhcTc (GhcPass p))
mctx
      , let rhsScope :: Scope
rhsScope = SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) (Located body) -> SrcSpan
forall p body. GRHSs p body -> SrcSpan
grhss_span GRHSs (GhcPass p) (Located body)
grhss
          in [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (Located (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)]
pats
      , GRHSs (GhcPass p) (Located body) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (Located body)
grhss
      ]
    where
      node :: HieM [HieAST Type]
node = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc -> Match (GhcPass p) (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode Match (GhcPass p) (Located body)
m SrcSpan
span
        HiePassEv p
HieRn -> Match (GhcPass p) (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode Match (GhcPass p) (Located body)
m SrcSpan
span

instance HiePass p => ToHie (HsMatchContext (GhcPass p)) where
  toHie :: HsMatchContext (GhcPass p) -> HieM [HieAST Type]
toHie (FunRhs{mc_fun :: forall p. HsMatchContext p -> LIdP p
mc_fun=LIdP (GhcPass p)
name}) = Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdGhcP p)) -> HieM [HieAST Type])
-> Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
MatchBind Located (IdGhcP p)
LIdP (GhcPass p)
name
  toHie (StmtCtxt HsStmtContext (GhcPass p)
a) = HsStmtContext (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsStmtContext (GhcPass p)
a
  toHie HsMatchContext (GhcPass p)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => ToHie (HsStmtContext (GhcPass p)) where
  toHie :: HsStmtContext (GhcPass p) -> HieM [HieAST Type]
toHie (PatGuard HsMatchContext (GhcPass p)
a) = HsMatchContext (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsMatchContext (GhcPass p)
a
  toHie (ParStmtCtxt HsStmtContext (GhcPass p)
a) = HsStmtContext (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsStmtContext (GhcPass p)
a
  toHie (TransStmtCtxt HsStmtContext (GhcPass p)
a) = HsStmtContext (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsStmtContext (GhcPass p)
a
  toHie HsStmtContext (GhcPass p)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => ToHie (PScoped (Located (Pat (GhcPass p)))) where
  toHie :: PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
toHie (PS Maybe Span
rsp Scope
scope Scope
pscope lpat :: Located (Pat (GhcPass p))
lpat@(L SrcSpan
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
$ Located (Pat (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode Located (Pat (GhcPass p))
lpat HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Pat (GhcPass p)
opat of
      WildPat XWildPat (GhcPass p)
_ ->
        []
      VarPat XVarPat (GhcPass p)
_ Located (IdP (GhcPass p))
lname ->
        [ Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdGhcP p)) -> HieM [HieAST Type])
-> Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe Span
rsp) Located (IdGhcP p)
Located (IdP (GhcPass p))
lname
        ]
      LazyPat XLazyPat (GhcPass p)
_ LPat (GhcPass p)
p ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
p
        ]
      AsPat XAsPat (GhcPass p)
_ Located (IdP (GhcPass p))
lname LPat (GhcPass p)
pat ->
        [ Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdGhcP p)) -> HieM [HieAST Type])
-> Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope
                                 (Scope -> Scope -> Scope
combineScopes (Located (Pat (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat) Scope
pscope)
                                 Maybe Span
rsp)
                    Located (IdGhcP p)
Located (IdP (GhcPass p))
lname
        , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        ]
      ParPat XParPat (GhcPass p)
_ LPat (GhcPass p)
pat ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        ]
      BangPat XBangPat (GhcPass p)
_ LPat (GhcPass p)
pat ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        ]
      ListPat XListPat (GhcPass p)
_ [LPat (GhcPass p)]
pats ->
        [ [PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (Located (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 (Located (Pat (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([PScoped (Located (Pat (GhcPass p)))] -> HieM [HieAST Type])
-> [PScoped (Located (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 (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        ]
      ConPat {pat_con :: forall p. Pat p -> Located (ConLikeP p)
pat_con = Located (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 (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 ContextInfo
Use (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ (ConLike -> Name) -> GenLocated SrcSpan ConLike -> Located Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConLike -> Name
conLikeName GenLocated SrcSpan ConLike
Located (ConLikeP (GhcPass p))
con
            , HsConDetails
  (PScoped (Located (Pat GhcTc)))
  (RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcTc)))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (PScoped (Located (Pat GhcTc)))
   (RContext
      (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcTc)))))
 -> HieM [HieAST Type])
-> HsConDetails
     (PScoped (Located (Pat GhcTc)))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcTc)))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (Located (Pat GhcTc))
  (HsRecFields (GhcPass p) (Located (Pat GhcTc)))
-> HsConDetails
     (PScoped (Located (Pat GhcTc)))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcTc)))))
forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify HsConDetails
  (Located (Pat GhcTc))
  (HsRecFields (GhcPass p) (Located (Pat GhcTc)))
HsConPatDetails (GhcPass p)
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 = SrcSpan -> Scope
mkScope SrcSpan
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 SrcSpan TcEvBinds) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpan TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
scope Maybe Span
rsp (GenLocated SrcSpan TcEvBinds
 -> EvBindContext (GenLocated SrcSpan TcEvBinds))
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> TcEvBinds -> GenLocated SrcSpan TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan TcEvBinds
ev_binds
                            , Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Located HsWrapper -> HieM [HieAST Type])
-> Located HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan HsWrapper
wrap
                            , [Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type])
-> [Context (GenLocated SrcSpan Id)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Id -> Context (GenLocated SrcSpan Id))
-> [Id] -> [Context (GenLocated SrcSpan Id)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvPatternBind Scope
evscope Maybe Span
rsp)
                                          (GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id))
-> (Id -> GenLocated SrcSpan Id)
-> Id
-> Context (GenLocated SrcSpan Id)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan) [Id]
ev_vars
                          ]
            ]
          HiePassEv p
HieRn ->
            [ 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 ContextInfo
Use Located Name
Located (ConLikeP (GhcPass p))
con
            , HsConDetails
  (PScoped (Located (Pat GhcRn)))
  (RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcRn)))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsConDetails
   (PScoped (Located (Pat GhcRn)))
   (RContext
      (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcRn)))))
 -> HieM [HieAST Type])
-> HsConDetails
     (PScoped (Located (Pat GhcRn)))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcRn)))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsConDetails
  (Located (Pat GhcRn))
  (HsRecFields (GhcPass p) (Located (Pat GhcRn)))
-> HsConDetails
     (PScoped (Located (Pat GhcRn)))
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat GhcRn)))))
forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify HsConDetails
  (Located (Pat GhcRn))
  (HsRecFields (GhcPass p) (Located (Pat GhcRn)))
HsConPatDetails (GhcPass p)
dets
            ]
      ViewPat XViewPat (GhcPass p)
_ LHsExpr (GhcPass p)
expr LPat (GhcPass p)
pat ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        ]
      SplicePat XSplicePat (GhcPass p)
_ HsSplice (GhcPass p)
sp ->
        [ GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type])
-> GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> HsSplice (GhcPass p)
-> GenLocated SrcSpan (HsSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan HsSplice (GhcPass p)
sp
        ]
      LitPat XLitPat (GhcPass p)
_ HsLit (GhcPass p)
_ ->
        []
      NPat XNPat (GhcPass p)
_ Located (HsOverLit (GhcPass p))
_ Maybe (SyntaxExpr (GhcPass p))
_ SyntaxExpr (GhcPass p)
_ ->
        []
      NPlusKPat XNPlusKPat (GhcPass p)
_ Located (IdP (GhcPass p))
n Located (HsOverLit (GhcPass p))
_ HsOverLit (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ ->
        [ Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located (IdGhcP p)) -> HieM [HieAST Type])
-> Context (Located (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located (IdGhcP p) -> Context (Located (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (Scope -> Scope -> Maybe Span -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe Span
rsp) Located (IdGhcP p)
Located (IdP (GhcPass p))
n
        ]
      SigPat XSigPat (GhcPass p)
_ LPat (GhcPass p)
pat HsPatSigType (NoGhcTc (GhcPass p))
sig ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        , case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
            HiePassEv p
HieTc ->
              let cscope :: Scope
cscope = Located (Pat GhcTc) -> Scope
forall a. Located a -> Scope
mkLScope Located (Pat GhcTc)
LPat (GhcPass p)
pat in
                TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type])
-> TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> HsPatSigType GhcRn -> TScoped (HsPatSigType GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
cscope, Scope
scope, Scope
pscope])
                           HsPatSigType GhcRn
HsPatSigType (NoGhcTc (GhcPass p))
sig
            HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        ]
      XPat XXPat (GhcPass p)
e ->
        case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieTc ->
            let CoPat HsWrapper
wrap Pat GhcTc
pat Type
_ = XXPat (GhcPass p)
CoPat
e
              in [ Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Located HsWrapper -> HieM [HieAST Type])
-> Located HsWrapper -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan HsWrapper
wrap
                 , PScoped (Located (Pat GhcTc)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat GhcTc)) -> HieM [HieAST Type])
-> PScoped (Located (Pat GhcTc)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat GhcTc)
-> PScoped (Located (Pat GhcTc))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
pscope (Located (Pat GhcTc) -> PScoped (Located (Pat GhcTc)))
-> Located (Pat GhcTc) -> PScoped (Located (Pat GhcTc))
forall a b. (a -> b) -> a -> b
$ (SrcSpan -> Pat GhcTc -> Located (Pat GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
ospan Pat GhcTc
pat)
                 ]
#if __GLASGOW_HASKELL__ < 811
          HieRn -> []
#endif
    where
      contextify :: a ~ LPat (GhcPass p) => HsConDetails a (HsRecFields (GhcPass p) a)
                 -> HsConDetails (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
      contextify :: forall a.
(a ~ LPat (GhcPass p)) =>
HsConDetails a (HsRecFields (GhcPass p) a)
-> HsConDetails
     (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
contextify (PrefixCon [a]
args) = [PScoped a]
-> HsConDetails
     (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon ([PScoped a]
 -> HsConDetails
      (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a))))
-> [PScoped a]
-> HsConDetails
     (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
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 [a]
[LPat (GhcPass p)]
args
      contextify (InfixCon a
a a
b) = PScoped a
-> PScoped a
-> HsConDetails
     (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon PScoped a
a' PScoped a
b'
        where [PScoped a
a', PScoped 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 [a
LPat (GhcPass p)
a,a
LPat (GhcPass p)
b]
      contextify (RecCon HsRecFields (GhcPass p) a
r) = RContext
  (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> HsConDetails
     (PScoped a)
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall arg rec. rec -> HsConDetails arg rec
RecCon (RContext
   (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
 -> HsConDetails
      (PScoped a)
      (RContext
         (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> HsConDetails
     (PScoped a)
     (RContext
        (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldMatch (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
 -> RContext
      (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))))
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
-> RContext
     (HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
forall a b. (a -> b) -> a -> b
$ HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
contextify_rec HsRecFields (GhcPass p) a
HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
r
      contextify_rec :: HsRecFields (GhcPass p) (Located (Pat (GhcPass p)))
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
contextify_rec (HsRecFields [LHsRecField (GhcPass p) (Located (Pat (GhcPass p)))]
fds Maybe (Located TypeIndex)
a) = [LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))]
-> Maybe (Located TypeIndex)
-> HsRecFields (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
forall p arg.
[LHsRecField p arg]
-> Maybe (Located TypeIndex) -> HsRecFields p arg
HsRecFields ((RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))
 -> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
-> [LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))]
forall a b. (a -> b) -> [a] -> [b]
map RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
go [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
scoped_fds) Maybe (Located TypeIndex)
a
        where
          go :: RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
go (RS Scope
fscope (L SrcSpan
spn (HsRecField Located (FieldOcc (GhcPass p))
lbl Located (Pat (GhcPass p))
pat Bool
pun))) =
            SrcSpan
-> HsRecField'
     (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
forall l e. l -> e -> GenLocated l e
L SrcSpan
spn (HsRecField'
   (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
 -> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p)))))
-> HsRecField'
     (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
-> LHsRecField (GhcPass p) (PScoped (Located (Pat (GhcPass p))))
forall a b. (a -> b) -> a -> b
$ Located (FieldOcc (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
-> Bool
-> HsRecField'
     (FieldOcc (GhcPass p)) (PScoped (Located (Pat (GhcPass p))))
forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField Located (FieldOcc (GhcPass p))
lbl (Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
rsp Scope
scope Scope
fscope Located (Pat (GhcPass p))
pat) Bool
pun
          scoped_fds :: [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
scoped_fds = Scope
-> [LHsRecField (GhcPass p) (Located (Pat (GhcPass p)))]
-> [RScoped (LHsRecField (GhcPass p) (Located (Pat (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
pscope [LHsRecField (GhcPass p) (Located (Pat (GhcPass p)))]
fds


instance ToHie (TScoped (HsPatSigType GhcRn)) where
  toHie :: TScoped (HsPatSigType GhcRn) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsPS (HsPSRn [Name]
wcs [Name]
tvs) body :: GenLocated SrcSpan (HsType GhcRn)
body@(L SrcSpan
span HsType GhcRn
_))) = [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
mkScope SrcSpan
span) TyVarScope
sc) ([Name]
wcs[Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++[Name]
tvs)
      , GenLocated SrcSpan (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GenLocated SrcSpan (HsType GhcRn)
body
      ]
  -- See Note [Scoping Rules for SigPat]

instance ( ToHie (Located body)
         , HiePass p
         , Data body
         ) => ToHie (GRHSs (GhcPass p) (Located body)) where
  toHie :: GRHSs (GhcPass p) (Located body) -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (Located body)
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) (Located body)
grhs of
    GRHSs XCGRHSs (GhcPass p) (Located body)
_ [LGRHS (GhcPass p) (Located body)]
grhss LHsLocalBinds (GhcPass p)
binds ->
     [ [LGRHS (GhcPass p) (Located body)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (Located body)]
grhss
     , RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBinds (GhcPass p) -> RScoped (LHsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GRHSs (GhcPass p) (Located body) -> SrcSpan
forall p body. GRHSs p body -> SrcSpan
grhss_span GRHSs (GhcPass p) (Located body)
grhs) LHsLocalBinds (GhcPass p)
binds
     ]

instance ( ToHie (Located body)
         , HiePass a
         , Data body
         ) => ToHie (LGRHS (GhcPass a) (Located body)) where
  toHie :: LGRHS (GhcPass a) (Located body) -> HieM [HieAST Type]
toHie (L SrcSpan
span GRHS (GhcPass a) (Located body)
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
$ HieM [HieAST Type]
node HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case GRHS (GhcPass a) (Located body)
g of
    GRHS XCGRHS (GhcPass a) (Located body)
_ [Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a)))]
guards Located body
body ->
      [ [RScoped
   (Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a)))]
-> [RScoped
      (Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes (Located body -> Scope
forall a. Located a -> Scope
mkLScope Located body
body) [Located (StmtLR (GhcPass a) (GhcPass a) (LHsExpr (GhcPass a)))]
guards
      , Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
      ]
    where
      node :: HieM [HieAST Type]
node = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @a of
        HiePassEv a
HieRn -> GRHS (GhcPass a) (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode GRHS (GhcPass a) (Located body)
g SrcSpan
span
        HiePassEv a
HieTc -> GRHS (GhcPass a) (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode GRHS (GhcPass a) (Located body)
g SrcSpan
span

instance HiePass p => ToHie (LHsExpr (GhcPass p)) where
  toHie :: LHsExpr (GhcPass p) -> HieM [HieAST Type]
toHie e :: LHsExpr (GhcPass p)
e@(L SrcSpan
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
$ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode LHsExpr (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 SrcSpan
_ IdP (GhcPass p)
var) ->
        [ Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan (IdGhcP p)
-> Context (GenLocated SrcSpan (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (SrcSpan -> IdGhcP p -> GenLocated SrcSpan (IdGhcP p)
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan IdGhcP p
IdP (GhcPass p)
var)
             -- Patch up var location since typechecker removes it
        ]
      HsUnboundVar XUnboundVar (GhcPass p)
_ OccName
_ ->
        []
      HsConLikeOut XConLikeOut (GhcPass p)
_ ConLike
con ->
        [ 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 ContextInfo
Use (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
mspan (Name -> Located Name) -> Name -> Located Name
forall a b. (a -> b) -> a -> b
$ ConLike -> Name
conLikeName ConLike
con
        ]
      HsRecFld XRecFld (GhcPass p)
_ AmbiguousFieldOcc (GhcPass p)
fld ->
        [ RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
 -> HieM [HieAST Type])
-> RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe Span
-> GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p))
-> RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
forall a. RecFieldContext -> Maybe Span -> a -> RFContext a
RFC RecFieldContext
RecFieldOcc Maybe Span
forall a. Maybe a
Nothing (SrcSpan
-> AmbiguousFieldOcc (GhcPass p)
-> GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan AmbiguousFieldOcc (GhcPass p)
fld)
        ]
      HsOverLabel XOverLabel (GhcPass p)
_ Maybe (IdP (GhcPass p))
_ FastString
_ -> []
      HsIPVar XIPVar (GhcPass p)
_ HsIPName
_ -> []
      HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
_ -> []
      HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
_ -> []
      HsLam XLam (GhcPass p)
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
        ]
      HsLamCase XLamCase (GhcPass p)
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
        ]
      HsApp XApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      HsAppType XAppTypeE (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsWcType (NoGhcTc (GhcPass p))
sig ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , TScoped (LHsWcType (GhcPass (NoGhcTcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))
 -> HieM [HieAST Type])
-> TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsWcType (GhcPass (NoGhcTcPass p))
-> TScoped (LHsWcType (GhcPass (NoGhcTcPass p)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsWcType (GhcPass (NoGhcTcPass p))
LHsWcType (NoGhcTc (GhcPass p))
sig
        ]
      OpApp XOpApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
c
        ]
      NegApp XNegApp (GhcPass p)
_ LHsExpr (GhcPass p)
a SyntaxExpr (GhcPass p)
_ ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        ]
      HsPar XPar (GhcPass p)
_ LHsExpr (GhcPass p)
a ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        ]
      SectionL XSectionL (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      SectionR XSectionR (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      ExplicitTuple XExplicitTuple (GhcPass p)
_ [LHsTupArg (GhcPass p)]
args Boxity
_ ->
        [ [LHsTupArg (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsTupArg (GhcPass p)]
args
        ]
      ExplicitSum XExplicitSum (GhcPass p)
_ TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsCase XCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches
        ]
      HsIf XIf (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
c
        ]
      HsMultiIf XMultiIf (GhcPass p)
_ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss ->
        [ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss
        ]
      HsLet XLet (GhcPass p)
_ LHsLocalBinds (GhcPass p)
binds LHsExpr (GhcPass p)
expr ->
        [ RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBinds (GhcPass p) -> RScoped (LHsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LHsExpr (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsExpr (GhcPass p)
expr) LHsLocalBinds (GhcPass p)
binds
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsDo XDo (GhcPass p)
_ HsStmtContext GhcRn
_ (L SrcSpan
ispan [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts) ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
ispan
        , [RScoped
   (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts
        ]
      ExplicitList XExplicitList (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ [LHsExpr (GhcPass p)]
exprs ->
        [ [LHsExpr (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsExpr (GhcPass p)]
exprs
        ]
      RecordCon {rcon_ext :: forall p. HsExpr p -> XRecordCon p
rcon_ext = XRecordCon (GhcPass p)
mrealcon, rcon_con_name :: forall p. HsExpr p -> Located (IdP p)
rcon_con_name = GenLocated SrcSpan (IdP (GhcPass p))
name, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds (GhcPass p)
binds} ->
        [ Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan (IdGhcP p)
-> Context (GenLocated SrcSpan (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (forall p.
HasRealDataConName p =>
XRecordCon p -> Located (IdP p) -> Located (IdP p)
getRealDataCon @(GhcPass p) XRecordCon (GhcPass p)
mrealcon GenLocated SrcSpan (IdP (GhcPass p))
name)
            -- See Note [Real DataCon 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
        ]
      RecordUpd {rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr (GhcPass p)
expr, rupd_flds :: forall p. HsExpr p -> [LHsRecUpdField p]
rupd_flds = [LHsRecUpdField (GhcPass p)]
upds}->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , [RContext (LHsRecUpdField (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext (LHsRecUpdField (GhcPass p))] -> HieM [HieAST Type])
-> [RContext (LHsRecUpdField (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsRecUpdField (GhcPass p)
 -> RContext (LHsRecUpdField (GhcPass p)))
-> [LHsRecUpdField (GhcPass p)]
-> [RContext (LHsRecUpdField (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> LHsRecUpdField (GhcPass p)
-> RContext (LHsRecUpdField (GhcPass p))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign) [LHsRecUpdField (GhcPass p)]
upds
        ]
      ExprWithTySig XExprWithTySig (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsSigWcType (NoGhcTc (GhcPass p))
sig ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
 -> HieM [HieAST Type])
-> TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> LHsSigWcType (GhcPass (NoGhcTcPass p))
-> TScoped (LHsSigWcType (GhcPass (NoGhcTcPass p)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [LHsExpr (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsExpr (GhcPass p)
expr]) LHsSigWcType (GhcPass (NoGhcTcPass p))
LHsSigWcType (NoGhcTc (GhcPass p))
sig
        ]
      ArithSeq XArithSeq (GhcPass p)
_ 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
        ]
      HsPragE XPragE (GhcPass p)
_ HsPragE (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsProc XProc (GhcPass p)
_ LPat (GhcPass p)
pat LHsCmdTop (GhcPass p)
cmdtop ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing (LHsCmdTop (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsCmdTop (GhcPass p)
cmdtop) Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        , LHsCmdTop (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmdTop (GhcPass p)
cmdtop
        ]
      HsStatic XStatic (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsTick XTick (GhcPass p)
_ Tickish (IdP (GhcPass p))
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsBinTick XBinTick (GhcPass p)
_ TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
expr ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        ]
      HsBracket XBracket (GhcPass p)
_ HsBracket (GhcPass p)
b ->
        [ HsBracket (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsBracket (GhcPass p)
b
        ]
      HsRnBracketOut XRnBracketOut (GhcPass p)
_ HsBracket GhcRn
b [PendingRnSplice]
p ->
        [ HsBracket GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsBracket GhcRn
b
        , [PendingRnSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingRnSplice]
p
        ]
      HsTcBracketOut XTcBracketOut (GhcPass p)
_ Maybe QuoteWrapper
_wrap HsBracket GhcRn
b [PendingTcSplice]
p ->
        [ HsBracket GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsBracket GhcRn
b
        , [PendingTcSplice] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [PendingTcSplice]
p
        ]
      HsSpliceE XSpliceE (GhcPass p)
_ HsSplice (GhcPass p)
x ->
        [ GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type])
-> GenLocated SrcSpan (HsSplice (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> HsSplice (GhcPass p)
-> GenLocated SrcSpan (HsSplice (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsSplice (GhcPass p)
x
        ]
      XExpr XXExpr (GhcPass p)
x
        | GhcPass p
GhcTc <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
        , WrapExpr (HsWrap HsWrapper
w HsExpr GhcTc
a) <- XXExpr (GhcPass p)
x
        -> [ LHsExpr GhcTc -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (LHsExpr GhcTc -> HieM [HieAST Type])
-> LHsExpr GhcTc -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsExpr GhcTc -> LHsExpr GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsExpr GhcTc
a
           , Located HsWrapper -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsWrapper -> Located HsWrapper
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsWrapper
w)
           ]
        | GhcPass p
GhcTc <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
        , ExpansionExpr (HsExpanded HsExpr GhcRn
_ HsExpr GhcTc
b) <- XXExpr (GhcPass p)
x
        -> [ LHsExpr GhcTc -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsExpr GhcTc -> LHsExpr GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsExpr GhcTc
b)
           ]
        | Bool
otherwise -> []

instance HiePass p => ToHie (LHsTupArg (GhcPass p)) where
  toHie :: LHsTupArg (GhcPass p) -> HieM [HieAST Type]
toHie (L SrcSpan
span 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
$ HsTupArg (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsTupArg (GhcPass p)
arg SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsTupArg (GhcPass p)
arg of
    Present XPresent (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
      [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
      ]
    Missing XMissing (GhcPass p)
_ -> []

instance ( ToHie (Located body)
         , Data body
         , HiePass p
         ) => ToHie (RScoped (LStmt (GhcPass p) (Located body))) where
  toHie :: RScoped (LStmt (GhcPass p) (Located body)) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpan
span StmtLR (GhcPass p) (GhcPass p) (Located body)
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 StmtLR (GhcPass p) (GhcPass p) (Located body)
stmt of
      LastStmt XLastStmt (GhcPass p) (GhcPass p) (Located body)
_ Located body
body Maybe Bool
_ SyntaxExpr (GhcPass p)
_ ->
        [ Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
        ]
      BindStmt XBindStmt (GhcPass p) (GhcPass p) (Located body)
_ LPat (GhcPass p)
pat Located body
body ->
        [ PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (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
$ Located body -> SrcSpan
forall l e. GenLocated l e -> l
getLoc Located body
body) Scope
scope Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        , Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
        ]
      ApplicativeStmt XApplicativeStmt (GhcPass p) (GhcPass p) (Located body)
_ [(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 :: * -> *) a b. Monad m => (a -> m [b]) -> [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
        ]
      BodyStmt XBodyStmt (GhcPass p) (GhcPass p) (Located body)
_ Located body
body SyntaxExpr (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ ->
        [ Located body -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located body
body
        ]
      LetStmt XLetStmt (GhcPass p) (GhcPass p) (Located body)
_ LHsLocalBindsLR (GhcPass p) (GhcPass p)
binds ->
        [ RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
 -> HieM [HieAST Type])
-> RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBindsLR (GhcPass p) (GhcPass p)
-> RScoped (LHsLocalBindsLR (GhcPass p) (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
scope LHsLocalBindsLR (GhcPass p) (GhcPass p)
binds
        ]
      ParStmt XParStmt (GhcPass p) (GhcPass p) (Located body)
_ [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 :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (\(ParStmtBlock XParStmtBlock (GhcPass p) (GhcPass p)
_ [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts [IdP (GhcPass p)]
_ SyntaxExpr (GhcPass p)
_) ->
                          [RScoped
   (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts)
                     [ParStmtBlock (GhcPass p) (GhcPass p)]
parstmts
        ]
      TransStmt {trS_stmts :: forall idL idR body. StmtLR idL idR body -> [ExprLStmt idL]
trS_stmts = [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (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
   (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
scope [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
using
        , Maybe (LHsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LHsExpr (GhcPass p))
by
        ]
      RecStmt {recS_stmts :: forall idL idR body. StmtLR idL idR body -> [LStmtLR idL idR body]
recS_stmts = [LStmt (GhcPass p) (Located body)]
stmts} ->
        [ [RScoped (LStmt (GhcPass p) (Located body))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (LStmt (GhcPass p) (Located body))]
 -> HieM [HieAST Type])
-> [RScoped (LStmt (GhcPass p) (Located body))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LStmt (GhcPass p) (Located body)
 -> RScoped (LStmt (GhcPass p) (Located body)))
-> [LStmt (GhcPass p) (Located body)]
-> [RScoped (LStmt (GhcPass p) (Located body))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> LStmt (GhcPass p) (Located body)
-> RScoped (LStmt (GhcPass p) (Located body))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> LStmt (GhcPass p) (Located body)
 -> RScoped (LStmt (GhcPass p) (Located body)))
-> Scope
-> LStmt (GhcPass p) (Located body)
-> RScoped (LStmt (GhcPass p) (Located body))
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes Scope
scope (SrcSpan -> Scope
mkScope SrcSpan
span)) [LStmt (GhcPass p) (Located body)]
stmts
        ]
    where
      node :: HieM [HieAST Type]
node = case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc -> StmtLR (GhcPass p) (GhcPass p) (Located body)
-> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode StmtLR (GhcPass p) (GhcPass p) (Located body)
stmt SrcSpan
span
        HiePassEv p
HieRn -> StmtLR (GhcPass p) (GhcPass p) (Located body)
-> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode StmtLR (GhcPass p) (GhcPass p) (Located body)
stmt SrcSpan
span

instance HiePass p => ToHie (RScoped (LHsLocalBinds (GhcPass p))) where
  toHie :: RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpan
sp 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 SrcSpan
sp 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
$ SrcSpan -> Scope
mkScope SrcSpan
sp in
          [ case forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
              HiePassEv p
HieTc -> EvBindContext (GenLocated SrcSpan TcEvBinds) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (EvBindContext (GenLocated SrcSpan TcEvBinds)
 -> HieM [HieAST Type])
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Maybe Span
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe Span -> a -> EvBindContext a
EvBindContext Scope
sc (SrcSpan -> Maybe Span
getRealSpan SrcSpan
sp) (GenLocated SrcSpan TcEvBinds
 -> EvBindContext (GenLocated SrcSpan TcEvBinds))
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> TcEvBinds -> GenLocated SrcSpan TcEvBinds
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp XIPBinds (GhcPass p)
TcEvBinds
evbinds
              HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          , [RScoped (LIPBind (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (LIPBind (GhcPass p))] -> HieM [HieAST Type])
-> [RScoped (LIPBind (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LIPBind (GhcPass p) -> RScoped (LIPBind (GhcPass p)))
-> [LIPBind (GhcPass p)] -> [RScoped (LIPBind (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope -> LIPBind (GhcPass p) -> RScoped (LIPBind (GhcPass p))
forall a. Scope -> a -> RScoped a
RS Scope
sc) [LIPBind (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 (Scope -> Scope) -> Scope -> Scope
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Scope
mkScope SrcSpan
sp)
                      HsValBindsLR (GhcPass p) (GhcPass p)
valBinds
        ]

instance HiePass p => ToHie (RScoped (LIPBind (GhcPass p))) where
  toHie :: RScoped (LIPBind (GhcPass p)) -> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpan
sp IPBind (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
$ IPBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode IPBind (GhcPass p)
bind SrcSpan
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IPBind (GhcPass p)
bind of
    IPBind XCIPBind (GhcPass p)
_ (Left Located HsIPName
_) LHsExpr (GhcPass p)
expr -> [LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr]
    IPBind XCIPBind (GhcPass p)
_ (Right IdP (GhcPass p)
v) LHsExpr (GhcPass p)
expr ->
      [ Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan (IdGhcP p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan (IdGhcP p)
-> Context (GenLocated SrcSpan (IdGhcP p))
forall a. ContextInfo -> a -> Context a
C (EvVarSource -> Scope -> Maybe Span -> ContextInfo
EvidenceVarBind EvVarSource
EvImplicitBind Scope
scope (SrcSpan -> Maybe Span
getRealSpan SrcSpan
sp))
                  (GenLocated SrcSpan (IdGhcP p)
 -> Context (GenLocated SrcSpan (IdGhcP p)))
-> GenLocated SrcSpan (IdGhcP p)
-> Context (GenLocated SrcSpan (IdGhcP p))
forall a b. (a -> b) -> a -> b
$ SrcSpan -> IdGhcP p -> GenLocated SrcSpan (IdGhcP p)
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp IdGhcP p
IdP (GhcPass p)
v
      , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
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 ->
      [ Bag (BindContext (LHsBindLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBindLR (GhcPass p) (GhcPass p)))
 -> HieM [HieAST Type])
-> Bag (BindContext (LHsBindLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBindLR (GhcPass p) (GhcPass p)
 -> BindContext (LHsBindLR (GhcPass p) (GhcPass p)))
-> LHsBindsLR (GhcPass p) (GhcPass p)
-> Bag (BindContext (LHsBindLR (GhcPass p) (GhcPass p)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> LHsBindLR (GhcPass p) (GhcPass p)
-> BindContext (LHsBindLR (GhcPass p) (GhcPass p))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) LHsBindsLR (GhcPass p) (GhcPass p)
binds
      , [SigContext (LSig (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig (GhcPass p))] -> HieM [HieAST Type])
-> [SigContext (LSig (GhcPass p))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig (GhcPass p) -> SigContext (LSig (GhcPass p)))
-> [LSig (GhcPass p)] -> [SigContext (LSig (GhcPass p))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo -> LSig (GhcPass p) -> SigContext (LSig (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)]
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 GhcRn]
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 (LHsBindLR (GhcPass p) (GhcPass p))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (((RecFlag, LHsBinds (GhcPass p))
 -> [BindContext (LHsBindLR (GhcPass p) (GhcPass p))])
-> [(RecFlag, LHsBinds (GhcPass p))]
-> [BindContext (LHsBindLR (GhcPass p) (GhcPass p))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((LHsBindLR (GhcPass p) (GhcPass p)
 -> BindContext (LHsBindLR (GhcPass p) (GhcPass p)))
-> [LHsBindLR (GhcPass p) (GhcPass p)]
-> [BindContext (LHsBindLR (GhcPass p) (GhcPass p))]
forall a b. (a -> b) -> [a] -> [b]
map (BindType
-> Scope
-> LHsBindLR (GhcPass p) (GhcPass p)
-> BindContext (LHsBindLR (GhcPass p) (GhcPass p))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) ([LHsBindLR (GhcPass p) (GhcPass p)]
 -> [BindContext (LHsBindLR (GhcPass p) (GhcPass p))])
-> ((RecFlag, LHsBinds (GhcPass p))
    -> [LHsBindLR (GhcPass p) (GhcPass p)])
-> (RecFlag, LHsBinds (GhcPass p))
-> [BindContext (LHsBindLR (GhcPass p) (GhcPass p))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsBinds (GhcPass p) -> [LHsBindLR (GhcPass p) (GhcPass p)]
forall a. Bag a -> [a]
bagToList (LHsBinds (GhcPass p) -> [LHsBindLR (GhcPass p) (GhcPass p)])
-> ((RecFlag, LHsBinds (GhcPass p)) -> LHsBinds (GhcPass p))
-> (RecFlag, LHsBinds (GhcPass p))
-> [LHsBindLR (GhcPass p) (GhcPass p)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag, LHsBinds (GhcPass p)) -> LHsBinds (GhcPass p)
forall a b. (a, b) -> b
snd) [(RecFlag, LHsBinds (GhcPass p))]
binds)
    , [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig GhcRn)] -> HieM [HieAST Type])
-> [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig GhcRn -> SigContext (LSig GhcRn))
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe Span -> SigInfo
SI SigType
BindSig Maybe Span
forall a. Maybe a
Nothing)) [LSig GhcRn]
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 [LHsRecField (GhcPass p) arg]
fields Maybe (Located TypeIndex)
_)) = [RContext (LHsRecField (GhcPass p) arg)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext (LHsRecField (GhcPass p) arg)] -> HieM [HieAST Type])
-> [RContext (LHsRecField (GhcPass p) arg)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsRecField (GhcPass p) arg
 -> RContext (LHsRecField (GhcPass p) arg))
-> [LHsRecField (GhcPass p) arg]
-> [RContext (LHsRecField (GhcPass p) arg)]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> LHsRecField (GhcPass p) arg
-> RContext (LHsRecField (GhcPass p) arg)
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
c) [LHsRecField (GhcPass p) arg]
fields

instance ( ToHie (RFContext (Located label))
         , ToHie arg , HasLoc arg , Data arg
         , Data label
         ) => ToHie (RContext (LHsRecField' label arg)) where
  toHie :: RContext (LHsRecField' label arg) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (L SrcSpan
span HsRecField' 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
$ HsRecField' label arg -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsRecField' label arg
recfld SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsRecField' label arg
recfld of
    HsRecField Located label
label arg
expr Bool
_ ->
      [ RFContext (Located label) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RFContext (Located label) -> HieM [HieAST Type])
-> RFContext (Located label) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> Maybe Span -> Located label -> RFContext (Located 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
loc arg
expr) Located label
label
      , arg -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie arg
expr
      ]

instance ToHie (RFContext (LFieldOcc GhcRn)) where
  toHie :: RFContext (Located (FieldOcc GhcRn)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpan
nspan FieldOcc GhcRn
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 FieldOcc GhcRn
f of
    FieldOcc XCFieldOcc GhcRn
name Located RdrName
_ ->
      [ 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 SrcSpan
nspan Name
XCFieldOcc GhcRn
name)
      ]

instance ToHie (RFContext (LFieldOcc GhcTc)) where
  toHie :: RFContext (Located (FieldOcc GhcTc)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpan
nspan FieldOcc GhcTc
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 FieldOcc GhcTc
f of
    FieldOcc XCFieldOcc GhcTc
var Located RdrName
_ ->
      [ Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Id
XCFieldOcc GhcTc
var)
      ]

instance ToHie (RFContext (Located (AmbiguousFieldOcc GhcRn))) where
  toHie :: RFContext (Located (AmbiguousFieldOcc GhcRn)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpan
nspan AmbiguousFieldOcc GhcRn
afo)) = [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 AmbiguousFieldOcc GhcRn
afo of
    Unambiguous XUnambiguous GhcRn
name Located RdrName
_ ->
      [ 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) (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
nspan Name
XUnambiguous GhcRn
name
      ]
    Ambiguous XAmbiguous GhcRn
_name Located RdrName
_ ->
      [ ]

instance ToHie (RFContext (Located (AmbiguousFieldOcc GhcTc))) where
  toHie :: RFContext (Located (AmbiguousFieldOcc GhcTc)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe Span
rhs (L SrcSpan
nspan AmbiguousFieldOcc GhcTc
afo)) = [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 AmbiguousFieldOcc GhcTc
afo of
    Unambiguous XUnambiguous GhcTc
var Located RdrName
_ ->
      [ Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Id
XUnambiguous GhcTc
var)
      ]
    Ambiguous XAmbiguous GhcTc
var Located RdrName
_ ->
      [ Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan Id) -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan Id) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan Id -> Context (GenLocated SrcSpan Id)
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe Span -> ContextInfo
RecField RecFieldContext
c Maybe Span
rhs) (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Id
XAmbiguous GhcTc
var)
      ]

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 (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
sc Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
    , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
    ]
  toHie (RS Scope
sc (ApplicativeArgMany XApplicativeArgMany (GhcPass p)
_ [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts HsExpr (GhcPass p)
_ LPat (GhcPass p)
pat HsStmtContext GhcRn
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ [RScoped
   (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located (StmtLR (GhcPass p) (GhcPass p) (LHsExpr (GhcPass p)))]
stmts
    , PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type])
-> PScoped (Located (Pat (GhcPass p))) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Maybe Span
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe Span -> Scope -> Scope -> a -> PScoped a
PS Maybe Span
forall a. Maybe a
Nothing Scope
sc Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
    ]

instance (ToHie arg, ToHie rec) => ToHie (HsConDetails arg rec) where
  toHie :: HsConDetails arg rec -> HieM [HieAST Type]
toHie (PrefixCon [arg]
args) = [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 HiePass p => ToHie (LHsCmdTop (GhcPass p)) where
  toHie :: LHsCmdTop (GhcPass p) -> HieM [HieAST Type]
toHie (L SrcSpan
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) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsCmdTop (GhcPass p)
top SrcSpan
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 ->
      [ LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
cmd
      ]

instance HiePass p => ToHie (LHsCmd (GhcPass p)) where
  toHie :: LHsCmd (GhcPass p) -> HieM [HieAST Type]
toHie (L SrcSpan
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) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsCmd (GhcPass p)
cmd SrcSpan
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
_ ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      HsCmdArrForm XCmdArrForm (GhcPass p)
_ LHsExpr (GhcPass p)
a LexicalFixity
_ Maybe Fixity
_ [LHsCmdTop (GhcPass p)]
cmdtops ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , [LHsCmdTop (GhcPass p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LHsCmdTop (GhcPass p)]
cmdtops
        ]
      HsCmdApp XCmdApp (GhcPass p)
_ LHsCmd (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
a
        , LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
b
        ]
      HsCmdLam XCmdLam (GhcPass p)
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (LHsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
mg
        ]
      HsCmdPar XCmdPar (GhcPass p)
_ LHsCmd (GhcPass p)
a ->
        [ LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
a
        ]
      HsCmdCase XCmdCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
expr
        , MatchGroup (GhcPass p) (LHsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts
        ]
      HsCmdLamCase XCmdLamCase (GhcPass p)
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ MatchGroup (GhcPass p) (LHsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts
        ]
      HsCmdIf XCmdIf (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsCmd (GhcPass p)
b LHsCmd (GhcPass p)
c ->
        [ LHsExpr (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsExpr (GhcPass p)
a
        , LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
b
        , LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
c
        ]
      HsCmdLet XCmdLet (GhcPass p)
_ LHsLocalBinds (GhcPass p)
binds LHsCmd (GhcPass p)
cmd' ->
        [ RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type])
-> RScoped (LHsLocalBinds (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> LHsLocalBinds (GhcPass p) -> RScoped (LHsLocalBinds (GhcPass p))
forall a. Scope -> a -> RScoped a
RS (LHsCmd (GhcPass p) -> Scope
forall a. Located a -> Scope
mkLScope LHsCmd (GhcPass p)
cmd') LHsLocalBinds (GhcPass p)
binds
        , LHsCmd (GhcPass p) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsCmd (GhcPass p)
cmd'
        ]
      HsCmdDo XCmdDo (GhcPass p)
_ (L SrcSpan
ispan [Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p)))]
stmts) ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
ispan
        , [RScoped
   (Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p)))]
-> [RScoped
      (Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located (StmtLR (GhcPass p) (GhcPass p) (LHsCmd (GhcPass p)))]
stmts
        ]
      XCmd XXCmd (GhcPass p)
_ -> []

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

instance ToHie (LTyClDecl GhcRn) where
  toHie :: LTyClDecl GhcRn -> HieM [HieAST Type]
toHie (L SrcSpan
span TyClDecl GhcRn
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 GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode TyClDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case TyClDecl GhcRn
decl of
      FamDecl {tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl GhcRn
fdecl} ->
        [ GenLocated SrcSpan (FamilyDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan
-> FamilyDecl GhcRn -> GenLocated SrcSpan (FamilyDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span FamilyDecl GhcRn
fdecl)
        ]
      SynDecl {tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdLName = Located (IdP GhcRn)
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars, tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = GenLocated SrcSpan (HsType GhcRn)
typ} ->
        [ 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 (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
SynDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) Located Name
Located (IdP GhcRn)
name
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpan (HsType GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc GenLocated SrcSpan (HsType GhcRn)
typ]) LHsQTyVars GhcRn
vars
        , GenLocated SrcSpan (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GenLocated SrcSpan (HsType GhcRn)
typ
        ]
      DataDecl {tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdLName = Located (IdP GhcRn)
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars, tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn GhcRn
defn} ->
        [ 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 (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
DataDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) Located Name
Located (IdP GhcRn)
name
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
quant_scope, Scope
rhs_scope]) LHsQTyVars GhcRn
vars
        , HsDataDefn GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsDataDefn GhcRn
defn
        ]
        where
          quant_scope :: Scope
quant_scope = LHsContext GhcRn -> Scope
forall a. Located a -> Scope
mkLScope (LHsContext GhcRn -> Scope) -> LHsContext GhcRn -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> LHsContext GhcRn
forall pass. HsDataDefn pass -> LHsContext pass
dd_ctxt HsDataDefn GhcRn
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 SrcSpan (HsType GhcRn) -> Scope)
-> Maybe (GenLocated SrcSpan (HsType GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope GenLocated SrcSpan (HsType GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope (Maybe (GenLocated SrcSpan (HsType GhcRn)) -> Scope)
-> Maybe (GenLocated SrcSpan (HsType GhcRn)) -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Maybe (GenLocated SrcSpan (HsType GhcRn))
forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_kindSig HsDataDefn GhcRn
defn
          con_sc :: Scope
con_sc = (Scope -> Scope -> Scope) -> Scope -> [Scope] -> Scope
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
$ (LConDecl GhcRn -> Scope) -> [LConDecl GhcRn] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map LConDecl GhcRn -> Scope
forall a. Located a -> Scope
mkLScope ([LConDecl GhcRn] -> [Scope]) -> [LConDecl GhcRn] -> [Scope]
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> [LConDecl GhcRn]
forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons HsDataDefn GhcRn
defn
          deriv_sc :: Scope
deriv_sc = Located [LHsDerivingClause GhcRn] -> Scope
forall a. Located a -> Scope
mkLScope (Located [LHsDerivingClause GhcRn] -> Scope)
-> Located [LHsDerivingClause GhcRn] -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Located [LHsDerivingClause GhcRn]
forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs HsDataDefn GhcRn
defn
      ClassDecl { tcdCtxt :: forall pass. TyClDecl pass -> LHsContext pass
tcdCtxt = LHsContext GhcRn
context
                , tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdLName = Located (IdP GhcRn)
name
                , tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars
                , tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdFDs = [LHsFunDep GhcRn]
deps
                , tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdSigs = [LSig GhcRn]
sigs
                , tcdMeths :: forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths = LHsBinds GhcRn
meths
                , tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATs = [GenLocated SrcSpan (FamilyDecl GhcRn)]
typs
                , tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATDefs = [LTyFamDefltDecl GhcRn]
deftyps
                } ->
        [ 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 (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
ClassDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) Located Name
Located (IdP GhcRn)
name
        , LHsContext GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LHsContext GhcRn
context
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
context_scope, Scope
rhs_scope]) LHsQTyVars GhcRn
vars
        , [Located (FunDep (Located Name))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (FunDep (Located Name))]
[LHsFunDep GhcRn]
deps
        , [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (LSig GhcRn)] -> HieM [HieAST Type])
-> [SigContext (LSig GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LSig GhcRn -> SigContext (LSig GhcRn))
-> [LSig GhcRn] -> [SigContext (LSig GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
forall a. SigInfo -> a -> SigContext a
SC (SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn))
-> SigInfo -> LSig GhcRn -> SigContext (LSig GhcRn)
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
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) [LSig GhcRn]
sigs
        , Bag (BindContext (LHsBindLR GhcRn GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (LHsBindLR GhcRn GhcRn)) -> HieM [HieAST Type])
-> Bag (BindContext (LHsBindLR GhcRn GhcRn)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LHsBindLR GhcRn GhcRn -> BindContext (LHsBindLR GhcRn GhcRn))
-> LHsBinds GhcRn -> Bag (BindContext (LHsBindLR GhcRn GhcRn))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> LHsBindLR GhcRn GhcRn
-> BindContext (LHsBindLR GhcRn GhcRn)
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) LHsBinds GhcRn
meths
        , [GenLocated SrcSpan (FamilyDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpan (FamilyDecl GhcRn)]
typs
        , (LTyFamDefltDecl GhcRn -> HieM [HieAST Type])
-> [LTyFamDefltDecl GhcRn] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (LTyFamDefltDecl GhcRn -> SrcSpan)
-> LTyFamDefltDecl GhcRn
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamDefltDecl GhcRn -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) [LTyFamDefltDecl GhcRn]
deftyps
        , [LTyFamDefltDecl GhcRn] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [LTyFamDefltDecl GhcRn]
deftyps
        ]
        where
          context_scope :: Scope
context_scope = LHsContext GhcRn -> Scope
forall a. Located a -> Scope
mkLScope LHsContext GhcRn
context
          rhs_scope :: Scope
rhs_scope = (Scope -> Scope -> Scope) -> [Scope] -> Scope
forall a. (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
mkScope
            [ [Located (FunDep (Located Name))] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [Located (FunDep (Located Name))]
[LHsFunDep GhcRn]
deps, [LSig GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LSig GhcRn]
sigs, [LHsBindLR GhcRn GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc (LHsBinds GhcRn -> [LHsBindLR GhcRn GhcRn]
forall a. Bag a -> [a]
bagToList LHsBinds GhcRn
meths), [GenLocated SrcSpan (FamilyDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [GenLocated SrcSpan (FamilyDecl GhcRn)]
typs, [LTyFamDefltDecl GhcRn] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [LTyFamDefltDecl GhcRn]
deftyps]

instance ToHie (LFamilyDecl GhcRn) where
  toHie :: GenLocated SrcSpan (FamilyDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span FamilyDecl GhcRn
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 GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode FamilyDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FamilyDecl GhcRn
decl of
      FamilyDecl XCFamilyDecl GhcRn
_ FamilyInfo GhcRn
info Located (IdP GhcRn)
name LHsQTyVars GhcRn
vars LexicalFixity
_ LFamilyResultSig GhcRn
sig Maybe (LInjectivityAnn GhcRn)
inj ->
        [ 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 (DeclType -> Maybe Span -> ContextInfo
Decl DeclType
FamDec (Maybe Span -> ContextInfo) -> Maybe Span -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe Span
getRealSpan SrcSpan
span) Located Name
Located (IdP GhcRn)
name
        , TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type])
-> TScoped (LHsQTyVars GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> LHsQTyVars GhcRn -> TScoped (LHsQTyVars GhcRn)
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Scope
rhsSpan]) LHsQTyVars GhcRn
vars
        , FamilyInfo GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamilyInfo GhcRn
info
        , RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type])
-> RScoped (LFamilyResultSig GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope -> LFamilyResultSig GhcRn -> RScoped (LFamilyResultSig GhcRn)
forall a. Scope -> a -> RScoped a
RS Scope
injSpan LFamilyResultSig GhcRn
sig
        , Maybe (LInjectivityAnn GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (LInjectivityAnn GhcRn)
inj
        ]
        where
          rhsSpan :: Scope
rhsSpan = Scope
sigSpan Scope -> Scope -> Scope
`combineScopes` Scope
injSpan
          sigSpan :: Scope
sigSpan = SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ LFamilyResultSig GhcRn -> SrcSpan
forall l e. GenLocated l e -> l
getLoc LFamilyResultSig GhcRn
sig
          injSpan :: Scope
injSpan = Scope
-> (LInjectivityAnn GhcRn -> Scope)
-> Maybe (LInjectivityAnn GhcRn)
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope (SrcSpan -> Scope
mkScope (SrcSpan -> Scope)
-> (LInjectivityAnn GhcRn -> SrcSpan)
-> LInjectivityAnn GhcRn
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LInjectivityAnn GhcRn -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) Maybe (LInjectivityAnn GhcRn)
inj

instance ToHie (FamilyInfo GhcRn) where
  toHie :: FamilyInfo GhcRn -> HieM [HieAST Type]
toHie (ClosedTypeFamily (Just [LTyFamInstEqn GhcRn]
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
$
    [ (LTyFamInstEqn GhcRn -> HieM [HieAST Type])
-> [LTyFamInstEqn GhcRn] -> HieM [HieAST Type]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (LTyFamInstEqn GhcRn -> SrcSpan)
-> LTyFamInstEqn GhcRn
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamInstEqn GhcRn -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) [LTyFamInstEqn GhcRn]
eqns
    , [TScoped (TyFamInstEqn GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (TyFamInstEqn GhcRn)] -> HieM [HieAST Type])
-> [TScoped (TyFamInstEqn GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LTyFamInstEqn GhcR