{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}

-- | This module is used to perform a dependency analysis of top-level
-- function definitions, i.e. to find out which defintions are
-- (mutual) recursive. To this end, this module also provides
-- functions to compute, bound variables and variable occurrences.

module Rattus.Plugin.Dependency (dependency, HasBV (..),printBinds) where

#if __GLASGOW_HASKELL__ >= 900
import GHC.Plugins
import GHC.Data.Bag
import GHC.Hs.Type
#else
import GhcPlugins
import Bag
#if __GLASGOW_HASKELL__ >= 810
import GHC.Hs.Types
#else
import HsTypes
#endif
#endif

#if __GLASGOW_HASKELL__ >= 810
import GHC.Hs.Extension
import GHC.Hs.Expr
import GHC.Hs.Pat
import GHC.Hs.Binds
#else 
import HsExtension
import HsExpr
import HsPat
import HsBinds
#endif

#if __GLASGOW_HASKELL__ >= 904
import GHC.Parser.Annotation
#elif __GLASGOW_HASKELL__ >= 902
import Language.Haskell.Syntax.Extension
import GHC.Parser.Annotation
#endif


import Data.Set (Set)
import qualified Data.Set as Set
import Data.Graph
import Data.Maybe
import Data.Either
import Prelude hiding ((<>))



-- | Compute the dependencies of a bag of bindings, returning a list
-- of the strongly-connected components.
dependency :: Bag (LHsBindLR GhcTc GhcTc) -> [SCC (LHsBindLR GhcTc GhcTc, Set Var)]
dependency :: Bag (LHsBindLR GhcTc GhcTc)
-> [SCC (LHsBindLR GhcTc GhcTc, Set Var)]
dependency Bag (LHsBindLR GhcTc GhcTc)
binds = forall a b. (a -> b) -> [a] -> [b]
map forall vertex. vertex -> SCC vertex
AcyclicSCC [(GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc), Set Var)]
noDeps forall a. [a] -> [a] -> [a]
++ forall a. [Maybe a] -> [a]
catMaybes (forall a b. (a -> b) -> [a] -> [b]
map forall {vertex}. SCC (Maybe vertex) -> Maybe (SCC vertex)
filterJust (forall key node. Ord key => [(node, key, [key])] -> [SCC node]
stronglyConnComp (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[(Maybe (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc), Set Var),
   Name, [Name])]]
deps)))
  where ([[(Maybe (GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc), Set Var),
   Name, [Name])]]
deps,[(GenLocated SrcSpanAnnA (HsBindLR GhcTc GhcTc), Set Var)]
noDeps) = forall a b. [Either a b] -> ([a], [b])
partitionEithers forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall l.
GenLocated l (HsBindLR GhcTc GhcTc)
-> Either
     [(Maybe (GenLocated l (HsBindLR GhcTc GhcTc), Set Var), Name,
       [Name])]
     (GenLocated l (HsBindLR GhcTc GhcTc), Set Var)
mkDep forall a b. (a -> b) -> a -> b
$ forall a. Bag a -> [a]
bagToList Bag (LHsBindLR GhcTc GhcTc)
binds
        mkDep :: GenLocated l (HsBindLR GhcTc GhcTc) ->
                 Either [(Maybe (GenLocated l (HsBindLR GhcTc GhcTc), Set Var), Name, [Name])]
                 (GenLocated l (HsBindLR GhcTc GhcTc), Set Var)
        mkDep :: forall l.
GenLocated l (HsBindLR GhcTc GhcTc)
-> Either
     [(Maybe (GenLocated l (HsBindLR GhcTc GhcTc), Set Var), Name,
       [Name])]
     (GenLocated l (HsBindLR GhcTc GhcTc), Set Var)
mkDep GenLocated l (HsBindLR GhcTc GhcTc)
b =
          let dep :: [Name]
dep = forall a b. (a -> b) -> [a] -> [b]
map Var -> Name
varName forall a b. (a -> b) -> a -> b
$ forall a. Set a -> [a]
Set.toList (forall a. HasFV a => a -> Set Var
getFV GenLocated l (HsBindLR GhcTc GhcTc)
b)
              vars :: Set Var
vars = forall a. HasBV a => a -> Set Var
getBV GenLocated l (HsBindLR GhcTc GhcTc)
b in
          case forall a. Set a -> [a]
Set.toList Set Var
vars of
            (Var
v:[Var]
vs) -> forall a b. a -> Either a b
Left ((forall a. a -> Maybe a
Just (GenLocated l (HsBindLR GhcTc GhcTc)
b,Set Var
vars), Var -> Name
varName Var
v , [Name]
dep) forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map (\ Var
v' -> (forall a. Maybe a
Nothing, Var -> Name
varName Var
v' , [Name]
dep)) [Var]
vs)
            [] -> forall a b. b -> Either a b
Right (GenLocated l (HsBindLR GhcTc GhcTc)
b,Set Var
vars)
        filterJust :: SCC (Maybe vertex) -> Maybe (SCC vertex)
filterJust (AcyclicSCC Maybe vertex
Nothing) = forall a. Maybe a
Nothing -- this should not happen
        filterJust (AcyclicSCC (Just vertex
b)) = forall a. a -> Maybe a
Just (forall vertex. vertex -> SCC vertex
AcyclicSCC vertex
b)
        filterJust (CyclicSCC [Maybe vertex]
bs) = forall a. a -> Maybe a
Just (forall vertex. [vertex] -> SCC vertex
CyclicSCC (forall a. [Maybe a] -> [a]
catMaybes [Maybe vertex]
bs))


