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

{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

{-
Main functions for .hie file generation
-}

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.Env
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.Builtin.Uniques
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 GHC.Unit.Module            ( ModuleName, ml_hs_file )
import GHC.Unit.Module.ModSummary

import qualified Data.Array as A
import qualified Data.ByteString as BS
import qualified Data.Map as M
import qualified Data.Set as S
import Data.Data                  ( Data, Typeable )
import Data.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 RealSrcSpan
spn Maybe BufSpan
_
          | RealSrcSpan -> FastString
srcSpanFile RealSrcSpan
spn FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
== FastString
file ->
            let node :: HieAST Type
node = SourcedNodeInfo Type -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a.
SourcedNodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node (NodeOrigin -> NodeInfo Type -> SourcedNodeInfo Type
forall a. NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
mkSourcedNodeInfo NodeOrigin
org NodeInfo Type
ni) RealSrcSpan
spn []
                ni :: NodeInfo Type
ni = Set NodeAnnotation
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Monoid a => a
mempty [] (NodeIdentifiers Type -> NodeInfo Type)
-> NodeIdentifiers Type -> NodeInfo Type
forall a b. (a -> b) -> a -> b
$ [(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 :: [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, [LImportDecl 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 (Located (HsBindLR GhcTc GhcTc)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (Located (HsBindLR GhcTc GhcTc)))
 -> HieM [HieAST Type])
-> Bag (BindContext (Located (HsBindLR GhcTc GhcTc)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (HsBindLR GhcTc GhcTc)
 -> BindContext (Located (HsBindLR GhcTc GhcTc)))
-> Bag (Located (HsBindLR GhcTc GhcTc))
-> Bag (BindContext (Located (HsBindLR GhcTc GhcTc)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> Located (HsBindLR GhcTc GhcTc)
-> BindContext (Located (HsBindLR GhcTc GhcTc))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
ModuleScope) Bag (Located (HsBindLR GhcTc GhcTc))
LHsBinds GhcTc
ts
    [HieAST Type]
rasts <- HsGroup GhcRn -> HieM [HieAST Type]
forall p.
(ToHie (XRec p (SpliceDecl p)), ToHie (XRec p (DerivDecl p)),
 ToHie (XRec p (FixitySig p)), ToHie (XRec p (DefaultDecl p)),
 ToHie (XRec p (ForeignDecl p)), ToHie (XRec p (WarnDecls p)),
 ToHie (XRec p (AnnDecl p)), ToHie (XRec p (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)]
[LImportDecl GhcRn]
imports
    [HieAST Type]
exps <- Maybe [IEContext (Located (IE GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [IEContext (Located (IE GhcRn))] -> HieM [HieAST Type])
-> Maybe [IEContext (Located (IE GhcRn))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([(Located (IE GhcRn), [AvailInfo])]
 -> [IEContext (Located (IE GhcRn))])
-> Maybe [(Located (IE GhcRn), [AvailInfo])]
-> Maybe [IEContext (Located (IE GhcRn))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Located (IE GhcRn), [AvailInfo])
 -> IEContext (Located (IE GhcRn)))
-> [(Located (IE GhcRn), [AvailInfo])]
-> [IEContext (Located (IE GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (((Located (IE GhcRn), [AvailInfo])
  -> IEContext (Located (IE GhcRn)))
 -> [(Located (IE GhcRn), [AvailInfo])]
 -> [IEContext (Located (IE GhcRn))])
-> ((Located (IE GhcRn), [AvailInfo])
    -> IEContext (Located (IE GhcRn)))
-> [(Located (IE GhcRn), [AvailInfo])]
-> [IEContext (Located (IE GhcRn))]
forall a b. (a -> b) -> a -> b
$ IEType -> Located (IE GhcRn) -> IEContext (Located (IE GhcRn))
forall a. IEType -> a -> IEContext a
IEC IEType
Export (Located (IE GhcRn) -> IEContext (Located (IE GhcRn)))
-> ((Located (IE GhcRn), [AvailInfo]) -> Located (IE GhcRn))
-> (Located (IE GhcRn), [AvailInfo])
-> IEContext (Located (IE GhcRn))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (IE GhcRn), [AvailInfo]) -> Located (IE GhcRn)
forall a b. (a, b) -> a
fst) Maybe [(Located (IE GhcRn), [AvailInfo])]
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 RealSrcSpan -> ContextInfo
EvidenceVarBind (Bool -> Name -> EvVarSource
EvInstBind Bool
False (ClsInst -> Name
is_cls_nm ClsInst
i)) Scope
ModuleScope Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
EvidenceVarBind (Bool -> Name -> EvVarSource
EvInstBind Bool
True (Class -> Name
className Class
c)) Scope
ModuleScope Maybe RealSrcSpan
forall a. Maybe a
Nothing)
    let spanFile :: FastString -> [HieAST a] -> RealSrcSpan
spanFile FastString
file [HieAST a]
children = case [HieAST a]
children of
          [] -> RealSrcLoc -> RealSrcSpan
realSrcLocSpan (FastString -> TypeIndex -> TypeIndex -> RealSrcLoc
mkRealSrcLoc FastString
file TypeIndex
1 TypeIndex
1)
          [HieAST a]
_ -> RealSrcLoc -> RealSrcLoc -> RealSrcSpan
mkRealSrcSpan (RealSrcSpan -> RealSrcLoc
realSrcSpanStart (RealSrcSpan -> RealSrcLoc) -> RealSrcSpan -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> RealSrcSpan
forall a. HieAST a -> RealSrcSpan
nodeSpan (HieAST a -> RealSrcSpan) -> HieAST a -> RealSrcSpan
forall a b. (a -> b) -> a -> b
$ [HieAST a] -> HieAST a
forall a. [a] -> a
head [HieAST a]
children)
                             (RealSrcSpan -> RealSrcLoc
realSrcSpanEnd   (RealSrcSpan -> RealSrcLoc) -> RealSrcSpan -> RealSrcLoc
forall a b. (a -> b) -> a -> b
$ HieAST a -> RealSrcSpan
forall a. HieAST a -> RealSrcSpan
nodeSpan (HieAST a -> RealSrcSpan) -> HieAST a -> RealSrcSpan
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 :: HiePath
-> [HieAST Type]
-> ReaderT NodeOrigin (StateT HieState Hsc) (HieAST Type)
modulify (HiePath 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 RealSrcSpan
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe RealSrcSpan -> a -> EvBindContext a
EvBindContext Scope
ModuleScope Maybe RealSrcSpan
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 (RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan (RealSrcLoc -> RealSrcSpan
realSrcLocSpan (RealSrcLoc -> RealSrcSpan) -> RealSrcLoc -> RealSrcSpan
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 :: RealSrcSpan
span = FastString -> [HieAST Type] -> RealSrcSpan
forall a. FastString -> [HieAST a] -> RealSrcSpan
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 -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a.
SourcedNodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node SourcedNodeInfo Type
moduleInfo RealSrcSpan
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 retur:ed more than one result" ([RealSrcSpan] -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([RealSrcSpan] -> SDoc) -> [RealSrcSpan] -> SDoc
forall a b. (a -> b) -> a -> b
$ (HieAST Type -> RealSrcSpan) -> [HieAST Type] -> [RealSrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map HieAST Type -> RealSrcSpan
forall a. HieAST a -> RealSrcSpan
nodeSpan [HieAST Type]
xs)

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

    let asts :: HieASTs Type
asts = Map HiePath (HieAST Type) -> HieASTs Type
forall a. Map HiePath (HieAST a) -> HieASTs a
HieASTs (Map HiePath (HieAST Type) -> HieASTs Type)
-> Map HiePath (HieAST Type) -> HieASTs Type
forall a b. (a -> b) -> a -> b
$ Map HiePath (HieAST Type) -> Map HiePath (HieAST Type)
forall a. Map HiePath (HieAST a) -> Map HiePath (HieAST a)
resolveTyVarScopes Map HiePath (HieAST Type)
asts'
    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
      , [XRec p (SpliceDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (SpliceDecl p)] -> HieM [HieAST Type])
-> [XRec p (SpliceDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (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
      , [XRec p (DerivDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (DerivDecl p)] -> HieM [HieAST Type])
-> [XRec p (DerivDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (DerivDecl p)]
forall p. HsGroup p -> [LDerivDecl p]
hs_derivds HsGroup p
grp
      , [XRec p (FixitySig p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (FixitySig p)] -> HieM [HieAST Type])
-> [XRec p (FixitySig p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (FixitySig p)]
forall p. HsGroup p -> [LFixitySig p]
hs_fixds HsGroup p
grp
      , [XRec p (DefaultDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (DefaultDecl p)] -> HieM [HieAST Type])
-> [XRec p (DefaultDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (DefaultDecl p)]
forall p. HsGroup p -> [LDefaultDecl p]
hs_defds HsGroup p
grp
      , [XRec p (ForeignDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (ForeignDecl p)] -> HieM [HieAST Type])
-> [XRec p (ForeignDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (ForeignDecl p)]
forall p. HsGroup p -> [LForeignDecl p]
hs_fords HsGroup p
grp
      , [XRec p (WarnDecls p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (WarnDecls p)] -> HieM [HieAST Type])
-> [XRec p (WarnDecls p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (WarnDecls p)]
forall p. HsGroup p -> [LWarnDecls p]
hs_warnds HsGroup p
grp
      , [XRec p (AnnDecl p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (AnnDecl p)] -> HieM [HieAST Type])
-> [XRec p (AnnDecl p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (AnnDecl p)]
forall p. HsGroup p -> [LAnnDecl p]
hs_annds HsGroup p
grp
      , [XRec p (RuleDecls p)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([XRec p (RuleDecls p)] -> HieM [HieAST Type])
-> [XRec p (RuleDecls p)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsGroup p -> [XRec p (RuleDecls p)]
forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds HsGroup p
grp
      ]

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

grhss_span :: GRHSs (GhcPass p) body -> SrcSpan
grhss_span :: GRHSs (GhcPass p) body -> SrcSpan
grhss_span (GRHSs XCGRHSs (GhcPass p) body
_ [LGRHS (GhcPass p) body]
xs LHsLocalBinds (GhcPass 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 (GenLocated SrcSpan (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> SrcSpan
forall l e. GenLocated l e -> l
getLoc GenLocated SrcSpan (HsLocalBindsLR (GhcPass p) (GhcPass p))
LHsLocalBinds (GhcPass p)
bs) ((GenLocated SrcSpan (GRHS (GhcPass p) body) -> SrcSpan)
-> [GenLocated SrcSpan (GRHS (GhcPass p) body)] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpan (GRHS (GhcPass p) body) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc [GenLocated SrcSpan (GRHS (GhcPass p) body)]
[LGRHS (GhcPass p) body]
xs)

bindingsOnly :: [Context Name] -> HieM [HieAST a]
bindingsOnly :: [Context Name] -> HieM [HieAST a]
bindingsOnly [] = [HieAST a] -> HieM [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] -> HieM [HieAST a]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [Context Name]
xs
  [HieAST a] -> HieM [HieAST a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([HieAST a] -> HieM [HieAST a]) -> [HieAST a] -> HieM [HieAST a]
forall a b. (a -> b) -> a -> b
$ case Name -> SrcSpan
nameSrcSpan Name
n of
    RealSrcSpan RealSrcSpan
span Maybe BufSpan
_ -> SourcedNodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
forall a.
SourcedNodeInfo a -> RealSrcSpan -> [HieAST a] -> HieAST a
Node (NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
forall a. NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
mkSourcedNodeInfo NodeOrigin
org NodeInfo a
nodeinfo) RealSrcSpan
span [] HieAST a -> [HieAST a] -> [HieAST a]
forall a. a -> [a] -> [a]
: [HieAST a]
rest
      where nodeinfo :: NodeInfo a
nodeinfo = Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Set a
S.empty [] (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 :: [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)
DataType
Constr
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 d. Data d => c (t d)) -> Maybe (c (PScoped a))
(forall b. Data b => b -> b) -> PScoped a -> PScoped a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PScoped a -> c (PScoped a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (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))
$cPS :: Constr
$tPScoped :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> PScoped a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> PScoped a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (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 :: 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 :: Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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 (GhcPass a)]
  -> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes :: TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tvScope Scope
rhsScope [LHsTyVarBndr flag (GhcPass a)]
xs =
  (RScoped (Located (HsTyVarBndr flag (GhcPass a)))
 -> TVScoped (Located (HsTyVarBndr flag (GhcPass a))))
-> [RScoped (Located (HsTyVarBndr flag (GhcPass a)))]
-> [TVScoped (Located (HsTyVarBndr flag (GhcPass a)))]
forall a b. (a -> b) -> [a] -> [b]
map (\(RS Scope
sc Located (HsTyVarBndr flag (GhcPass a))
a)-> TyVarScope
-> Scope
-> Located (HsTyVarBndr flag (GhcPass a))
-> TVScoped (Located (HsTyVarBndr flag (GhcPass a)))
forall a. TyVarScope -> Scope -> a -> TVScoped a
TVS TyVarScope
tvScope Scope
sc Located (HsTyVarBndr flag (GhcPass a))
a) ([RScoped (Located (HsTyVarBndr flag (GhcPass a)))]
 -> [TVScoped (Located (HsTyVarBndr flag (GhcPass a)))])
-> [RScoped (Located (HsTyVarBndr flag (GhcPass a)))]
-> [TVScoped (Located (HsTyVarBndr flag (GhcPass a)))]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located (HsTyVarBndr flag (GhcPass a))]
-> [RScoped (Located (HsTyVarBndr flag (GhcPass a)))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
rhsScope [Located (HsTyVarBndr flag (GhcPass a))]
[LHsTyVarBndr flag (GhcPass a)]
xs

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

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

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

This case in handled in the instance for HsPatSigType
-}

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 RealSrcSpan
_ 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) = [Located (HsTyVarBndr () GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [Located (HsTyVarBndr () GhcRn)]
[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 (GhcPass s) a) where
  loc :: FamEqn (GhcPass s) a -> SrcSpan
loc (FamEqn XCFamEqn (GhcPass s) a
_ LIdP (GhcPass s)
a Maybe [LHsTyVarBndr () (GhcPass s)]
Nothing HsTyPats (GhcPass s)
b LexicalFixity
_ a
c) = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans [Located (IdGhcP s) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (IdGhcP s)
LIdP (GhcPass s)
a, [HsArg
   (Located (HsType (GhcPass s))) (Located (HsType (GhcPass s)))]
-> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [HsArg
   (Located (HsType (GhcPass s))) (Located (HsType (GhcPass s)))]
HsTyPats (GhcPass s)
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
c]
  loc (FamEqn XCFamEqn (GhcPass s) a
_ LIdP (GhcPass s)
a (Just [LHsTyVarBndr () (GhcPass s)]
tvs) HsTyPats (GhcPass s)
b LexicalFixity
_ a
c) = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall a. (a -> a -> a) -> [a] -> a
foldl1' SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans
                                              [Located (IdGhcP s) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (IdGhcP s)
LIdP (GhcPass s)
a, [Located (HsTyVarBndr () (GhcPass s))] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [Located (HsTyVarBndr () (GhcPass s))]
[LHsTyVarBndr () (GhcPass s)]
tvs, [HsArg
   (Located (HsType (GhcPass s))) (Located (HsType (GhcPass s)))]
-> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [HsArg
   (Located (HsType (GhcPass s))) (Located (HsType (GhcPass s)))]
HsTyPats (GhcPass s)
b, a -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc a
c]

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{}) = [Located (ConDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc ([Located (ConDecl GhcRn)] -> SrcSpan)
-> [Located (ConDecl 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 = 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 RealSrcSpan
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 -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a.
SourcedNodeInfo a -> RealSrcSpan -> [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 NodeAnnotation
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
forall a. Set a
S.empty [] NodeIdentifiers Type
idents) RealSrcSpan
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 RealSrcSpan
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 -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a.
SourcedNodeInfo a -> RealSrcSpan -> [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 NodeAnnotation
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
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)))
              RealSrcSpan
span
              []]
      C (EvidenceVarBind EvVarSource
i Scope
_ Maybe RealSrcSpan
sp)  (L SrcSpan
_ Id
name) -> do
        Id -> ContextInfo -> HieM ()
addUnlocatedEvBind Id
name (EvVarSource -> Scope -> Maybe RealSrcSpan -> ContextInfo
EvidenceVarBind EvVarSource
i Scope
ModuleScope Maybe RealSrcSpan
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 RealSrcSpan
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 -> RealSrcSpan -> [HieAST Type] -> HieAST Type
forall a.
SourcedNodeInfo a -> RealSrcSpan -> [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 NodeAnnotation
-> [Type] -> NodeIdentifiers Type -> NodeInfo Type
forall a.
Set NodeAnnotation -> [a] -> NodeIdentifiers a -> NodeInfo a
NodeInfo Set NodeAnnotation
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)))
              RealSrcSpan
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 RealSrcSpan
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 RealSrcSpan -> ContextInfo
EvidenceVarBind (EvBindDeps -> EvVarSource
EvLetBind EvBindDeps
depNames) (Scope -> Scope -> Scope
combineScopes Scope
sc (SrcSpan -> Scope
mkScope SrcSpan
span)) Maybe RealSrcSpan
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 RealSrcSpan
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe RealSrcSpan -> a -> EvBindContext a
EvBindContext (SrcSpan -> Scope
mkScope SrcSpan
osp) (SrcSpan -> Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
EvidenceVarBind EvVarSource
EvWrapperBind (SrcSpan -> Scope
mkScope SrcSpan
osp) (SrcSpan -> Maybe RealSrcSpan
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 (Located (HsBind (GhcPass p))) where
  getTypeNode :: Located (HsBind (GhcPass p)) -> HieM [HieAST Type]
getTypeNode (L SrcSpan
spn HsBind (GhcPass p)
bind) =
    case HiePass p => HiePassEv p
forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieRn -> HsBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsBind (GhcPass p)
bind SrcSpan
spn
      HiePassEv p
HieTc ->  case HsBind (GhcPass p)
bind of
        FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP (GhcPass p)
name} -> HsBind (GhcPass p) -> SrcSpan -> Type -> HieM [HieAST Type]
forall (m :: * -> *) a.
(Monad m, Data a) =>
a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]
makeTypeNode HsBind (GhcPass p)
bind 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
LIdP (GhcPass p)
name)
        HsBind (GhcPass p)
_ -> HsBind (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsBind (GhcPass p)
bind 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 HiePass p => HiePassEv p
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 (Located (HsExpr (GhcPass p))) where
  getTypeNode :: Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
getTypeNode e :: Located (HsExpr (GhcPass p))
e@(L SrcSpan
spn HsExpr (GhcPass p)
e') =
    case HiePass p => HiePassEv p
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 MatchGroupTc
XMG (GhcPass p) (LHsExpr (GhcPass p))
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 MatchGroupTc
XMG (GhcPass p) (LHsExpr (GhcPass p))
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 MatchGroupTc
XMG (GhcPass p) (LHsExpr (GhcPass p))
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
_ XRec (GhcPass p) [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 Located (HsExpr (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 (Context (Located (XUnboundVar (GhcPass 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 ToHie (Context (Located NoExtField)) where
  toHie :: Context (Located NoExtField) -> HieM [HieAST Type]
toHie Context (Located NoExtField)
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance HiePass p => ToHie (BindContext (Located (HsBind (GhcPass p)))) where
  toHie :: BindContext (Located (HsBind (GhcPass p))) -> HieM [HieAST Type]
toHie (BC BindType
context Scope
scope b :: Located (HsBind (GhcPass p))
b@(L SrcSpan
span HsBind (GhcPass p)
bind)) =
    [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Located (HsBind (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode Located (HsBind (GhcPass p))
b HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsBind (GhcPass p)
bind of
      FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = LIdP (GhcPass p)
name, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches, fun_ext :: forall idL idR. HsBindLR idL idR -> XFunBind idL idR
fun_ext = XFunBind (GhcPass p) (GhcPass p)
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 RealSrcSpan -> ContextInfo
ValBind BindType
context Scope
scope (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located (IdGhcP p)
LIdP (GhcPass p)
name
        , MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches
        , case HiePass p => HiePassEv p
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 HsWrapper
XFunBind (GhcPass p) (GhcPass p)
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Scope
scope Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
lhs
        , GRHSs (GhcPass p) (Located (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GRHSs (GhcPass p) (Located (HsExpr (GhcPass p)))
GRHSs (GhcPass p) (LHsExpr (GhcPass p))
rhs
        ]
      VarBind{var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr (GhcPass p)
expr} ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
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 (Located (HsBind (GhcPass p))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (Located (HsBind (GhcPass p))))
 -> HieM [HieAST Type])
-> Bag (BindContext (Located (HsBind (GhcPass p))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (HsBind (GhcPass p))
 -> BindContext (Located (HsBind (GhcPass p))))
-> Bag (Located (HsBind (GhcPass p)))
-> Bag (BindContext (Located (HsBind (GhcPass p))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> Located (HsBind (GhcPass p))
-> BindContext (Located (HsBind (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
context Scope
scope) Bag (Located (HsBind (GhcPass p)))
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 RealSrcSpan
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe RealSrcSpan -> a -> EvBindContext a
EvBindContext (SrcSpan -> Scope
mkScope SrcSpan
span) (SrcSpan -> Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
EvidenceVarBind EvVarSource
EvSigBind
                                    (SrcSpan -> Scope
mkScope SrcSpan
span)
                                    (SrcSpan -> Maybe RealSrcSpan
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 -> XRec p [LMatch p body]
mg_alts = (L span 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
        , [Located (Match (GhcPass p) (Located body))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (Match (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 -> LIdP idL
psb_id=LIdP (GhcPass p)
var, psb_args :: forall idL idR. PatSynBind idL idR -> HsPatSynDetails idR
psb_args=HsPatSynDetails (GhcPass p)
dets, psb_def :: forall idL idR. PatSynBind idL idR -> LPat idR
psb_def=LPat (GhcPass p)
pat, psb_dir :: forall idL idR. PatSynBind idL idR -> HsPatSynDir idR
psb_dir=HsPatSynDir (GhcPass p)
dir} ->
        [ Context (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 RealSrcSpan -> ContextInfo
Decl DeclType
PatSynDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
sp) Located (IdGhcP p)
LIdP (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 (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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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)
LIdP (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 (GhcPass p)
dets of
            (PrefixCon [LIdP (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)]
[LIdP (GhcPass p)]
args
            (InfixCon LIdP (GhcPass p)
a LIdP (GhcPass p)
b) -> Scope -> Scope -> Scope
combineScopes (Located (IdGhcP p) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdGhcP p)
LIdP (GhcPass p)
a) (Located (IdGhcP p) -> Scope
forall a. Located a -> Scope
mkLScope Located (IdGhcP p)
LIdP (GhcPass p)
b)
            (RecCon [RecordPatSynField (LIdP (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 (LIdP (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 RealSrcSpan
detSpan = case Scope
detScope of
            LocalScope RealSrcSpan
a -> RealSrcSpan -> Maybe RealSrcSpan
forall a. a -> Maybe a
Just RealSrcSpan
a
            Scope
_ -> Maybe RealSrcSpan
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 RealSrcSpan
-> RecordPatSynField (Located (IdGhcP p))
-> PatSynFieldContext (RecordPatSynField (Located (IdGhcP p)))
forall a. Maybe RealSrcSpan -> a -> PatSynFieldContext a
PSC Maybe RealSrcSpan
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) (Located (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
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 (Located (Match (GhcPass p) (Located body))) where
  toHie :: Located (Match (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 :: Pass) body. GRHSs (GhcPass 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 RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
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 HiePass p => HiePassEv p
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 RealSrcSpan
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)
_ LIdP (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 RealSrcSpan -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe RealSrcSpan
rsp) Located (IdGhcP p)
LIdP (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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
p
        ]
      AsPat XAsPat (GhcPass p)
_ LIdP (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 RealSrcSpan -> 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 RealSrcSpan
rsp)
                    Located (IdGhcP p)
LIdP (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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        ]
      ConPat {pat_con :: forall p. Pat p -> XRec p (ConLikeP p)
pat_con = XRec (GhcPass p) (ConLikeP (GhcPass p))
con, pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = HsConPatDetails (GhcPass p)
dets, pat_con_ext :: forall p. Pat p -> XConPat p
pat_con_ext = XConPat (GhcPass p)
ext} ->
        case HiePass p => HiePassEv p
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
XRec (GhcPass p) (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 ConPatTc
XConPat (GhcPass p)
ext
                  ev_vars :: [Id]
ev_vars = ConPatTc -> [Id]
cpt_dicts ConPatTc
XConPat (GhcPass p)
ext
                  wrap :: HsWrapper
wrap = ConPatTc -> HsWrapper
cpt_wrap ConPatTc
XConPat (GhcPass p)
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 RealSrcSpan
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe RealSrcSpan -> a -> EvBindContext a
EvBindContext Scope
scope Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
EvidenceVarBind EvVarSource
EvPatternBind Scope
evscope Maybe RealSrcSpan
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
XRec (GhcPass p) (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 ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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)
_ XRec (GhcPass p) (HsOverLit (GhcPass p))
_ Maybe (SyntaxExpr (GhcPass p))
_ SyntaxExpr (GhcPass p)
_ ->
        []
      NPlusKPat XNPlusKPat (GhcPass p)
_ LIdP (GhcPass p)
n XRec (GhcPass p) (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 RealSrcSpan -> ContextInfo
PatternBind Scope
scope Scope
pscope Maybe RealSrcSpan
rsp) Located (IdGhcP p)
LIdP (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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
rsp Scope
scope Scope
pscope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        , case HiePass p => HiePassEv p
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 HiePass p => HiePassEv p
forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
          HiePassEv p
HieTc ->
            let CoPat HsWrapper
wrap Pat GhcTc
pat Type
_ = CoPat
XXPat (GhcPass p)
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat GhcTc)
-> PScoped (Located (Pat GhcTc))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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
          HiePassEv p
HieRn -> []
#endif
    where
      contextify :: a ~ LPat (GhcPass p) => HsConDetails a (HsRecFields (GhcPass p) a)
                 -> HsConDetails (PScoped a) (RContext (HsRecFields (GhcPass p) (PScoped a)))
      contextify :: 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 RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
forall (p :: Pass).
Maybe RealSrcSpan
-> Scope
-> Scope
-> [LPat (GhcPass p)]
-> [PScoped (LPat (GhcPass p))]
patScopes Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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 wcs tvs) body :: LHsType GhcRn
body@(L span _))) = [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)
      , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType 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 ->
     [ [Located (GRHS (GhcPass p) (Located body))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (GRHS (GhcPass p) (Located body))]
[LGRHS (GhcPass p) (Located body)]
grhss
     , RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
 -> HieM [HieAST Type])
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (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 :: Pass) body. GRHSs (GhcPass p) body -> SrcSpan
grhss_span GRHSs (GhcPass p) (Located body)
grhs) Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
LHsLocalBinds (GhcPass p)
binds
     ]

instance ( ToHie (Located body)
         , HiePass a
         , Data body
         ) => ToHie (Located (GRHS (GhcPass a) (Located body))) where
  toHie :: Located (GRHS (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)
_ [GuardLStmt (GhcPass a)]
guards Located body
body ->
      [ [RScoped
   (Located
      (StmtLR (GhcPass a) (GhcPass a) (Located (HsExpr (GhcPass a)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located
       (StmtLR (GhcPass a) (GhcPass a) (Located (HsExpr (GhcPass a)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located
         (StmtLR (GhcPass a) (GhcPass a) (Located (HsExpr (GhcPass a)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located
      (StmtLR (GhcPass a) (GhcPass a) (Located (HsExpr (GhcPass a))))]
-> [RScoped
      (Located
         (StmtLR (GhcPass a) (GhcPass a) (Located (HsExpr (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) (Located (HsExpr (GhcPass a))))]
[GuardLStmt (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 HiePass a => HiePassEv a
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 (Located (HsExpr (GhcPass p))) where
  toHie :: Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
toHie e :: Located (HsExpr (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
$ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. HasType a => a -> HieM [HieAST Type]
getTypeNode Located (HsExpr (GhcPass p))
e HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsExpr (GhcPass p)
oexpr of
      HsVar XVar (GhcPass p)
_ (L _ 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
var)
             -- Patch up var location since typechecker removes it
        ]
      HsUnboundVar XUnboundVar (GhcPass p)
var OccName
_ ->
        [ Context (GenLocated SrcSpan (XUnboundVar (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (GenLocated SrcSpan (XUnboundVar (GhcPass p)))
 -> HieM [HieAST Type])
-> Context (GenLocated SrcSpan (XUnboundVar (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo
-> GenLocated SrcSpan (XUnboundVar (GhcPass p))
-> Context (GenLocated SrcSpan (XUnboundVar (GhcPass p)))
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use (SrcSpan
-> XUnboundVar (GhcPass p)
-> GenLocated SrcSpan (XUnboundVar (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan XUnboundVar (GhcPass p)
var) ]
      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 RealSrcSpan
-> GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p))
-> RFContext (GenLocated SrcSpan (AmbiguousFieldOcc (GhcPass p)))
forall a. RecFieldContext -> Maybe RealSrcSpan -> a -> RFContext a
RFC RecFieldContext
RecFieldOcc Maybe RealSrcSpan
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) (Located (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
        ]
      HsLamCase XLamCase (GhcPass p)
_ MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
mg
        ]
      HsApp XApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        ]
      HsAppType XAppTypeE (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsWcType (NoGhcTc (GhcPass p))
sig ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        , TScoped
  (HsWildCardBndrs
     (GhcPass (NoGhcTcPass p))
     (Located (HsType (GhcPass (NoGhcTcPass p)))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass (NoGhcTcPass p))
      (Located (HsType (GhcPass (NoGhcTcPass p)))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass (NoGhcTcPass p))
        (Located (HsType (GhcPass (NoGhcTcPass p)))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass (NoGhcTcPass p))
     (Located (HsType (GhcPass (NoGhcTcPass p))))
-> TScoped
     (HsWildCardBndrs
        (GhcPass (NoGhcTcPass p))
        (Located (HsType (GhcPass (NoGhcTcPass p)))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) HsWildCardBndrs
  (GhcPass (NoGhcTcPass p))
  (Located (HsType (GhcPass (NoGhcTcPass p))))
LHsWcType (NoGhcTc (GhcPass p))
sig
        ]
      OpApp XOpApp (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
c
        ]
      NegApp XNegApp (GhcPass p)
_ LHsExpr (GhcPass p)
a SyntaxExpr (GhcPass p)
_ ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        ]
      HsPar XPar (GhcPass p)
_ LHsExpr (GhcPass p)
a ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        ]
      SectionL XSectionL (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        ]
      SectionR XSectionR (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        ]
      ExplicitTuple XExplicitTuple (GhcPass p)
_ [LHsTupArg (GhcPass p)]
args Boxity
_ ->
        [ [Located (HsTupArg (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsTupArg (GhcPass p))]
[LHsTupArg (GhcPass p)]
args
        ]
      ExplicitSum XExplicitSum (GhcPass p)
_ TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
expr ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        ]
      HsCase XCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        , MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsExpr (GhcPass p)))
MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
matches
        ]
      HsIf XIf (GhcPass p)
_ LHsExpr (GhcPass p)
a LHsExpr (GhcPass p)
b LHsExpr (GhcPass p)
c ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
c
        ]
      HsMultiIf XMultiIf (GhcPass p)
_ [LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss ->
        [ [Located (GRHS (GhcPass p) (Located (HsExpr (GhcPass p))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (GRHS (GhcPass p) (Located (HsExpr (GhcPass p))))]
[LGRHS (GhcPass p) (LHsExpr (GhcPass p))]
grhss
        ]
      HsLet XLet (GhcPass p)
_ LHsLocalBinds (GhcPass p)
binds LHsExpr (GhcPass p)
expr ->
        [ RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
 -> HieM [HieAST Type])
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
forall a. Scope -> a -> RScoped a
RS (Located (HsExpr (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr) Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
LHsLocalBinds (GhcPass p)
binds
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        ]
      HsDo XDo (GhcPass p)
_ HsStmtContext GhcRn
_ (L ispan 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) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located
       (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located
   (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
stmts
        ]
      ExplicitList XExplicitList (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ [LHsExpr (GhcPass p)]
exprs ->
        [ [Located (HsExpr (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsExpr (GhcPass p))]
[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 -> LIdP p
rcon_con_name = LIdP (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 (XRecordCon (GhcPass p)
-> Located (IdP (GhcPass p)) -> Located (IdP (GhcPass p))
forall p.
HasRealDataConName p =>
XRecordCon p -> Located (IdP p) -> Located (IdP p)
getRealDataCon @(GhcPass p) XRecordCon (GhcPass p)
mrealcon Located (IdP (GhcPass p))
LIdP (GhcPass p)
name)
            -- See Note [Real DataCon Name]
        , RContext (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RContext (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p))))
 -> HieM [HieAST Type])
-> RContext
     (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RecFieldContext
-> HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p)))
-> RContext
     (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p)))
 -> RContext
      (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p)))))
-> HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p)))
-> RContext
     (HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p))))
forall a b. (a -> b) -> a -> b
$ HsRecFields (GhcPass p) (Located (HsExpr (GhcPass p)))
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}->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        , [RContext
   (Located
      (HsRecField'
         (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RContext
    (Located
       (HsRecField'
          (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RContext
      (Located
         (HsRecField'
            (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located
   (HsRecField'
      (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p))))
 -> RContext
      (Located
         (HsRecField'
            (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p))))))
-> [Located
      (HsRecField'
         (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p))))]
-> [RContext
      (Located
         (HsRecField'
            (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p)))))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> Located
     (HsRecField'
        (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p))))
-> RContext
     (Located
        (HsRecField'
           (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p)))))
forall a. RecFieldContext -> a -> RContext a
RC RecFieldContext
RecFieldAssign) [Located
   (HsRecField'
      (AmbiguousFieldOcc (GhcPass p)) (Located (HsExpr (GhcPass p))))]
[LHsRecUpdField (GhcPass p)]
upds
        ]
      ExprWithTySig XExprWithTySig (GhcPass p)
_ LHsExpr (GhcPass p)
expr LHsSigWcType (NoGhcTc (GhcPass p))
sig ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        , TScoped
  (HsWildCardBndrs
     (GhcPass (NoGhcTcPass p))
     (HsImplicitBndrs
        (GhcPass (NoGhcTcPass p))
        (Located (HsType (GhcPass (NoGhcTcPass p))))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      (GhcPass (NoGhcTcPass p))
      (HsImplicitBndrs
         (GhcPass (NoGhcTcPass p))
         (Located (HsType (GhcPass (NoGhcTcPass p))))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        (GhcPass (NoGhcTcPass p))
        (HsImplicitBndrs
           (GhcPass (NoGhcTcPass p))
           (Located (HsType (GhcPass (NoGhcTcPass p))))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     (GhcPass (NoGhcTcPass p))
     (HsImplicitBndrs
        (GhcPass (NoGhcTcPass p))
        (Located (HsType (GhcPass (NoGhcTcPass p)))))
-> TScoped
     (HsWildCardBndrs
        (GhcPass (NoGhcTcPass p))
        (HsImplicitBndrs
           (GhcPass (NoGhcTcPass p))
           (Located (HsType (GhcPass (NoGhcTcPass p))))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [Located (HsExpr (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr]) HsWildCardBndrs
  (GhcPass (NoGhcTcPass p))
  (HsImplicitBndrs
     (GhcPass (NoGhcTcPass p))
     (Located (HsType (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 ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
forall a. Maybe a
Nothing (Located (HsCmdTop (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope Located (HsCmdTop (GhcPass p))
LHsCmdTop (GhcPass p)
cmdtop) Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
        , Located (HsCmdTop (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmdTop (GhcPass p))
LHsCmdTop (GhcPass p)
cmdtop
        ]
      HsStatic XStatic (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        ]
      HsTick XTick (GhcPass p)
_ Tickish (IdP (GhcPass p))
_ LHsExpr (GhcPass p)
expr ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        ]
      HsBinTick XBinTick (GhcPass p)
_ TypeIndex
_ TypeIndex
_ LHsExpr (GhcPass p)
expr ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
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 <- IsPass p => GhcPass p
forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
        , WrapExpr (HsWrap w a) <- XXExpr (GhcPass p)
x
        -> [ Located (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Located (HsExpr GhcTc) -> HieM [HieAST Type])
-> Located (HsExpr GhcTc) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsExpr GhcTc -> Located (HsExpr 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 <- IsPass p => GhcPass p
forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
        , ExpansionExpr (HsExpanded _ b) <- XXExpr (GhcPass p)
x
        -> [ Located (HsExpr GhcTc) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (SrcSpan -> HsExpr GhcTc -> Located (HsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
mspan HsExpr GhcTc
b)
           ]
        | Bool
otherwise -> []

instance HiePass p => ToHie (Located (HsTupArg (GhcPass p))) where
  toHie :: Located (HsTupArg (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 ->
      [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
      ]
    Missing XMissing (GhcPass p)
_ -> []

instance ( ToHie (Located body)
         , Data body
         , HiePass p
         ) => ToHie (RScoped (Located (Stmt (GhcPass p) (Located body)))) where
  toHie :: RScoped (Located (Stmt (GhcPass p) (Located body)))
-> HieM [HieAST Type]
toHie (RS Scope
scope (L SrcSpan
span Stmt (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 Stmt (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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS (SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
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 (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
 -> HieM [HieAST Type])
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
forall a. Scope -> a -> RScoped a
RS Scope
scope Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
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)
_ [ExprLStmt (GhcPass p)]
stmts [IdP (GhcPass p)]
_ SyntaxExpr (GhcPass p)
_) ->
                          [RScoped
   (Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located
       (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located
   (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
[ExprLStmt (GhcPass p)]
stmts)
                     [ParStmtBlock (GhcPass p) (GhcPass p)]
parstmts
        ]
      TransStmt {trS_stmts :: forall idL idR body. StmtLR idL idR body -> [ExprLStmt idL]
trS_stmts = [ExprLStmt (GhcPass p)]
stmts, trS_using :: forall idL idR body. StmtLR idL idR body -> LHsExpr idR
trS_using = LHsExpr (GhcPass p)
using, trS_by :: forall idL idR body. StmtLR idL idR body -> Maybe (LHsExpr idR)
trS_by = Maybe (LHsExpr (GhcPass p))
by} ->
        [ [RScoped
   (Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located
       (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
scope [Located
   (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
[ExprLStmt (GhcPass p)]
stmts
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
using
        , Maybe (Located (HsExpr (GhcPass p))) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (HsExpr (GhcPass p)))
Maybe (LHsExpr (GhcPass p))
by
        ]
      RecStmt {recS_stmts :: forall idL idR body. StmtLR idL idR body -> [LStmtLR idL idR body]
recS_stmts = [LStmtLR (GhcPass p) (GhcPass p) (Located body)]
stmts} ->
        [ [RScoped (Located (Stmt (GhcPass p) (Located body)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (Located (Stmt (GhcPass p) (Located body)))]
 -> HieM [HieAST Type])
-> [RScoped (Located (Stmt (GhcPass p) (Located body)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (Stmt (GhcPass p) (Located body))
 -> RScoped (Located (Stmt (GhcPass p) (Located body))))
-> [Located (Stmt (GhcPass p) (Located body))]
-> [RScoped (Located (Stmt (GhcPass p) (Located body)))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> Located (Stmt (GhcPass p) (Located body))
-> RScoped (Located (Stmt (GhcPass p) (Located body)))
forall a. Scope -> a -> RScoped a
RS (Scope
 -> Located (Stmt (GhcPass p) (Located body))
 -> RScoped (Located (Stmt (GhcPass p) (Located body))))
-> Scope
-> Located (Stmt (GhcPass p) (Located body))
-> RScoped (Located (Stmt (GhcPass p) (Located body)))
forall a b. (a -> b) -> a -> b
$ Scope -> Scope -> Scope
combineScopes Scope
scope (SrcSpan -> Scope
mkScope SrcSpan
span)) [Located (Stmt (GhcPass p) (Located body))]
[LStmtLR (GhcPass p) (GhcPass p) (Located body)]
stmts
        ]
    where
      node :: HieM [HieAST Type]
node = case HiePass p => HiePassEv p
forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
        HiePassEv p
HieTc -> Stmt (GhcPass p) (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode Stmt (GhcPass p) (Located body)
stmt SrcSpan
span
        HiePassEv p
HieRn -> Stmt (GhcPass p) (Located body) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode Stmt (GhcPass p) (Located body)
stmt SrcSpan
span

instance HiePass p => ToHie (RScoped (Located (HsLocalBinds (GhcPass p)))) where
  toHie :: RScoped (Located (HsLocalBinds (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 HiePass p => HiePassEv p
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 RealSrcSpan
-> GenLocated SrcSpan TcEvBinds
-> EvBindContext (GenLocated SrcSpan TcEvBinds)
forall a. Scope -> Maybe RealSrcSpan -> a -> EvBindContext a
EvBindContext Scope
sc (SrcSpan -> Maybe RealSrcSpan
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 TcEvBinds
XIPBinds (GhcPass p)
evbinds
              HiePassEv p
HieRn -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
          , [RScoped (Located (IPBind (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped (Located (IPBind (GhcPass p)))] -> HieM [HieAST Type])
-> [RScoped (Located (IPBind (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (IPBind (GhcPass p))
 -> RScoped (Located (IPBind (GhcPass p))))
-> [Located (IPBind (GhcPass p))]
-> [RScoped (Located (IPBind (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (Scope
-> Located (IPBind (GhcPass p))
-> RScoped (Located (IPBind (GhcPass p)))
forall a. Scope -> a -> RScoped a
RS Scope
sc) [Located (IPBind (GhcPass p))]
[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 (Located (IPBind (GhcPass p)))) where
  toHie :: RScoped (Located (IPBind (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 XRec (GhcPass p) HsIPName
_) LHsExpr (GhcPass p)
expr -> [Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
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 RealSrcSpan -> ContextInfo
EvidenceVarBind EvVarSource
EvImplicitBind Scope
scope (SrcSpan -> Maybe RealSrcSpan
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 IdP (GhcPass p)
IdGhcP p
v
      , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
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 (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (Located (HsBindLR (GhcPass p) (GhcPass p))))
 -> HieM [HieAST Type])
-> Bag (BindContext (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (HsBindLR (GhcPass p) (GhcPass p))
 -> BindContext (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> Bag (Located (HsBindLR (GhcPass p) (GhcPass p)))
-> Bag (BindContext (Located (HsBindLR (GhcPass p) (GhcPass p))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> Located (HsBindLR (GhcPass p) (GhcPass p))
-> BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) Bag (Located (HsBindLR (GhcPass p) (GhcPass p)))
LHsBindsLR (GhcPass p) (GhcPass p)
binds
      , [SigContext (Located (Sig (GhcPass p)))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (Located (Sig (GhcPass p)))] -> HieM [HieAST Type])
-> [SigContext (Located (Sig (GhcPass p)))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (Sig (GhcPass p))
 -> SigContext (Located (Sig (GhcPass p))))
-> [Located (Sig (GhcPass p))]
-> [SigContext (Located (Sig (GhcPass p)))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo
-> Located (Sig (GhcPass p))
-> SigContext (Located (Sig (GhcPass p)))
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
BindSig Maybe RealSrcSpan
forall a. Maybe a
Nothing)) [Located (Sig (GhcPass p))]
[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 NHsValBindsLR (GhcPass p)
XXValBindsLR (GhcPass p) (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 (Located (HsBindLR (GhcPass p) (GhcPass p)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (((RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
 -> [BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))])
-> [(RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))]
-> [BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((Located (HsBindLR (GhcPass p) (GhcPass p))
 -> BindContext (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> [Located (HsBindLR (GhcPass p) (GhcPass p))]
-> [BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))]
forall a b. (a -> b) -> [a] -> [b]
map (BindType
-> Scope
-> Located (HsBindLR (GhcPass p) (GhcPass p))
-> BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
RegularBind Scope
sc) ([Located (HsBindLR (GhcPass p) (GhcPass p))]
 -> [BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))])
-> ((RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
    -> [Located (HsBindLR (GhcPass p) (GhcPass p))])
-> (RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> [BindContext (Located (HsBindLR (GhcPass p) (GhcPass p)))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bag (Located (HsBindLR (GhcPass p) (GhcPass p)))
-> [Located (HsBindLR (GhcPass p) (GhcPass p))]
forall a. Bag a -> [a]
bagToList (Bag (Located (HsBindLR (GhcPass p) (GhcPass p)))
 -> [Located (HsBindLR (GhcPass p) (GhcPass p))])
-> ((RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
    -> Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> (RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> [Located (HsBindLR (GhcPass p) (GhcPass p))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))
-> Bag (Located (HsBindLR (GhcPass p) (GhcPass p)))
forall a b. (a, b) -> b
snd) [(RecFlag, Bag (Located (HsBindLR (GhcPass p) (GhcPass p))))]
[(RecFlag, LHsBinds (GhcPass p))]
binds)
    , [SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type])
-> [SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn)))
-> [Located (Sig GhcRn)] -> [SigContext (Located (Sig GhcRn))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SigInfo -> Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn))
forall a. SigInfo -> a -> SigContext a
SC (SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
BindSig Maybe RealSrcSpan
forall a. Maybe a
Nothing)) [Located (Sig GhcRn)]
[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 RealSrcSpan -> Located label -> RFContext (Located label)
forall a. RecFieldContext -> Maybe RealSrcSpan -> a -> RFContext a
RFC RecFieldContext
c (SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
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 (Located (FieldOcc GhcRn))) where
  toHie :: RFContext (Located (FieldOcc GhcRn)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
rhs) (SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
nspan Name
XCFieldOcc GhcRn
name)
      ]

instance ToHie (RFContext (Located (FieldOcc GhcTc))) where
  toHie :: RFContext (Located (FieldOcc GhcTc)) -> HieM [HieAST Type]
toHie (RFC RecFieldContext
c Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
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 RealSrcSpan
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 RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
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 RealSrcSpan
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 RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
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 RealSrcSpan -> ContextInfo
RecField RecFieldContext
c Maybe RealSrcSpan
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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
forall a. Maybe a
Nothing Scope
sc Scope
NoScope Located (Pat (GhcPass p))
LPat (GhcPass p)
pat
    , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
    ]
  toHie (RS Scope
sc (ApplicativeArgMany XApplicativeArgMany (GhcPass p)
_ [ExprLStmt (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) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located
       (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p)))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located
   (StmtLR (GhcPass p) (GhcPass p) (Located (HsExpr (GhcPass p))))]
[ExprLStmt (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 RealSrcSpan
-> Scope
-> Scope
-> Located (Pat (GhcPass p))
-> PScoped (Located (Pat (GhcPass p)))
forall a. Maybe RealSrcSpan -> Scope -> Scope -> a -> PScoped a
PS Maybe RealSrcSpan
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 ToHie (HsConDeclGADTDetails GhcRn) where
  toHie :: HsConDeclGADTDetails GhcRn -> HieM [HieAST Type]
toHie (PrefixConGADT [HsScaled GhcRn (LHsType GhcRn)]
args) = [HsScaled GhcRn (Located (HsType GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [HsScaled GhcRn (Located (HsType GhcRn))]
[HsScaled GhcRn (LHsType GhcRn)]
args
  toHie (RecConGADT XRec GhcRn [LConDeclField GhcRn]
rec) = Located [Located (ConDeclField GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located [Located (ConDeclField GhcRn)]
XRec GhcRn [LConDeclField GhcRn]
rec

instance HiePass p => ToHie (Located (HsCmdTop (GhcPass p))) where
  toHie :: Located (HsCmdTop (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 ->
      [ Located (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
cmd
      ]

instance HiePass p => ToHie (Located (HsCmd (GhcPass p))) where
  toHie :: Located (HsCmd (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
_ ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        ]
      HsCmdArrForm XCmdArrForm (GhcPass p)
_ LHsExpr (GhcPass p)
a LexicalFixity
_ Maybe Fixity
_ [LHsCmdTop (GhcPass p)]
cmdtops ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , [Located (HsCmdTop (GhcPass p))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsCmdTop (GhcPass p))]
[LHsCmdTop (GhcPass p)]
cmdtops
        ]
      HsCmdApp XCmdApp (GhcPass p)
_ LHsCmd (GhcPass p)
a LHsExpr (GhcPass p)
b ->
        [ Located (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
a
        , Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
b
        ]
      HsCmdLam XCmdLam (GhcPass p)
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
mg ->
        [ MatchGroup (GhcPass p) (Located (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsCmd (GhcPass p)))
MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
mg
        ]
      HsCmdPar XCmdPar (GhcPass p)
_ LHsCmd (GhcPass p)
a ->
        [ Located (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
a
        ]
      HsCmdCase XCmdCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        , MatchGroup (GhcPass p) (Located (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsCmd (GhcPass p)))
MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts
        ]
      HsCmdLamCase XCmdLamCase (GhcPass p)
_ MatchGroup (GhcPass p) (LHsCmd (GhcPass p))
alts ->
        [ MatchGroup (GhcPass p) (Located (HsCmd (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie MatchGroup (GhcPass p) (Located (HsCmd (GhcPass p)))
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 ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
a
        , Located (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
b
        , Located (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
c
        ]
      HsCmdLet XCmdLet (GhcPass p)
_ LHsLocalBinds (GhcPass p)
binds LHsCmd (GhcPass p)
cmd' ->
        [ RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
 -> HieM [HieAST Type])
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
-> RScoped (Located (HsLocalBindsLR (GhcPass p) (GhcPass p)))
forall a. Scope -> a -> RScoped a
RS (Located (HsCmd (GhcPass p)) -> Scope
forall a. Located a -> Scope
mkLScope Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
cmd') Located (HsLocalBindsLR (GhcPass p) (GhcPass p))
LHsLocalBinds (GhcPass p)
binds
        , Located (HsCmd (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsCmd (GhcPass p))
LHsCmd (GhcPass p)
cmd'
        ]
      HsCmdDo XCmdDo (GhcPass p)
_ (L ispan 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) (Located (HsCmd (GhcPass p)))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RScoped
    (Located
       (StmtLR (GhcPass p) (GhcPass p) (Located (HsCmd (GhcPass p)))))]
 -> HieM [HieAST Type])
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsCmd (GhcPass p)))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> [Located
      (StmtLR (GhcPass p) (GhcPass p) (Located (HsCmd (GhcPass p))))]
-> [RScoped
      (Located
         (StmtLR (GhcPass p) (GhcPass p) (Located (HsCmd (GhcPass p)))))]
forall a. Scope -> [Located a] -> [RScoped (Located a)]
listScopes Scope
NoScope [Located
   (StmtLR (GhcPass p) (GhcPass p) (Located (HsCmd (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
    [ [Located (TyClDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (TyClDecl GhcRn)]
[LTyClDecl GhcRn]
classes
    , [Located (StandaloneKindSig GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (StandaloneKindSig GhcRn)]
[LStandaloneKindSig GhcRn]
sigs
    , [Located (RoleAnnotDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (RoleAnnotDecl GhcRn)]
[LRoleAnnotDecl GhcRn]
roles
    , [Located (InstDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (InstDecl GhcRn)]
[LInstDecl GhcRn]
instances
    ]

instance ToHie (Located (TyClDecl GhcRn)) where
  toHie :: Located (TyClDecl 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 -> LIdP pass
tcdLName = LIdP GhcRn
name, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
vars, tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LHsType 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 RealSrcSpan -> ContextInfo
Decl DeclType
SynDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located Name
LIdP 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
$ Located (HsType GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc Located (HsType GhcRn)
LHsType GhcRn
typ]) LHsQTyVars GhcRn
vars
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
typ
        ]
      DataDecl {tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP 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 RealSrcSpan -> ContextInfo
Decl DeclType
DataDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located Name
LIdP 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 = Located [Located (HsType GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope (Located [Located (HsType GhcRn)] -> Scope)
-> Located [Located (HsType 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
-> (Located (HsType GhcRn) -> Scope)
-> Maybe (Located (HsType GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope Located (HsType GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope (Maybe (Located (HsType GhcRn)) -> Scope)
-> Maybe (Located (HsType GhcRn)) -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> Maybe (LHsType 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
$ (Located (ConDecl GhcRn) -> Scope)
-> [Located (ConDecl GhcRn)] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map Located (ConDecl GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope ([Located (ConDecl GhcRn)] -> [Scope])
-> [Located (ConDecl 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 [Located (HsDerivingClause GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope (Located [Located (HsDerivingClause GhcRn)] -> Scope)
-> Located [Located (HsDerivingClause GhcRn)] -> Scope
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> HsDeriving 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 -> LIdP pass
tcdLName = LIdP 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 = [LFamilyDecl 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 RealSrcSpan -> ContextInfo
Decl DeclType
ClassDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located Name
LIdP GhcRn
name
        , Located [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located [Located (HsType GhcRn)]
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 ([Located Name], [Located Name])] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located ([Located Name], [Located Name])]
[LHsFunDep GhcRn]
deps
        , [SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type])
-> [SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn)))
-> [Located (Sig GhcRn)] -> [SigContext (Located (Sig GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo -> Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn))
forall a. SigInfo -> a -> SigContext a
SC (SigInfo
 -> Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn)))
-> SigInfo
-> Located (Sig GhcRn)
-> SigContext (Located (Sig GhcRn))
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
ClassSig (Maybe RealSrcSpan -> SigInfo) -> Maybe RealSrcSpan -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) [Located (Sig GhcRn)]
[LSig GhcRn]
sigs
        , Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
 -> HieM [HieAST Type])
-> Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (HsBindLR GhcRn GhcRn)
 -> BindContext (Located (HsBindLR GhcRn GhcRn)))
-> Bag (Located (HsBindLR GhcRn GhcRn))
-> Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> Located (HsBindLR GhcRn GhcRn)
-> BindContext (Located (HsBindLR GhcRn GhcRn))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) Bag (Located (HsBindLR GhcRn GhcRn))
LHsBinds GhcRn
meths
        , [GenLocated SrcSpan (FamilyDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpan (FamilyDecl GhcRn)]
[LFamilyDecl GhcRn]
typs
        , (GenLocated SrcSpan (TyFamInstDecl GhcRn) -> HieM [HieAST Type])
-> [GenLocated SrcSpan (TyFamInstDecl 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])
-> (GenLocated SrcSpan (TyFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpan (TyFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (TyFamInstDecl GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) [GenLocated SrcSpan (TyFamInstDecl GhcRn)]
[LTyFamDefltDecl GhcRn]
deftyps
        , [GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [GenLocated SrcSpan (TyFamInstDecl GhcRn)]
[LTyFamDefltDecl GhcRn]
deftyps
        ]
        where
          context_scope :: Scope
context_scope = Located [Located (HsType GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope Located [Located (HsType GhcRn)]
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 ([Located Name], [Located Name])] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [Located ([Located Name], [Located Name])]
[LHsFunDep GhcRn]
deps, [Located (Sig GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [Located (Sig GhcRn)]
[LSig GhcRn]
sigs, [Located (HsBindLR GhcRn GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc (Bag (Located (HsBindLR GhcRn GhcRn))
-> [Located (HsBindLR GhcRn GhcRn)]
forall a. Bag a -> [a]
bagToList Bag (Located (HsBindLR GhcRn GhcRn))
LHsBinds GhcRn
meths), [GenLocated SrcSpan (FamilyDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [GenLocated SrcSpan (FamilyDecl GhcRn)]
[LFamilyDecl GhcRn]
typs, [GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [GenLocated SrcSpan (TyFamInstDecl GhcRn)]
[LTyFamDefltDecl GhcRn]
deftyps]

instance ToHie (Located (FamilyDecl 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 LIdP 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 RealSrcSpan -> ContextInfo
Decl DeclType
FamDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located Name
LIdP 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 (Located (FamilyResultSig GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (RScoped (Located (FamilyResultSig GhcRn)) -> HieM [HieAST Type])
-> RScoped (Located (FamilyResultSig GhcRn)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Scope
-> Located (FamilyResultSig GhcRn)
-> RScoped (Located (FamilyResultSig GhcRn))
forall a. Scope -> a -> RScoped a
RS Scope
injSpan Located (FamilyResultSig GhcRn)
LFamilyResultSig GhcRn
sig
        , Maybe (Located (InjectivityAnn GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (InjectivityAnn GhcRn))
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
$ Located (FamilyResultSig GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc Located (FamilyResultSig GhcRn)
LFamilyResultSig GhcRn
sig
          injSpan :: Scope
injSpan = Scope
-> (Located (InjectivityAnn GhcRn) -> Scope)
-> Maybe (Located (InjectivityAnn GhcRn))
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope (SrcSpan -> Scope
mkScope (SrcSpan -> Scope)
-> (Located (InjectivityAnn GhcRn) -> SrcSpan)
-> Located (InjectivityAnn GhcRn)
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (InjectivityAnn GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) Maybe (Located (InjectivityAnn GhcRn))
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
$
    [ (GenLocated
   SrcSpan
   (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
 -> HieM [HieAST Type])
-> [GenLocated
      SrcSpan
      (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType 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])
-> (GenLocated
      SrcSpan
      (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
    -> SrcSpan)
-> GenLocated
     SrcSpan
     (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated
  SrcSpan
  (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
-> SrcSpan
forall l e. GenLocated l e -> l
getLoc) [GenLocated
   SrcSpan
   (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
[LTyFamInstEqn GhcRn]
eqns
    , [TScoped
   (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped
    (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
 -> HieM [HieAST Type])
-> [TScoped
      (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (GenLocated
   SrcSpan
   (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
 -> TScoped
      (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn)))))
-> [GenLocated
      SrcSpan
      (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
-> [TScoped
      (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated
  SrcSpan
  (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
-> TScoped
     (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
forall a. GenLocated SrcSpan a -> TScoped a
go [GenLocated
   SrcSpan
   (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))]
[LTyFamInstEqn GhcRn]
eqns
    ]
    where
      go :: GenLocated SrcSpan a -> TScoped a
go (L SrcSpan
l a
ib) = TyVarScope -> a -> TScoped a
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
l]) a
ib
  toHie FamilyInfo GhcRn
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

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

instance ToHie (Located (FunDep (Located Name))) where
  toHie :: Located ([Located Name], [Located Name]) -> HieM [HieAST Type]
toHie (L SrcSpan
span fd :: ([Located Name], [Located Name])
fd@([Located Name]
lhs, [Located Name]
rhs)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ ([Located Name], [Located Name]) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ([Located Name], [Located Name])
fd SrcSpan
span
    , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
lhs
    , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
rhs
    ]

instance (ToHie rhs, HasLoc rhs)
    => ToHie (TScoped (FamEqn GhcRn rhs)) where
  toHie :: TScoped (FamEqn GhcRn rhs) -> HieM [HieAST Type]
toHie (TS TyVarScope
_ FamEqn GhcRn rhs
f) = FamEqn GhcRn rhs -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie FamEqn GhcRn rhs
f

instance (ToHie rhs, HasLoc rhs)
    => ToHie (FamEqn GhcRn rhs) where
  toHie :: FamEqn GhcRn rhs -> HieM [HieAST Type]
toHie fe :: FamEqn GhcRn rhs
fe@(FamEqn XCFamEqn GhcRn rhs
_ LIdP GhcRn
var Maybe [LHsTyVarBndr () GhcRn]
tybndrs HsTyPats GhcRn
pats LexicalFixity
_ rhs
rhs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ Context (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 RealSrcSpan -> ContextInfo
Decl DeclType
InstDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ FamEqn GhcRn rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc FamEqn GhcRn rhs
fe) Located Name
LIdP GhcRn
var
    , Maybe [TVScoped (Located (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe [TVScoped (Located (HsTyVarBndr () GhcRn))]
 -> HieM [HieAST Type])
-> Maybe [TVScoped (Located (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ([Located (HsTyVarBndr () GhcRn)]
 -> [TVScoped (Located (HsTyVarBndr () GhcRn))])
-> Maybe [Located (HsTyVarBndr () GhcRn)]
-> Maybe [TVScoped (Located (HsTyVarBndr () GhcRn))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TyVarScope
-> Scope
-> [LHsTyVarBndr () GhcRn]
-> [TVScoped (LHsTyVarBndr () GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
scope) Maybe [Located (HsTyVarBndr () GhcRn)]
Maybe [LHsTyVarBndr () GhcRn]
tybndrs
    , [HsArg (Located (HsType GhcRn)) (Located (HsType GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [HsArg (Located (HsType GhcRn)) (Located (HsType GhcRn))]
HsTyPats GhcRn
pats
    , rhs -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie rhs
rhs
    ]
    where scope :: Scope
scope = Scope -> Scope -> Scope
combineScopes Scope
patsScope Scope
rhsScope
          patsScope :: Scope
patsScope = SrcSpan -> Scope
mkScope ([HsArg (Located (HsType GhcRn)) (Located (HsType GhcRn))]
-> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [HsArg (Located (HsType GhcRn)) (Located (HsType GhcRn))]
HsTyPats GhcRn
pats)
          rhsScope :: Scope
rhsScope = SrcSpan -> Scope
mkScope (rhs -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc rhs
rhs)

instance ToHie (Located (InjectivityAnn GhcRn)) where
  toHie :: Located (InjectivityAnn GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span InjectivityAnn GhcRn
ann) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ InjectivityAnn GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode InjectivityAnn GhcRn
ann SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InjectivityAnn GhcRn
ann of
      InjectivityAnn LIdP GhcRn
lhs [LIdP GhcRn]
rhs ->
        [ 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
LIdP GhcRn
lhs
        , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
[LIdP GhcRn]
rhs
        ]

instance ToHie (HsDataDefn GhcRn) where
  toHie :: HsDataDefn GhcRn -> HieM [HieAST Type]
toHie (HsDataDefn XCHsDataDefn GhcRn
_ NewOrData
_ LHsContext GhcRn
ctx Maybe (XRec GhcRn CType)
_ Maybe (LHsType GhcRn)
mkind [LConDecl GhcRn]
cons HsDeriving GhcRn
derivs) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ Located [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located [Located (HsType GhcRn)]
LHsContext GhcRn
ctx
    , Maybe (Located (HsType GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (HsType GhcRn))
Maybe (LHsType GhcRn)
mkind
    , [Located (ConDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (ConDecl GhcRn)]
[LConDecl GhcRn]
cons
    , Located [Located (HsDerivingClause GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located [Located (HsDerivingClause GhcRn)]
HsDeriving GhcRn
derivs
    ]

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

instance ToHie (Located (HsDerivingClause GhcRn)) where
  toHie :: Located (HsDerivingClause GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span HsDerivingClause GhcRn
cl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsDerivingClause GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsDerivingClause GhcRn
cl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsDerivingClause GhcRn
cl of
      HsDerivingClause XCHsDerivingClause GhcRn
_ Maybe (LDerivStrategy GhcRn)
strat LDerivClauseTys GhcRn
dct ->
        [ Maybe (Located (DerivStrategy GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (DerivStrategy GhcRn))
Maybe (LDerivStrategy GhcRn)
strat
        , Located (DerivClauseTys GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (DerivClauseTys GhcRn)
LDerivClauseTys GhcRn
dct
        ]

instance ToHie (Located (DerivClauseTys GhcRn)) where
  toHie :: Located (DerivClauseTys GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span DerivClauseTys GhcRn
dct) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivClauseTys GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode DerivClauseTys GhcRn
dct SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivClauseTys GhcRn
dct of
      DctSingle XDctSingle GhcRn
_ LHsSigType GhcRn
ty -> [ TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes[]) HsImplicitBndrs GhcRn (Located (HsType GhcRn))
LHsSigType GhcRn
ty ]
      DctMulti XDctMulti GhcRn
_ [LHsSigType GhcRn]
tys -> [ [TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
 -> HieM [HieAST Type])
-> [TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HsImplicitBndrs GhcRn (Located (HsType GhcRn))
 -> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> [HsImplicitBndrs GhcRn (Located (HsType GhcRn))]
-> [TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [HsImplicitBndrs GhcRn (Located (HsType GhcRn))]
[LHsSigType GhcRn]
tys ]

instance ToHie (Located (DerivStrategy GhcRn)) where
  toHie :: Located (DerivStrategy GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span DerivStrategy GhcRn
strat) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ DerivStrategy GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode DerivStrategy GhcRn
strat SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivStrategy GhcRn
strat of
      DerivStrategy GhcRn
StockStrategy -> []
      DerivStrategy GhcRn
AnyclassStrategy -> []
      DerivStrategy GhcRn
NewtypeStrategy -> []
      ViaStrategy XViaStrategy GhcRn
s -> [ TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) HsImplicitBndrs GhcRn (Located (HsType GhcRn))
XViaStrategy GhcRn
s ]

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

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

instance ToHie (Located (ConDecl GhcRn)) where
  toHie :: Located (ConDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span ConDecl 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
$ ConDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ConDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ConDecl GhcRn
decl of
      ConDeclGADT { con_names :: forall pass. ConDecl pass -> [LIdP pass]
con_names = [LIdP GhcRn]
names, con_qvars :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_qvars = [LHsTyVarBndr Specificity GhcRn]
exp_vars, con_g_ext :: forall pass. ConDecl pass -> XConDeclGADT pass
con_g_ext = XConDeclGADT GhcRn
imp_vars
                  , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext GhcRn)
ctx, con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_g_args = HsConDeclGADTDetails GhcRn
args, con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LHsType 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
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (DeclType -> Maybe RealSrcSpan -> ContextInfo
Decl DeclType
ConDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span)) [Located Name]
[LIdP GhcRn]
names
        , [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly [Context Name]
bindings
                    , [TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity GhcRn]
-> [TVScoped (LHsTyVarBndr Specificity GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
resScope Scope
NoScope [LHsTyVarBndr Specificity GhcRn]
exp_vars ]
        , Maybe (Located [Located (HsType GhcRn)]) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located [Located (HsType GhcRn)])
Maybe (LHsContext GhcRn)
ctx
        , HsConDeclGADTDetails GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDeclGADTDetails GhcRn
args
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
typ
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
argsScope Scope
tyScope
          ctxScope :: Scope
ctxScope = Scope
-> (Located [Located (HsType GhcRn)] -> Scope)
-> Maybe (Located [Located (HsType GhcRn)])
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope Located [Located (HsType GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope Maybe (Located [Located (HsType GhcRn)])
Maybe (LHsContext GhcRn)
ctx
          argsScope :: Scope
argsScope = case HsConDeclGADTDetails GhcRn
args of
            PrefixConGADT [HsScaled GhcRn (LHsType GhcRn)]
xs -> [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope [HsScaled GhcRn (LHsType GhcRn)]
xs
            RecConGADT XRec GhcRn [LConDeclField GhcRn]
x     -> Located [Located (ConDeclField GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope Located [Located (ConDeclField GhcRn)]
XRec GhcRn [LConDeclField GhcRn]
x
          tyScope :: Scope
tyScope = Located (HsType GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope Located (HsType GhcRn)
LHsType GhcRn
typ
          resScope :: TyVarScope
resScope = [Scope] -> TyVarScope
ResolvedScopes [Scope
ctxScope, Scope
rhsScope]
          bindings :: [Context Name]
bindings = (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
mkScope ([Located (HsTyVarBndr Specificity GhcRn)] -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc [Located (HsTyVarBndr Specificity GhcRn)]
[LHsTyVarBndr Specificity GhcRn]
exp_vars)) TyVarScope
resScope) [Name]
XConDeclGADT GhcRn
imp_vars
      ConDeclH98 { con_name :: forall pass. ConDecl pass -> LIdP pass
con_name = LIdP GhcRn
name, con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_ex_tvs = [LHsTyVarBndr Specificity GhcRn]
qvars
                 , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext GhcRn)
ctx, con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_args = HsConDeclH98Details GhcRn
dets } ->
        [ 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 RealSrcSpan -> ContextInfo
Decl DeclType
ConDec (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located Name
LIdP GhcRn
name
        , [TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity GhcRn]
-> [TVScoped (LHsTyVarBndr Specificity GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes ([Scope] -> TyVarScope
ResolvedScopes []) Scope
rhsScope [LHsTyVarBndr Specificity GhcRn]
qvars
        , Maybe (Located [Located (HsType GhcRn)]) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located [Located (HsType GhcRn)])
Maybe (LHsContext GhcRn)
ctx
        , HsConDetails
  (HsScaled GhcRn (Located (HsType GhcRn)))
  (Located [Located (ConDeclField GhcRn)])
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie HsConDetails
  (HsScaled GhcRn (Located (HsType GhcRn)))
  (Located [Located (ConDeclField GhcRn)])
HsConDeclH98Details GhcRn
dets
        ]
        where
          rhsScope :: Scope
rhsScope = Scope -> Scope -> Scope
combineScopes Scope
ctxScope Scope
argsScope
          ctxScope :: Scope
ctxScope = Scope
-> (Located [Located (HsType GhcRn)] -> Scope)
-> Maybe (Located [Located (HsType GhcRn)])
-> Scope
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Scope
NoScope Located [Located (HsType GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope Maybe (Located [Located (HsType GhcRn)])
Maybe (LHsContext GhcRn)
ctx
          argsScope :: Scope
argsScope = case HsConDeclH98Details GhcRn
dets of
            PrefixCon [HsScaled GhcRn (LHsType GhcRn)]
xs -> [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope [HsScaled GhcRn (LHsType GhcRn)]
xs
            InfixCon HsScaled GhcRn (LHsType GhcRn)
a HsScaled GhcRn (LHsType GhcRn)
b -> [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope [HsScaled GhcRn (LHsType GhcRn)
a, HsScaled GhcRn (LHsType GhcRn)
b]
            RecCon XRec GhcRn [LConDeclField GhcRn]
x     -> Located [Located (ConDeclField GhcRn)] -> Scope
forall a. Located a -> Scope
mkLScope Located [Located (ConDeclField GhcRn)]
XRec GhcRn [LConDeclField GhcRn]
x
    where scaled_args_scope :: [HsScaled GhcRn (LHsType GhcRn)] -> Scope
          scaled_args_scope :: [HsScaled GhcRn (LHsType GhcRn)] -> Scope
scaled_args_scope = (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)
-> ([HsScaled GhcRn (Located (HsType GhcRn))] -> [Scope])
-> [HsScaled GhcRn (Located (HsType GhcRn))]
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HsScaled GhcRn (Located (HsType GhcRn)) -> Scope)
-> [HsScaled GhcRn (Located (HsType GhcRn))] -> [Scope]
forall a b. (a -> b) -> [a] -> [b]
map (Located (HsType GhcRn) -> Scope
forall a. Located a -> Scope
mkLScope (Located (HsType GhcRn) -> Scope)
-> (HsScaled GhcRn (Located (HsType GhcRn))
    -> Located (HsType GhcRn))
-> HsScaled GhcRn (Located (HsType GhcRn))
-> Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsScaled GhcRn (Located (HsType GhcRn)) -> Located (HsType GhcRn)
forall pass a. HsScaled pass a -> a
hsScaledThing)

instance ToHie (Located [Located (ConDeclField GhcRn)]) where
  toHie :: Located [Located (ConDeclField GhcRn)] -> HieM [HieAST Type]
toHie (L SrcSpan
span [Located (ConDeclField GhcRn)]
decls) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
span
    , [Located (ConDeclField GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (ConDeclField GhcRn)]
decls
    ]

instance ( HasLoc thing
         , ToHie (TScoped thing)
         ) => ToHie (TScoped (HsImplicitBndrs GhcRn thing)) where
  toHie :: TScoped (HsImplicitBndrs GhcRn thing) -> HieM [HieAST Type]
toHie (TS TyVarScope
sc (HsIB XHsIB GhcRn thing
ibrn thing
a)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ [Context Name] -> HieM [HieAST Type]
forall a. [Context Name] -> HieM [HieAST a]
bindingsOnly ([Context Name] -> HieM [HieAST Type])
-> [Context Name] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Name -> Context Name) -> [Name] -> [Context Name]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Name -> Context Name
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Name -> Context Name)
-> ContextInfo -> Name -> Context Name
forall a b. (a -> b) -> a -> b
$ Scope -> TyVarScope -> ContextInfo
TyVarBind (SrcSpan -> Scope
mkScope SrcSpan
span) TyVarScope
sc) [Name]
XHsIB GhcRn thing
ibrn
      , TScoped thing -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped thing -> HieM [HieAST Type])
-> TScoped thing -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope -> thing -> TScoped thing
forall a. TyVarScope -> a -> TScoped a
TS TyVarScope
sc thing
a
      ]
    where span :: SrcSpan
span = thing -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc thing
a

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

instance ToHie (Located (StandaloneKindSig GhcRn)) where
  toHie :: Located (StandaloneKindSig GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
sp StandaloneKindSig GhcRn
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM [StandaloneKindSig GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode StandaloneKindSig GhcRn
sig SrcSpan
sp, StandaloneKindSig GhcRn -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie StandaloneKindSig GhcRn
sig]

instance ToHie (StandaloneKindSig GhcRn) where
  toHie :: StandaloneKindSig GhcRn -> HieM [HieAST Type]
toHie StandaloneKindSig GhcRn
sig = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ case StandaloneKindSig GhcRn
sig of
    StandaloneKindSig XStandaloneKindSig GhcRn
_ LIdP GhcRn
name LHsSigType 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 ContextInfo
TyDecl Located Name
LIdP GhcRn
name
      , TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) HsImplicitBndrs GhcRn (Located (HsType GhcRn))
LHsSigType GhcRn
typ
      ]

instance HiePass p => ToHie (SigContext (Located (Sig (GhcPass p)))) where
  toHie :: SigContext (Located (Sig (GhcPass p))) -> HieM [HieAST Type]
toHie (SC (SI SigType
styp Maybe RealSrcSpan
msp) (L SrcSpan
sp Sig (GhcPass p)
sig)) =
    case HiePass p => HiePassEv p
forall (p :: Pass). HiePass p => HiePassEv p
hiePass @p of
      HiePassEv p
HieTc -> [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
      HiePassEv p
HieRn -> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ Sig (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode Sig (GhcPass p)
sig SrcSpan
sp HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case Sig (GhcPass p)
sig of
        TypeSig XTypeSig (GhcPass p)
_ [LIdP (GhcPass p)]
names LHsSigWcType (GhcPass p)
typ ->
          [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [Located Name]
[LIdP (GhcPass p)]
names
          , TScoped
  (HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> TScoped
     (HsWildCardBndrs
        GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe RealSrcSpan -> TyVarScope
UnresolvedScope ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall l e. GenLocated l e -> e
unLoc [Located Name]
[LIdP (GhcPass p)]
names) Maybe RealSrcSpan
forall a. Maybe a
Nothing) LHsSigWcType (GhcPass p)
HsWildCardBndrs
  GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
typ
          ]
        PatSynSig XPatSynSig (GhcPass p)
_ [LIdP (GhcPass p)]
names LHsSigType (GhcPass p)
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
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
TyDecl) [Located Name]
[LIdP (GhcPass p)]
names
          , TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe RealSrcSpan -> TyVarScope
UnresolvedScope ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall l e. GenLocated l e -> e
unLoc [Located Name]
[LIdP (GhcPass p)]
names) Maybe RealSrcSpan
forall a. Maybe a
Nothing) LHsSigType (GhcPass p)
HsImplicitBndrs GhcRn (Located (HsType GhcRn))
typ
          ]
        ClassOpSig XClassOpSig (GhcPass p)
_ Bool
_ [LIdP (GhcPass p)]
names LHsSigType (GhcPass p)
typ ->
          [ case SigType
styp of
              SigType
ClassSig -> [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Located Name -> Context (Located Name))
-> ContextInfo -> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ Maybe RealSrcSpan -> ContextInfo
ClassTyDecl (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
sp) [Located Name]
[LIdP (GhcPass p)]
names
              SigType
_  -> [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (ContextInfo -> Located Name -> Context (Located Name))
-> ContextInfo -> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ ContextInfo
TyDecl) [Located Name]
[LIdP (GhcPass p)]
names
          , TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Name] -> Maybe RealSrcSpan -> TyVarScope
UnresolvedScope ((Located Name -> Name) -> [Located Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Located Name -> Name
forall l e. GenLocated l e -> e
unLoc [Located Name]
[LIdP (GhcPass p)]
names) Maybe RealSrcSpan
msp) LHsSigType (GhcPass p)
HsImplicitBndrs GhcRn (Located (HsType GhcRn))
typ
          ]
        IdSig XIdSig (GhcPass p)
_ Id
_ -> []
        FixSig XFixSig (GhcPass p)
_ FixitySig (GhcPass p)
fsig ->
          [ GenLocated SrcSpan (FixitySig (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (FixitySig (GhcPass p)) -> HieM [HieAST Type])
-> GenLocated SrcSpan (FixitySig (GhcPass p)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> FixitySig (GhcPass p)
-> GenLocated SrcSpan (FixitySig (GhcPass p))
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp FixitySig (GhcPass p)
fsig
          ]
        InlineSig XInlineSig (GhcPass p)
_ LIdP (GhcPass p)
name InlinePragma
_ ->
          [ 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
LIdP (GhcPass p)
name
          ]
        SpecSig XSpecSig (GhcPass p)
_ LIdP (GhcPass p)
name [LHsSigType (GhcPass p)]
typs InlinePragma
_ ->
          [ 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
LIdP (GhcPass p)
name
          , [TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
 -> HieM [HieAST Type])
-> [TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (HsImplicitBndrs GhcRn (Located (HsType GhcRn))
 -> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> [HsImplicitBndrs GhcRn (Located (HsType GhcRn))]
-> [TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [])) [LHsSigType (GhcPass p)]
[HsImplicitBndrs GhcRn (Located (HsType GhcRn))]
typs
          ]
        SpecInstSig XSpecInstSig (GhcPass p)
_ SourceText
_ LHsSigType (GhcPass p)
typ ->
          [ TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) LHsSigType (GhcPass p)
HsImplicitBndrs GhcRn (Located (HsType GhcRn))
typ
          ]
        MinimalSig XMinimalSig (GhcPass p)
_ SourceText
_ LBooleanFormula (LIdP (GhcPass p))
form ->
          [ LBooleanFormula (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie LBooleanFormula (Located Name)
LBooleanFormula (LIdP (GhcPass p))
form
          ]
        SCCFunSig XSCCFunSig (GhcPass p)
_ SourceText
_ LIdP (GhcPass p)
name Maybe (XRec (GhcPass p) StringLiteral)
mtxt ->
          [ 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
LIdP (GhcPass p)
name
          , HieM [HieAST Type]
-> (GenLocated SrcSpan StringLiteral -> HieM [HieAST Type])
-> Maybe (GenLocated SrcSpan StringLiteral)
-> 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 []) (SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly (SrcSpan -> HieM [HieAST Type])
-> (GenLocated SrcSpan StringLiteral -> SrcSpan)
-> GenLocated SrcSpan StringLiteral
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan StringLiteral -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) Maybe (GenLocated SrcSpan StringLiteral)
Maybe (XRec (GhcPass p) StringLiteral)
mtxt
          ]
        CompleteMatchSig XCompleteMatchSig (GhcPass p)
_ SourceText
_ (L ispan names) Maybe (LIdP (GhcPass p))
typ ->
          [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
ispan
          , [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
names
          , Maybe (Context (Located Name)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (Context (Located Name)) -> HieM [HieAST Type])
-> Maybe (Context (Located Name)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> Maybe (Located Name) -> Maybe (Context (Located Name))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) Maybe (Located Name)
Maybe (LIdP (GhcPass p))
typ
          ]

instance ToHie (Located (HsType GhcRn)) where
  toHie :: Located (HsType GhcRn) -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
x = TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type])
-> TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Located (HsType GhcRn) -> TScoped (Located (HsType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) Located (HsType GhcRn)
x

instance ToHie (TScoped (Located (HsType GhcRn))) where
  toHie :: TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type]
toHie (TS TyVarScope
tsc (L SrcSpan
span HsType GhcRn
t)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsType GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsType GhcRn
t SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsType GhcRn
t of
      HsForAllTy XForAllTy GhcRn
_ HsForAllTelescope GhcRn
tele LHsType GhcRn
body ->
        let scope :: Scope
scope = SrcSpan -> Scope
mkScope (SrcSpan -> Scope) -> SrcSpan -> Scope
forall a b. (a -> b) -> a -> b
$ Located (HsType GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc Located (HsType GhcRn)
LHsType GhcRn
body in
        [ case HsForAllTelescope GhcRn
tele of
            HsForAllVis { hsf_vis_bndrs :: forall pass. HsForAllTelescope pass -> [LHsTyVarBndr () pass]
hsf_vis_bndrs = [LHsTyVarBndr () GhcRn]
bndrs } ->
              [TVScoped (Located (HsTyVarBndr () GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (Located (HsTyVarBndr () GhcRn))] -> HieM [HieAST Type])
-> [TVScoped (Located (HsTyVarBndr () GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr () GhcRn]
-> [TVScoped (LHsTyVarBndr () GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tsc Scope
scope [LHsTyVarBndr () GhcRn]
bndrs
            HsForAllInvis { hsf_invis_bndrs :: forall pass.
HsForAllTelescope pass -> [LHsTyVarBndr Specificity pass]
hsf_invis_bndrs = [LHsTyVarBndr Specificity GhcRn]
bndrs } ->
              [TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
 -> HieM [HieAST Type])
-> [TVScoped (Located (HsTyVarBndr Specificity GhcRn))]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Scope
-> [LHsTyVarBndr Specificity GhcRn]
-> [TVScoped (LHsTyVarBndr Specificity GhcRn)]
forall flag (a :: Pass).
TyVarScope
-> Scope
-> [LHsTyVarBndr flag (GhcPass a)]
-> [TVScoped (LHsTyVarBndr flag (GhcPass a))]
tvScopes TyVarScope
tsc Scope
scope [LHsTyVarBndr Specificity GhcRn]
bndrs
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
body
        ]
      HsQualTy XQualTy GhcRn
_ LHsContext GhcRn
ctx LHsType GhcRn
body ->
        [ Located [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located [Located (HsType GhcRn)]
LHsContext GhcRn
ctx
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
body
        ]
      HsTyVar XTyVar GhcRn
_ PromotionFlag
_ LIdP GhcRn
var ->
        [ 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
LIdP GhcRn
var
        ]
      HsAppTy XAppTy GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
b
        ]
      HsAppKindTy XAppKindTy GhcRn
_ LHsType GhcRn
ty LHsType GhcRn
ki ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
ty
        , TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type])
-> TScoped (Located (HsType GhcRn)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> Located (HsType GhcRn) -> TScoped (Located (HsType GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) Located (HsType GhcRn)
LHsType GhcRn
ki
        ]
      HsFunTy XFunTy GhcRn
_ HsArrow GhcRn
w LHsType GhcRn
a LHsType GhcRn
b ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (HsArrow GhcRn -> LHsType GhcRn
arrowToHsType HsArrow GhcRn
w)
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
b
        ]
      HsListTy XListTy GhcRn
_ LHsType GhcRn
a ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        ]
      HsTupleTy XTupleTy GhcRn
_ HsTupleSort
_ [LHsType GhcRn]
tys ->
        [ [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsType GhcRn)]
[LHsType GhcRn]
tys
        ]
      HsSumTy XSumTy GhcRn
_ [LHsType GhcRn]
tys ->
        [ [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsType GhcRn)]
[LHsType GhcRn]
tys
        ]
      HsOpTy XOpTy GhcRn
_ LHsType GhcRn
a LIdP GhcRn
op LHsType GhcRn
b ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        , Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located Name
LIdP GhcRn
op
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
b
        ]
      HsParTy XParTy GhcRn
_ LHsType GhcRn
a ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        ]
      HsIParamTy XIParamTy GhcRn
_ XRec GhcRn HsIPName
ip LHsType GhcRn
ty ->
        [ Located HsIPName -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located HsIPName
XRec GhcRn HsIPName
ip
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
ty
        ]
      HsKindSig XKindSig GhcRn
_ LHsType GhcRn
a LHsType GhcRn
b ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
b
        ]
      HsSpliceTy XSpliceTy GhcRn
_ HsSplice GhcRn
a ->
        [ GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsSplice GhcRn -> GenLocated SrcSpan (HsSplice GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span HsSplice GhcRn
a
        ]
      HsDocTy XDocTy GhcRn
_ LHsType GhcRn
a LHsDocString
_ ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
a
        ]
      HsBangTy XBangTy GhcRn
_ HsSrcBang
_ LHsType GhcRn
ty ->
        [ Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
ty
        ]
      HsRecTy XRecTy GhcRn
_ [LConDeclField GhcRn]
fields ->
        [ [Located (ConDeclField GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (ConDeclField GhcRn)]
[LConDeclField GhcRn]
fields
        ]
      HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
_ [LHsType GhcRn]
tys ->
        [ [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsType GhcRn)]
[LHsType GhcRn]
tys
        ]
      HsExplicitTupleTy XExplicitTupleTy GhcRn
_ [LHsType GhcRn]
tys ->
        [ [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsType GhcRn)]
[LHsType GhcRn]
tys
        ]
      HsTyLit XTyLit GhcRn
_ HsTyLit
_ -> []
      HsWildCardTy XWildCardTy GhcRn
_ -> []
      HsStarTy XStarTy GhcRn
_ Bool
_ -> []
      XHsType XXType GhcRn
_ -> []

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

instance Data flag => ToHie (TVScoped (Located (HsTyVarBndr flag GhcRn))) where
  toHie :: TVScoped (Located (HsTyVarBndr flag GhcRn)) -> HieM [HieAST Type]
toHie (TVS TyVarScope
tsc Scope
sc (L SrcSpan
span HsTyVarBndr flag GhcRn
bndr)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsTyVarBndr flag GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsTyVarBndr flag GhcRn
bndr SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsTyVarBndr flag GhcRn
bndr of
      UserTyVar XUserTyVar GhcRn
_ flag
_ LIdP GhcRn
var ->
        [ 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 (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) Located Name
LIdP GhcRn
var
        ]
      KindedTyVar XKindedTyVar GhcRn
_ flag
_ LIdP GhcRn
var LHsType GhcRn
kind ->
        [ 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 (Scope -> TyVarScope -> ContextInfo
TyVarBind Scope
sc TyVarScope
tsc) Located Name
LIdP GhcRn
var
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
kind
        ]

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

instance ToHie (Located [Located (HsType GhcRn)]) where
  toHie :: Located [Located (HsType GhcRn)] -> HieM [HieAST Type]
toHie (L SrcSpan
span [Located (HsType GhcRn)]
tys) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
      [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
span
      , [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsType GhcRn)]
tys
      ]

instance ToHie (Located (ConDeclField GhcRn)) where
  toHie :: Located (ConDeclField GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span ConDeclField GhcRn
field) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ConDeclField GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ConDeclField GhcRn
field SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ConDeclField GhcRn
field of
      ConDeclField XConDeclField GhcRn
_ [LFieldOcc GhcRn]
fields LHsType GhcRn
typ Maybe LHsDocString
_ ->
        [ [RFContext (Located (FieldOcc GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([RFContext (Located (FieldOcc GhcRn))] -> HieM [HieAST Type])
-> [RFContext (Located (FieldOcc GhcRn))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (FieldOcc GhcRn) -> RFContext (Located (FieldOcc GhcRn)))
-> [Located (FieldOcc GhcRn)]
-> [RFContext (Located (FieldOcc GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (RecFieldContext
-> Maybe RealSrcSpan
-> Located (FieldOcc GhcRn)
-> RFContext (Located (FieldOcc GhcRn))
forall a. RecFieldContext -> Maybe RealSrcSpan -> a -> RFContext a
RFC RecFieldContext
RecFieldDecl (SrcSpan -> Maybe RealSrcSpan
getRealSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ Located (HsType GhcRn) -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
loc Located (HsType GhcRn)
LHsType GhcRn
typ)) [Located (FieldOcc GhcRn)]
[LFieldOcc GhcRn]
fields
        , Located (HsType GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsType GhcRn)
LHsType GhcRn
typ
        ]

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

instance ToHie (Located (SpliceDecl GhcRn)) where
  toHie :: Located (SpliceDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span SpliceDecl 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
$ SpliceDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode SpliceDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case SpliceDecl GhcRn
decl of
      SpliceDecl XSpliceDecl GhcRn
_ XRec GhcRn (HsSplice GhcRn)
splice SpliceExplicitFlag
_ ->
        [ GenLocated SrcSpan (HsSplice GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie GenLocated SrcSpan (HsSplice GhcRn)
XRec GhcRn (HsSplice GhcRn)
splice
        ]

instance ToHie (HsBracket a) where
  toHie :: HsBracket a -> HieM [HieAST Type]
toHie HsBracket a
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie PendingRnSplice where
  toHie :: PendingRnSplice -> HieM [HieAST Type]
toHie PendingRnSplice
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie PendingTcSplice where
  toHie :: PendingTcSplice -> HieM [HieAST Type]
toHie PendingTcSplice
_ = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

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

instance ToHie (Located HsIPName) where
  toHie :: Located HsIPName -> HieM [HieAST Type]
toHie (L SrcSpan
span HsIPName
e) = HsIPName -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsIPName
e SrcSpan
span

instance HiePass p => ToHie (Located (HsSplice (GhcPass p))) where
  toHie :: Located (HsSplice (GhcPass p)) -> HieM [HieAST Type]
toHie (L SrcSpan
span HsSplice (GhcPass p)
sp) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ HsSplice (GhcPass p) -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode HsSplice (GhcPass p)
sp SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case HsSplice (GhcPass p)
sp of
      HsTypedSplice XTypedSplice (GhcPass p)
_ SpliceDecoration
_ IdP (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        ]
      HsUntypedSplice XUntypedSplice (GhcPass p)
_ SpliceDecoration
_ IdP (GhcPass p)
_ LHsExpr (GhcPass p)
expr ->
        [ Located (HsExpr (GhcPass p)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr (GhcPass p))
LHsExpr (GhcPass p)
expr
        ]
      HsQuasiQuote XQuasiQuote (GhcPass p)
_ IdP (GhcPass p)
_ IdP (GhcPass p)
_ SrcSpan
ispan FastString
_ ->
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
ispan
        ]
      HsSpliced XSpliced (GhcPass p)
_ ThModFinalizers
_ HsSplicedThing (GhcPass p)
_ ->
        []
      XSplice XXSplice (GhcPass p)
x -> case IsPass p => GhcPass p
forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
#if __GLASGOW_HASKELL__ < 811
                     GhcPass p
GhcPs -> NoExtCon -> [HieM [HieAST Type]]
forall a. NoExtCon -> a
noExtCon NoExtCon
XXSplice (GhcPass p)
x
                     GhcPass p
GhcRn -> NoExtCon -> [HieM [HieAST Type]]
forall a. NoExtCon -> a
noExtCon NoExtCon
XXSplice (GhcPass p)
x
#endif
                     GhcPass p
GhcTc -> case XXSplice (GhcPass p)
x of
                                HsSplicedT _ -> []

instance ToHie (Located (RoleAnnotDecl GhcRn)) where
  toHie :: Located (RoleAnnotDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span RoleAnnotDecl GhcRn
annot) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RoleAnnotDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode RoleAnnotDecl GhcRn
annot SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RoleAnnotDecl GhcRn
annot of
      RoleAnnotDecl XCRoleAnnotDecl GhcRn
_ LIdP GhcRn
var [XRec GhcRn (Maybe Role)]
roles ->
        [ 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
LIdP GhcRn
var
        , (GenLocated SrcSpan (Maybe Role) -> HieM [HieAST Type])
-> [GenLocated SrcSpan (Maybe Role)] -> 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])
-> (GenLocated SrcSpan (Maybe Role) -> SrcSpan)
-> GenLocated SrcSpan (Maybe Role)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (Maybe Role) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) [GenLocated SrcSpan (Maybe Role)]
[XRec GhcRn (Maybe Role)]
roles
        ]

instance ToHie (Located (InstDecl GhcRn)) where
  toHie :: Located (InstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span InstDecl 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
$ InstDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode InstDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case InstDecl GhcRn
decl of
      ClsInstD XClsInstD GhcRn
_ ClsInstDecl GhcRn
d ->
        [ GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> ClsInstDecl GhcRn -> GenLocated SrcSpan (ClsInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span ClsInstDecl GhcRn
d
        ]
      DataFamInstD XDataFamInstD GhcRn
_ DataFamInstDecl GhcRn
d ->
        [ GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> DataFamInstDecl GhcRn
-> GenLocated SrcSpan (DataFamInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span DataFamInstDecl GhcRn
d
        ]
      TyFamInstD XTyFamInstD GhcRn
_ TyFamInstDecl GhcRn
d ->
        [ GenLocated SrcSpan (TyFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (GenLocated SrcSpan (TyFamInstDecl GhcRn) -> HieM [HieAST Type])
-> GenLocated SrcSpan (TyFamInstDecl GhcRn) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ SrcSpan
-> TyFamInstDecl GhcRn -> GenLocated SrcSpan (TyFamInstDecl GhcRn)
forall l e. l -> e -> GenLocated l e
L SrcSpan
span TyFamInstDecl GhcRn
d
        ]

instance ToHie (Located (ClsInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpan (ClsInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span ClsInstDecl GhcRn
decl) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM
    [ TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
span]) (HsImplicitBndrs GhcRn (Located (HsType GhcRn))
 -> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> LHsSigType GhcRn
forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty ClsInstDecl GhcRn
decl
    , Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
 -> HieM [HieAST Type])
-> Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (HsBindLR GhcRn GhcRn)
 -> BindContext (Located (HsBindLR GhcRn GhcRn)))
-> Bag (Located (HsBindLR GhcRn GhcRn))
-> Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (BindType
-> Scope
-> Located (HsBindLR GhcRn GhcRn)
-> BindContext (Located (HsBindLR GhcRn GhcRn))
forall a. BindType -> Scope -> a -> BindContext a
BC BindType
InstanceBind Scope
ModuleScope) (Bag (Located (HsBindLR GhcRn GhcRn))
 -> Bag (BindContext (Located (HsBindLR GhcRn GhcRn))))
-> Bag (Located (HsBindLR GhcRn GhcRn))
-> Bag (BindContext (Located (HsBindLR GhcRn GhcRn)))
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> LHsBinds GhcRn
forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds ClsInstDecl GhcRn
decl
    , [SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type])
-> [SigContext (Located (Sig GhcRn))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn)))
-> [Located (Sig GhcRn)] -> [SigContext (Located (Sig GhcRn))]
forall a b. (a -> b) -> [a] -> [b]
map (SigInfo -> Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn))
forall a. SigInfo -> a -> SigContext a
SC (SigInfo
 -> Located (Sig GhcRn) -> SigContext (Located (Sig GhcRn)))
-> SigInfo
-> Located (Sig GhcRn)
-> SigContext (Located (Sig GhcRn))
forall a b. (a -> b) -> a -> b
$ SigType -> Maybe RealSrcSpan -> SigInfo
SI SigType
InstSig (Maybe RealSrcSpan -> SigInfo) -> Maybe RealSrcSpan -> SigInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) ([Located (Sig GhcRn)] -> [SigContext (Located (Sig GhcRn))])
-> [Located (Sig GhcRn)] -> [SigContext (Located (Sig GhcRn))]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LSig GhcRn]
forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs ClsInstDecl GhcRn
decl
    , (GenLocated SrcSpan (TyFamInstDecl GhcRn) -> HieM [HieAST Type])
-> [GenLocated SrcSpan (TyFamInstDecl 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])
-> (GenLocated SrcSpan (TyFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpan (TyFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (TyFamInstDecl GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) ([GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LTyFamDefltDecl GhcRn]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl GhcRn
decl
    , [GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> HieM [HieAST Type])
-> [GenLocated SrcSpan (TyFamInstDecl GhcRn)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LTyFamDefltDecl GhcRn]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl GhcRn
decl
    , (GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DataFamInstDecl 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])
-> (GenLocated SrcSpan (DataFamInstDecl GhcRn) -> SrcSpan)
-> GenLocated SrcSpan (DataFamInstDecl GhcRn)
-> HieM [HieAST Type]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (DataFamInstDecl GhcRn) -> SrcSpan
forall l e. GenLocated l e -> l
getLoc) ([GenLocated SrcSpan (DataFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LDataFamInstDecl GhcRn]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
decl
    , [GenLocated SrcSpan (DataFamInstDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([GenLocated SrcSpan (DataFamInstDecl GhcRn)]
 -> HieM [HieAST Type])
-> [GenLocated SrcSpan (DataFamInstDecl GhcRn)]
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> [LDataFamInstDecl GhcRn]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
decl
    , Maybe (Located OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (Located OverlapMode) -> HieM [HieAST Type])
-> Maybe (Located OverlapMode) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcRn -> Maybe (XRec GhcRn OverlapMode)
forall pass. ClsInstDecl pass -> Maybe (XRec pass OverlapMode)
cid_overlap_mode ClsInstDecl GhcRn
decl
    ]

instance ToHie (Located (DataFamInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpan (DataFamInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
sp (DataFamInstDecl FamInstEqn GhcRn (HsDataDefn GhcRn)
d)) = TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn))
 -> HieM [HieAST Type])
-> TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> FamInstEqn GhcRn (HsDataDefn GhcRn)
-> TScoped (FamInstEqn GhcRn (HsDataDefn GhcRn))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
sp]) FamInstEqn GhcRn (HsDataDefn GhcRn)
d

instance ToHie (Located (TyFamInstDecl GhcRn)) where
  toHie :: GenLocated SrcSpan (TyFamInstDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
sp (TyFamInstDecl TyFamInstEqn GhcRn
d)) = TScoped
  (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
 -> HieM [HieAST Type])
-> TScoped
     (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn)))
-> TScoped
     (HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes [SrcSpan -> Scope
mkScope SrcSpan
sp]) HsImplicitBndrs GhcRn (FamEqn GhcRn (Located (HsType GhcRn)))
TyFamInstEqn GhcRn
d

instance ToHie (Context a)
         => ToHie (PatSynFieldContext (RecordPatSynField a)) where
  toHie :: PatSynFieldContext (RecordPatSynField a) -> HieM [HieAST Type]
toHie (PSC Maybe RealSrcSpan
sp (RecordPatSynField a
a a
b)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ Context a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context a -> HieM [HieAST Type])
-> Context a -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> a -> Context a
forall a. ContextInfo -> a -> Context a
C (RecFieldContext -> Maybe RealSrcSpan -> ContextInfo
RecField RecFieldContext
RecFieldDecl Maybe RealSrcSpan
sp) a
a
    , Context a -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context a -> HieM [HieAST Type])
-> Context a -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> a -> Context a
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use a
b
    ]

instance ToHie (Located (DerivDecl GhcRn)) where
  toHie :: Located (DerivDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span DerivDecl 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
$ DerivDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode DerivDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DerivDecl GhcRn
decl of
      DerivDecl XCDerivDecl GhcRn
_ LHsSigWcType GhcRn
typ Maybe (LDerivStrategy GhcRn)
strat Maybe (XRec GhcRn OverlapMode)
overlap ->
        [ TScoped
  (HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped
   (HsWildCardBndrs
      GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
 -> HieM [HieAST Type])
-> TScoped
     (HsWildCardBndrs
        GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsWildCardBndrs
     GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> TScoped
     (HsWildCardBndrs
        GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn))))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) HsWildCardBndrs
  GhcRn (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
LHsSigWcType GhcRn
typ
        , Maybe (Located (DerivStrategy GhcRn)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located (DerivStrategy GhcRn))
Maybe (LDerivStrategy GhcRn)
strat
        , Maybe (Located OverlapMode) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Maybe (Located OverlapMode)
Maybe (XRec GhcRn OverlapMode)
overlap
        ]

instance ToHie (Located (FixitySig GhcRn)) where
  toHie :: Located (FixitySig GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span FixitySig GhcRn
sig) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ FixitySig GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode FixitySig GhcRn
sig SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FixitySig GhcRn
sig of
      FixitySig XFixitySig GhcRn
_ [LIdP GhcRn]
vars Fixity
_ ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
[LIdP GhcRn]
vars
        ]

instance ToHie (Located (DefaultDecl GhcRn)) where
  toHie :: Located (DefaultDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span DefaultDecl 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
$ DefaultDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode DefaultDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case DefaultDecl GhcRn
decl of
      DefaultDecl XCDefaultDecl GhcRn
_ [LHsType GhcRn]
typs ->
        [ [Located (HsType GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (HsType GhcRn)]
[LHsType GhcRn]
typs
        ]

instance ToHie (Located (ForeignDecl GhcRn)) where
  toHie :: Located (ForeignDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span ForeignDecl 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
$ ForeignDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ForeignDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ForeignDecl GhcRn
decl of
      ForeignImport {fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP GhcRn
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType GhcRn
sig, fd_fi :: forall pass. ForeignDecl pass -> ForeignImport
fd_fi = ForeignImport
fi} ->
        [ 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 (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
RegularBind Scope
ModuleScope (Maybe RealSrcSpan -> ContextInfo)
-> Maybe RealSrcSpan -> ContextInfo
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
getRealSpan SrcSpan
span) Located Name
LIdP GhcRn
name
        , TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) HsImplicitBndrs GhcRn (Located (HsType GhcRn))
LHsSigType GhcRn
sig
        , ForeignImport -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignImport
fi
        ]
      ForeignExport {fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP GhcRn
name, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType GhcRn
sig, fd_fe :: forall pass. ForeignDecl pass -> ForeignExport
fd_fe = ForeignExport
fe} ->
        [ 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
LIdP GhcRn
name
        , TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
 -> HieM [HieAST Type])
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
-> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ TyVarScope
-> HsImplicitBndrs GhcRn (Located (HsType GhcRn))
-> TScoped (HsImplicitBndrs GhcRn (Located (HsType GhcRn)))
forall a. TyVarScope -> a -> TScoped a
TS ([Scope] -> TyVarScope
ResolvedScopes []) HsImplicitBndrs GhcRn (Located (HsType GhcRn))
LHsSigType GhcRn
sig
        , ForeignExport -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ForeignExport
fe
        ]

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

instance ToHie ForeignExport where
  toHie :: ForeignExport -> HieM [HieAST Type]
toHie (CExport (L SrcSpan
a CExportSpec
_) (L SrcSpan
b SourceText
_)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
    [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
a
    , SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
b
    ]

instance ToHie (Located (WarnDecls GhcRn)) where
  toHie :: Located (WarnDecls GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span WarnDecls 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
$ WarnDecls GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode WarnDecls GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecls GhcRn
decl of
      Warnings XWarnings GhcRn
_ SourceText
_ [LWarnDecl GhcRn]
warnings ->
        [ [Located (WarnDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (WarnDecl GhcRn)]
[LWarnDecl GhcRn]
warnings
        ]

instance ToHie (Located (WarnDecl GhcRn)) where
  toHie :: Located (WarnDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span WarnDecl 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
$ WarnDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode WarnDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case WarnDecl GhcRn
decl of
      Warning XWarning GhcRn
_ [LIdP GhcRn]
vars WarningTxt
_ ->
        [ [Context (Located Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([Context (Located Name)] -> HieM [HieAST Type])
-> [Context (Located Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located Name -> Context (Located Name))
-> [Located Name] -> [Context (Located Name)]
forall a b. (a -> b) -> [a] -> [b]
map (ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use) [Located Name]
[LIdP GhcRn]
vars
        ]

instance ToHie (Located (AnnDecl GhcRn)) where
  toHie :: Located (AnnDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span AnnDecl 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
$ AnnDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode AnnDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case AnnDecl GhcRn
decl of
      HsAnnotation XHsAnnotation GhcRn
_ SourceText
_ AnnProvenance (IdP GhcRn)
prov XRec GhcRn (HsExpr GhcRn)
expr ->
        [ AnnProvenance Name -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie AnnProvenance Name
AnnProvenance (IdP GhcRn)
prov
        , Located (HsExpr GhcRn) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie Located (HsExpr GhcRn)
XRec GhcRn (HsExpr GhcRn)
expr
        ]

instance ToHie (Context (Located a)) => ToHie (AnnProvenance a) where
  toHie :: AnnProvenance a -> HieM [HieAST Type]
toHie (ValueAnnProvenance Located a
a) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located a) -> HieM [HieAST Type])
-> Context (Located a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located a
a
  toHie (TypeAnnProvenance Located a
a) = Context (Located a) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located a) -> HieM [HieAST Type])
-> Context (Located a) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located a -> Context (Located a)
forall a. ContextInfo -> a -> Context a
C ContextInfo
Use Located a
a
  toHie AnnProvenance a
ModuleAnnProvenance = [HieAST Type] -> HieM [HieAST Type]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

instance ToHie (Located (RuleDecls GhcRn)) where
  toHie :: Located (RuleDecls GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span RuleDecls 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
$ RuleDecls GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode RuleDecls GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleDecls GhcRn
decl of
      HsRules XCRuleDecls GhcRn
_ SourceText
_ [LRuleDecl GhcRn]
rules ->
        [ [Located (RuleDecl GhcRn)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie [Located (RuleDecl GhcRn)]
[LRuleDecl GhcRn]
rules
        ]

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

instance ToHie (RScoped (Located (RuleBndr GhcRn))) where
  toHie :: RScoped (Located (RuleBndr GhcRn)) -> HieM [HieAST Type]
toHie (RS Scope
sc (L SrcSpan
span RuleBndr GhcRn
bndr)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ RuleBndr GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode RuleBndr GhcRn
bndr SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case RuleBndr GhcRn
bndr of
      RuleBndr XCRuleBndr GhcRn
_ LIdP GhcRn
var ->
        [ 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 (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe RealSrcSpan
forall a. Maybe a
Nothing) Located Name
LIdP GhcRn
var
        ]
      RuleBndrSig XRuleBndrSig GhcRn
_ LIdP GhcRn
var HsPatSigType 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 (BindType -> Scope -> Maybe RealSrcSpan -> ContextInfo
ValBind BindType
RegularBind Scope
sc Maybe RealSrcSpan
forall a. Maybe a
Nothing) Located Name
LIdP GhcRn
var
        , 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
sc]) HsPatSigType GhcRn
typ
        ]

instance ToHie (Located (ImportDecl GhcRn)) where
  toHie :: GenLocated SrcSpan (ImportDecl GhcRn) -> HieM [HieAST Type]
toHie (L SrcSpan
span ImportDecl 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
$ ImportDecl GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode ImportDecl GhcRn
decl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case ImportDecl GhcRn
decl of
      ImportDecl { ideclName :: forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName = XRec GhcRn ModuleName
name, ideclAs :: forall pass. ImportDecl pass -> Maybe (XRec pass ModuleName)
ideclAs = Maybe (XRec GhcRn ModuleName)
as, ideclHiding :: forall pass. ImportDecl pass -> Maybe (Bool, XRec pass [LIE pass])
ideclHiding = Maybe (Bool, XRec GhcRn [LIE GhcRn])
hidden } ->
        [ IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (Located ModuleName) -> HieM [HieAST Type])
-> IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> Located ModuleName -> IEContext (Located ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
Import Located ModuleName
XRec GhcRn ModuleName
name
        , Maybe (IEContext (Located ModuleName)) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Maybe (IEContext (Located ModuleName)) -> HieM [HieAST Type])
-> Maybe (IEContext (Located ModuleName)) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located ModuleName -> IEContext (Located ModuleName))
-> Maybe (Located ModuleName)
-> Maybe (IEContext (Located ModuleName))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IEType -> Located ModuleName -> IEContext (Located ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
ImportAs) Maybe (Located ModuleName)
Maybe (XRec GhcRn ModuleName)
as
        , HieM [HieAST Type]
-> ((Bool, GenLocated SrcSpan [Located (IE GhcRn)])
    -> HieM [HieAST Type])
-> Maybe (Bool, GenLocated SrcSpan [Located (IE GhcRn)])
-> 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 []) (Bool, GenLocated SrcSpan [Located (IE GhcRn)])
-> HieM [HieAST Type]
forall a.
ToHie (IEContext a) =>
(Bool, GenLocated SrcSpan [a]) -> HieM [HieAST Type]
goIE Maybe (Bool, GenLocated SrcSpan [Located (IE GhcRn)])
Maybe (Bool, XRec GhcRn [LIE GhcRn])
hidden
        ]
    where
      goIE :: (Bool, GenLocated SrcSpan [a]) -> HieM [HieAST Type]
goIE (Bool
hiding, (L SrcSpan
sp [a]
liens)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$
        [ SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a.
Monad m =>
SrcSpan -> ReaderT NodeOrigin m [HieAST a]
locOnly SrcSpan
sp
        , [IEContext a] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext a] -> HieM [HieAST Type])
-> [IEContext a] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (a -> IEContext a) -> [a] -> [IEContext a]
forall a b. (a -> b) -> [a] -> [b]
map (IEType -> a -> IEContext a
forall a. IEType -> a -> IEContext a
IEC IEType
c) [a]
liens
        ]
        where
         c :: IEType
c = if Bool
hiding then IEType
ImportHiding else IEType
Import

instance ToHie (IEContext (Located (IE GhcRn))) where
  toHie :: IEContext (Located (IE GhcRn)) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span IE GhcRn
ie)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IE GhcRn -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode IE GhcRn
ie SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IE GhcRn
ie of
      IEVar XIEVar GhcRn
_ LIEWrappedName (IdP GhcRn)
n ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName Name
LIEWrappedName (IdP GhcRn)
n
        ]
      IEThingAbs XIEThingAbs GhcRn
_ LIEWrappedName (IdP GhcRn)
n ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName Name
LIEWrappedName (IdP GhcRn)
n
        ]
      IEThingAll XIEThingAll GhcRn
_ LIEWrappedName (IdP GhcRn)
n ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName Name
LIEWrappedName (IdP GhcRn)
n
        ]
      IEThingWith XIEThingWith GhcRn
_ LIEWrappedName (IdP GhcRn)
n IEWildcard
_ [LIEWrappedName (IdP GhcRn)]
ns [XRec GhcRn (FieldLbl (IdP GhcRn))]
flds ->
        [ IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (LIEWrappedName Name) -> HieM [HieAST Type])
-> IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c LIEWrappedName Name
LIEWrappedName (IdP GhcRn)
n
        , [IEContext (LIEWrappedName Name)] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext (LIEWrappedName Name)] -> HieM [HieAST Type])
-> [IEContext (LIEWrappedName Name)] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (LIEWrappedName Name -> IEContext (LIEWrappedName Name))
-> [LIEWrappedName Name] -> [IEContext (LIEWrappedName Name)]
forall a b. (a -> b) -> [a] -> [b]
map (IEType -> LIEWrappedName Name -> IEContext (LIEWrappedName Name)
forall a. IEType -> a -> IEContext a
IEC IEType
c) [LIEWrappedName Name]
[LIEWrappedName (IdP GhcRn)]
ns
        , [IEContext (Located (FieldLbl Name))] -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie ([IEContext (Located (FieldLbl Name))] -> HieM [HieAST Type])
-> [IEContext (Located (FieldLbl Name))] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ (Located (FieldLbl Name) -> IEContext (Located (FieldLbl Name)))
-> [Located (FieldLbl Name)]
-> [IEContext (Located (FieldLbl Name))]
forall a b. (a -> b) -> [a] -> [b]
map (IEType
-> Located (FieldLbl Name) -> IEContext (Located (FieldLbl Name))
forall a. IEType -> a -> IEContext a
IEC IEType
c) [Located (FieldLbl Name)]
[XRec GhcRn (FieldLbl (IdP GhcRn))]
flds
        ]
      IEModuleContents XIEModuleContents GhcRn
_ XRec GhcRn ModuleName
n ->
        [ IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (IEContext (Located ModuleName) -> HieM [HieAST Type])
-> IEContext (Located ModuleName) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEType -> Located ModuleName -> IEContext (Located ModuleName)
forall a. IEType -> a -> IEContext a
IEC IEType
c Located ModuleName
XRec GhcRn ModuleName
n
        ]
      IEGroup XIEGroup GhcRn
_ TypeIndex
_ HsDocString
_ -> []
      IEDoc XIEDoc GhcRn
_ HsDocString
_ -> []
      IEDocNamed XIEDocNamed GhcRn
_ FilePath
_ -> []

instance ToHie (IEContext (LIEWrappedName Name)) where
  toHie :: IEContext (LIEWrappedName Name) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span IEWrappedName Name
iewn)) = [HieM [HieAST Type]] -> HieM [HieAST Type]
forall (m :: * -> *) a. Monad m => [m [a]] -> m [a]
concatM ([HieM [HieAST Type]] -> HieM [HieAST Type])
-> [HieM [HieAST Type]] -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ IEWrappedName Name -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode IEWrappedName Name
iewn SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case IEWrappedName Name
iewn of
      IEName Located Name
n ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) Located Name
n
        ]
      IEPattern Located Name
p ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) Located Name
p
        ]
      IEType Located Name
n ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) Located Name
n
        ]

instance ToHie (IEContext (Located (FieldLbl Name))) where
  toHie :: IEContext (Located (FieldLbl Name)) -> HieM [HieAST Type]
toHie (IEC IEType
c (L SrcSpan
span FieldLbl Name
lbl)) = [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
$ FieldLbl Name -> SrcSpan -> HieM [HieAST Type]
forall (m :: * -> *) a b.
(Monad m, Data a) =>
a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
makeNode FieldLbl Name
lbl SrcSpan
span HieM [HieAST Type] -> [HieM [HieAST Type]] -> [HieM [HieAST Type]]
forall a. a -> [a] -> [a]
: case FieldLbl Name
lbl of
      FieldLabel FastString
_ Bool
_ Name
n ->
        [ Context (Located Name) -> HieM [HieAST Type]
forall a. ToHie a => a -> HieM [HieAST Type]
toHie (Context (Located Name) -> HieM [HieAST Type])
-> Context (Located Name) -> HieM [HieAST Type]
forall a b. (a -> b) -> a -> b
$ ContextInfo -> Located Name -> Context (Located Name)
forall a. ContextInfo -> a -> Context a
C (IEType -> ContextInfo
IEThing IEType
c) (Located Name -> Context (Located Name))
-> Located Name -> Context (Located Name)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
span Name
n
        ]