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

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

{-
Main functions for .hie file generation
-}

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

import GHC.Utils.Outputable(ppr)

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

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

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

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

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

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

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

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

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

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

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

`Context` is a data type that looks like:

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

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

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

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

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

   toHie $ C Use located_name

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

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

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

For a function definition `foo`:

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

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

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

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

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

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

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

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

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

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

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

-}

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


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

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

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

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

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

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

  pure $ (M.fromList nis, asts)

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 = extendNameEnv (name_remapping hs) (varName mono) poly}

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

type HieM = ReaderT NodeOrigin (State HieState)

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

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

getCompressedAsts :: TypecheckedSource -> RenamedSource -> Bag EvBind -> [ClsInst] -> [TyCon]
  -> (HieASTs TypeIndex, A.Array TypeIndex HieTypeFlat)
getCompressedAsts :: LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
getCompressedAsts LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs =
  let asts :: HieASTs Type
asts = LHsBinds GhcTc
-> RenamedSource
-> Bag EvBind
-> [ClsInst]
-> [TyCon]
-> HieASTs Type
enrichHie LHsBinds GhcTc
ts RenamedSource
rs Bag EvBind
top_ev_binds [ClsInst]
insts [TyCon]
tcs in
  HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
compressTypes HieASTs Type
asts

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

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

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

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

          (uloc_evs,more_ev_asts) <- getUnlocatedEvBinds file

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

data SigInfo = SI SigType (Maybe Span)

data SigType = BindSig | ClassSig | InstSig

data EvBindContext a = EvBindContext Scope (Maybe Span) a

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

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

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

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

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

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

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

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

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

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

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

This case in handled in the instance for HsPatSigType
-}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

See #16233

-}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

instance ( ToHie (RFContext label)
         , ToHie arg, HasLoc arg, Data arg
         , Data label
         ) => ToHie (RContext (LocatedA (HsFieldBind label arg))) where
  toHie :: RContext (LocatedA (HsFieldBind label arg)) -> HieM [HieAST Type]
toHie (RC RecFieldContext
c (L SrcSpanAnnA
span HsFieldBind label arg