printBinds :: SCC (GenLocated l (HsBindLR p idR), b) -> m ()
printBinds (AcyclicSCC (GenLocated l (HsBindLR p idR), b)
bind) = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> IO ()
putStr String
"acyclic bind: ") forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {p} {l} {m :: * -> *} {l} {idR}.
(XRec p (IdP p) ~ GenLocated l (IdP p), MonadIO m,
 NamedThing (IdP p)) =>
GenLocated l (HsBindLR p idR) -> m ()
printBind (forall a b. (a, b) -> a
fst (GenLocated l (HsBindLR p idR), b)
bind) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> IO ()
putStrLn String
"") 
printBinds (CyclicSCC [(GenLocated l (HsBindLR p idR), b)]
binds) = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> IO ()
putStr String
"cyclic binds: ") forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall {p} {l} {m :: * -> *} {l} {idR}.
(XRec p (IdP p) ~ GenLocated l (IdP p), MonadIO m,
 NamedThing (IdP p)) =>
GenLocated l (HsBindLR p idR) -> m ()
printBind forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(GenLocated l (HsBindLR p idR), b)]
binds forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> IO ()
putStrLn String
"") 


printBind :: GenLocated l (HsBindLR p idR) -> m ()
printBind (L l
_ FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = L l
_ IdP p
name}) = 
  forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> IO ()
putStr forall a b. (a -> b) -> a -> b
$ (forall a. NamedThing a => a -> String
getOccString IdP p
name forall a. [a] -> [a] -> [a]
++ String
" ")
printBind (L l
_ (VarBind {var_id :: forall idL idR. HsBindLR idL idR -> IdP idL
var_id = IdP p
name})) =   forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> IO ()
putStr forall a b. (a -> b) -> a -> b
$ (forall a. NamedThing a => a -> String
getOccString IdP p
name forall a. [a] -> [a] -> [a]
++ String
" ")
#if __GLASGOW_HASKELL__ < 904
printBind (L l
_ (AbsBinds {abs_exports :: forall idL idR. HsBindLR idL idR -> [ABExport idL]
abs_exports = [ABExport p]
exp})) = 
#else
printBind (L _ (XHsBindsLR (AbsBinds {abs_exports = exp}))) = 
#endif
  forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ ABExport p
e -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> IO ()
putStr forall a b. (a -> b) -> a -> b
$ ((forall a. NamedThing a => a -> String
getOccString forall a b. (a -> b) -> a -> b
$ forall p. ABExport p -> IdP p
abe_poly ABExport p
e)  forall a. [a] -> [a] -> [a]
++ String
" ")) [ABExport p]
exp
printBind GenLocated l (HsBindLR p idR)
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- | Computes the variables that are bound by a given piece of syntax.

class HasBV a where
  getBV :: a -> Set Var

instance HasBV (HsBindLR GhcTc GhcTc) where
  getBV :: HsBindLR GhcTc GhcTc -> Set Var
getBV (FunBind{fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = L SrcSpanAnnN
_ Var
v}) = forall a. a -> Set a
Set.singleton Var
v
  getBV (PatBind {pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat GhcTc
pat}) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
pat
  getBV (VarBind {var_id :: forall idL idR. HsBindLR idL idR -> IdP idL
var_id = IdP GhcTc
v}) = forall a. a -> Set a
Set.singleton IdP GhcTc
v
  getBV PatSynBind{} = forall a. Set a
Set.empty
#if __GLASGOW_HASKELL__ < 900
  getBV (XHsBindsLR e) = getBV e
  getBV (AbsBinds {abs_exports = es}) = Set.fromList (map abe_poly es)
#elif __GLASGOW_HASKELL__ < 904
  getBV (AbsBinds {abs_exports :: forall idL idR. HsBindLR idL idR -> [ABExport idL]
abs_exports = [ABExport GhcTc]
es}) = forall a. Ord a => [a] -> Set a
Set.fromList (forall a b. (a -> b) -> [a] -> [b]
map forall p. ABExport p -> IdP p
abe_poly [ABExport GhcTc]
es)
#else
  getBV (XHsBindsLR (AbsBinds {abs_exports = es})) = Set.fromList (map abe_poly es)
#endif
  
instance HasBV a => HasBV (GenLocated b a) where
  getBV :: GenLocated b a -> Set Var
getBV (L b
_ a
e) = forall a. HasBV a => a -> Set Var
getBV a
e

instance HasBV a => HasBV [a] where
  getBV :: [a] -> Set Var
getBV [a]
ps = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\Set Var
s a
p -> forall a. HasBV a => a -> Set Var
getBV a
p forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set Var
s) forall a. Set a
Set.empty [a]
ps

#if __GLASGOW_HASKELL__ >= 904
getRecFieldRhs = hfbRHS
#else
getRecFieldRhs :: HsRecField' id arg -> arg
getRecFieldRhs = forall id arg. HsRecField' id arg -> arg
hsRecFieldArg
#endif

#if __GLASGOW_HASKELL__ >= 902
getConBV :: HsConDetails tyarg a (HsRecFields p arg) -> Set Var
getConBV (PrefixCon [tyarg]
_ [a]
ps) = forall a. HasBV a => a -> Set Var
getBV [a]
ps
#else
getConBV (PrefixCon ps) = getBV ps
#endif
getConBV (InfixCon a
p a
p') = forall a. HasBV a => a -> Set Var
getBV a
p forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasBV a => a -> Set Var
getBV a
p'
getConBV (RecCon (HsRecFields {rec_flds :: forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds = [XRec p (HsRecField p arg)]
fs})) = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl forall {a} {l} {id}.
HasBV a =>
Set Var -> GenLocated l (HsRecField' id a) -> Set Var
run forall a. Set a
Set.empty [XRec p (HsRecField p arg)]
fs
      where run :: Set Var -> GenLocated l (HsRecField' id a) -> Set Var
run Set Var
s (L l
_ HsRecField' id a
f) = forall a. HasBV a => a -> Set Var
getBV (forall id arg. HsRecField' id arg -> arg
getRecFieldRhs HsRecField' id a
f) forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set Var
s

#if __GLASGOW_HASKELL__ >= 900 && __GLASGOW_HASKELL__ < 904
instance HasBV CoPat where
  getBV :: CoPat -> Set Var
getBV CoPat {co_pat_inner :: CoPat -> Pat GhcTc
co_pat_inner = Pat GhcTc
p} = forall a. HasBV a => a -> Set Var
getBV Pat GhcTc
p
#elif __GLASGOW_HASKELL__ >= 904
instance HasBV XXPatGhcTc where
  getBV CoPat {co_pat_inner = p} = getBV p
  getBV (ExpansionPat _ p) = getBV p
#endif

instance HasBV (Pat GhcTc) where
  getBV :: Pat GhcTc -> Set Var
getBV (VarPat XVarPat GhcTc
_ (L SrcSpanAnnN
_ Var
v)) = forall a. a -> Set a
Set.singleton Var
v
  getBV (LazyPat XLazyPat GhcTc
_ LPat GhcTc
p) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p
#if __GLASGOW_HASKELL__ >= 906
  getBV (AsPat _ (L _ v) _ p) = Set.insert v (getBV p)
#else
  getBV (AsPat XAsPat GhcTc
_ (L SrcSpanAnnN
_ Var
v) LPat GhcTc
p) = forall a. Ord a => a -> Set a -> Set a
Set.insert Var
v (forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p)
#endif
  getBV (BangPat XBangPat GhcTc
_ LPat GhcTc
p) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p
  getBV (ListPat XListPat GhcTc
_ [LPat GhcTc]
ps) = forall a. HasBV a => a -> Set Var
getBV [LPat GhcTc]
ps
  getBV (TuplePat XTuplePat GhcTc
_ [LPat GhcTc]
ps Boxity
_) = forall a. HasBV a => a -> Set Var
getBV [LPat GhcTc]
ps
  getBV (SumPat XSumPat GhcTc
_ LPat GhcTc
p ConTag
_ ConTag
_) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p
  getBV (ViewPat XViewPat GhcTc
_ LHsExpr GhcTc
_ LPat GhcTc
p) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p

  getBV (SplicePat XSplicePat GhcTc
_ HsSplice GhcTc
sp) =
    case HsSplice GhcTc
sp of
#if __GLASGOW_HASKELL__ < 906
      HsTypedSplice XTypedSplice GhcTc
_ SpliceDecoration
_ IdP GhcTc
v LHsExpr GhcTc
_ -> forall a. a -> Set a
Set.singleton IdP GhcTc
v
      HsSpliced XSpliced GhcTc
_ ThModFinalizers
_ (HsSplicedPat Pat GhcTc
p) -> forall a. HasBV a => a -> Set Var
getBV Pat GhcTc
p
      HsUntypedSplice XUntypedSplice GhcTc
_ SpliceDecoration
_ IdP GhcTc
v LHsExpr GhcTc
_ ->  forall a. a -> Set a
Set.singleton IdP GhcTc
v
      HsQuasiQuote XQuasiQuote GhcTc
_ IdP GhcTc
p IdP GhcTc
p' SrcSpan
_ FastString
_ -> forall a. Ord a => [a] -> Set a
Set.fromList [IdP GhcTc
p,IdP GhcTc
p']
      HsSplice GhcTc
_ -> forall a. Set a
Set.empty
#else
      HsUntypedSpliceExpr _ e -> getFV e
      HsQuasiQuote _ v _  -> Set.singleton v
#endif

  getBV (NPlusKPat XNPlusKPat GhcTc
_ (L SrcSpanAnnN
_ Var
v) XRec GhcTc (HsOverLit GhcTc)
_ HsOverLit GhcTc
_ SyntaxExpr GhcTc
_ SyntaxExpr GhcTc
_) = forall a. a -> Set a
Set.singleton Var
v
  getBV (NPat {}) = forall a. Set a
Set.empty
  getBV (XPat XXPat GhcTc
p) = forall a. HasBV a => a -> Set Var
getBV XXPat GhcTc
p
  getBV (WildPat {}) = forall a. Set a
Set.empty
  getBV (LitPat {}) = forall a. Set a
Set.empty
#if __GLASGOW_HASKELL__ >= 904  
  getBV (ParPat _ _ p _) = getBV p
#else
  getBV (ParPat XParPat GhcTc
_ LPat GhcTc
p) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p
#endif
#if __GLASGOW_HASKELL__ >= 900
  getBV (ConPat {pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = HsConPatDetails GhcTc
con}) = forall {p} {arg} {l} {a} {tyarg}.
(XRec p (HsRecField p arg) ~ GenLocated l (HsRecField p arg),
 HasBV a, HasBV arg) =>
HsConDetails tyarg a (HsRecFields p arg) -> Set Var
getConBV HsConPatDetails GhcTc
con
#else
  getBV (ConPatIn (L _ v) con) = Set.insert v (getConBV con)
  getBV (ConPatOut {pat_args = con}) = getConBV con
  getBV (CoPat _ _ p _) = getBV p
#endif
#if __GLASGOW_HASKELL__ >= 808
  getBV (SigPat XSigPat GhcTc
_ LPat GhcTc
p HsPatSigType (NoGhcTc GhcTc)
_) = forall a. HasBV a => a -> Set Var
getBV LPat GhcTc
p
#else
  getBV (SigPat _ p)   = getBV p
#endif

#if __GLASGOW_HASKELL__ >= 904

#elif __GLASGOW_HASKELL__ >= 810
instance HasBV NoExtCon where
#else
instance HasBV NoExt where
#endif
#if __GLASGOW_HASKELL__ < 904
  getBV :: NoExtCon -> Set Var
getBV NoExtCon
_ = forall a. Set a
Set.empty
#endif

-- | Syntax that may contain variables.
class HasFV a where
  -- | Compute the set of variables occurring in the given piece of
  -- syntax.  The name falsely suggests that returns free variables,
  -- but in fact it returns all variable occurrences, no matter
  -- whether they are free or bound.
  getFV :: a -> Set Var 

instance HasFV a => HasFV (GenLocated b a) where
  getFV :: GenLocated b a -> Set Var
getFV (L b
_ a
e) = forall a. HasFV a => a -> Set Var
getFV a
e
  
instance HasFV a => HasFV [a] where
  getFV :: [a] -> Set Var
getFV [a]
es = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. HasFV a => a -> Set Var
getFV [a]
es

instance HasFV a => HasFV (Bag a) where
  getFV :: Bag a -> Set Var
getFV Bag a
es = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. HasFV a => a -> Set Var
getFV Bag a
es

instance HasFV Var where
  getFV :: Var -> Set Var
getFV Var
v = forall a. a -> Set a
Set.singleton Var
v

instance HasFV a => HasFV (MatchGroup GhcTc a) where
  getFV :: MatchGroup GhcTc a -> Set Var
getFV MG {mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = XRec GhcTc [LMatch GhcTc a]
alts} = forall a. HasFV a => a -> Set Var
getFV XRec GhcTc [LMatch GhcTc a]
alts
#if __GLASGOW_HASKELL__ < 900
  getFV (XMatchGroup e) = getFV e
#endif
  
instance HasFV a => HasFV (Match GhcTc a) where
  getFV :: Match GhcTc a -> Set Var
getFV Match {m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs GhcTc a
rhss} = forall a. HasFV a => a -> Set Var
getFV GRHSs GhcTc a
rhss
#if __GLASGOW_HASKELL__ < 900
  getFV (XMatch e) = getFV e
#endif

instance HasFV (HsTupArg GhcTc) where
  getFV :: HsTupArg GhcTc -> Set Var
getFV (Present XPresent GhcTc
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV Missing {} = forall a. Set a
Set.empty
#if __GLASGOW_HASKELL__ < 900
  getFV (XTupArg e) = getFV e
#endif

instance HasFV a => HasFV (GRHS GhcTc a) where
  getFV :: GRHS GhcTc a -> Set Var
getFV (GRHS XCGRHS GhcTc a
_ [GuardLStmt GhcTc]
g a
b) = forall a. HasFV a => a -> Set Var
getFV [GuardLStmt GhcTc]
g forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV a
b
#if __GLASGOW_HASKELL__ < 900
  getFV (XGRHS e) = getFV e
#endif

instance HasFV a => HasFV (GRHSs GhcTc a) where
  getFV :: GRHSs GhcTc a -> Set Var
getFV GRHSs {grhssGRHSs :: forall p body. GRHSs p body -> [LGRHS p body]
grhssGRHSs = [LGRHS GhcTc a]
rhs, grhssLocalBinds :: forall p body. GRHSs p body -> HsLocalBinds p
grhssLocalBinds = HsLocalBinds GhcTc
lbs} =
    forall a. HasFV a => a -> Set Var
getFV [LGRHS GhcTc a]
rhs forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV HsLocalBinds GhcTc
lbs
#if __GLASGOW_HASKELL__ < 900
  getFV (XGRHSs e) = getFV e
#endif


instance HasFV (HsLocalBindsLR GhcTc GhcTc) where
  getFV :: HsLocalBinds GhcTc -> Set Var
getFV (HsValBinds XHsValBinds GhcTc GhcTc
_ HsValBindsLR GhcTc GhcTc
bs) = forall a. HasFV a => a -> Set Var
getFV HsValBindsLR GhcTc GhcTc
bs
  getFV (HsIPBinds XHsIPBinds GhcTc GhcTc
_ HsIPBinds GhcTc
bs) = forall a. HasFV a => a -> Set Var
getFV HsIPBinds GhcTc
bs
  getFV EmptyLocalBinds {} = forall a. Set a
Set.empty
#if __GLASGOW_HASKELL__ < 900
  getFV (XHsLocalBindsLR e) = getFV e
#endif
  
instance HasFV (HsValBindsLR GhcTc GhcTc) where
  getFV :: HsValBindsLR GhcTc GhcTc -> Set Var
getFV (ValBinds XValBinds GhcTc GhcTc
_ Bag (LHsBindLR GhcTc GhcTc)
b [LSig GhcTc]
_) = forall a. HasFV a => a -> Set Var
getFV Bag (LHsBindLR GhcTc GhcTc)
b
  getFV (XValBindsLR XXValBindsLR GhcTc GhcTc
b) = forall a. HasFV a => a -> Set Var
getFV XXValBindsLR GhcTc GhcTc
b

instance HasFV (NHsValBindsLR GhcTc) where
  getFV :: NHsValBindsLR GhcTc -> Set Var
getFV (NValBinds [(RecFlag, Bag (LHsBindLR GhcTc GhcTc))]
bs [LSig GhcRn]
_) = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. HasFV a => a -> Set Var
getFV forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(RecFlag, Bag (LHsBindLR GhcTc GhcTc))]
bs

instance HasFV (HsBindLR GhcTc GhcTc) where
  getFV :: HsBindLR GhcTc GhcTc -> Set Var
getFV FunBind {fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup GhcTc (LHsExpr GhcTc)
ms} = forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsExpr GhcTc)
ms
  getFV PatBind {pat_rhs :: forall idL idR. HsBindLR idL idR -> GRHSs idR (LHsExpr idR)
pat_rhs = GRHSs GhcTc (LHsExpr GhcTc)
rhs} = forall a. HasFV a => a -> Set Var
getFV GRHSs GhcTc (LHsExpr GhcTc)
rhs
  getFV VarBind {var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr GhcTc
rhs} = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
rhs
  getFV PatSynBind {} = forall a. Set a
Set.empty
#if __GLASGOW_HASKELL__ < 904
  getFV AbsBinds {abs_binds :: forall idL idR. HsBindLR idL idR -> LHsBinds idL
abs_binds = Bag (LHsBindLR GhcTc GhcTc)
bs} = forall a. HasFV a => a -> Set Var
getFV Bag (LHsBindLR GhcTc GhcTc)
bs
#else
  getFV (XHsBindsLR AbsBinds {abs_binds = bs}) = getFV bs
#endif
#if __GLASGOW_HASKELL__ < 900
  getFV (XHsBindsLR e) = getFV e
#endif

instance HasFV (IPBind GhcTc) where
  getFV :: IPBind GhcTc -> Set Var
getFV (IPBind XCIPBind GhcTc
_ Either (XRec GhcTc HsIPName) (IdP GhcTc)
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
#if __GLASGOW_HASKELL__ < 900
  getFV (XIPBind e) = getFV e
#endif

instance HasFV (HsIPBinds GhcTc) where
  getFV :: HsIPBinds GhcTc -> Set Var
getFV (IPBinds XIPBinds GhcTc
_ [LIPBind GhcTc]
bs) = forall a. HasFV a => a -> Set Var
getFV [LIPBind GhcTc]
bs
#if __GLASGOW_HASKELL__ < 900
  getFV (XHsIPBinds e) = getFV e
#endif
  
instance HasFV (ApplicativeArg GhcTc) where
#if __GLASGOW_HASKELL__ >= 810
  getFV :: ApplicativeArg GhcTc -> Set Var
getFV ApplicativeArgOne { arg_expr :: forall idL. ApplicativeArg idL -> LHsExpr idL
arg_expr = LHsExpr GhcTc
e }     = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV ApplicativeArgMany {app_stmts :: forall idL. ApplicativeArg idL -> [ExprLStmt idL]
app_stmts = [GuardLStmt GhcTc]
es, final_expr :: forall idL. ApplicativeArg idL -> HsExpr idL
final_expr = HsExpr GhcTc
e} = forall a. HasFV a => a -> Set Var
getFV [GuardLStmt GhcTc]
es forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV HsExpr GhcTc
e
#else
  getFV (ApplicativeArgOne _ _ e _) = getFV e
  getFV (ApplicativeArgMany _ es e _) = getFV es `Set.union` getFV e
#endif
#if __GLASGOW_HASKELL__ < 900
  getFV (XApplicativeArg e) = getFV e
#endif

instance HasFV (ParStmtBlock GhcTc GhcTc) where
  getFV :: ParStmtBlock GhcTc GhcTc -> Set Var
getFV (ParStmtBlock XParStmtBlock GhcTc GhcTc
_ [GuardLStmt GhcTc]
es [IdP GhcTc]
_ SyntaxExpr GhcTc
_) = forall a. HasFV a => a -> Set Var
getFV [GuardLStmt GhcTc]
es
#if __GLASGOW_HASKELL__ < 900
  getFV (XParStmtBlock e) = getFV e
#endif
  
instance HasFV a => HasFV (StmtLR GhcTc GhcTc a) where
  getFV :: StmtLR GhcTc GhcTc a -> Set Var
getFV (LastStmt XLastStmt GhcTc GhcTc a
_ a
e Maybe Bool
_ SyntaxExpr GhcTc
_) = forall a. HasFV a => a -> Set Var
getFV a
e
#if __GLASGOW_HASKELL__ >= 900
  getFV (BindStmt XBindStmt GhcTc GhcTc a
_ LPat GhcTc
_ a
e) = forall a. HasFV a => a -> Set Var
getFV a
e
#else
  getFV (BindStmt _ _ e _ _) = getFV e
#endif
  getFV (ApplicativeStmt XApplicativeStmt GhcTc GhcTc a
_ [(SyntaxExpr GhcTc, ApplicativeArg GhcTc)]
args Maybe (SyntaxExpr GhcTc)
_) = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. HasFV a => a -> Set Var
getFV forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(SyntaxExpr GhcTc, ApplicativeArg GhcTc)]
args
  getFV (BodyStmt XBodyStmt GhcTc GhcTc a
_ a
e SyntaxExpr GhcTc
_ SyntaxExpr GhcTc
_) = forall a. HasFV a => a -> Set Var
getFV a
e
  getFV (LetStmt XLetStmt GhcTc GhcTc a
_ HsLocalBinds GhcTc
bs) = forall a. HasFV a => a -> Set Var
getFV HsLocalBinds GhcTc
bs
  getFV (ParStmt XParStmt GhcTc GhcTc a
_ [ParStmtBlock GhcTc GhcTc]
stms HsExpr GhcTc
e SyntaxExpr GhcTc
_) = forall a. HasFV a => a -> Set Var
getFV [ParStmtBlock GhcTc GhcTc]
stms forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV HsExpr GhcTc
e
  getFV TransStmt{} = forall a. Set a
Set.empty -- TODO
  getFV RecStmt{} = forall a. Set a
Set.empty -- TODO
#if __GLASGOW_HASKELL__ < 900
  getFV (XStmtLR e) = getFV e
#endif

#if __GLASGOW_HASKELL__ >= 902
instance HasFV (HsRecFields GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc))) where
#else
instance HasFV (HsRecordBinds GhcTc) where
#endif
  getFV :: HsRecFields GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc))
-> Set Var
getFV HsRecFields{rec_flds :: forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds = [LHsRecField GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc))]
fs} = forall a. HasFV a => a -> Set Var
getFV [LHsRecField GhcTc (GenLocated SrcSpanAnnA (HsExpr GhcTc))]
fs

#if __GLASGOW_HASKELL__ >= 904
instance HasFV (HsFieldBind o (GenLocated SrcSpanAnnA (HsExpr GhcTc))) where
#elif __GLASGOW_HASKELL__ >= 902
instance HasFV (HsRecField' o (GenLocated SrcSpanAnnA (HsExpr GhcTc))) where
#else
instance HasFV (HsRecField' o (LHsExpr GhcTc)) where
#endif
  getFV :: HsRecField' o (GenLocated SrcSpanAnnA (HsExpr GhcTc)) -> Set Var
getFV HsRecField' o (GenLocated SrcSpanAnnA (HsExpr GhcTc))
rf  = forall a. HasFV a => a -> Set Var
getFV (forall id arg. HsRecField' id arg -> arg
getRecFieldRhs HsRecField' o (GenLocated SrcSpanAnnA (HsExpr GhcTc))
rf)

instance HasFV (ArithSeqInfo GhcTc) where
  getFV :: ArithSeqInfo GhcTc -> Set Var
getFV (From LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (FromThen LHsExpr GhcTc
e1 LHsExpr GhcTc
e2) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2
  getFV (FromTo LHsExpr GhcTc
e1 LHsExpr GhcTc
e2) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2
  getFV (FromThenTo LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 LHsExpr GhcTc
e3) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e3
  
#if __GLASGOW_HASKELL__ >= 904
instance HasFV (HsQuote GhcTc) where
#else
instance HasFV (HsBracket GhcTc) where
#endif
  getFV :: HsBracket GhcTc -> Set Var
getFV (ExpBr XExpBr GhcTc
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (VarBr XVarBr GhcTc
_ Bool
_ LIdP GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LIdP GhcTc
e
  getFV HsBracket GhcTc
_ = forall a. Set a
Set.empty

instance HasFV (HsCmd GhcTc) where
  getFV :: HsCmd GhcTc -> Set Var
getFV (HsCmdArrApp XCmdArrApp GhcTc
_ LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 HsArrAppType
_ Bool
_) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2
  getFV (HsCmdArrForm XCmdArrForm GhcTc
_ LHsExpr GhcTc
e LexicalFixity
_ Maybe Fixity
_ [LHsCmdTop GhcTc]
cmd) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV [LHsCmdTop GhcTc]
cmd
  getFV (HsCmdApp XCmdApp GhcTc
_ LHsCmd GhcTc
e1 LHsExpr GhcTc
e2) = forall a. HasFV a => a -> Set Var
getFV LHsCmd GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2
  getFV (HsCmdLam XCmdLam GhcTc
_ MatchGroup GhcTc (LHsCmd GhcTc)
l) = forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsCmd GhcTc)
l
  getFV (HsCmdCase XCmdCase GhcTc
_ LHsExpr GhcTc
_ MatchGroup GhcTc (LHsCmd GhcTc)
mg) = forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsCmd GhcTc)
mg
  getFV (HsCmdIf XCmdIf GhcTc
_ SyntaxExpr GhcTc
_ LHsExpr GhcTc
e1 LHsCmd GhcTc
e2 LHsCmd GhcTc
e3) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsCmd GhcTc
e2 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsCmd GhcTc
e3
  getFV (HsCmdDo XCmdDo GhcTc
_ XRec GhcTc [CmdLStmt GhcTc]
cmd) = forall a. HasFV a => a -> Set Var
getFV XRec GhcTc [CmdLStmt GhcTc]
cmd
#if __GLASGOW_HASKELL__ >= 904
  getFV (HsCmdPar _ _ cmd _) = getFV cmd
  getFV (HsCmdLet _ _ bs _ _) = getFV bs
#else
  getFV (HsCmdPar XCmdPar GhcTc
_ LHsCmd GhcTc
cmd) = forall a. HasFV a => a -> Set Var
getFV LHsCmd GhcTc
cmd
  getFV (HsCmdLet XCmdLet GhcTc
_ HsLocalBinds GhcTc
bs LHsCmd GhcTc
_) = forall a. HasFV a => a -> Set Var
getFV HsLocalBinds GhcTc
bs
#endif
#if __GLASGOW_HASKELL__ >= 904
  getFV (HsCmdLamCase _ _ mg) = getFV mg
#elif __GLASGOW_HASKELL__ >= 900
  getFV (HsCmdLamCase XCmdLamCase GhcTc
_ MatchGroup GhcTc (LHsCmd GhcTc)
mg) = forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsCmd GhcTc)
mg
#else
  getFV (HsCmdWrap _ _ cmd) = getFV cmd
#endif
  getFV (XCmd XXCmd GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV XXCmd GhcTc
e
  

instance HasFV (HsCmdTop GhcTc) where
  getFV :: HsCmdTop GhcTc -> Set Var
getFV (HsCmdTop XCmdTop GhcTc
_ LHsCmd GhcTc
cmd) = forall a. HasFV a => a -> Set Var
getFV LHsCmd GhcTc
cmd
#if __GLASGOW_HASKELL__ < 900
  getFV (XCmdTop e) = getFV e
#endif

instance HasFV (HsExpr GhcTc) where
  getFV :: HsExpr GhcTc -> Set Var
getFV (HsVar XVar GhcTc
_ LIdP GhcTc
v) = forall a. HasFV a => a -> Set Var
getFV LIdP GhcTc
v
  getFV HsUnboundVar {} = forall a. Set a
Set.empty
  getFV HsOverLabel {} = forall a. Set a
Set.empty
  getFV HsIPVar {} = forall a. Set a
Set.empty
  getFV HsOverLit {} = forall a. Set a
Set.empty
  getFV HsLit {} = forall a. Set a
Set.empty
  getFV (HsLam XLam GhcTc
_ MatchGroup GhcTc (LHsExpr GhcTc)
mg) = forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsExpr GhcTc)
mg
  getFV (HsApp XApp GhcTc
_ LHsExpr GhcTc
e1 LHsExpr GhcTc
e2) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2      
  getFV (OpApp XOpApp GhcTc
_ LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 LHsExpr GhcTc
e3) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e3
  getFV (NegApp XNegApp GhcTc
_ LHsExpr GhcTc
e SyntaxExpr GhcTc
_) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (SectionL XSectionL GhcTc
_ LHsExpr GhcTc
e1 LHsExpr GhcTc
e2) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2
  getFV (SectionR XSectionR GhcTc
_ LHsExpr GhcTc
e1 LHsExpr GhcTc
e2) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2
  getFV (ExplicitTuple XExplicitTuple GhcTc
_ [HsTupArg GhcTc]
es Boxity
_) = forall a. HasFV a => a -> Set Var
getFV [HsTupArg GhcTc]
es
  getFV (ExplicitSum XExplicitSum GhcTc
_ ConTag
_ ConTag
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (HsCase XCase GhcTc
_ LHsExpr GhcTc
e MatchGroup GhcTc (LHsExpr GhcTc)
mg) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e  forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsExpr GhcTc)
mg
  getFV (HsMultiIf XMultiIf GhcTc
_ [LGRHS GhcTc (LHsExpr GhcTc)]
es) = forall a. HasFV a => a -> Set Var
getFV [LGRHS GhcTc (LHsExpr GhcTc)]
es
  getFV (HsDo XDo GhcTc
_ HsStmtContext (HsDoRn GhcTc)
_ XRec GhcTc [GuardLStmt GhcTc]
e) = forall a. HasFV a => a -> Set Var
getFV XRec GhcTc [GuardLStmt GhcTc]
e
#if __GLASGOW_HASKELL__ >= 902
  getFV HsProjection {} = forall a. Set a
Set.empty
  getFV HsGetField {gf_expr :: forall p. HsExpr p -> LHsExpr p
gf_expr = LHsExpr GhcTc
e} = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (ExplicitList XExplicitList GhcTc
_ [LHsExpr GhcTc]
es) = forall a. HasFV a => a -> Set Var
getFV [LHsExpr GhcTc]
es
  getFV (RecordUpd {rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr GhcTc
e, rupd_flds :: forall p. HsExpr p -> Either [LHsRecUpdField p] [LHsRecUpdProj p]
rupd_flds = Either [LHsRecUpdField GhcTc] [LHsRecUpdProj GhcTc]
fs}) =
    forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasFV a => a -> Set Var
getFV forall a. HasFV a => a -> Set Var
getFV Either [LHsRecUpdField GhcTc] [LHsRecUpdProj GhcTc]
fs
#else
  getFV (ExplicitList _ _ es) = getFV es
  getFV (RecordUpd {rupd_expr = e, rupd_flds = fs}) = getFV e `Set.union` getFV fs
#endif
  getFV (RecordCon {rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds GhcTc
fs}) = forall a. HasFV a => a -> Set Var
getFV HsRecordBinds GhcTc
fs
  getFV (ArithSeq XArithSeq GhcTc
_ Maybe (SyntaxExpr GhcTc)
_ ArithSeqInfo GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV ArithSeqInfo GhcTc
e
#if __GLASGOW_HASKELL__ >= 906
  getFV HsTypedSplice{} = Set.empty
  getFV HsUntypedSplice{} = Set.empty
#else
  getFV HsSpliceE{} = forall a. Set a
Set.empty
#endif
  getFV (HsProc XProc GhcTc
_ LPat GhcTc
_ LHsCmdTop GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsCmdTop GhcTc
e
  getFV (HsStatic XStatic GhcTc
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (XExpr XXExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV XXExpr GhcTc
e
#if __GLASGOW_HASKELL__ >= 904
  getFV (HsPar _ _ e _) = getFV e  
  getFV (HsLamCase _ _ mg) = getFV mg
  getFV (HsLet _ _ bs _ e) = getFV bs `Set.union` getFV e
  getFV HsRecSel {} = Set.empty
  getFV (HsTypedBracket _ e) = getFV e
  getFV (HsUntypedBracket _ e) = getFV e
#else  
  getFV (HsBinTick XBinTick GhcTc
_ ConTag
_ ConTag
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (HsTick XTick GhcTc
_ CoreTickish
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (HsLet XLet GhcTc
_ HsLocalBinds GhcTc
bs LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV HsLocalBinds GhcTc
bs forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (HsPar XPar GhcTc
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (HsLamCase XLamCase GhcTc
_ MatchGroup GhcTc (LHsExpr GhcTc)
mg) = forall a. HasFV a => a -> Set Var
getFV MatchGroup GhcTc (LHsExpr GhcTc)
mg
  getFV HsConLikeOut {} = forall a. Set a
Set.empty
  getFV HsRecFld {} = forall a. Set a
Set.empty
  getFV (HsBracket XBracket GhcTc
_ HsBracket GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV HsBracket GhcTc
e
  getFV HsRnBracketOut {} = forall a. Set a
Set.empty
  getFV HsTcBracketOut {} = forall a. Set a
Set.empty
#endif

#if __GLASGOW_HASKELL__ >= 906
  getFV (HsAppType _ e _ _) = getFV e
  getFV (ExprWithTySig _ e _) = getFV e  
#elif __GLASGOW_HASKELL__ >= 808
  getFV (HsAppType XAppTypeE GhcTc
_ LHsExpr GhcTc
e LHsWcType (NoGhcTc GhcTc)
_) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
  getFV (ExprWithTySig XExprWithTySig GhcTc
_ LHsExpr GhcTc
e LHsSigWcType (NoGhcTc GhcTc)
_) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e  
#else
  getFV (ExprWithTySig _ e)   = getFV e
  getFV (HsAppType _ e)   = getFV e
#endif

#if __GLASGOW_HASKELL__ >= 900
  getFV (HsIf XIf GhcTc
_ LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 LHsExpr GhcTc
e3) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e1 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e2 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e3
  getFV (HsPragE XPragE GhcTc
_ HsPragE GhcTc
_ LHsExpr GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV LHsExpr GhcTc
e
#else
  getFV (HsIf _ _ e1 e2 e3) = getFV e1 `Set.union` getFV e2 `Set.union` getFV e3
  getFV (HsSCC _ _ _ e) = getFV e
  getFV (HsCoreAnn _ _ _ e) = getFV e
  getFV (HsTickPragma _ _ _ _ e) = getFV e
  getFV (HsWrap _ _ e) = getFV e
#endif

#if __GLASGOW_HASKELL__ < 810  
  getFV (HsArrApp _ e1 e2 _ _) = getFV e1 `Set.union` getFV e2
  getFV (HsArrForm _ e _ cmd) = getFV e `Set.union` getFV cmd
  getFV EWildPat {} = Set.empty
  getFV (EAsPat _ e1 e2) = getFV e1 `Set.union` getFV e2
  getFV (EViewPat _ e1 e2) = getFV e1 `Set.union` getFV e2
  getFV (ELazyPat _ e) = getFV e
#endif


#if __GLASGOW_HASKELL__ >= 900
instance HasFV XXExprGhcTc where
  getFV :: XXExprGhcTc -> Set Var
getFV (WrapExpr HsWrap HsExpr
e) = forall a. HasFV a => a -> Set Var
getFV HsWrap HsExpr
e
  getFV (ExpansionExpr (HsExpanded HsExpr GhcRn
_e1 HsExpr GhcTc
e2)) = forall a. HasFV a => a -> Set Var
getFV HsExpr GhcTc
e2
#if __GLASGOW_HASKELL__ >= 904  
  getFV (HsTick _ e) = getFV e
  getFV (HsBinTick _ _ e) = getFV e
  getFV ConLikeTc{} = Set.empty
#endif


instance HasFV (e GhcTc) => HasFV (HsWrap e) where
  getFV :: HsWrap e -> Set Var
getFV (HsWrap HsWrapper
_ e GhcTc
e) = forall a. HasFV a => a -> Set Var
getFV e GhcTc
e
#elif __GLASGOW_HASKELL__ >= 810
instance HasFV NoExtCon where
  getFV _ = Set.empty
#else
instance HasFV NoExt where
  getFV _ = Set.empty
#endif