{-# LANGUAGE CPP, TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ViewPatterns #-}

-----------------------------------------------------------------------------
--
-- (c) The University of Glasgow 2006
--
-- The purpose of this module is to transform an HsExpr into a CoreExpr which
-- when evaluated, returns a (Meta.Q Meta.Exp) computation analogous to the
-- input HsExpr. We do this in the DsM monad, which supplies access to
-- CoreExpr's of the "smart constructors" of the Meta.Exp datatype.
--
-- It also defines a bunch of knownKeyNames, in the same way as is done
-- in prelude/PrelNames.  It's much more convenient to do it here, because
-- otherwise we have to recompile PrelNames whenever we add a Name, which is
-- a Royal Pain (triggers other recompilation).
-----------------------------------------------------------------------------

module DsMeta( dsBracket ) where

#include "HsVersions.h"

import GhcPrelude

import {-# SOURCE #-}   DsExpr ( dsExpr )

import MatchLit
import DsMonad

import qualified Language.Haskell.TH as TH

import HsSyn
import PrelNames
-- To avoid clashes with DsMeta.varName we must make a local alias for
-- OccName.varName we do this by removing varName from the import of
-- OccName above, making a qualified instance of OccName and using
-- OccNameAlias.varName where varName ws previously used in this file.
import qualified OccName( isDataOcc, isVarOcc, isTcOcc )

import Module
import Id
import Name hiding( isVarOcc, isTcOcc, varName, tcName )
import THNames
import NameEnv
import NameSet
import TcType
import TyCon
import TysWiredIn
import CoreSyn
import MkCore
import CoreUtils
import SrcLoc
import Unique
import BasicTypes
import Outputable
import Bag
import DynFlags
import FastString
import ForeignCall
import Util
import Maybes
import MonadUtils

import Data.ByteString ( unpack )
import Control.Monad
import Data.List

-----------------------------------------------------------------------------
dsBracket :: HsBracket GhcRn -> [PendingTcSplice] -> DsM CoreExpr
-- Returns a CoreExpr of type TH.ExpQ
-- The quoted thing is parameterised over Name, even though it has
-- been type checked.  We don't want all those type decorations!

dsBracket :: HsBracket GhcRn -> [PendingTcSplice] -> DsM CoreExpr
dsBracket brack :: HsBracket GhcRn
brack splices :: [PendingTcSplice]
splices
  = DsMetaEnv -> DsM CoreExpr -> DsM CoreExpr
forall a. DsMetaEnv -> DsM a -> DsM a
dsExtendMetaEnv DsMetaEnv
new_bit (HsBracket GhcRn -> DsM CoreExpr
do_brack HsBracket GhcRn
brack)
  where
    new_bit :: DsMetaEnv
new_bit = [(Name, DsMetaVal)] -> DsMetaEnv
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name
n, HsExpr GhcTc -> DsMetaVal
DsSplice (LHsExpr GhcTc -> SrcSpanLess (LHsExpr GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsExpr GhcTc
e))
                        | PendingTcSplice n :: Name
n e :: LHsExpr GhcTc
e <- [PendingTcSplice]
splices]

    do_brack :: HsBracket GhcRn -> DsM CoreExpr
do_brack (VarBr _ _ n :: IdP GhcRn
n) = do { MkC e1 :: CoreExpr
e1  <- Name -> DsM (Core Name)
lookupOcc Name
IdP GhcRn
n ; CoreExpr -> DsM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
e1 }
    do_brack (ExpBr _ e :: LHsExpr GhcRn
e)   = do { MkC e1 :: CoreExpr
e1  <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e     ; CoreExpr -> DsM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
e1 }
    do_brack (PatBr _ p :: LPat GhcRn
p)   = do { MkC p1 :: CoreExpr
p1  <- LPat GhcRn -> DsM (Core PatQ)
repTopP LPat GhcRn
p   ; CoreExpr -> DsM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
p1 }
    do_brack (TypBr _ t :: LHsType GhcRn
t)   = do { MkC t1 :: CoreExpr
t1  <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t    ; CoreExpr -> DsM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
t1 }
    do_brack (DecBrG _ gp :: HsGroup GhcRn
gp) = do { MkC ds1 :: CoreExpr
ds1 <- HsGroup GhcRn -> DsM (Core (Q [Dec]))
repTopDs HsGroup GhcRn
gp ; CoreExpr -> DsM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
ds1 }
    do_brack (DecBrL {})   = String -> DsM CoreExpr
forall a. String -> a
panic "dsBracket: unexpected DecBrL"
    do_brack (TExpBr _ e :: LHsExpr GhcRn
e)  = do { MkC e1 :: CoreExpr
e1  <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e     ; CoreExpr -> DsM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
e1 }
    do_brack (XBracket {}) = String -> DsM CoreExpr
forall a. String -> a
panic "dsBracket: unexpected XBracket"

{- -------------- Examples --------------------

  [| \x -> x |]
====>
  gensym (unpackString "x"#) `bindQ` \ x1::String ->
  lam (pvar x1) (var x1)


  [| \x -> $(f [| x |]) |]
====>
  gensym (unpackString "x"#) `bindQ` \ x1::String ->
  lam (pvar x1) (f (var x1))
-}


-------------------------------------------------------
--                      Declarations
-------------------------------------------------------

repTopP :: LPat GhcRn -> DsM (Core TH.PatQ)
repTopP :: LPat GhcRn -> DsM (Core PatQ)
repTopP pat :: LPat GhcRn
pat = do { [GenSymBind]
ss <- [Name] -> DsM [GenSymBind]
mkGenSyms (LPat GhcRn -> [IdP GhcRn]
forall (p :: Pass). LPat (GhcPass p) -> [IdP (GhcPass p)]
collectPatBinders LPat GhcRn
pat)
                 ; Core PatQ
pat' <- [GenSymBind] -> DsM (Core PatQ) -> DsM (Core PatQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss (LPat GhcRn -> DsM (Core PatQ)
repLP LPat GhcRn
pat)
                 ; [GenSymBind] -> Core PatQ -> DsM (Core PatQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core PatQ
pat' }

repTopDs :: HsGroup GhcRn -> DsM (Core (TH.Q [TH.Dec]))
repTopDs :: HsGroup GhcRn -> DsM (Core (Q [Dec]))
repTopDs group :: HsGroup GhcRn
group@(HsGroup { hs_valds :: forall p. HsGroup p -> HsValBinds p
hs_valds   = HsValBinds GhcRn
valds
                        , hs_splcds :: forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds  = [LSpliceDecl GhcRn]
splcds
                        , hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds  = [TyClGroup GhcRn]
tyclds
                        , hs_derivds :: forall p. HsGroup p -> [LDerivDecl p]
hs_derivds = [LDerivDecl GhcRn]
derivds
                        , hs_fixds :: forall p. HsGroup p -> [LFixitySig p]
hs_fixds   = [LFixitySig GhcRn]
fixds
                        , hs_defds :: forall p. HsGroup p -> [LDefaultDecl p]
hs_defds   = [LDefaultDecl GhcRn]
defds
                        , hs_fords :: forall p. HsGroup p -> [LForeignDecl p]
hs_fords   = [LForeignDecl GhcRn]
fords
                        , hs_warnds :: forall p. HsGroup p -> [LWarnDecls p]
hs_warnds  = [LWarnDecls GhcRn]
warnds
                        , hs_annds :: forall p. HsGroup p -> [LAnnDecl p]
hs_annds   = [LAnnDecl GhcRn]
annds
                        , hs_ruleds :: forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds  = [LRuleDecls GhcRn]
ruleds
                        , hs_docs :: forall p. HsGroup p -> [LDocDecl]
hs_docs    = [LDocDecl]
docs })
 = do { let { bndrs :: [Name]
bndrs  = HsValBinds GhcRn -> [Name]
hsScopedTvBinders HsValBinds GhcRn
valds
                       [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ HsGroup GhcRn -> [Name]
hsGroupBinders HsGroup GhcRn
group
                       [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ HsValBinds GhcRn -> [IdP GhcRn]
forall (p :: Pass). HsValBinds (GhcPass p) -> [IdP (GhcPass p)]
hsPatSynSelectors HsValBinds GhcRn
valds
            ; instds :: [LInstDecl GhcRn]
instds = [TyClGroup GhcRn]
tyclds [TyClGroup GhcRn]
-> (TyClGroup GhcRn -> [LInstDecl GhcRn]) -> [LInstDecl GhcRn]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TyClGroup GhcRn -> [LInstDecl GhcRn]
forall pass. TyClGroup pass -> [LInstDecl pass]
group_instds } ;
        [GenSymBind]
ss <- [Name] -> DsM [GenSymBind]
mkGenSyms [Name]
bndrs ;

        -- Bind all the names mainly to avoid repeated use of explicit strings.
        -- Thus we get
        --      do { t :: String <- genSym "T" ;
        --           return (Data t [] ...more t's... }
        -- The other important reason is that the output must mention
        -- only "T", not "Foo:T" where Foo is the current module

        [Core DecQ]
decls <- [GenSymBind] -> DsM [Core DecQ] -> DsM [Core DecQ]
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss (
                  do { [(SrcSpan, Core DecQ)]
val_ds   <- HsValBinds GhcRn -> DsM [(SrcSpan, Core DecQ)]
rep_val_binds HsValBinds GhcRn
valds
                     ; [Any]
_        <- (LSpliceDecl GhcRn -> IOEnv (Env DsGblEnv DsLclEnv) Any)
-> [LSpliceDecl GhcRn] -> IOEnv (Env DsGblEnv DsLclEnv) [Any]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LSpliceDecl GhcRn -> IOEnv (Env DsGblEnv DsLclEnv) Any
forall a a. HasSrcSpan a => a -> DsM a
no_splice [LSpliceDecl GhcRn]
splcds
                     ; [Maybe (SrcSpan, Core DecQ)]
tycl_ds  <- (LTyClDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ)))
-> [LTyClDecl GhcRn]
-> IOEnv (Env DsGblEnv DsLclEnv) [Maybe (SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LTyClDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
repTyClD ([TyClGroup GhcRn] -> [LTyClDecl GhcRn]
forall pass. [TyClGroup pass] -> [LTyClDecl pass]
tyClGroupTyClDecls [TyClGroup GhcRn]
tyclds)
                     ; [(SrcSpan, Core DecQ)]
role_ds  <- (LRoleAnnotDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LRoleAnnotDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LRoleAnnotDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repRoleD ((TyClGroup GhcRn -> [LRoleAnnotDecl GhcRn])
-> [TyClGroup GhcRn] -> [LRoleAnnotDecl GhcRn]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TyClGroup GhcRn -> [LRoleAnnotDecl GhcRn]
forall pass. TyClGroup pass -> [LRoleAnnotDecl pass]
group_roles [TyClGroup GhcRn]
tyclds)
                     ; [(SrcSpan, Core DecQ)]
inst_ds  <- (LInstDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LInstDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LInstDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repInstD [LInstDecl GhcRn]
instds
                     ; [(SrcSpan, Core DecQ)]
deriv_ds <- (LDerivDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LDerivDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LDerivDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repStandaloneDerivD [LDerivDecl GhcRn]
derivds
                     ; [[(SrcSpan, Core DecQ)]]
fix_ds   <- (LFixitySig GhcRn -> DsM [(SrcSpan, Core DecQ)])
-> [LFixitySig GhcRn]
-> IOEnv (Env DsGblEnv DsLclEnv) [[(SrcSpan, Core DecQ)]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LFixitySig GhcRn -> DsM [(SrcSpan, Core DecQ)]
repFixD [LFixitySig GhcRn]
fixds
                     ; [Any]
_        <- (LDefaultDecl GhcRn -> IOEnv (Env DsGblEnv DsLclEnv) Any)
-> [LDefaultDecl GhcRn] -> IOEnv (Env DsGblEnv DsLclEnv) [Any]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LDefaultDecl GhcRn -> IOEnv (Env DsGblEnv DsLclEnv) Any
forall a a.
(HasSrcSpan a, Outputable (SrcSpanLess a)) =>
a -> DsM a
no_default_decl [LDefaultDecl GhcRn]
defds
                     ; [(SrcSpan, Core DecQ)]
for_ds   <- (LForeignDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LForeignDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LForeignDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repForD [LForeignDecl GhcRn]
fords
                     ; [Any]
_        <- (LWarnDecl GhcRn -> IOEnv (Env DsGblEnv DsLclEnv) Any)
-> [LWarnDecl GhcRn] -> IOEnv (Env DsGblEnv DsLclEnv) [Any]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LWarnDecl GhcRn -> IOEnv (Env DsGblEnv DsLclEnv) Any
forall a pass a.
(HasSrcSpan a, Outputable (IdP pass),
 SrcSpanLess a ~ WarnDecl pass) =>
a -> DsM a
no_warn ((LWarnDecls GhcRn -> [LWarnDecl GhcRn])
-> [LWarnDecls GhcRn] -> [LWarnDecl GhcRn]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (WarnDecls GhcRn -> [LWarnDecl GhcRn]
forall pass. WarnDecls pass -> [LWarnDecl pass]
wd_warnings (WarnDecls GhcRn -> [LWarnDecl GhcRn])
-> (LWarnDecls GhcRn -> WarnDecls GhcRn)
-> LWarnDecls GhcRn
-> [LWarnDecl GhcRn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LWarnDecls GhcRn -> WarnDecls GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc)
                                                           [LWarnDecls GhcRn]
warnds)
                     ; [(SrcSpan, Core DecQ)]
ann_ds   <- (LAnnDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LAnnDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LAnnDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repAnnD [LAnnDecl GhcRn]
annds
                     ; [(SrcSpan, Core DecQ)]
rule_ds  <- (LRuleDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LRuleDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LRuleDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repRuleD ((LRuleDecls GhcRn -> [LRuleDecl GhcRn])
-> [LRuleDecls GhcRn] -> [LRuleDecl GhcRn]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (RuleDecls GhcRn -> [LRuleDecl GhcRn]
forall pass. RuleDecls pass -> [LRuleDecl pass]
rds_rules (RuleDecls GhcRn -> [LRuleDecl GhcRn])
-> (LRuleDecls GhcRn -> RuleDecls GhcRn)
-> LRuleDecls GhcRn
-> [LRuleDecl GhcRn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LRuleDecls GhcRn -> RuleDecls GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc)
                                                            [LRuleDecls GhcRn]
ruleds)
                     ; [Any]
_        <- (LDocDecl -> IOEnv (Env DsGblEnv DsLclEnv) Any)
-> [LDocDecl] -> IOEnv (Env DsGblEnv DsLclEnv) [Any]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LDocDecl -> IOEnv (Env DsGblEnv DsLclEnv) Any
forall a a. HasSrcSpan a => a -> DsM a
no_doc [LDocDecl]
docs

                        -- more needed
                     ;  [Core DecQ] -> DsM [Core DecQ]
forall (m :: * -> *) a. Monad m => a -> m a
return ([(SrcSpan, Core DecQ)] -> [Core DecQ]
forall a b. [(a, b)] -> [b]
de_loc ([(SrcSpan, Core DecQ)] -> [Core DecQ])
-> [(SrcSpan, Core DecQ)] -> [Core DecQ]
forall a b. (a -> b) -> a -> b
$ [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [(SrcSpan, a)] -> [(SrcSpan, a)]
sort_by_loc ([(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)])
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a b. (a -> b) -> a -> b
$
                                [(SrcSpan, Core DecQ)]
val_ds [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [Maybe (SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [Maybe a] -> [a]
catMaybes [Maybe (SrcSpan, Core DecQ)]
tycl_ds [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
role_ds
                                       [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ ([[(SrcSpan, Core DecQ)]] -> [(SrcSpan, Core DecQ)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[(SrcSpan, Core DecQ)]]
fix_ds)
                                       [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
inst_ds [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
rule_ds [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
for_ds
                                       [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
ann_ds [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
deriv_ds) }) ;

        Type
decl_ty <- Name -> DsM Type
lookupType Name
decQTyConName ;
        let { core_list :: Core [DecQ]
core_list = Type -> [Core DecQ] -> Core [DecQ]
forall a. Type -> [Core a] -> Core [a]
coreList' Type
decl_ty [Core DecQ]
decls } ;

        Type
dec_ty <- Name -> DsM Type
lookupType Name
decTyConName ;
        Core (Q [Dec])
q_decs  <- Type -> Core [DecQ] -> DsM (Core (Q [Dec]))
forall a. Type -> Core [Q a] -> DsM (Core (Q [a]))
repSequenceQ Type
dec_ty Core [DecQ]
core_list ;

        [GenSymBind] -> Core (Q [Dec]) -> DsM (Core (Q [Dec]))
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core (Q [Dec])
q_decs
      }
  where
    no_splice :: a -> DsM a
no_splice (a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc _)
      = SrcSpan -> String -> SDoc -> DsM a
forall a. SrcSpan -> String -> SDoc -> DsM a
notHandledL SrcSpan
loc "Splices within declaration brackets" SDoc
empty
    no_default_decl :: a -> DsM a
no_default_decl (a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc decl :: SrcSpanLess a
decl)
      = SrcSpan -> String -> SDoc -> DsM a
forall a. SrcSpan -> String -> SDoc -> DsM a
notHandledL SrcSpan
loc "Default declarations" (SrcSpanLess a -> SDoc
forall a. Outputable a => a -> SDoc
ppr SrcSpanLess a
decl)
    no_warn :: a -> DsM a
no_warn (a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (Warning _ thing _))
      = SrcSpan -> String -> SDoc -> DsM a
forall a. SrcSpan -> String -> SDoc -> DsM a
notHandledL SrcSpan
loc "WARNING and DEPRECATION pragmas" (SDoc -> DsM a) -> SDoc -> DsM a
forall a b. (a -> b) -> a -> b
$
                    String -> SDoc
text "Pragma for declaration of" SDoc -> SDoc -> SDoc
<+> [Located (IdP pass)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Located (IdP pass)]
thing
    no_warn _ = String -> DsM a
forall a. String -> a
panic "repTopDs"
    no_doc :: a -> DsM a
no_doc (a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc _)
      = SrcSpan -> String -> SDoc -> DsM a
forall a. SrcSpan -> String -> SDoc -> DsM a
notHandledL SrcSpan
loc "Haddock documentation" SDoc
empty
repTopDs (XHsGroup _) = String -> DsM (Core (Q [Dec]))
forall a. String -> a
panic "repTopDs"

hsScopedTvBinders :: HsValBinds GhcRn -> [Name]
-- See Note [Scoped type variables in bindings]
hsScopedTvBinders :: HsValBinds GhcRn -> [Name]
hsScopedTvBinders binds :: HsValBinds GhcRn
binds
  = (LSig GhcRn -> [Name]) -> [LSig GhcRn] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap LSig GhcRn -> [Name]
get_scoped_tvs [LSig GhcRn]
sigs
  where
    sigs :: [LSig GhcRn]
sigs = case HsValBinds GhcRn
binds of
             ValBinds           _ _ sigs :: [LSig GhcRn]
sigs  -> [LSig GhcRn]
sigs
             XValBindsLR (NValBinds _ sigs) -> [LSig GhcRn]
sigs

get_scoped_tvs :: LSig GhcRn -> [Name]
get_scoped_tvs :: LSig GhcRn -> [Name]
get_scoped_tvs (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ signature :: SrcSpanLess (LSig GhcRn)
signature)
  | TypeSig _ _ sig <- SrcSpanLess (LSig GhcRn)
signature
  = HsImplicitBndrs GhcRn (LHsType GhcRn) -> [IdP GhcRn]
forall pass pass.
(XHsIB pass (LHsType pass) ~ [IdP pass]) =>
HsImplicitBndrs pass (LHsType pass) -> [IdP pass]
get_scoped_tvs_from_sig (HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
sig)
  | ClassOpSig _ _ _ sig <- SrcSpanLess (LSig GhcRn)
signature
  = HsImplicitBndrs GhcRn (LHsType GhcRn) -> [IdP GhcRn]
forall pass pass.
(XHsIB pass (LHsType pass) ~ [IdP pass]) =>
HsImplicitBndrs pass (LHsType pass) -> [IdP pass]
get_scoped_tvs_from_sig HsImplicitBndrs GhcRn (LHsType GhcRn)
sig
  | PatSynSig _ _ sig <- SrcSpanLess (LSig GhcRn)
signature
  = HsImplicitBndrs GhcRn (LHsType GhcRn) -> [IdP GhcRn]
forall pass pass.
(XHsIB pass (LHsType pass) ~ [IdP pass]) =>
HsImplicitBndrs pass (LHsType pass) -> [IdP pass]
get_scoped_tvs_from_sig HsImplicitBndrs GhcRn (LHsType GhcRn)
sig
  | Bool
otherwise
  = []
  where
    get_scoped_tvs_from_sig :: HsImplicitBndrs pass (LHsType pass) -> [IdP pass]
get_scoped_tvs_from_sig sig :: HsImplicitBndrs pass (LHsType pass)
sig
      -- Both implicit and explicit quantified variables
      -- We need the implicit ones for   f :: forall (a::k). blah
      --    here 'k' scopes too
      | HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB pass (LHsType pass)
implicit_vars
             , hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsType pass
hs_ty } <- HsImplicitBndrs pass (LHsType pass)
sig
      , (explicit_vars :: [LHsTyVarBndr pass]
explicit_vars, _) <- LHsType pass -> ([LHsTyVarBndr pass], LHsType pass)
forall pass. LHsType pass -> ([LHsTyVarBndr pass], LHsType pass)
splitLHsForAllTy LHsType pass
hs_ty
      = [IdP pass]
XHsIB pass (LHsType pass)
implicit_vars [IdP pass] -> [IdP pass] -> [IdP pass]
forall a. [a] -> [a] -> [a]
++ (LHsTyVarBndr pass -> IdP pass)
-> [LHsTyVarBndr pass] -> [IdP pass]
forall a b. (a -> b) -> [a] -> [b]
map LHsTyVarBndr pass -> IdP pass
forall pass. LHsTyVarBndr pass -> IdP pass
hsLTyVarName [LHsTyVarBndr pass]
explicit_vars
    get_scoped_tvs_from_sig (XHsImplicitBndrs _)
      = String -> [IdP pass]
forall a. String -> a
panic "get_scoped_tvs_from_sig"

{- Notes

Note [Scoped type variables in bindings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
   f :: forall a. a -> a
   f x = x::a
Here the 'forall a' brings 'a' into scope over the binding group.
To achieve this we

  a) Gensym a binding for 'a' at the same time as we do one for 'f'
     collecting the relevant binders with hsScopedTvBinders

  b) When processing the 'forall', don't gensym

The relevant places are signposted with references to this Note

Note [Scoped type variables in class and instance declarations]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scoped type variables may occur in default methods and default
signatures. We need to bring the type variables in 'foralls'
into the scope of the method bindings.

Consider
   class Foo a where
     foo :: forall (b :: k). a -> Proxy b -> Proxy b
     foo _ x = (x :: Proxy b)

We want to ensure that the 'b' in the type signature and the default
implementation are the same, so we do the following:

  a) Before desugaring the signature and binding of 'foo', use
     get_scoped_tvs to collect type variables in 'forall' and
     create symbols for them.
  b) Use 'addBinds' to bring these symbols into the scope of the type
     signatures and bindings.
  c) Use these symbols to generate Core for the class/instance declaration.

Note that when desugaring the signatures, we lookup the type variables
from the scope rather than recreate symbols for them. See more details
in "rep_ty_sig" and in Trac#14885.

Note [Binders and occurrences]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When we desugar [d| data T = MkT |]
we want to get
        Data "T" [] [Con "MkT" []] []
and *not*
        Data "Foo:T" [] [Con "Foo:MkT" []] []
That is, the new data decl should fit into whatever new module it is
asked to fit in.   We do *not* clone, though; no need for this:
        Data "T79" ....

But if we see this:
        data T = MkT
        foo = reifyDecl T

then we must desugar to
        foo = Data "Foo:T" [] [Con "Foo:MkT" []] []

So in repTopDs we bring the binders into scope with mkGenSyms and addBinds.
And we use lookupOcc, rather than lookupBinder
in repTyClD and repC.

Note [Don't quantify implicit type variables in quotes]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you're not careful, it's suprisingly easy to take this quoted declaration:

  [d| idProxy :: forall proxy (b :: k). proxy b -> proxy b
      idProxy x = x
    |]

and have Template Haskell turn it into this:

  idProxy :: forall k proxy (b :: k). proxy b -> proxy b
  idProxy x = x

Notice that we explicitly quantified the variable `k`! The latter declaration
isn't what the user wrote in the first place.

Usually, the culprit behind these bugs is taking implicitly quantified type
variables (often from the hsib_vars field of HsImplicitBinders) and putting
them into a `ForallT` or `ForallC`. Doing so caused #13018 and #13123.
-}

-- represent associated family instances
--
repTyClD :: LTyClDecl GhcRn -> DsM (Maybe (SrcSpan, Core TH.DecQ))

repTyClD :: LTyClDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
repTyClD (LTyClDecl GhcRn -> Located (SrcSpanLess (LTyClDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (FamDecl { tcdFam = fam })) = ((SrcSpan, Core DecQ) -> Maybe (SrcSpan, Core DecQ))
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (SrcSpan, Core DecQ) -> Maybe (SrcSpan, Core DecQ)
forall a. a -> Maybe a
Just (IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
 -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ)))
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall a b. (a -> b) -> a -> b
$
                                                  LFamilyDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repFamilyDecl (SrcSpan -> FamilyDecl GhcRn -> LFamilyDecl GhcRn
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc FamilyDecl GhcRn
fam)

repTyClD (LTyClDecl GhcRn -> Located (SrcSpanLess (LTyClDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (SynDecl { tcdLName = tc, tcdTyVars = tvs, tcdRhs = rhs }))
  = do { Core Name
tc1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tc           -- See note [Binders and occurrences]
       ; Core DecQ
dec <- LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
tvs ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \bndrs :: Core [TyVarBndrQ]
bndrs ->
                Core Name -> Core [TyVarBndrQ] -> LHsType GhcRn -> DsM (Core DecQ)
repSynDecl Core Name
tc1 Core [TyVarBndrQ]
bndrs LHsType GhcRn
rhs
       ; Maybe (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall (m :: * -> *) a. Monad m => a -> m a
return ((SrcSpan, Core DecQ) -> Maybe (SrcSpan, Core DecQ)
forall a. a -> Maybe a
Just (SrcSpan
loc, Core DecQ
dec)) }

repTyClD (LTyClDecl GhcRn -> Located (SrcSpanLess (LTyClDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (DataDecl { tcdLName = tc
                              , tcdTyVars = tvs
                              , tcdDataDefn = defn }))
  = do { Core Name
tc1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tc           -- See note [Binders and occurrences]
       ; Core DecQ
dec <- LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
tvs ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \bndrs :: Core [TyVarBndrQ]
bndrs ->
                Core Name
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
-> HsDataDefn GhcRn
-> DsM (Core DecQ)
repDataDefn Core Name
tc1 (Core [TyVarBndrQ]
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
forall a b. a -> Either a b
Left Core [TyVarBndrQ]
bndrs) HsDataDefn GhcRn
defn
       ; Maybe (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall (m :: * -> *) a. Monad m => a -> m a
return ((SrcSpan, Core DecQ) -> Maybe (SrcSpan, Core DecQ)
forall a. a -> Maybe a
Just (SrcSpan
loc, Core DecQ
dec)) }

repTyClD (LTyClDecl GhcRn -> Located (SrcSpanLess (LTyClDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (ClassDecl { tcdCtxt = cxt, tcdLName = cls,
                             tcdTyVars = tvs, tcdFDs = fds,
                             tcdSigs = sigs, tcdMeths = meth_binds,
                             tcdATs = ats, tcdATDefs = atds }))
  = do { Core Name
cls1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
cls         -- See note [Binders and occurrences]
       ; Core DecQ
dec  <- LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyVarBinds LHsQTyVars GhcRn
tvs ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \bndrs :: Core [TyVarBndrQ]
bndrs ->
           do { Core CxtQ
cxt1   <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
cxt
          -- See Note [Scoped type variables in class and instance declarations]
              ; (ss :: [GenSymBind]
ss, sigs_binds :: [Core DecQ]
sigs_binds) <- [LSig GhcRn] -> LHsBinds GhcRn -> DsM ([GenSymBind], [Core DecQ])
rep_sigs_binds [LSig GhcRn]
sigs LHsBinds GhcRn
meth_binds
              ; Core [FunDep]
fds1   <- [LHsFunDep GhcRn] -> DsM (Core [FunDep])
repLFunDeps [LHsFunDep GhcRn]
fds
              ; [Core DecQ]
ats1   <- [LFamilyDecl GhcRn] -> DsM [Core DecQ]
repFamilyDecls [LFamilyDecl GhcRn]
ats
              ; [Core DecQ]
atds1  <- [LTyFamDefltEqn GhcRn] -> DsM [Core DecQ]
repAssocTyFamDefaults [LTyFamDefltEqn GhcRn]
atds
              ; Core [DecQ]
decls1 <- Name -> [Core DecQ] -> DsM (Core [DecQ])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
decQTyConName ([Core DecQ]
ats1 [Core DecQ] -> [Core DecQ] -> [Core DecQ]
forall a. [a] -> [a] -> [a]
++ [Core DecQ]
atds1 [Core DecQ] -> [Core DecQ] -> [Core DecQ]
forall a. [a] -> [a] -> [a]
++ [Core DecQ]
sigs_binds)
              ; Core DecQ
decls2 <- Core CxtQ
-> Core Name
-> Core [TyVarBndrQ]
-> Core [FunDep]
-> Core [DecQ]
-> DsM (Core DecQ)
repClass Core CxtQ
cxt1 Core Name
cls1 Core [TyVarBndrQ]
bndrs Core [FunDep]
fds1 Core [DecQ]
decls1
              ; [GenSymBind] -> Core DecQ -> DsM (Core DecQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core DecQ
decls2 }
       ; Maybe (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SrcSpan, Core DecQ)
 -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ)))
-> Maybe (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall a b. (a -> b) -> a -> b
$ (SrcSpan, Core DecQ) -> Maybe (SrcSpan, Core DecQ)
forall a. a -> Maybe a
Just (SrcSpan
loc, Core DecQ
dec)
       }

repTyClD _ = String
-> IOEnv (Env DsGblEnv DsLclEnv) (Maybe (SrcSpan, Core DecQ))
forall a. String -> a
panic "repTyClD"

-------------------------
repRoleD :: LRoleAnnotDecl GhcRn -> DsM (SrcSpan, Core TH.DecQ)
repRoleD :: LRoleAnnotDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repRoleD (LRoleAnnotDecl GhcRn
-> Located (SrcSpanLess (LRoleAnnotDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (RoleAnnotDecl _ tycon roles))
  = do { Core Name
tycon1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tycon
       ; [Core Role]
roles1 <- (Located (Maybe Role) -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role))
-> [Located (Maybe Role)]
-> IOEnv (Env DsGblEnv DsLclEnv) [Core Role]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Located (Maybe Role) -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
repRole [Located (Maybe Role)]
roles
       ; Core [Role]
roles2 <- Name -> [Core Role] -> DsM (Core [Role])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
roleTyConName [Core Role]
roles1
       ; Core DecQ
dec <- Core Name -> Core [Role] -> DsM (Core DecQ)
repRoleAnnotD Core Name
tycon1 Core [Role]
roles2
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec) }
repRoleD _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "repRoleD"

-------------------------
repDataDefn :: Core TH.Name
            -> Either (Core [TH.TyVarBndrQ])
                        -- the repTyClD case
                      (Core (Maybe [TH.TyVarBndrQ]), Core TH.TypeQ)
                        -- the repDataFamInstD case
            -> HsDataDefn GhcRn
            -> DsM (Core TH.DecQ)
repDataDefn :: Core Name
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
-> HsDataDefn GhcRn
-> DsM (Core DecQ)
repDataDefn tc :: Core Name
tc opts :: Either (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
opts
          (HsDataDefn { dd_ND :: forall pass. HsDataDefn pass -> NewOrData
dd_ND = NewOrData
new_or_data, dd_ctxt :: forall pass. HsDataDefn pass -> LHsContext pass
dd_ctxt = LHsContext GhcRn
cxt, dd_kindSig :: forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_kindSig = Maybe (LHsType GhcRn)
ksig
                      , dd_cons :: forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons = [LConDecl GhcRn]
cons, dd_derivs :: forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs = HsDeriving GhcRn
mb_derivs })
  = do { Core CxtQ
cxt1     <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
cxt
       ; Core [DerivClauseQ]
derivs1  <- HsDeriving GhcRn -> DsM (Core [DerivClauseQ])
repDerivs HsDeriving GhcRn
mb_derivs
       ; case (NewOrData
new_or_data, [LConDecl GhcRn]
cons) of
           (NewType, [con :: LConDecl GhcRn
con])  -> do { Core ConQ
con'  <- LConDecl GhcRn -> DsM (Core ConQ)
repC LConDecl GhcRn
con
                                   ; Core (Maybe TypeQ)
ksig' <- Maybe (LHsType GhcRn) -> DsM (Core (Maybe TypeQ))
repMaybeLTy Maybe (LHsType GhcRn)
ksig
                                   ; Core CxtQ
-> Core Name
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
-> Core (Maybe TypeQ)
-> Core ConQ
-> Core [DerivClauseQ]
-> DsM (Core DecQ)
repNewtype Core CxtQ
cxt1 Core Name
tc Either (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
opts Core (Maybe TypeQ)
ksig' Core ConQ
con'
                                                Core [DerivClauseQ]
derivs1 }
           (NewType, _) -> SDoc -> DsM (Core DecQ)
forall a. SDoc -> DsM a
failWithDs (String -> SDoc
text "Multiple constructors for newtype:"
                                       SDoc -> SDoc -> SDoc
<+> [Located Name] -> SDoc
forall a. Outputable a => [a] -> SDoc
pprQuotedList
                                       (ConDecl GhcRn -> [Located Name]
forall pass. ConDecl pass -> [Located (IdP pass)]
getConNames (ConDecl GhcRn -> [Located Name])
-> ConDecl GhcRn -> [Located Name]
forall a b. (a -> b) -> a -> b
$ LConDecl GhcRn -> ConDecl GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (LConDecl GhcRn -> ConDecl GhcRn)
-> LConDecl GhcRn -> ConDecl GhcRn
forall a b. (a -> b) -> a -> b
$ [LConDecl GhcRn] -> LConDecl GhcRn
forall a. [a] -> a
head [LConDecl GhcRn]
cons))
           (DataType, _) -> do { Core (Maybe TypeQ)
ksig' <- Maybe (LHsType GhcRn) -> DsM (Core (Maybe TypeQ))
repMaybeLTy Maybe (LHsType GhcRn)
ksig
                               ; [Core ConQ]
consL <- (LConDecl GhcRn -> DsM (Core ConQ))
-> [LConDecl GhcRn] -> IOEnv (Env DsGblEnv DsLclEnv) [Core ConQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LConDecl GhcRn -> DsM (Core ConQ)
repC [LConDecl GhcRn]
cons
                               ; Core [ConQ]
cons1 <- Name -> [Core ConQ] -> DsM (Core [ConQ])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
conQTyConName [Core ConQ]
consL
                               ; Core CxtQ
-> Core Name
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
-> Core (Maybe TypeQ)
-> Core [ConQ]
-> Core [DerivClauseQ]
-> DsM (Core DecQ)
repData Core CxtQ
cxt1 Core Name
tc Either (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
opts Core (Maybe TypeQ)
ksig' Core [ConQ]
cons1
                                         Core [DerivClauseQ]
derivs1 }
       }
repDataDefn _ _ (XHsDataDefn _) = String -> DsM (Core DecQ)
forall a. String -> a
panic "repDataDefn"

repSynDecl :: Core TH.Name -> Core [TH.TyVarBndrQ]
           -> LHsType GhcRn
           -> DsM (Core TH.DecQ)
repSynDecl :: Core Name -> Core [TyVarBndrQ] -> LHsType GhcRn -> DsM (Core DecQ)
repSynDecl tc :: Core Name
tc bndrs :: Core [TyVarBndrQ]
bndrs ty :: LHsType GhcRn
ty
  = do { Core TypeQ
ty1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
       ; Core Name -> Core [TyVarBndrQ] -> Core TypeQ -> DsM (Core DecQ)
repTySyn Core Name
tc Core [TyVarBndrQ]
bndrs Core TypeQ
ty1 }

repFamilyDecl :: LFamilyDecl GhcRn -> DsM (SrcSpan, Core TH.DecQ)
repFamilyDecl :: LFamilyDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repFamilyDecl decl :: LFamilyDecl GhcRn
decl@(LFamilyDecl GhcRn -> Located (SrcSpanLess (LFamilyDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (FamilyDecl { fdInfo      = info
                                          , fdLName     = tc
                                          , fdTyVars    = tvs
                                          , fdResultSig = dL->L _ resultSig
                                          , fdInjectivityAnn = injectivity }))
  = do { Core Name
tc1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tc           -- See note [Binders and occurrences]
       ; let mkHsQTvs :: [LHsTyVarBndr GhcRn] -> LHsQTyVars GhcRn
             mkHsQTvs :: [LHsTyVarBndr GhcRn] -> LHsQTyVars GhcRn
mkHsQTvs tvs :: [LHsTyVarBndr GhcRn]
tvs = HsQTvs :: forall pass. XHsQTvs pass -> [LHsTyVarBndr pass] -> LHsQTyVars pass
HsQTvs { hsq_ext :: XHsQTvs GhcRn
hsq_ext = HsQTvsRn :: [Name] -> NameSet -> HsQTvsRn
HsQTvsRn
                                                { hsq_implicit :: [Name]
hsq_implicit = []
                                                , hsq_dependent :: NameSet
hsq_dependent = NameSet
emptyNameSet }
                                   , hsq_explicit :: [LHsTyVarBndr GhcRn]
hsq_explicit = [LHsTyVarBndr GhcRn]
tvs }
             resTyVar :: LHsQTyVars GhcRn
resTyVar = case SrcSpanLess (LFamilyResultSig GhcRn)
resultSig of
                     TyVarSig _ bndr -> [LHsTyVarBndr GhcRn] -> LHsQTyVars GhcRn
mkHsQTvs [LHsTyVarBndr GhcRn
bndr]
                     _               -> [LHsTyVarBndr GhcRn] -> LHsQTyVars GhcRn
mkHsQTvs []
       ; Core DecQ
dec <- LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
tvs ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \bndrs :: Core [TyVarBndrQ]
bndrs ->
                LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
resTyVar ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \_ ->
           case FamilyInfo GhcRn
info of
             ClosedTypeFamily Nothing ->
                 String -> SDoc -> DsM (Core DecQ)
forall a. String -> SDoc -> DsM a
notHandled "abstract closed type family" (LFamilyDecl GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr LFamilyDecl GhcRn
decl)
             ClosedTypeFamily (Just eqns :: [LTyFamInstEqn GhcRn]
eqns) ->
               do { [Core TySynEqnQ]
eqns1  <- (LTyFamInstEqn GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ))
-> [LTyFamInstEqn GhcRn]
-> IOEnv (Env DsGblEnv DsLclEnv) [Core TySynEqnQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TyFamInstEqn GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
repTyFamEqn (TyFamInstEqn GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ))
-> (LTyFamInstEqn GhcRn -> TyFamInstEqn GhcRn)
-> LTyFamInstEqn GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamInstEqn GhcRn -> TyFamInstEqn GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LTyFamInstEqn GhcRn]
eqns
                  ; Core [TySynEqnQ]
eqns2  <- Name -> [Core TySynEqnQ] -> DsM (Core [TySynEqnQ])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
tySynEqnQTyConName [Core TySynEqnQ]
eqns1
                  ; Core FamilyResultSigQ
result <- FamilyResultSig GhcRn -> DsM (Core FamilyResultSigQ)
repFamilyResultSig SrcSpanLess (LFamilyResultSig GhcRn)
FamilyResultSig GhcRn
resultSig
                  ; Core (Maybe InjectivityAnn)
inj    <- Maybe (LInjectivityAnn GhcRn) -> DsM (Core (Maybe InjectivityAnn))
repInjectivityAnn Maybe (LInjectivityAnn GhcRn)
injectivity
                  ; Core Name
-> Core [TyVarBndrQ]
-> Core FamilyResultSigQ
-> Core (Maybe InjectivityAnn)
-> Core [TySynEqnQ]
-> DsM (Core DecQ)
repClosedFamilyD Core Name
tc1 Core [TyVarBndrQ]
bndrs Core FamilyResultSigQ
result Core (Maybe InjectivityAnn)
inj Core [TySynEqnQ]
eqns2 }
             OpenTypeFamily ->
               do { Core FamilyResultSigQ
result <- FamilyResultSig GhcRn -> DsM (Core FamilyResultSigQ)
repFamilyResultSig SrcSpanLess (LFamilyResultSig GhcRn)
FamilyResultSig GhcRn
resultSig
                  ; Core (Maybe InjectivityAnn)
inj    <- Maybe (LInjectivityAnn GhcRn) -> DsM (Core (Maybe InjectivityAnn))
repInjectivityAnn Maybe (LInjectivityAnn GhcRn)
injectivity
                  ; Core Name
-> Core [TyVarBndrQ]
-> Core FamilyResultSigQ
-> Core (Maybe InjectivityAnn)
-> DsM (Core DecQ)
repOpenFamilyD Core Name
tc1 Core [TyVarBndrQ]
bndrs Core FamilyResultSigQ
result Core (Maybe InjectivityAnn)
inj }
             DataFamily ->
               do { Core (Maybe TypeQ)
kind <- FamilyResultSig GhcRn -> DsM (Core (Maybe TypeQ))
repFamilyResultSigToMaybeKind SrcSpanLess (LFamilyResultSig GhcRn)
FamilyResultSig GhcRn
resultSig
                  ; Core Name
-> Core [TyVarBndrQ] -> Core (Maybe TypeQ) -> DsM (Core DecQ)
repDataFamilyD Core Name
tc1 Core [TyVarBndrQ]
bndrs Core (Maybe TypeQ)
kind }
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec)
       }
repFamilyDecl _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "repFamilyDecl"

-- | Represent result signature of a type family
repFamilyResultSig :: FamilyResultSig GhcRn -> DsM (Core TH.FamilyResultSigQ)
repFamilyResultSig :: FamilyResultSig GhcRn -> DsM (Core FamilyResultSigQ)
repFamilyResultSig (NoSig _)         = DsM (Core FamilyResultSigQ)
repNoSig
repFamilyResultSig (KindSig _ ki :: LHsType GhcRn
ki)    = do { Core TypeQ
ki' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ki
                                          ; Core TypeQ -> DsM (Core FamilyResultSigQ)
repKindSig Core TypeQ
ki' }
repFamilyResultSig (TyVarSig _ bndr :: LHsTyVarBndr GhcRn
bndr) = do { Core TyVarBndrQ
bndr' <- LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
repTyVarBndr LHsTyVarBndr GhcRn
bndr
                                          ; Core TyVarBndrQ -> DsM (Core FamilyResultSigQ)
repTyVarSig Core TyVarBndrQ
bndr' }
repFamilyResultSig (XFamilyResultSig _) = String -> DsM (Core FamilyResultSigQ)
forall a. String -> a
panic "repFamilyResultSig"

-- | Represent result signature using a Maybe Kind. Used with data families,
-- where the result signature can be either missing or a kind but never a named
-- result variable.
repFamilyResultSigToMaybeKind :: FamilyResultSig GhcRn
                              -> DsM (Core (Maybe TH.KindQ))
repFamilyResultSigToMaybeKind :: FamilyResultSig GhcRn -> DsM (Core (Maybe TypeQ))
repFamilyResultSigToMaybeKind (NoSig _) =
    do { Name -> DsM (Core (Maybe TypeQ))
forall a. Name -> DsM (Core (Maybe a))
coreNothing Name
kindQTyConName }
repFamilyResultSigToMaybeKind (KindSig _ ki :: LHsType GhcRn
ki) =
    do { Core TypeQ
ki' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ki
       ; Name -> Core TypeQ -> DsM (Core (Maybe TypeQ))
forall a. Name -> Core a -> DsM (Core (Maybe a))
coreJust Name
kindQTyConName Core TypeQ
ki' }
repFamilyResultSigToMaybeKind _ = String -> DsM (Core (Maybe TypeQ))
forall a. String -> a
panic "repFamilyResultSigToMaybeKind"

-- | Represent injectivity annotation of a type family
repInjectivityAnn :: Maybe (LInjectivityAnn GhcRn)
                  -> DsM (Core (Maybe TH.InjectivityAnn))
repInjectivityAnn :: Maybe (LInjectivityAnn GhcRn) -> DsM (Core (Maybe InjectivityAnn))
repInjectivityAnn Nothing =
    do { Name -> DsM (Core (Maybe InjectivityAnn))
forall a. Name -> DsM (Core (Maybe a))
coreNothing Name
injAnnTyConName }
repInjectivityAnn (Just (LInjectivityAnn GhcRn
-> Located (SrcSpanLess (LInjectivityAnn GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (InjectivityAnn lhs rhs))) =
    do { Core Name
lhs'   <- Name -> DsM (Core Name)
lookupBinder (Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
Located (IdP GhcRn)
lhs)
       ; [Core Name]
rhs1   <- (Located Name -> DsM (Core Name))
-> [Located Name] -> IOEnv (Env DsGblEnv DsLclEnv) [Core Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Name -> DsM (Core Name)
lookupBinder (Name -> DsM (Core Name))
-> (Located Name -> Name) -> Located Name -> DsM (Core Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [Located Name]
[Located (IdP GhcRn)]
rhs
       ; Core [Name]
rhs2   <- Name -> [Core Name] -> DsM (Core [Name])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
nameTyConName [Core Name]
rhs1
       ; Core InjectivityAnn
injAnn <- Name -> [CoreExpr] -> DsM (Core InjectivityAnn)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
injectivityAnnName [Core Name -> CoreExpr
forall a. Core a -> CoreExpr
unC Core Name
lhs', Core [Name] -> CoreExpr
forall a. Core a -> CoreExpr
unC Core [Name]
rhs2]
       ; Name -> Core InjectivityAnn -> DsM (Core (Maybe InjectivityAnn))
forall a. Name -> Core a -> DsM (Core (Maybe a))
coreJust Name
injAnnTyConName Core InjectivityAnn
injAnn }

repFamilyDecls :: [LFamilyDecl GhcRn] -> DsM [Core TH.DecQ]
repFamilyDecls :: [LFamilyDecl GhcRn] -> DsM [Core DecQ]
repFamilyDecls fds :: [LFamilyDecl GhcRn]
fds = ([(SrcSpan, Core DecQ)] -> [Core DecQ])
-> DsM [(SrcSpan, Core DecQ)] -> DsM [Core DecQ]
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [(SrcSpan, Core DecQ)] -> [Core DecQ]
forall a b. [(a, b)] -> [b]
de_loc ((LFamilyDecl GhcRn
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [LFamilyDecl GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LFamilyDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repFamilyDecl [LFamilyDecl GhcRn]
fds)

repAssocTyFamDefaults :: [LTyFamDefltEqn GhcRn] -> DsM [Core TH.DecQ]
repAssocTyFamDefaults :: [LTyFamDefltEqn GhcRn] -> DsM [Core DecQ]
repAssocTyFamDefaults = (LTyFamDefltEqn GhcRn -> DsM (Core DecQ))
-> [LTyFamDefltEqn GhcRn] -> DsM [Core DecQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LTyFamDefltEqn GhcRn -> DsM (Core DecQ)
rep_deflt
  where
     -- very like repTyFamEqn, but different in the details
    rep_deflt :: LTyFamDefltEqn GhcRn -> DsM (Core TH.DecQ)
    rep_deflt :: LTyFamDefltEqn GhcRn -> DsM (Core DecQ)
rep_deflt (LTyFamDefltEqn GhcRn
-> Located (SrcSpanLess (LTyFamDefltEqn GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (FamEqn { feqn_tycon = tc
                               , feqn_bndrs = bndrs
                               , feqn_pats  = tys
                               , feqn_fixity = fixity
                               , feqn_rhs   = rhs }))
      = LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
tys ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \ _ ->
        do { Core Name
tc1  <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tc
           ; Core (Maybe [TyVarBndrQ])
no_bndrs <- ASSERT( isNothing bndrs )
                         Name -> IOEnv (Env DsGblEnv DsLclEnv) (Core (Maybe [TyVarBndrQ]))
forall a. Name -> DsM (Core (Maybe [a]))
coreNothingList Name
tyVarBndrQTyConName
           ; [Core TypeQ]
tys1 <- [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys (LHsQTyVars GhcRn -> [LHsType GhcRn]
forall (p :: Pass). LHsQTyVars (GhcPass p) -> [LHsType (GhcPass p)]
hsLTyVarBndrsToTypes LHsQTyVars GhcRn
tys)
           ; Core TypeQ
lhs <- case LexicalFixity
fixity of
                      Prefix -> do { Core TypeQ
head_ty <- Core Name -> DsM (Core TypeQ)
repNamedTyCon Core Name
tc1
                                   ; Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
head_ty [Core TypeQ]
tys1 }
                      Infix -> do { (t1 :: Core TypeQ
t1:t2 :: Core TypeQ
t2:args :: [Core TypeQ]
args) <- [Core TypeQ] -> DsM [Core TypeQ]
checkTys [Core TypeQ]
tys1
                                  ; Core TypeQ
head_ty <- Core TypeQ -> Core Name -> Core TypeQ -> DsM (Core TypeQ)
repTInfix Core TypeQ
t1 Core Name
tc1 Core TypeQ
t2
                                  ; Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
head_ty [Core TypeQ]
args }
           ; Core TypeQ
rhs1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
rhs
           ; Core TySynEqnQ
eqn1 <- Core (Maybe [TyVarBndrQ])
-> Core TypeQ
-> Core TypeQ
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
repTySynEqn Core (Maybe [TyVarBndrQ])
no_bndrs Core TypeQ
lhs Core TypeQ
rhs1
           ; Core TySynEqnQ -> DsM (Core DecQ)
repTySynInst Core TySynEqnQ
eqn1 }
    rep_deflt _ = String -> DsM (Core DecQ)
forall a. String -> a
panic "repAssocTyFamDefaults"

    checkTys :: [Core TH.TypeQ] -> DsM [Core TH.TypeQ]
    checkTys :: [Core TypeQ] -> DsM [Core TypeQ]
checkTys tys :: [Core TypeQ]
tys@(_:_:_) = [Core TypeQ] -> DsM [Core TypeQ]
forall (m :: * -> *) a. Monad m => a -> m a
return [Core TypeQ]
tys
    checkTys _ = String -> DsM [Core TypeQ]
forall a. String -> a
panic "repAssocTyFamDefaults:checkTys"

-------------------------
-- represent fundeps
--
repLFunDeps :: [LHsFunDep GhcRn] -> DsM (Core [TH.FunDep])
repLFunDeps :: [LHsFunDep GhcRn] -> DsM (Core [FunDep])
repLFunDeps fds :: [LHsFunDep GhcRn]
fds = Name
-> (Located (FunDep (Located Name)) -> DsM (Core FunDep))
-> [Located (FunDep (Located Name))]
-> DsM (Core [FunDep])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
funDepTyConName Located (FunDep (Located Name)) -> DsM (Core FunDep)
LHsFunDep GhcRn -> DsM (Core FunDep)
repLFunDep [Located (FunDep (Located Name))]
[LHsFunDep GhcRn]
fds

repLFunDep :: LHsFunDep GhcRn -> DsM (Core TH.FunDep)
repLFunDep :: LHsFunDep GhcRn -> DsM (Core FunDep)
repLFunDep (LHsFunDep GhcRn
-> Located (SrcSpanLess (Located (FunDep (Located Name))))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (xs, ys))
   = do Core [Name]
xs' <- Name
-> (Located Name -> DsM (Core Name))
-> [Located Name]
-> DsM (Core [Name])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
nameTyConName (Name -> DsM (Core Name)
lookupBinder (Name -> DsM (Core Name))
-> (Located Name -> Name) -> Located Name -> DsM (Core Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [Located Name]
xs
        Core [Name]
ys' <- Name
-> (Located Name -> DsM (Core Name))
-> [Located Name]
-> DsM (Core [Name])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
nameTyConName (Name -> DsM (Core Name)
lookupBinder (Name -> DsM (Core Name))
-> (Located Name -> Name) -> Located Name -> DsM (Core Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located Name -> Name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [Located Name]
ys
        Core [Name] -> Core [Name] -> DsM (Core FunDep)
repFunDep Core [Name]
xs' Core [Name]
ys'

-- Represent instance declarations
--
repInstD :: LInstDecl GhcRn -> DsM (SrcSpan, Core TH.DecQ)
repInstD :: LInstDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repInstD (LInstDecl GhcRn -> Located (SrcSpanLess (LInstDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (TyFamInstD { tfid_inst = fi_decl }))
  = do { Core DecQ
dec <- TyFamInstDecl GhcRn -> DsM (Core DecQ)
repTyFamInstD TyFamInstDecl GhcRn
fi_decl
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec) }
repInstD (LInstDecl GhcRn -> Located (SrcSpanLess (LInstDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (DataFamInstD { dfid_inst = fi_decl }))
  = do { Core DecQ
dec <- DataFamInstDecl GhcRn -> DsM (Core DecQ)
repDataFamInstD DataFamInstDecl GhcRn
fi_decl
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec) }
repInstD (LInstDecl GhcRn -> Located (SrcSpanLess (LInstDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (ClsInstD { cid_inst = cls_decl }))
  = do { Core DecQ
dec <- ClsInstDecl GhcRn -> DsM (Core DecQ)
repClsInstD ClsInstDecl GhcRn
cls_decl
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec) }
repInstD _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "repInstD"

repClsInstD :: ClsInstDecl GhcRn -> DsM (Core TH.DecQ)
repClsInstD :: ClsInstDecl GhcRn -> DsM (Core DecQ)
repClsInstD (ClsInstDecl { cid_poly_ty :: forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty = HsImplicitBndrs GhcRn (LHsType GhcRn)
ty, cid_binds :: forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds = LHsBinds GhcRn
binds
                         , cid_sigs :: forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs = [LSig GhcRn]
sigs, cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts = [LTyFamInstDecl GhcRn]
ats
                         , cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts = [LDataFamInstDecl GhcRn]
adts
                         , cid_overlap_mode :: forall pass. ClsInstDecl pass -> Maybe (Located OverlapMode)
cid_overlap_mode = Maybe (Located OverlapMode)
overlap
                         })
  = [Name] -> DsM (Core DecQ) -> DsM (Core DecQ)
forall a. [Name] -> DsM (Core (Q a)) -> DsM (Core (Q a))
addSimpleTyVarBinds [Name]
tvs (DsM (Core DecQ) -> DsM (Core DecQ))
-> DsM (Core DecQ) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$
            -- We must bring the type variables into scope, so their
            -- occurrences don't fail, even though the binders don't
            -- appear in the resulting data structure
            --
            -- But we do NOT bring the binders of 'binds' into scope
            -- because they are properly regarded as occurrences
            -- For example, the method names should be bound to
            -- the selector Ids, not to fresh names (Trac #5410)
            --
            do { Core CxtQ
cxt1     <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
cxt
               ; Core TypeQ
inst_ty1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
inst_ty
          -- See Note [Scoped type variables in class and instance declarations]
               ; (ss :: [GenSymBind]
ss, sigs_binds :: [Core DecQ]
sigs_binds) <- [LSig GhcRn] -> LHsBinds GhcRn -> DsM ([GenSymBind], [Core DecQ])
rep_sigs_binds [LSig GhcRn]
sigs LHsBinds GhcRn
binds
               ; [Core DecQ]
ats1   <- (LTyFamInstDecl GhcRn -> DsM (Core DecQ))
-> [LTyFamInstDecl GhcRn] -> DsM [Core DecQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TyFamInstDecl GhcRn -> DsM (Core DecQ)
repTyFamInstD (TyFamInstDecl GhcRn -> DsM (Core DecQ))
-> (LTyFamInstDecl GhcRn -> TyFamInstDecl GhcRn)
-> LTyFamInstDecl GhcRn
-> DsM (Core DecQ)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LTyFamInstDecl GhcRn -> TyFamInstDecl GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LTyFamInstDecl GhcRn]
ats
               ; [Core DecQ]
adts1  <- (LDataFamInstDecl GhcRn -> DsM (Core DecQ))
-> [LDataFamInstDecl GhcRn] -> DsM [Core DecQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (DataFamInstDecl GhcRn -> DsM (Core DecQ)
repDataFamInstD (DataFamInstDecl GhcRn -> DsM (Core DecQ))
-> (LDataFamInstDecl GhcRn -> DataFamInstDecl GhcRn)
-> LDataFamInstDecl GhcRn
-> DsM (Core DecQ)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LDataFamInstDecl GhcRn -> DataFamInstDecl GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LDataFamInstDecl GhcRn]
adts
               ; Core [DecQ]
decls1 <- Name -> [Core DecQ] -> DsM (Core [DecQ])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
decQTyConName ([Core DecQ]
ats1 [Core DecQ] -> [Core DecQ] -> [Core DecQ]
forall a. [a] -> [a] -> [a]
++ [Core DecQ]
adts1 [Core DecQ] -> [Core DecQ] -> [Core DecQ]
forall a. [a] -> [a] -> [a]
++ [Core DecQ]
sigs_binds)
               ; Core (Maybe Overlap)
rOver  <- Maybe OverlapMode -> DsM (Core (Maybe Overlap))
repOverlap ((Located OverlapMode -> OverlapMode)
-> Maybe (Located OverlapMode) -> Maybe OverlapMode
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Located OverlapMode -> OverlapMode
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Maybe (Located OverlapMode)
overlap)
               ; Core DecQ
decls2 <- Core (Maybe Overlap)
-> Core CxtQ -> Core TypeQ -> Core [DecQ] -> DsM (Core DecQ)
repInst Core (Maybe Overlap)
rOver Core CxtQ
cxt1 Core TypeQ
inst_ty1 Core [DecQ]
decls1
               ; [GenSymBind] -> Core DecQ -> DsM (Core DecQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core DecQ
decls2 }
 where
   (tvs :: [Name]
tvs, cxt :: LHsContext GhcRn
cxt, inst_ty :: LHsType GhcRn
inst_ty) = HsImplicitBndrs GhcRn (LHsType GhcRn)
-> ([Name], LHsContext GhcRn, LHsType GhcRn)
splitLHsInstDeclTy HsImplicitBndrs GhcRn (LHsType GhcRn)
ty
repClsInstD (XClsInstDecl _) = String -> DsM (Core DecQ)
forall a. String -> a
panic "repClsInstD"

repStandaloneDerivD :: LDerivDecl GhcRn -> DsM (SrcSpan, Core TH.DecQ)
repStandaloneDerivD :: LDerivDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repStandaloneDerivD (LDerivDecl GhcRn -> Located (SrcSpanLess (LDerivDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (DerivDecl { deriv_strategy = strat
                                          , deriv_type     = ty }))
  = do { Core DecQ
dec <- [Name] -> DsM (Core DecQ) -> DsM (Core DecQ)
forall a. [Name] -> DsM (Core (Q a)) -> DsM (Core (Q a))
addSimpleTyVarBinds [Name]
tvs (DsM (Core DecQ) -> DsM (Core DecQ))
-> DsM (Core DecQ) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$
                do { Core CxtQ
cxt'     <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
cxt
                   ; Core (Maybe DerivStrategyQ)
strat'   <- Maybe (LDerivStrategy GhcRn) -> DsM (Core (Maybe DerivStrategyQ))
repDerivStrategy Maybe (LDerivStrategy GhcRn)
strat
                   ; Core TypeQ
inst_ty' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
inst_ty
                   ; Core (Maybe DerivStrategyQ)
-> Core CxtQ -> Core TypeQ -> DsM (Core DecQ)
repDeriv Core (Maybe DerivStrategyQ)
strat' Core CxtQ
cxt' Core TypeQ
inst_ty' }
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec) }
  where
    (tvs :: [Name]
tvs, cxt :: LHsContext GhcRn
cxt, inst_ty :: LHsType GhcRn
inst_ty) = HsImplicitBndrs GhcRn (LHsType GhcRn)
-> ([Name], LHsContext GhcRn, LHsType GhcRn)
splitLHsInstDeclTy (HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
forall pass. LHsSigWcType pass -> LHsSigType pass
dropWildCards HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
ty)
repStandaloneDerivD _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "repStandaloneDerivD"

repTyFamInstD :: TyFamInstDecl GhcRn -> DsM (Core TH.DecQ)
repTyFamInstD :: TyFamInstDecl GhcRn -> DsM (Core DecQ)
repTyFamInstD (TyFamInstDecl { tfid_eqn :: forall pass. TyFamInstDecl pass -> TyFamInstEqn pass
tfid_eqn = TyFamInstEqn GhcRn
eqn })
  = do { Core TySynEqnQ
eqn1 <- TyFamInstEqn GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
repTyFamEqn TyFamInstEqn GhcRn
eqn
       ; Core TySynEqnQ -> DsM (Core DecQ)
repTySynInst Core TySynEqnQ
eqn1 }

repTyFamEqn :: TyFamInstEqn GhcRn -> DsM (Core TH.TySynEqnQ)
repTyFamEqn :: TyFamInstEqn GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
repTyFamEqn (HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (FamEqn GhcRn (HsTyPats GhcRn) (LHsType GhcRn))
var_names
                  , hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = FamEqn { feqn_tycon :: forall pass pats rhs. FamEqn pass pats rhs -> Located (IdP pass)
feqn_tycon = Located (IdP GhcRn)
tc_name
                                       , feqn_bndrs :: forall pass pats rhs.
FamEqn pass pats rhs -> Maybe [LHsTyVarBndr pass]
feqn_bndrs = Maybe [LHsTyVarBndr GhcRn]
mb_bndrs
                                       , feqn_pats :: forall pass pats rhs. FamEqn pass pats rhs -> pats
feqn_pats = HsTyPats GhcRn
tys
                                       , feqn_fixity :: forall pass pats rhs. FamEqn pass pats rhs -> LexicalFixity
feqn_fixity = LexicalFixity
fixity
                                       , feqn_rhs :: forall pass pats rhs. FamEqn pass pats rhs -> rhs
feqn_rhs  = LHsType GhcRn
rhs }})
  = do { Core Name
tc <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tc_name     -- See note [Binders and occurrences]
       ; let hs_tvs :: LHsQTyVars GhcRn
hs_tvs = HsQTvs :: forall pass. XHsQTvs pass -> [LHsTyVarBndr pass] -> LHsQTyVars pass
HsQTvs { hsq_ext :: XHsQTvs GhcRn
hsq_ext = HsQTvsRn :: [Name] -> NameSet -> HsQTvsRn
HsQTvsRn
                               { hsq_implicit :: [Name]
hsq_implicit = [Name]
XHsIB GhcRn (FamEqn GhcRn (HsTyPats GhcRn) (LHsType GhcRn))
var_names
                               , hsq_dependent :: NameSet
hsq_dependent = NameSet
emptyNameSet }   -- Yuk
                             , hsq_explicit :: [LHsTyVarBndr GhcRn]
hsq_explicit = [LHsTyVarBndr GhcRn]
-> Maybe [LHsTyVarBndr GhcRn] -> [LHsTyVarBndr GhcRn]
forall a. a -> Maybe a -> a
fromMaybe [] Maybe [LHsTyVarBndr GhcRn]
mb_bndrs }
       ; LHsQTyVars GhcRn
-> (Core [TyVarBndrQ]
    -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ))
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
hs_tvs ((Core [TyVarBndrQ]
  -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ))
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ))
-> (Core [TyVarBndrQ]
    -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ))
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
forall a b. (a -> b) -> a -> b
$ \ _ ->
         do { Core (Maybe [TyVarBndrQ])
mb_bndrs1 <- Name
-> (LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ))
-> Maybe [LHsTyVarBndr GhcRn]
-> IOEnv (Env DsGblEnv DsLclEnv) (Core (Maybe [TyVarBndrQ]))
forall a b.
Name -> (a -> DsM (Core b)) -> Maybe [a] -> DsM (Core (Maybe [b]))
repMaybeList Name
tyVarBndrQTyConName
                                        LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
repTyVarBndr
                                        Maybe [LHsTyVarBndr GhcRn]
mb_bndrs
            ; Core TypeQ
tys1 <- case LexicalFixity
fixity of
                        Prefix -> DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs (Core Name -> DsM (Core TypeQ)
repNamedTyCon Core Name
tc) HsTyPats GhcRn
tys
                        Infix  -> do { (HsValArg t1 :: LHsType GhcRn
t1: HsValArg t2 :: LHsType GhcRn
t2: args :: HsTyPats GhcRn
args) <- HsTyPats GhcRn -> DsM (HsTyPats GhcRn)
checkTys HsTyPats GhcRn
tys
                                     ; Core TypeQ
t1' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t1
                                     ; Core TypeQ
t2'  <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t2
                                     ; DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs (Core TypeQ -> Core Name -> Core TypeQ -> DsM (Core TypeQ)
repTInfix Core TypeQ
t1' Core Name
tc Core TypeQ
t2') HsTyPats GhcRn
args }
            ; Core TypeQ
rhs1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
rhs
            ; Core (Maybe [TyVarBndrQ])
-> Core TypeQ
-> Core TypeQ
-> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
repTySynEqn Core (Maybe [TyVarBndrQ])
mb_bndrs1 Core TypeQ
tys1 Core TypeQ
rhs1 } }
     where checkTys :: [LHsTypeArg GhcRn] -> DsM [LHsTypeArg GhcRn]
           checkTys :: HsTyPats GhcRn -> DsM (HsTyPats GhcRn)
checkTys tys :: HsTyPats GhcRn
tys@(HsValArg _:HsValArg _:_) = HsTyPats GhcRn -> DsM (HsTyPats GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return HsTyPats GhcRn
tys
           checkTys _ = String -> DsM (HsTyPats GhcRn)
forall a. String -> a
panic "repTyFamEqn:checkTys"
repTyFamEqn (XHsImplicitBndrs _) = String -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
forall a. String -> a
panic "repTyFamEqn"
repTyFamEqn (HsIB _ (XFamEqn _)) = String -> IOEnv (Env DsGblEnv DsLclEnv) (Core TySynEqnQ)
forall a. String -> a
panic "repTyFamEqn"

repTyArgs :: DsM (Core TH.TypeQ) -> [LHsTypeArg GhcRn] -> DsM (Core TH.TypeQ)
repTyArgs :: DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs f :: DsM (Core TypeQ)
f [] = DsM (Core TypeQ)
f
repTyArgs f :: DsM (Core TypeQ)
f (HsValArg ty :: LHsType GhcRn
ty : as :: HsTyPats GhcRn
as) = do { Core TypeQ
f' <- DsM (Core TypeQ)
f
                                    ; Core TypeQ
ty' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
                                    ; DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs (Core TypeQ -> Core TypeQ -> DsM (Core TypeQ)
repTapp Core TypeQ
f' Core TypeQ
ty') HsTyPats GhcRn
as }
repTyArgs f :: DsM (Core TypeQ)
f (HsTypeArg _ ki :: LHsType GhcRn
ki : as :: HsTyPats GhcRn
as) = do { Core TypeQ
f' <- DsM (Core TypeQ)
f
                                       ; Core TypeQ
ki' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ki
                                       ; DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs (Core TypeQ -> Core TypeQ -> DsM (Core TypeQ)
repTappKind Core TypeQ
f' Core TypeQ
ki') HsTyPats GhcRn
as }
repTyArgs f :: DsM (Core TypeQ)
f (HsArgPar _ : as :: HsTyPats GhcRn
as) = DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs DsM (Core TypeQ)
f HsTyPats GhcRn
as

repDataFamInstD :: DataFamInstDecl GhcRn -> DsM (Core TH.DecQ)
repDataFamInstD :: DataFamInstDecl GhcRn -> DsM (Core DecQ)
repDataFamInstD (DataFamInstDecl { dfid_eqn :: forall pass.
DataFamInstDecl pass -> FamInstEqn pass (HsDataDefn pass)
dfid_eqn =
                  (HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (FamEqn GhcRn (HsTyPats GhcRn) (HsDataDefn GhcRn))
var_names
                        , hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = FamEqn { feqn_tycon :: forall pass pats rhs. FamEqn pass pats rhs -> Located (IdP pass)
feqn_tycon = Located (IdP GhcRn)
tc_name
                                             , feqn_bndrs :: forall pass pats rhs.
FamEqn pass pats rhs -> Maybe [LHsTyVarBndr pass]
feqn_bndrs = Maybe [LHsTyVarBndr GhcRn]
mb_bndrs
                                             , feqn_pats :: forall pass pats rhs. FamEqn pass pats rhs -> pats
feqn_pats  = HsTyPats GhcRn
tys
                                             , feqn_fixity :: forall pass pats rhs. FamEqn pass pats rhs -> LexicalFixity
feqn_fixity = LexicalFixity
fixity
                                             , feqn_rhs :: forall pass pats rhs. FamEqn pass pats rhs -> rhs
feqn_rhs   = HsDataDefn GhcRn
defn }})})
  = do { Core Name
tc <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
tc_name         -- See note [Binders and occurrences]
       ; let hs_tvs :: LHsQTyVars GhcRn
hs_tvs = HsQTvs :: forall pass. XHsQTvs pass -> [LHsTyVarBndr pass] -> LHsQTyVars pass
HsQTvs { hsq_ext :: XHsQTvs GhcRn
hsq_ext = HsQTvsRn :: [Name] -> NameSet -> HsQTvsRn
HsQTvsRn
                                 { hsq_implicit :: [Name]
hsq_implicit = [Name]
XHsIB GhcRn (FamEqn GhcRn (HsTyPats GhcRn) (HsDataDefn GhcRn))
var_names
                                 , hsq_dependent :: NameSet
hsq_dependent = NameSet
emptyNameSet }   -- Yuk
                             , hsq_explicit :: [LHsTyVarBndr GhcRn]
hsq_explicit = [LHsTyVarBndr GhcRn]
-> Maybe [LHsTyVarBndr GhcRn] -> [LHsTyVarBndr GhcRn]
forall a. a -> Maybe a -> a
fromMaybe [] Maybe [LHsTyVarBndr GhcRn]
mb_bndrs }
       ; LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds LHsQTyVars GhcRn
hs_tvs ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \ _ ->
         do { Core (Maybe [TyVarBndrQ])
mb_bndrs1 <- Name
-> (LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ))
-> Maybe [LHsTyVarBndr GhcRn]
-> IOEnv (Env DsGblEnv DsLclEnv) (Core (Maybe [TyVarBndrQ]))
forall a b.
Name -> (a -> DsM (Core b)) -> Maybe [a] -> DsM (Core (Maybe [b]))
repMaybeList Name
tyVarBndrQTyConName
                                        LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
repTyVarBndr
                                        Maybe [LHsTyVarBndr GhcRn]
mb_bndrs
            ; Core TypeQ
tys1 <- case LexicalFixity
fixity of
                        Prefix -> DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs (Core Name -> DsM (Core TypeQ)
repNamedTyCon Core Name
tc) HsTyPats GhcRn
tys
                        Infix  -> do { (HsValArg t1 :: LHsType GhcRn
t1: HsValArg t2 :: LHsType GhcRn
t2: args :: HsTyPats GhcRn
args) <- HsTyPats GhcRn -> DsM (HsTyPats GhcRn)
checkTys HsTyPats GhcRn
tys
                                     ; Core TypeQ
t1' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t1
                                     ; Core TypeQ
t2'  <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t2
                                     ; DsM (Core TypeQ) -> HsTyPats GhcRn -> DsM (Core TypeQ)
repTyArgs (Core TypeQ -> Core Name -> Core TypeQ -> DsM (Core TypeQ)
repTInfix Core TypeQ
t1' Core Name
tc Core TypeQ
t2') HsTyPats GhcRn
args }
            ; Core Name
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
-> HsDataDefn GhcRn
-> DsM (Core DecQ)
repDataDefn Core Name
tc ((Core (Maybe [TyVarBndrQ]), Core TypeQ)
-> Either
     (Core [TyVarBndrQ]) (Core (Maybe [TyVarBndrQ]), Core TypeQ)
forall a b. b -> Either a b
Right (Core (Maybe [TyVarBndrQ])
mb_bndrs1, Core TypeQ
tys1)) HsDataDefn GhcRn
defn } }

      where checkTys :: [LHsTypeArg GhcRn] -> DsM [LHsTypeArg GhcRn]
            checkTys :: HsTyPats GhcRn -> DsM (HsTyPats GhcRn)
checkTys tys :: HsTyPats GhcRn
tys@(HsValArg _: HsValArg _: _) = HsTyPats GhcRn -> DsM (HsTyPats GhcRn)
forall (m :: * -> *) a. Monad m => a -> m a
return HsTyPats GhcRn
tys
            checkTys _ = String -> DsM (HsTyPats GhcRn)
forall a. String -> a
panic "repDataFamInstD:checkTys"

repDataFamInstD (DataFamInstDecl (XHsImplicitBndrs _))
  = String -> DsM (Core DecQ)
forall a. String -> a
panic "repDataFamInstD"
repDataFamInstD (DataFamInstDecl (HsIB _ (XFamEqn _)))
  = String -> DsM (Core DecQ)
forall a. String -> a
panic "repDataFamInstD"

repForD :: Located (ForeignDecl GhcRn) -> DsM (SrcSpan, Core TH.DecQ)
repForD :: LForeignDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repForD (LForeignDecl GhcRn -> Located (SrcSpanLess (LForeignDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (ForeignImport { fd_name = name, fd_sig_ty = typ
                                  , fd_fi = CImport (dL->L _ cc)
                                                    (dL->L _ s) mch cis _ }))
 = do MkC name' :: CoreExpr
name' <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
name
      MkC typ' :: CoreExpr
typ' <- HsImplicitBndrs GhcRn (LHsType GhcRn) -> DsM (Core TypeQ)
repHsSigType HsImplicitBndrs GhcRn (LHsType GhcRn)
typ
      MkC cc' :: CoreExpr
cc' <- CCallConv -> DsM (Core Callconv)
repCCallConv SrcSpanLess (Located CCallConv)
CCallConv
cc
      MkC s' :: CoreExpr
s' <- Safety -> DsM (Core Safety)
repSafety SrcSpanLess (Located Safety)
Safety
s
      String
cis' <- CImportSpec -> DsM String
conv_cimportspec CImportSpec
cis
      MkC str :: CoreExpr
str <- String -> DsM (Core String)
coreStringLit (String
static String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
chStr String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
cis')
      Core DecQ
dec <- Name -> [CoreExpr] -> DsM (Core DecQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
forImpDName [CoreExpr
cc', CoreExpr
s', CoreExpr
str, CoreExpr
name', CoreExpr
typ']
      (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec)
 where
    conv_cimportspec :: CImportSpec -> DsM String
conv_cimportspec (CLabel cls :: CLabelString
cls)
      = String -> SDoc -> DsM String
forall a. String -> SDoc -> DsM a
notHandled "Foreign label" (SDoc -> SDoc
doubleQuotes (CLabelString -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabelString
cls))
    conv_cimportspec (CFunction DynamicTarget) = String -> DsM String
forall (m :: * -> *) a. Monad m => a -> m a
return "dynamic"
    conv_cimportspec (CFunction (StaticTarget _ fs :: CLabelString
fs _ True))
                            = String -> DsM String
forall (m :: * -> *) a. Monad m => a -> m a
return (CLabelString -> String
unpackFS CLabelString
fs)
    conv_cimportspec (CFunction (StaticTarget _ _  _ False))
                            = String -> DsM String
forall a. String -> a
panic "conv_cimportspec: values not supported yet"
    conv_cimportspec CWrapper = String -> DsM String
forall (m :: * -> *) a. Monad m => a -> m a
return "wrapper"
    -- these calling conventions do not support headers and the static keyword
    raw_cconv :: Bool
raw_cconv = SrcSpanLess (Located CCallConv)
CCallConv
cc CCallConv -> CCallConv -> Bool
forall a. Eq a => a -> a -> Bool
== CCallConv
PrimCallConv Bool -> Bool -> Bool
|| SrcSpanLess (Located CCallConv)
CCallConv
cc CCallConv -> CCallConv -> Bool
forall a. Eq a => a -> a -> Bool
== CCallConv
JavaScriptCallConv
    static :: String
static = case CImportSpec
cis of
                 CFunction (StaticTarget _ _ _ _) | Bool -> Bool
not Bool
raw_cconv -> "static "
                 _ -> ""
    chStr :: String
chStr = case Maybe Header
mch of
            Just (Header _ h :: CLabelString
h) | Bool -> Bool
not Bool
raw_cconv -> CLabelString -> String
unpackFS CLabelString
h String -> String -> String
forall a. [a] -> [a] -> [a]
++ " "
            _ -> ""
repForD decl :: LForeignDecl GhcRn
decl = String
-> SDoc -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> SDoc -> DsM a
notHandled "Foreign declaration" (LForeignDecl GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr LForeignDecl GhcRn
decl)

repCCallConv :: CCallConv -> DsM (Core TH.Callconv)
repCCallConv :: CCallConv -> DsM (Core Callconv)
repCCallConv CCallConv          = Name -> [CoreExpr] -> DsM (Core Callconv)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
cCallName []
repCCallConv StdCallConv        = Name -> [CoreExpr] -> DsM (Core Callconv)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
stdCallName []
repCCallConv CApiConv           = Name -> [CoreExpr] -> DsM (Core Callconv)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
cApiCallName []
repCCallConv PrimCallConv       = Name -> [CoreExpr] -> DsM (Core Callconv)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
primCallName []
repCCallConv JavaScriptCallConv = Name -> [CoreExpr] -> DsM (Core Callconv)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
javaScriptCallName []

repSafety :: Safety -> DsM (Core TH.Safety)
repSafety :: Safety -> DsM (Core Safety)
repSafety PlayRisky = Name -> [CoreExpr] -> DsM (Core Safety)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
unsafeName []
repSafety PlayInterruptible = Name -> [CoreExpr] -> DsM (Core Safety)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
interruptibleName []
repSafety PlaySafe = Name -> [CoreExpr] -> DsM (Core Safety)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
safeName []

repFixD :: LFixitySig GhcRn -> DsM [(SrcSpan, Core TH.DecQ)]
repFixD :: LFixitySig GhcRn -> DsM [(SrcSpan, Core DecQ)]
repFixD (LFixitySig GhcRn -> Located (SrcSpanLess (LFixitySig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (FixitySig _ names (Fixity _ prec dir)))
  = do { MkC prec' :: CoreExpr
prec' <- Int -> DsM (Core Int)
coreIntLit Int
prec
       ; let rep_fn :: Name
rep_fn = case FixityDirection
dir of
                        InfixL -> Name
infixLDName
                        InfixR -> Name
infixRDName
                        InfixN -> Name
infixNDName
       ; let do_one :: Located Name -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
do_one name :: Located Name
name
              = do { MkC name' :: CoreExpr
name' <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
name
                   ; Core DecQ
dec <- Name -> [CoreExpr] -> DsM (Core DecQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
rep_fn [CoreExpr
prec', CoreExpr
name']
                   ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc,Core DecQ
dec) }
       ; (Located Name
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [Located Name] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Located Name -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
do_one [Located Name]
[Located (IdP GhcRn)]
names }
repFixD _ = String -> DsM [(SrcSpan, Core DecQ)]
forall a. String -> a
panic "repFixD"

repRuleD :: LRuleDecl GhcRn -> DsM (SrcSpan, Core TH.DecQ)
repRuleD :: LRuleDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repRuleD (LRuleDecl GhcRn -> Located (SrcSpanLess (LRuleDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (HsRule { rd_name = n
                            , rd_act = act
                            , rd_tyvs = ty_bndrs
                            , rd_tmvs = tm_bndrs
                            , rd_lhs = lhs
                            , rd_rhs = rhs }))
  = do { Core DecQ
rule <- [LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a.
[LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addHsTyVarBinds ([LHsTyVarBndr GhcRn]
-> Maybe [LHsTyVarBndr GhcRn] -> [LHsTyVarBndr GhcRn]
forall a. a -> Maybe a -> a
fromMaybe [] Maybe [LHsTyVarBndr (NoGhcTc GhcRn)]
Maybe [LHsTyVarBndr GhcRn]
ty_bndrs) ((Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ))
-> (Core [TyVarBndrQ] -> DsM (Core DecQ)) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$ \ ex_bndrs :: Core [TyVarBndrQ]
ex_bndrs ->
         do { let tm_bndr_names :: [Name]
tm_bndr_names = (LRuleBndr GhcRn -> [Name]) -> [LRuleBndr GhcRn] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap LRuleBndr GhcRn -> [Name]
ruleBndrNames [LRuleBndr GhcRn]
tm_bndrs
            ; [GenSymBind]
ss <- [Name] -> DsM [GenSymBind]
mkGenSyms [Name]
tm_bndr_names
            ; Core DecQ
rule <- [GenSymBind] -> DsM (Core DecQ) -> DsM (Core DecQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss (DsM (Core DecQ) -> DsM (Core DecQ))
-> DsM (Core DecQ) -> DsM (Core DecQ)
forall a b. (a -> b) -> a -> b
$
                      do { Core (Maybe [TyVarBndrQ])
ty_bndrs' <- case Maybe [LHsTyVarBndr (NoGhcTc GhcRn)]
ty_bndrs of
                             Nothing -> Name -> IOEnv (Env DsGblEnv DsLclEnv) (Core (Maybe [TyVarBndrQ]))
forall a. Name -> DsM (Core (Maybe [a]))
coreNothingList Name
tyVarBndrQTyConName
                             Just _  -> Name
-> Core [TyVarBndrQ]
-> IOEnv (Env DsGblEnv DsLclEnv) (Core (Maybe [TyVarBndrQ]))
forall a. Name -> Core [a] -> DsM (Core (Maybe [a]))
coreJustList Name
tyVarBndrQTyConName
                                          Core [TyVarBndrQ]
ex_bndrs
                         ; Core [RuleBndrQ]
tm_bndrs' <- Name
-> (LRuleBndr GhcRn -> DsM (Core RuleBndrQ))
-> [LRuleBndr GhcRn]
-> DsM (Core [RuleBndrQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
ruleBndrQTyConName
                                                LRuleBndr GhcRn -> DsM (Core RuleBndrQ)
repRuleBndr
                                                [LRuleBndr GhcRn]
tm_bndrs
                         ; Core String
n'   <- String -> DsM (Core String)
coreStringLit (String -> DsM (Core String)) -> String -> DsM (Core String)
forall a b. (a -> b) -> a -> b
$ CLabelString -> String
unpackFS (CLabelString -> String) -> CLabelString -> String
forall a b. (a -> b) -> a -> b
$ (SourceText, CLabelString) -> CLabelString
forall a b. (a, b) -> b
snd ((SourceText, CLabelString) -> CLabelString)
-> (SourceText, CLabelString) -> CLabelString
forall a b. (a -> b) -> a -> b
$ Located (SourceText, CLabelString)
-> SrcSpanLess (Located (SourceText, CLabelString))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located (SourceText, CLabelString)
n
                         ; Core Phases
act' <- Activation -> DsM (Core Phases)
repPhases Activation
act
                         ; Core ExpQ
lhs' <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
lhs
                         ; Core ExpQ
rhs' <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
rhs
                         ; Core String
-> Core (Maybe [TyVarBndrQ])
-> Core [RuleBndrQ]
-> Core ExpQ
-> Core ExpQ
-> Core Phases
-> DsM (Core DecQ)
repPragRule Core String
n' Core (Maybe [TyVarBndrQ])
ty_bndrs' Core [RuleBndrQ]
tm_bndrs' Core ExpQ
lhs' Core ExpQ
rhs' Core Phases
act' }
           ; [GenSymBind] -> Core DecQ -> DsM (Core DecQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core DecQ
rule  }
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
rule) }
repRuleD _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "repRuleD"

ruleBndrNames :: LRuleBndr GhcRn -> [Name]
ruleBndrNames :: LRuleBndr GhcRn -> [Name]
ruleBndrNames (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (RuleBndr _ n))      = [Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
Located (IdP GhcRn)
n]
ruleBndrNames (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (RuleBndrSig _ n sig))
  | HsWC { hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (LHsType GhcRn)
vars }} <- HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
sig
  = Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
Located (IdP GhcRn)
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: [Name]
XHsIB GhcRn (LHsType GhcRn)
vars
ruleBndrNames (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (RuleBndrSig _ _ (HsWC _ (XHsImplicitBndrs _))))
  = String -> [Name]
forall a. String -> a
panic "ruleBndrNames"
ruleBndrNames (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (RuleBndrSig _ _ (XHsWildCardBndrs _)))
  = String -> [Name]
forall a. String -> a
panic "ruleBndrNames"
ruleBndrNames (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (XRuleBndr _)) = String -> [Name]
forall a. String -> a
panic "ruleBndrNames"
ruleBndrNames _ = String -> [Name]
forall a. String -> a
panic "ruleBndrNames: Impossible Match" -- due to #15884

repRuleBndr :: LRuleBndr GhcRn -> DsM (Core TH.RuleBndrQ)
repRuleBndr :: LRuleBndr GhcRn -> DsM (Core RuleBndrQ)
repRuleBndr (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (RuleBndr _ n))
  = do { MkC n' :: CoreExpr
n' <- Located Name -> DsM (Core Name)
lookupLBinder Located Name
Located (IdP GhcRn)
n
       ; Name -> [CoreExpr] -> DsM (Core RuleBndrQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
ruleVarName [CoreExpr
n'] }
repRuleBndr (LRuleBndr GhcRn -> Located (SrcSpanLess (LRuleBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (RuleBndrSig _ n sig))
  = do { MkC n' :: CoreExpr
n'  <- Located Name -> DsM (Core Name)
lookupLBinder Located Name
Located (IdP GhcRn)
n
       ; MkC ty' :: CoreExpr
ty' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy (HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> LHsType GhcRn
forall pass. LHsSigWcType pass -> LHsType pass
hsSigWcType HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
sig)
       ; Name -> [CoreExpr] -> DsM (Core RuleBndrQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
typedRuleVarName [CoreExpr
n', CoreExpr
ty'] }
repRuleBndr _ = String -> DsM (Core RuleBndrQ)
forall a. String -> a
panic "repRuleBndr"

repAnnD :: LAnnDecl GhcRn -> DsM (SrcSpan, Core TH.DecQ)
repAnnD :: LAnnDecl GhcRn
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
repAnnD (LAnnDecl GhcRn -> Located (SrcSpanLess (LAnnDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (HsAnnotation _ _ ann_prov (dL->L _ exp)))
  = do { Core AnnTarget
target <- AnnProvenance Name -> DsM (Core AnnTarget)
repAnnProv AnnProvenance Name
AnnProvenance (IdP GhcRn)
ann_prov
       ; Core ExpQ
exp'   <- HsExpr GhcRn -> DsM (Core ExpQ)
repE SrcSpanLess (LHsExpr GhcRn)
HsExpr GhcRn
exp
       ; Core DecQ
dec    <- Core AnnTarget -> Core ExpQ -> DsM (Core DecQ)
repPragAnn Core AnnTarget
target Core ExpQ
exp'
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
dec) }
repAnnD _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "repAnnD"

repAnnProv :: AnnProvenance Name -> DsM (Core TH.AnnTarget)
repAnnProv :: AnnProvenance Name -> DsM (Core AnnTarget)
repAnnProv (ValueAnnProvenance (Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ n :: SrcSpanLess (Located Name)
n))
  = do { MkC n' :: CoreExpr
n' <- Name -> DsM (Core Name)
globalVar Name
SrcSpanLess (Located Name)
n  -- ANNs are allowed only at top-level
       ; Name -> [CoreExpr] -> DsM (Core AnnTarget)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
valueAnnotationName [ CoreExpr
n' ] }
repAnnProv (TypeAnnProvenance (Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ n :: SrcSpanLess (Located Name)
n))
  = do { MkC n' :: CoreExpr
n' <- Name -> DsM (Core Name)
globalVar Name
SrcSpanLess (Located Name)
n
       ; Name -> [CoreExpr] -> DsM (Core AnnTarget)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
typeAnnotationName [ CoreExpr
n' ] }
repAnnProv ModuleAnnProvenance
  = Name -> [CoreExpr] -> DsM (Core AnnTarget)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
moduleAnnotationName []

-------------------------------------------------------
--                      Constructors
-------------------------------------------------------

repC :: LConDecl GhcRn -> DsM (Core TH.ConQ)
repC :: LConDecl GhcRn -> DsM (Core ConQ)
repC (LConDecl GhcRn -> Located (SrcSpanLess (LConDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (ConDeclH98 { con_name   = con
                          , con_forall = (dL->L _ False)
                          , con_mb_cxt = Nothing
                          , con_args   = args }))
  = Located Name -> HsConDeclDetails GhcRn -> DsM (Core ConQ)
repDataCon Located Name
Located (IdP GhcRn)
con HsConDeclDetails GhcRn
args

repC (LConDecl GhcRn -> Located (SrcSpanLess (LConDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (ConDeclH98 { con_name = con
                          , con_forall = (dL->L _ is_existential)
                          , con_ex_tvs = con_tvs
                          , con_mb_cxt = mcxt
                          , con_args = args }))
  = do { [LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core ConQ)) -> DsM (Core ConQ)
forall a.
[LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addHsTyVarBinds [LHsTyVarBndr GhcRn]
con_tvs ((Core [TyVarBndrQ] -> DsM (Core ConQ)) -> DsM (Core ConQ))
-> (Core [TyVarBndrQ] -> DsM (Core ConQ)) -> DsM (Core ConQ)
forall a b. (a -> b) -> a -> b
$ \ ex_bndrs :: Core [TyVarBndrQ]
ex_bndrs ->
         do { Core ConQ
c'    <- Located Name -> HsConDeclDetails GhcRn -> DsM (Core ConQ)
repDataCon Located Name
Located (IdP GhcRn)
con HsConDeclDetails GhcRn
args
            ; Core CxtQ
ctxt' <- Maybe (LHsContext GhcRn) -> DsM (Core CxtQ)
repMbContext Maybe (LHsContext GhcRn)
mcxt
            ; if Bool -> Bool
not Bool
SrcSpanLess (Located Bool)
is_existential Bool -> Bool -> Bool
&& Maybe (LHsContext GhcRn) -> Bool
forall a. Maybe a -> Bool
isNothing Maybe (LHsContext GhcRn)
mcxt
              then Core ConQ -> DsM (Core ConQ)
forall (m :: * -> *) a. Monad m => a -> m a
return Core ConQ
c'
              else Name -> [CoreExpr] -> DsM (Core ConQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
forallCName ([Core [TyVarBndrQ] -> CoreExpr
forall a. Core a -> CoreExpr
unC Core [TyVarBndrQ]
ex_bndrs, Core CxtQ -> CoreExpr
forall a. Core a -> CoreExpr
unC Core CxtQ
ctxt', Core ConQ -> CoreExpr
forall a. Core a -> CoreExpr
unC Core ConQ
c'])
            }
       }

repC (LConDecl GhcRn -> Located (SrcSpanLess (LConDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (ConDeclGADT { con_names  = cons
                           , con_qvars  = qtvs
                           , con_mb_cxt = mcxt
                           , con_args   = args
                           , con_res_ty = res_ty }))
  | LHsQTyVars GhcRn -> Bool
isEmptyLHsQTvs LHsQTyVars GhcRn
qtvs  -- No implicit or explicit variables
  , Maybe (LHsContext GhcRn)
Nothing <- Maybe (LHsContext GhcRn)
mcxt      -- No context
                         -- ==> no need for a forall
  = [Located Name]
-> HsConDeclDetails GhcRn -> LHsType GhcRn -> DsM (Core ConQ)
repGadtDataCons [Located Name]
[Located (IdP GhcRn)]
cons HsConDeclDetails GhcRn
args LHsType GhcRn
res_ty

  | Bool
otherwise
  = LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core ConQ)) -> DsM (Core ConQ)
forall a.
LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyVarBinds LHsQTyVars GhcRn
qtvs ((Core [TyVarBndrQ] -> DsM (Core ConQ)) -> DsM (Core ConQ))
-> (Core [TyVarBndrQ] -> DsM (Core ConQ)) -> DsM (Core ConQ)
forall a b. (a -> b) -> a -> b
$ \ ex_bndrs :: Core [TyVarBndrQ]
ex_bndrs ->
             -- See Note [Don't quantify implicit type variables in quotes]
    do { Core ConQ
c'    <- [Located Name]
-> HsConDeclDetails GhcRn -> LHsType GhcRn -> DsM (Core ConQ)
repGadtDataCons [Located Name]
[Located (IdP GhcRn)]
cons HsConDeclDetails GhcRn
args LHsType GhcRn
res_ty
       ; Core CxtQ
ctxt' <- Maybe (LHsContext GhcRn) -> DsM (Core CxtQ)
repMbContext Maybe (LHsContext GhcRn)
mcxt
       ; if [LHsTyVarBndr GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (LHsQTyVars GhcRn -> [LHsTyVarBndr GhcRn]
forall pass. LHsQTyVars pass -> [LHsTyVarBndr pass]
hsQTvExplicit LHsQTyVars GhcRn
qtvs) Bool -> Bool -> Bool
&& Maybe (LHsContext GhcRn) -> Bool
forall a. Maybe a -> Bool
isNothing Maybe (LHsContext GhcRn)
mcxt
         then Core ConQ -> DsM (Core ConQ)
forall (m :: * -> *) a. Monad m => a -> m a
return Core ConQ
c'
         else Name -> [CoreExpr] -> DsM (Core ConQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
forallCName ([Core [TyVarBndrQ] -> CoreExpr
forall a. Core a -> CoreExpr
unC Core [TyVarBndrQ]
ex_bndrs, Core CxtQ -> CoreExpr
forall a. Core a -> CoreExpr
unC Core CxtQ
ctxt', Core ConQ -> CoreExpr
forall a. Core a -> CoreExpr
unC Core ConQ
c']) }

repC _ = String -> DsM (Core ConQ)
forall a. String -> a
panic "repC"


repMbContext :: Maybe (LHsContext GhcRn) -> DsM (Core TH.CxtQ)
repMbContext :: Maybe (LHsContext GhcRn) -> DsM (Core CxtQ)
repMbContext Nothing          = [LHsType GhcRn] -> DsM (Core CxtQ)
repContext []
repMbContext (Just (LHsContext GhcRn -> Located (SrcSpanLess (LHsContext GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ cxt :: SrcSpanLess (LHsContext GhcRn)
cxt)) = [LHsType GhcRn] -> DsM (Core CxtQ)
repContext [LHsType GhcRn]
SrcSpanLess (LHsContext GhcRn)
cxt

repSrcUnpackedness :: SrcUnpackedness -> DsM (Core TH.SourceUnpackednessQ)
repSrcUnpackedness :: SrcUnpackedness -> DsM (Core SourceUnpackednessQ)
repSrcUnpackedness SrcUnpack   = Name -> [CoreExpr] -> DsM (Core SourceUnpackednessQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
sourceUnpackName         []
repSrcUnpackedness SrcNoUnpack = Name -> [CoreExpr] -> DsM (Core SourceUnpackednessQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
sourceNoUnpackName       []
repSrcUnpackedness NoSrcUnpack = Name -> [CoreExpr] -> DsM (Core SourceUnpackednessQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
noSourceUnpackednessName []

repSrcStrictness :: SrcStrictness -> DsM (Core TH.SourceStrictnessQ)
repSrcStrictness :: SrcStrictness -> DsM (Core SourceStrictnessQ)
repSrcStrictness SrcLazy     = Name -> [CoreExpr] -> DsM (Core SourceStrictnessQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
sourceLazyName         []
repSrcStrictness SrcStrict   = Name -> [CoreExpr] -> DsM (Core SourceStrictnessQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
sourceStrictName       []
repSrcStrictness NoSrcStrict = Name -> [CoreExpr] -> DsM (Core SourceStrictnessQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
noSourceStrictnessName []

repBangTy :: LBangType GhcRn -> DsM (Core (TH.BangTypeQ))
repBangTy :: LHsType GhcRn -> DsM (Core BangTypeQ)
repBangTy ty :: LHsType GhcRn
ty = do
  MkC u :: CoreExpr
u <- SrcUnpackedness -> DsM (Core SourceUnpackednessQ)
repSrcUnpackedness SrcUnpackedness
su'
  MkC s :: CoreExpr
s <- SrcStrictness -> DsM (Core SourceStrictnessQ)
repSrcStrictness SrcStrictness
ss'
  MkC b :: CoreExpr
b <- Name -> [CoreExpr] -> DsM (Core Any)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
bangName [CoreExpr
u, CoreExpr
s]
  MkC t :: CoreExpr
t <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty'
  Name -> [CoreExpr] -> DsM (Core BangTypeQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
bangTypeName [CoreExpr
b, CoreExpr
t]
  where
    (su' :: SrcUnpackedness
su', ss' :: SrcStrictness
ss', ty' :: LHsType GhcRn
ty') = case LHsType GhcRn -> SrcSpanLess (LHsType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsType GhcRn
ty of
            HsBangTy _ (HsSrcBang _ su ss) ty -> (SrcUnpackedness
su, SrcStrictness
ss, LHsType GhcRn
ty)
            _ -> (SrcUnpackedness
NoSrcUnpack, SrcStrictness
NoSrcStrict, LHsType GhcRn
ty)

-------------------------------------------------------
--                      Deriving clauses
-------------------------------------------------------

repDerivs :: HsDeriving GhcRn -> DsM (Core [TH.DerivClauseQ])
repDerivs :: HsDeriving GhcRn -> DsM (Core [DerivClauseQ])
repDerivs (HsDeriving GhcRn -> Located (SrcSpanLess (HsDeriving GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ clauses :: SrcSpanLess (HsDeriving GhcRn)
clauses)
  = Name
-> (LHsDerivingClause GhcRn -> DsM (Core DerivClauseQ))
-> [LHsDerivingClause GhcRn]
-> DsM (Core [DerivClauseQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
derivClauseQTyConName LHsDerivingClause GhcRn -> DsM (Core DerivClauseQ)
repDerivClause [LHsDerivingClause GhcRn]
SrcSpanLess (HsDeriving GhcRn)
clauses

repDerivClause :: LHsDerivingClause GhcRn
               -> DsM (Core TH.DerivClauseQ)
repDerivClause :: LHsDerivingClause GhcRn -> DsM (Core DerivClauseQ)
repDerivClause (LHsDerivingClause GhcRn
-> Located (SrcSpanLess (LHsDerivingClause GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (HsDerivingClause
                          { deriv_clause_strategy = dcs
                          , deriv_clause_tys      = (dL->L _ dct) }))
  = do MkC dcs' :: CoreExpr
dcs' <- Maybe (LDerivStrategy GhcRn) -> DsM (Core (Maybe DerivStrategyQ))
repDerivStrategy Maybe (LDerivStrategy GhcRn)
dcs
       MkC dct' :: CoreExpr
dct' <- Name
-> (HsImplicitBndrs GhcRn (LHsType GhcRn) -> DsM (Core TypeQ))
-> [HsImplicitBndrs GhcRn (LHsType GhcRn)]
-> DsM (Core [TypeQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
typeQTyConName (LHsType GhcRn -> DsM (Core TypeQ)
rep_deriv_ty (LHsType GhcRn -> DsM (Core TypeQ))
-> (HsImplicitBndrs GhcRn (LHsType GhcRn) -> LHsType GhcRn)
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> DsM (Core TypeQ)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsImplicitBndrs GhcRn (LHsType GhcRn) -> LHsType GhcRn
forall pass. LHsSigType pass -> LHsType pass
hsSigType) [HsImplicitBndrs GhcRn (LHsType GhcRn)]
SrcSpanLess (Located [HsImplicitBndrs GhcRn (LHsType GhcRn)])
dct
       Name -> [CoreExpr] -> DsM (Core DerivClauseQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
derivClauseName [CoreExpr
dcs',CoreExpr
dct']
  where
    rep_deriv_ty :: LHsType GhcRn -> DsM (Core TH.TypeQ)
    rep_deriv_ty :: LHsType GhcRn -> DsM (Core TypeQ)
rep_deriv_ty ty :: LHsType GhcRn
ty = LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
repDerivClause _ = String -> DsM (Core DerivClauseQ)
forall a. String -> a
panic "repDerivClause"

rep_sigs_binds :: [LSig GhcRn] -> LHsBinds GhcRn
               -> DsM ([GenSymBind], [Core TH.DecQ])
-- Represent signatures and methods in class/instance declarations.
-- See Note [Scoped type variables in class and instance declarations]
--
-- Why not use 'repBinds': we have already created symbols for methods in
-- 'repTopDs' via 'hsGroupBinders'. However in 'repBinds', we recreate
-- these fun_id via 'collectHsValBinders decs', which would lead to the
-- instance declarations failing in TH.
rep_sigs_binds :: [LSig GhcRn] -> LHsBinds GhcRn -> DsM ([GenSymBind], [Core DecQ])
rep_sigs_binds sigs :: [LSig GhcRn]
sigs binds :: LHsBinds GhcRn
binds
  = do { let tvs :: [Name]
tvs = (LSig GhcRn -> [Name]) -> [LSig GhcRn] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap LSig GhcRn -> [Name]
get_scoped_tvs [LSig GhcRn]
sigs
       ; [GenSymBind]
ss <- [Name] -> DsM [GenSymBind]
mkGenSyms [Name]
tvs
       ; [(SrcSpan, Core DecQ)]
sigs1 <- [GenSymBind]
-> DsM [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss (DsM [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)])
-> DsM [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall a b. (a -> b) -> a -> b
$ [LSig GhcRn] -> DsM [(SrcSpan, Core DecQ)]
rep_sigs [LSig GhcRn]
sigs
       ; [(SrcSpan, Core DecQ)]
binds1 <- [GenSymBind]
-> DsM [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss (DsM [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)])
-> DsM [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall a b. (a -> b) -> a -> b
$ LHsBinds GhcRn -> DsM [(SrcSpan, Core DecQ)]
rep_binds LHsBinds GhcRn
binds
       ; ([GenSymBind], [Core DecQ]) -> DsM ([GenSymBind], [Core DecQ])
forall (m :: * -> *) a. Monad m => a -> m a
return ([GenSymBind]
ss, [(SrcSpan, Core DecQ)] -> [Core DecQ]
forall a b. [(a, b)] -> [b]
de_loc ([(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [(SrcSpan, a)] -> [(SrcSpan, a)]
sort_by_loc ([(SrcSpan, Core DecQ)]
sigs1 [(SrcSpan, Core DecQ)]
-> [(SrcSpan, Core DecQ)] -> [(SrcSpan, Core DecQ)]
forall a. [a] -> [a] -> [a]
++ [(SrcSpan, Core DecQ)]
binds1))) }

-------------------------------------------------------
--   Signatures in a class decl, or a group of bindings
-------------------------------------------------------

rep_sigs :: [LSig GhcRn] -> DsM [(SrcSpan, Core TH.DecQ)]
        -- We silently ignore ones we don't recognise
rep_sigs :: [LSig GhcRn] -> DsM [(SrcSpan, Core DecQ)]
rep_sigs = (LSig GhcRn -> DsM [(SrcSpan, Core DecQ)])
-> [LSig GhcRn] -> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM LSig GhcRn -> DsM [(SrcSpan, Core DecQ)]
rep_sig

rep_sig :: LSig GhcRn -> DsM [(SrcSpan, Core TH.DecQ)]
rep_sig :: LSig GhcRn -> DsM [(SrcSpan, Core DecQ)]
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (TypeSig _ nms ty))
  = (Located Name
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [Located Name] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Name
-> SrcSpan
-> HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_wc_ty_sig Name
sigDName SrcSpan
loc HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
ty) [Located Name]
[Located (IdP GhcRn)]
nms
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (PatSynSig _ nms ty))
  = (Located Name
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [Located Name] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SrcSpan
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_patsyn_ty_sig SrcSpan
loc HsImplicitBndrs GhcRn (LHsType GhcRn)
ty) [Located Name]
[Located (IdP GhcRn)]
nms
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (ClassOpSig _ is_deflt nms ty))
  | Bool
is_deflt     = (Located Name
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [Located Name] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Name
-> SrcSpan
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_ty_sig Name
defaultSigDName SrcSpan
loc HsImplicitBndrs GhcRn (LHsType GhcRn)
ty) [Located Name]
[Located (IdP GhcRn)]
nms
  | Bool
otherwise    = (Located Name
 -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ))
-> [Located Name] -> DsM [(SrcSpan, Core DecQ)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Name
-> SrcSpan
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_ty_sig Name
sigDName SrcSpan
loc HsImplicitBndrs GhcRn (LHsType GhcRn)
ty) [Located Name]
[Located (IdP GhcRn)]
nms
rep_sig d :: LSig GhcRn
d@(LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (IdSig {}))           = String -> SDoc -> DsM [(SrcSpan, Core DecQ)]
forall a. HasCallStack => String -> SDoc -> a
pprPanic "rep_sig IdSig" (LSig GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr LSig GhcRn
d)
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _   (FixSig {}))          = [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a. Monad m => a -> m a
return [] -- fixity sigs at top level
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (InlineSig _ nm ispec))= Located Name
-> InlinePragma -> SrcSpan -> DsM [(SrcSpan, Core DecQ)]
rep_inline Located Name
Located (IdP GhcRn)
nm InlinePragma
ispec SrcSpan
loc
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (SpecSig _ nm tys ispec))
  = (HsImplicitBndrs GhcRn (LHsType GhcRn)
 -> DsM [(SrcSpan, Core DecQ)])
-> [HsImplicitBndrs GhcRn (LHsType GhcRn)]
-> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (\t :: HsImplicitBndrs GhcRn (LHsType GhcRn)
t -> Located Name
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> InlinePragma
-> SrcSpan
-> DsM [(SrcSpan, Core DecQ)]
rep_specialise Located Name
Located (IdP GhcRn)
nm HsImplicitBndrs GhcRn (LHsType GhcRn)
t InlinePragma
ispec SrcSpan
loc) [HsImplicitBndrs GhcRn (LHsType GhcRn)]
tys
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (SpecInstSig _ _ ty))  = HsImplicitBndrs GhcRn (LHsType GhcRn)
-> SrcSpan -> DsM [(SrcSpan, Core DecQ)]
rep_specialiseInst HsImplicitBndrs GhcRn (LHsType GhcRn)
ty SrcSpan
loc
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _   (MinimalSig {}))       = String -> SDoc -> DsM [(SrcSpan, Core DecQ)]
forall a. String -> SDoc -> DsM a
notHandled "MINIMAL pragmas" SDoc
empty
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _   (SCCFunSig {}))        = String -> SDoc -> DsM [(SrcSpan, Core DecQ)]
forall a. String -> SDoc -> DsM a
notHandled "SCC pragmas" SDoc
empty
rep_sig (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc (CompleteMatchSig _ _st cls mty))
  = Located [Located Name]
-> Maybe (Located Name) -> SrcSpan -> DsM [(SrcSpan, Core DecQ)]
rep_complete_sig Located [Located Name]
Located [Located (IdP GhcRn)]
cls Maybe (Located Name)
Maybe (Located (IdP GhcRn))
mty SrcSpan
loc
rep_sig _ = String -> DsM [(SrcSpan, Core DecQ)]
forall a. String -> a
panic "rep_sig"

rep_ty_sig :: Name -> SrcSpan -> LHsSigType GhcRn -> Located Name
           -> DsM (SrcSpan, Core TH.DecQ)
-- Don't create the implicit and explicit variables when desugaring signatures,
-- see Note [Scoped type variables in class and instance declarations].
-- and Note [Don't quantify implicit type variables in quotes]
rep_ty_sig :: Name
-> SrcSpan
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_ty_sig mk_sig :: Name
mk_sig loc :: SrcSpan
loc sig_ty :: HsImplicitBndrs GhcRn (LHsType GhcRn)
sig_ty nm :: Located Name
nm
  | HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsType GhcRn
hs_ty } <- HsImplicitBndrs GhcRn (LHsType GhcRn)
sig_ty
  , (explicit_tvs :: [LHsTyVarBndr GhcRn]
explicit_tvs, ctxt :: LHsContext GhcRn
ctxt, ty :: LHsType GhcRn
ty) <- LHsType GhcRn
-> ([LHsTyVarBndr GhcRn], LHsContext GhcRn, LHsType GhcRn)
forall pass.
LHsType pass
-> ([LHsTyVarBndr pass], LHsContext pass, LHsType pass)
splitLHsSigmaTy LHsType GhcRn
hs_ty
  = do { Core Name
nm1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
nm
       ; let rep_in_scope_tv :: LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
rep_in_scope_tv tv :: LHsTyVarBndr GhcRn
tv = do { Core Name
name <- Name -> DsM (Core Name)
lookupBinder (LHsTyVarBndr GhcRn -> IdP GhcRn
forall pass. LHsTyVarBndr pass -> IdP pass
hsLTyVarName LHsTyVarBndr GhcRn
tv)
                                     ; LHsTyVarBndr GhcRn -> Core Name -> DsM (Core TyVarBndrQ)
repTyVarBndrWithKind LHsTyVarBndr GhcRn
tv Core Name
name }
       ; Core [TyVarBndrQ]
th_explicit_tvs <- Name
-> (LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ))
-> [LHsTyVarBndr GhcRn]
-> DsM (Core [TyVarBndrQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
tyVarBndrQTyConName LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
rep_in_scope_tv
                                    [LHsTyVarBndr GhcRn]
explicit_tvs

         -- NB: Don't pass any implicit type variables to repList above
         -- See Note [Don't quantify implicit type variables in quotes]

       ; Core CxtQ
th_ctxt <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
ctxt
       ; Core TypeQ
th_ty   <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
       ; Core TypeQ
ty1     <- if [LHsTyVarBndr GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsTyVarBndr GhcRn]
explicit_tvs Bool -> Bool -> Bool
&& [LHsType GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (LHsContext GhcRn -> SrcSpanLess (LHsContext GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsContext GhcRn
ctxt)
                       then Core TypeQ -> DsM (Core TypeQ)
forall (m :: * -> *) a. Monad m => a -> m a
return Core TypeQ
th_ty
                       else Core [TyVarBndrQ] -> Core CxtQ -> Core TypeQ -> DsM (Core TypeQ)
repTForall Core [TyVarBndrQ]
th_explicit_tvs Core CxtQ
th_ctxt Core TypeQ
th_ty
       ; Core DecQ
sig     <- Name -> Core Name -> Core TypeQ -> DsM (Core DecQ)
repProto Name
mk_sig Core Name
nm1 Core TypeQ
ty1
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
sig) }
rep_ty_sig _ _ (XHsImplicitBndrs _) _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "rep_ty_sig"

rep_patsyn_ty_sig :: SrcSpan -> LHsSigType GhcRn -> Located Name
                  -> DsM (SrcSpan, Core TH.DecQ)
-- represents a pattern synonym type signature;
-- see Note [Pattern synonym type signatures and Template Haskell] in Convert
--
-- Don't create the implicit and explicit variables when desugaring signatures,
-- see Note [Scoped type variables in class and instance declarations]
-- and Note [Don't quantify implicit type variables in quotes]
rep_patsyn_ty_sig :: SrcSpan
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_patsyn_ty_sig loc :: SrcSpan
loc sig_ty :: HsImplicitBndrs GhcRn (LHsType GhcRn)
sig_ty nm :: Located Name
nm
  | HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsType GhcRn
hs_ty } <- HsImplicitBndrs GhcRn (LHsType GhcRn)
sig_ty
  , (univs :: [LHsTyVarBndr GhcRn]
univs, reqs :: LHsContext GhcRn
reqs, exis :: [LHsTyVarBndr GhcRn]
exis, provs :: LHsContext GhcRn
provs, ty :: LHsType GhcRn
ty) <- LHsType GhcRn
-> ([LHsTyVarBndr GhcRn], LHsContext GhcRn, [LHsTyVarBndr GhcRn],
    LHsContext GhcRn, LHsType GhcRn)
forall pass.
LHsType pass
-> ([LHsTyVarBndr pass], LHsContext pass, [LHsTyVarBndr pass],
    LHsContext pass, LHsType pass)
splitLHsPatSynTy LHsType GhcRn
hs_ty
  = do { Core Name
nm1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
nm
       ; let rep_in_scope_tv :: LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
rep_in_scope_tv tv :: LHsTyVarBndr GhcRn
tv = do { Core Name
name <- Name -> DsM (Core Name)
lookupBinder (LHsTyVarBndr GhcRn -> IdP GhcRn
forall pass. LHsTyVarBndr pass -> IdP pass
hsLTyVarName LHsTyVarBndr GhcRn
tv)
                                     ; LHsTyVarBndr GhcRn -> Core Name -> DsM (Core TyVarBndrQ)
repTyVarBndrWithKind LHsTyVarBndr GhcRn
tv Core Name
name }
       ; Core [TyVarBndrQ]
th_univs <- Name
-> (LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ))
-> [LHsTyVarBndr GhcRn]
-> DsM (Core [TyVarBndrQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
tyVarBndrQTyConName LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
rep_in_scope_tv [LHsTyVarBndr GhcRn]
univs
       ; Core [TyVarBndrQ]
th_exis  <- Name
-> (LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ))
-> [LHsTyVarBndr GhcRn]
-> DsM (Core [TyVarBndrQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
tyVarBndrQTyConName LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
rep_in_scope_tv [LHsTyVarBndr GhcRn]
exis

         -- NB: Don't pass any implicit type variables to repList above
         -- See Note [Don't quantify implicit type variables in quotes]

       ; Core CxtQ
th_reqs  <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
reqs
       ; Core CxtQ
th_provs <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
provs
       ; Core TypeQ
th_ty    <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
       ; Core TypeQ
ty1      <- Core [TyVarBndrQ] -> Core CxtQ -> Core TypeQ -> DsM (Core TypeQ)
repTForall Core [TyVarBndrQ]
th_univs Core CxtQ
th_reqs (Core TypeQ -> DsM (Core TypeQ))
-> DsM (Core TypeQ) -> DsM (Core TypeQ)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
                       Core [TyVarBndrQ] -> Core CxtQ -> Core TypeQ -> DsM (Core TypeQ)
repTForall Core [TyVarBndrQ]
th_exis Core CxtQ
th_provs Core TypeQ
th_ty
       ; Core DecQ
sig      <- Name -> Core Name -> Core TypeQ -> DsM (Core DecQ)
repProto Name
patSynSigDName Core Name
nm1 Core TypeQ
ty1
       ; (SrcSpan, Core DecQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
loc, Core DecQ
sig) }
rep_patsyn_ty_sig _ (XHsImplicitBndrs _) _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
forall a. String -> a
panic "rep_patsyn_ty_sig"

rep_wc_ty_sig :: Name -> SrcSpan -> LHsSigWcType GhcRn -> Located Name
              -> DsM (SrcSpan, Core TH.DecQ)
rep_wc_ty_sig :: Name
-> SrcSpan
-> HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_wc_ty_sig mk_sig :: Name
mk_sig loc :: SrcSpan
loc sig_ty :: HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
sig_ty nm :: Located Name
nm
  = Name
-> SrcSpan
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> Located Name
-> IOEnv (Env DsGblEnv DsLclEnv) (SrcSpan, Core DecQ)
rep_ty_sig Name
mk_sig SrcSpan
loc (HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
sig_ty) Located Name
nm

rep_inline :: Located Name
           -> InlinePragma      -- Never defaultInlinePragma
           -> SrcSpan
           -> DsM [(SrcSpan, Core TH.DecQ)]
rep_inline :: Located Name
-> InlinePragma -> SrcSpan -> DsM [(SrcSpan, Core DecQ)]
rep_inline nm :: Located Name
nm ispec :: InlinePragma
ispec loc :: SrcSpan
loc
  = do { Core Name
nm1    <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
nm
       ; Core Inline
inline <- InlineSpec -> DsM (Core Inline)
repInline (InlineSpec -> DsM (Core Inline))
-> InlineSpec -> DsM (Core Inline)
forall a b. (a -> b) -> a -> b
$ InlinePragma -> InlineSpec
inl_inline InlinePragma
ispec
       ; Core RuleMatch
rm     <- RuleMatchInfo -> DsM (Core RuleMatch)
repRuleMatch (RuleMatchInfo -> DsM (Core RuleMatch))
-> RuleMatchInfo -> DsM (Core RuleMatch)
forall a b. (a -> b) -> a -> b
$ InlinePragma -> RuleMatchInfo
inl_rule InlinePragma
ispec
       ; Core Phases
phases <- Activation -> DsM (Core Phases)
repPhases (Activation -> DsM (Core Phases))
-> Activation -> DsM (Core Phases)
forall a b. (a -> b) -> a -> b
$ InlinePragma -> Activation
inl_act InlinePragma
ispec
       ; Core DecQ
pragma <- Core Name
-> Core Inline -> Core RuleMatch -> Core Phases -> DsM (Core DecQ)
repPragInl Core Name
nm1 Core Inline
inline Core RuleMatch
rm Core Phases
phases
       ; [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(SrcSpan
loc, Core DecQ
pragma)]
       }

rep_specialise :: Located Name -> LHsSigType GhcRn -> InlinePragma
               -> SrcSpan
               -> DsM [(SrcSpan, Core TH.DecQ)]
rep_specialise :: Located Name
-> HsImplicitBndrs GhcRn (LHsType GhcRn)
-> InlinePragma
-> SrcSpan
-> DsM [(SrcSpan, Core DecQ)]
rep_specialise nm :: Located Name
nm ty :: HsImplicitBndrs GhcRn (LHsType GhcRn)
ty ispec :: InlinePragma
ispec loc :: SrcSpan
loc
  = do { Core Name
nm1 <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
nm
       ; Core TypeQ
ty1 <- HsImplicitBndrs GhcRn (LHsType GhcRn) -> DsM (Core TypeQ)
repHsSigType HsImplicitBndrs GhcRn (LHsType GhcRn)
ty
       ; Core Phases
phases <- Activation -> DsM (Core Phases)
repPhases (Activation -> DsM (Core Phases))
-> Activation -> DsM (Core Phases)
forall a b. (a -> b) -> a -> b
$ InlinePragma -> Activation
inl_act InlinePragma
ispec
       ; let inline :: InlineSpec
inline = InlinePragma -> InlineSpec
inl_inline InlinePragma
ispec
       ; Core DecQ
pragma <- if InlineSpec -> Bool
noUserInlineSpec InlineSpec
inline
                   then -- SPECIALISE
                     Core Name -> Core TypeQ -> Core Phases -> DsM (Core DecQ)
repPragSpec Core Name
nm1 Core TypeQ
ty1 Core Phases
phases
                   else -- SPECIALISE INLINE
                     do { Core Inline
inline1 <- InlineSpec -> DsM (Core Inline)
repInline InlineSpec
inline
                        ; Core Name
-> Core TypeQ -> Core Inline -> Core Phases -> DsM (Core DecQ)
repPragSpecInl Core Name
nm1 Core TypeQ
ty1 Core Inline
inline1 Core Phases
phases }
       ; [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(SrcSpan
loc, Core DecQ
pragma)]
       }

rep_specialiseInst :: LHsSigType GhcRn -> SrcSpan
                   -> DsM [(SrcSpan, Core TH.DecQ)]
rep_specialiseInst :: HsImplicitBndrs GhcRn (LHsType GhcRn)
-> SrcSpan -> DsM [(SrcSpan, Core DecQ)]
rep_specialiseInst ty :: HsImplicitBndrs GhcRn (LHsType GhcRn)
ty loc :: SrcSpan
loc
  = do { Core TypeQ
ty1    <- HsImplicitBndrs GhcRn (LHsType GhcRn) -> DsM (Core TypeQ)
repHsSigType HsImplicitBndrs GhcRn (LHsType GhcRn)
ty
       ; Core DecQ
pragma <- Core TypeQ -> DsM (Core DecQ)
repPragSpecInst Core TypeQ
ty1
       ; [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(SrcSpan
loc, Core DecQ
pragma)] }

repInline :: InlineSpec -> DsM (Core TH.Inline)
repInline :: InlineSpec -> DsM (Core Inline)
repInline NoInline  = Name -> DsM (Core Inline)
forall a. Name -> DsM (Core a)
dataCon Name
noInlineDataConName
repInline Inline    = Name -> DsM (Core Inline)
forall a. Name -> DsM (Core a)
dataCon Name
inlineDataConName
repInline Inlinable = Name -> DsM (Core Inline)
forall a. Name -> DsM (Core a)
dataCon Name
inlinableDataConName
repInline spec :: InlineSpec
spec      = String -> SDoc -> DsM (Core Inline)
forall a. String -> SDoc -> DsM a
notHandled "repInline" (InlineSpec -> SDoc
forall a. Outputable a => a -> SDoc
ppr InlineSpec
spec)

repRuleMatch :: RuleMatchInfo -> DsM (Core TH.RuleMatch)
repRuleMatch :: RuleMatchInfo -> DsM (Core RuleMatch)
repRuleMatch ConLike = Name -> DsM (Core RuleMatch)
forall a. Name -> DsM (Core a)
dataCon Name
conLikeDataConName
repRuleMatch FunLike = Name -> DsM (Core RuleMatch)
forall a. Name -> DsM (Core a)
dataCon Name
funLikeDataConName

repPhases :: Activation -> DsM (Core TH.Phases)
repPhases :: Activation -> DsM (Core Phases)
repPhases (ActiveBefore _ i :: Int
i) = do { MkC arg :: CoreExpr
arg <- Int -> DsM (Core Int)
coreIntLit Int
i
                                  ; Name -> [CoreExpr] -> DsM (Core Phases)
forall a. Name -> [CoreExpr] -> DsM (Core a)
dataCon' Name
beforePhaseDataConName [CoreExpr
arg] }
repPhases (ActiveAfter _ i :: Int
i)  = do { MkC arg :: CoreExpr
arg <- Int -> DsM (Core Int)
coreIntLit Int
i
                                  ; Name -> [CoreExpr] -> DsM (Core Phases)
forall a. Name -> [CoreExpr] -> DsM (Core a)
dataCon' Name
fromPhaseDataConName [CoreExpr
arg] }
repPhases _                  = Name -> DsM (Core Phases)
forall a. Name -> DsM (Core a)
dataCon Name
allPhasesDataConName

rep_complete_sig :: Located [Located Name]
                 -> Maybe (Located Name)
                 -> SrcSpan
                 -> DsM [(SrcSpan, Core TH.DecQ)]
rep_complete_sig :: Located [Located Name]
-> Maybe (Located Name) -> SrcSpan -> DsM [(SrcSpan, Core DecQ)]
rep_complete_sig (Located [Located Name]
-> Located (SrcSpanLess (Located [Located Name]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ cls :: SrcSpanLess (Located [Located Name])
cls) mty :: Maybe (Located Name)
mty loc :: SrcSpan
loc
  = do { Core (Maybe Name)
mty' <- Name
-> (Located Name -> DsM (Core Name))
-> Maybe (Located Name)
-> DsM (Core (Maybe Name))
forall a b.
Name -> (a -> DsM (Core b)) -> Maybe a -> DsM (Core (Maybe b))
repMaybe Name
nameTyConName Located Name -> DsM (Core Name)
lookupLOcc Maybe (Located Name)
mty
       ; Core [Name]
cls' <- Name
-> (Located Name -> DsM (Core Name))
-> [Located Name]
-> DsM (Core [Name])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
nameTyConName Located Name -> DsM (Core Name)
lookupLOcc [Located Name]
SrcSpanLess (Located [Located Name])
cls
       ; Core DecQ
sig <- Core [Name] -> Core (Maybe Name) -> DsM (Core DecQ)
repPragComplete Core [Name]
cls' Core (Maybe Name)
mty'
       ; [(SrcSpan, Core DecQ)] -> DsM [(SrcSpan, Core DecQ)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(SrcSpan
loc, Core DecQ
sig)] }

-------------------------------------------------------
--                      Types
-------------------------------------------------------

addSimpleTyVarBinds :: [Name]                -- the binders to be added
                    -> DsM (Core (TH.Q a))   -- action in the ext env
                    -> DsM (Core (TH.Q a))
addSimpleTyVarBinds :: [Name] -> DsM (Core (Q a)) -> DsM (Core (Q a))
addSimpleTyVarBinds names :: [Name]
names thing_inside :: DsM (Core (Q a))
thing_inside
  = do { [GenSymBind]
fresh_names <- [Name] -> DsM [GenSymBind]
mkGenSyms [Name]
names
       ; Core (Q a)
term <- [GenSymBind] -> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
fresh_names DsM (Core (Q a))
thing_inside
       ; [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
fresh_names Core (Q a)
term }

addHsTyVarBinds :: [LHsTyVarBndr GhcRn]  -- the binders to be added
                -> (Core [TH.TyVarBndrQ] -> DsM (Core (TH.Q a)))  -- action in the ext env
                -> DsM (Core (TH.Q a))
addHsTyVarBinds :: [LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addHsTyVarBinds exp_tvs :: [LHsTyVarBndr GhcRn]
exp_tvs thing_inside :: Core [TyVarBndrQ] -> DsM (Core (Q a))
thing_inside
  = do { [GenSymBind]
fresh_exp_names <- [Name] -> DsM [GenSymBind]
mkGenSyms ((LHsTyVarBndr GhcRn -> Name) -> [LHsTyVarBndr GhcRn] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LHsTyVarBndr GhcRn -> Name
forall pass. LHsTyVarBndr pass -> IdP pass
hsLTyVarName [LHsTyVarBndr GhcRn]
exp_tvs)
       ; Core (Q a)
term <- [GenSymBind] -> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
fresh_exp_names (DsM (Core (Q a)) -> DsM (Core (Q a)))
-> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a b. (a -> b) -> a -> b
$
                 do { Core [TyVarBndrQ]
kbs <- Name
-> ((LHsTyVarBndr GhcRn, GenSymBind) -> DsM (Core TyVarBndrQ))
-> [(LHsTyVarBndr GhcRn, GenSymBind)]
-> DsM (Core [TyVarBndrQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
tyVarBndrQTyConName (LHsTyVarBndr GhcRn, GenSymBind) -> DsM (Core TyVarBndrQ)
forall a. (LHsTyVarBndr GhcRn, (a, Id)) -> DsM (Core TyVarBndrQ)
mk_tv_bndr
                                     ([LHsTyVarBndr GhcRn]
exp_tvs [LHsTyVarBndr GhcRn]
-> [GenSymBind] -> [(LHsTyVarBndr GhcRn, GenSymBind)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [GenSymBind]
fresh_exp_names)
                    ; Core [TyVarBndrQ] -> DsM (Core (Q a))
thing_inside Core [TyVarBndrQ]
kbs }
       ; [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
fresh_exp_names Core (Q a)
term }
  where
    mk_tv_bndr :: (LHsTyVarBndr GhcRn, (a, Id)) -> DsM (Core TyVarBndrQ)
mk_tv_bndr (tv :: LHsTyVarBndr GhcRn
tv, (_,v :: Id
v)) = LHsTyVarBndr GhcRn -> Core Name -> DsM (Core TyVarBndrQ)
repTyVarBndrWithKind LHsTyVarBndr GhcRn
tv (Id -> Core Name
coreVar Id
v)

addTyVarBinds :: LHsQTyVars GhcRn                    -- the binders to be added
              -> (Core [TH.TyVarBndrQ] -> DsM (Core (TH.Q a)))  -- action in the ext env
              -> DsM (Core (TH.Q a))
-- gensym a list of type variables and enter them into the meta environment;
-- the computations passed as the second argument is executed in that extended
-- meta environment and gets the *new* names on Core-level as an argument
addTyVarBinds :: LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyVarBinds (HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = HsQTvsRn { hsq_implicit = imp_tvs}
                      , hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr pass]
hsq_explicit = [LHsTyVarBndr GhcRn]
exp_tvs })
              thing_inside :: Core [TyVarBndrQ] -> DsM (Core (Q a))
thing_inside
  = [Name] -> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a. [Name] -> DsM (Core (Q a)) -> DsM (Core (Q a))
addSimpleTyVarBinds [Name]
imp_tvs (DsM (Core (Q a)) -> DsM (Core (Q a)))
-> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a b. (a -> b) -> a -> b
$
    [LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
forall a.
[LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addHsTyVarBinds [LHsTyVarBndr GhcRn]
exp_tvs ((Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a)))
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
forall a b. (a -> b) -> a -> b
$
    Core [TyVarBndrQ] -> DsM (Core (Q a))
thing_inside
addTyVarBinds (XLHsQTyVars _) _ = String -> DsM (Core (Q a))
forall a. String -> a
panic "addTyVarBinds"

addTyClTyVarBinds :: LHsQTyVars GhcRn
                  -> (Core [TH.TyVarBndrQ] -> DsM (Core (TH.Q a)))
                  -> DsM (Core (TH.Q a))

-- Used for data/newtype declarations, and family instances,
-- so that the nested type variables work right
--    instance C (T a) where
--      type W (T a) = blah
-- The 'a' in the type instance is the one bound by the instance decl
addTyClTyVarBinds :: LHsQTyVars GhcRn
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addTyClTyVarBinds tvs :: LHsQTyVars GhcRn
tvs m :: Core [TyVarBndrQ] -> DsM (Core (Q a))
m
  = do { let tv_names :: [Name]
tv_names = LHsQTyVars GhcRn -> [Name]
hsAllLTyVarNames LHsQTyVars GhcRn
tvs
       ; DsMetaEnv
env <- DsM DsMetaEnv
dsGetMetaEnv
       ; [GenSymBind]
freshNames <- [Name] -> DsM [GenSymBind]
mkGenSyms ((Name -> Bool) -> [Name] -> [Name]
forall a. (a -> Bool) -> [a] -> [a]
filterOut (Name -> DsMetaEnv -> Bool
forall a. Name -> NameEnv a -> Bool
`elemNameEnv` DsMetaEnv
env) [Name]
tv_names)
            -- Make fresh names for the ones that are not already in scope
            -- This makes things work for family declarations

       ; Core (Q a)
term <- [GenSymBind] -> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
freshNames (DsM (Core (Q a)) -> DsM (Core (Q a)))
-> DsM (Core (Q a)) -> DsM (Core (Q a))
forall a b. (a -> b) -> a -> b
$
                 do { Core [TyVarBndrQ]
kbs <- Name
-> (LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ))
-> [LHsTyVarBndr GhcRn]
-> DsM (Core [TyVarBndrQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
tyVarBndrQTyConName LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
mk_tv_bndr
                                     (LHsQTyVars GhcRn -> [LHsTyVarBndr GhcRn]
forall pass. LHsQTyVars pass -> [LHsTyVarBndr pass]
hsQTvExplicit LHsQTyVars GhcRn
tvs)
                    ; Core [TyVarBndrQ] -> DsM (Core (Q a))
m Core [TyVarBndrQ]
kbs }

       ; [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
freshNames Core (Q a)
term }
  where
    mk_tv_bndr :: LHsTyVarBndr GhcRn -> DsM (Core TH.TyVarBndrQ)
    mk_tv_bndr :: LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
mk_tv_bndr tv :: LHsTyVarBndr GhcRn
tv = do { Core Name
v <- Name -> DsM (Core Name)
lookupBinder (LHsTyVarBndr GhcRn -> IdP GhcRn
forall pass. LHsTyVarBndr pass -> IdP pass
hsLTyVarName LHsTyVarBndr GhcRn
tv)
                       ; LHsTyVarBndr GhcRn -> Core Name -> DsM (Core TyVarBndrQ)
repTyVarBndrWithKind LHsTyVarBndr GhcRn
tv Core Name
v }

-- Produce kinded binder constructors from the Haskell tyvar binders
--
repTyVarBndrWithKind :: LHsTyVarBndr GhcRn
                     -> Core TH.Name -> DsM (Core TH.TyVarBndrQ)
repTyVarBndrWithKind :: LHsTyVarBndr GhcRn -> Core Name -> DsM (Core TyVarBndrQ)
repTyVarBndrWithKind (LHsTyVarBndr GhcRn -> Located (SrcSpanLess (LHsTyVarBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (UserTyVar _ _)) nm :: Core Name
nm
  = Core Name -> DsM (Core TyVarBndrQ)
repPlainTV Core Name
nm
repTyVarBndrWithKind (LHsTyVarBndr GhcRn -> Located (SrcSpanLess (LHsTyVarBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (KindedTyVar _ _ ki)) nm :: Core Name
nm
  = LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ki DsM (Core TypeQ)
-> (Core TypeQ -> DsM (Core TyVarBndrQ)) -> DsM (Core TyVarBndrQ)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Core Name -> Core TypeQ -> DsM (Core TyVarBndrQ)
repKindedTV Core Name
nm
repTyVarBndrWithKind _ _ = String -> DsM (Core TyVarBndrQ)
forall a. String -> a
panic "repTyVarBndrWithKind"

-- | Represent a type variable binder
repTyVarBndr :: LHsTyVarBndr GhcRn -> DsM (Core TH.TyVarBndrQ)
repTyVarBndr :: LHsTyVarBndr GhcRn -> DsM (Core TyVarBndrQ)
repTyVarBndr (LHsTyVarBndr GhcRn -> Located (SrcSpanLess (LHsTyVarBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (UserTyVar _ (dL->L _ nm)) )
  = do { Core Name
nm' <- Name -> DsM (Core Name)
lookupBinder Name
SrcSpanLess (Located Name)
nm
       ; Core Name -> DsM (Core TyVarBndrQ)
repPlainTV Core Name
nm' }
repTyVarBndr (LHsTyVarBndr GhcRn -> Located (SrcSpanLess (LHsTyVarBndr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (KindedTyVar _ (dL->L _ nm) ki))
  = do { Core Name
nm' <- Name -> DsM (Core Name)
lookupBinder Name
SrcSpanLess (Located Name)
nm
       ; Core TypeQ
ki' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ki
       ; Core Name -> Core TypeQ -> DsM (Core TyVarBndrQ)
repKindedTV Core Name
nm' Core TypeQ
ki' }
repTyVarBndr _ = String -> DsM (Core TyVarBndrQ)
forall a. String -> a
panic "repTyVarBndr"

-- represent a type context
--
repLContext :: LHsContext GhcRn -> DsM (Core TH.CxtQ)
repLContext :: LHsContext GhcRn -> DsM (Core CxtQ)
repLContext ctxt :: LHsContext GhcRn
ctxt = [LHsType GhcRn] -> DsM (Core CxtQ)
repContext (LHsContext GhcRn -> SrcSpanLess (LHsContext GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsContext GhcRn
ctxt)

repContext :: HsContext GhcRn -> DsM (Core TH.CxtQ)
repContext :: [LHsType GhcRn] -> DsM (Core CxtQ)
repContext ctxt :: [LHsType GhcRn]
ctxt = do Core [TypeQ]
preds <- Name
-> (LHsType GhcRn -> DsM (Core TypeQ))
-> [LHsType GhcRn]
-> DsM (Core [TypeQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
typeQTyConName LHsType GhcRn -> DsM (Core TypeQ)
repLTy [LHsType GhcRn]
ctxt
                     Core [TypeQ] -> DsM (Core CxtQ)
repCtxt Core [TypeQ]
preds

repHsSigType :: LHsSigType GhcRn -> DsM (Core TH.TypeQ)
repHsSigType :: HsImplicitBndrs GhcRn (LHsType GhcRn) -> DsM (Core TypeQ)
repHsSigType (HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (LHsType GhcRn)
implicit_tvs
                   , hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsType GhcRn
body })
  | (explicit_tvs :: [LHsTyVarBndr GhcRn]
explicit_tvs, ctxt :: LHsContext GhcRn
ctxt, ty :: LHsType GhcRn
ty) <- LHsType GhcRn
-> ([LHsTyVarBndr GhcRn], LHsContext GhcRn, LHsType GhcRn)
forall pass.
LHsType pass
-> ([LHsTyVarBndr pass], LHsContext pass, LHsType pass)
splitLHsSigmaTy LHsType GhcRn
body
  = [Name] -> DsM (Core TypeQ) -> DsM (Core TypeQ)
forall a. [Name] -> DsM (Core (Q a)) -> DsM (Core (Q a))
addSimpleTyVarBinds [Name]
XHsIB GhcRn (LHsType GhcRn)
implicit_tvs (DsM (Core TypeQ) -> DsM (Core TypeQ))
-> DsM (Core TypeQ) -> DsM (Core TypeQ)
forall a b. (a -> b) -> a -> b
$
      -- See Note [Don't quantify implicit type variables in quotes]
    [LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core TypeQ)) -> DsM (Core TypeQ)
forall a.
[LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addHsTyVarBinds [LHsTyVarBndr GhcRn]
explicit_tvs ((Core [TyVarBndrQ] -> DsM (Core TypeQ)) -> DsM (Core TypeQ))
-> (Core [TyVarBndrQ] -> DsM (Core TypeQ)) -> DsM (Core TypeQ)
forall a b. (a -> b) -> a -> b
$ \ th_explicit_tvs :: Core [TyVarBndrQ]
th_explicit_tvs ->
    do { Core CxtQ
th_ctxt <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
ctxt
       ; Core TypeQ
th_ty   <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
       ; if [LHsTyVarBndr GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsTyVarBndr GhcRn]
explicit_tvs Bool -> Bool -> Bool
&& [LHsType GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (LHsContext GhcRn -> SrcSpanLess (LHsContext GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsContext GhcRn
ctxt)
         then Core TypeQ -> DsM (Core TypeQ)
forall (m :: * -> *) a. Monad m => a -> m a
return Core TypeQ
th_ty
         else Core [TyVarBndrQ] -> Core CxtQ -> Core TypeQ -> DsM (Core TypeQ)
repTForall Core [TyVarBndrQ]
th_explicit_tvs Core CxtQ
th_ctxt Core TypeQ
th_ty }
repHsSigType (XHsImplicitBndrs _) = String -> DsM (Core TypeQ)
forall a. String -> a
panic "repHsSigType"

repHsSigWcType :: LHsSigWcType GhcRn -> DsM (Core TH.TypeQ)
repHsSigWcType :: HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> DsM (Core TypeQ)
repHsSigWcType (HsWC { hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = HsImplicitBndrs GhcRn (LHsType GhcRn)
sig1 })
  = HsImplicitBndrs GhcRn (LHsType GhcRn) -> DsM (Core TypeQ)
repHsSigType HsImplicitBndrs GhcRn (LHsType GhcRn)
sig1
repHsSigWcType (XHsWildCardBndrs _) = String -> DsM (Core TypeQ)
forall a. String -> a
panic "repHsSigWcType"

-- yield the representation of a list of types
repLTys :: [LHsType GhcRn] -> DsM [Core TH.TypeQ]
repLTys :: [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys tys :: [LHsType GhcRn]
tys = (LHsType GhcRn -> DsM (Core TypeQ))
-> [LHsType GhcRn] -> DsM [Core TypeQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LHsType GhcRn -> DsM (Core TypeQ)
repLTy [LHsType GhcRn]
tys

-- represent a type
repLTy :: LHsType GhcRn -> DsM (Core TH.TypeQ)
repLTy :: LHsType GhcRn -> DsM (Core TypeQ)
repLTy ty :: LHsType GhcRn
ty = HsType GhcRn -> DsM (Core TypeQ)
repTy (LHsType GhcRn -> SrcSpanLess (LHsType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsType GhcRn
ty)

repForall :: HsType GhcRn -> DsM (Core TH.TypeQ)
-- Arg of repForall is always HsForAllTy or HsQualTy
repForall :: HsType GhcRn -> DsM (Core TypeQ)
repForall ty :: HsType GhcRn
ty
 | (tvs :: [LHsTyVarBndr GhcRn]
tvs, ctxt :: LHsContext GhcRn
ctxt, tau :: LHsType GhcRn
tau) <- LHsType GhcRn
-> ([LHsTyVarBndr GhcRn], LHsContext GhcRn, LHsType GhcRn)
forall pass.
LHsType pass
-> ([LHsTyVarBndr pass], LHsContext pass, LHsType pass)
splitLHsSigmaTy (SrcSpanLess (LHsType GhcRn) -> LHsType GhcRn
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (LHsType GhcRn)
HsType GhcRn
ty)
 = [LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core TypeQ)) -> DsM (Core TypeQ)
forall a.
[LHsTyVarBndr GhcRn]
-> (Core [TyVarBndrQ] -> DsM (Core (Q a))) -> DsM (Core (Q a))
addHsTyVarBinds [LHsTyVarBndr GhcRn]
tvs ((Core [TyVarBndrQ] -> DsM (Core TypeQ)) -> DsM (Core TypeQ))
-> (Core [TyVarBndrQ] -> DsM (Core TypeQ)) -> DsM (Core TypeQ)
forall a b. (a -> b) -> a -> b
$ \bndrs :: Core [TyVarBndrQ]
bndrs ->
   do { Core CxtQ
ctxt1  <- LHsContext GhcRn -> DsM (Core CxtQ)
repLContext LHsContext GhcRn
ctxt
      ; Core TypeQ
ty1    <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
tau
      ; Core [TyVarBndrQ] -> Core CxtQ -> Core TypeQ -> DsM (Core TypeQ)
repTForall Core [TyVarBndrQ]
bndrs Core CxtQ
ctxt1 Core TypeQ
ty1 }

repTy :: HsType GhcRn -> DsM (Core TH.TypeQ)
repTy :: HsType GhcRn -> DsM (Core TypeQ)
repTy ty :: HsType GhcRn
ty@(HsForAllTy {}) = HsType GhcRn -> DsM (Core TypeQ)
repForall HsType GhcRn
ty
repTy ty :: HsType GhcRn
ty@(HsQualTy {})   = HsType GhcRn -> DsM (Core TypeQ)
repForall HsType GhcRn
ty

repTy (HsTyVar _ _ (Located (IdP GhcRn) -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ n :: SrcSpanLess (Located Name)
n))
  | Name -> Bool
isLiftedTypeKindTyConName Name
SrcSpanLess (Located Name)
n       = DsM (Core TypeQ)
repTStar
  | Name
SrcSpanLess (Located Name)
n Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
constraintKindTyConKey = DsM (Core TypeQ)
repTConstraint
  | Name
SrcSpanLess (Located Name)
n Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
funTyConKey            = DsM (Core TypeQ)
repArrowTyCon
  | OccName -> Bool
isTvOcc OccName
occ   = do Core Name
tv1 <- Name -> DsM (Core Name)
lookupOcc Name
SrcSpanLess (Located Name)
n
                       Core Name -> DsM (Core TypeQ)
repTvar Core Name
tv1
  | OccName -> Bool
isDataOcc OccName
occ = do Core Name
tc1 <- Name -> DsM (Core Name)
lookupOcc Name
SrcSpanLess (Located Name)
n
                       Core Name -> DsM (Core TypeQ)
repPromotedDataCon Core Name
tc1
  | Name
SrcSpanLess (Located Name)
n Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
eqTyConName = DsM (Core TypeQ)
repTequality
  | Bool
otherwise     = do Core Name
tc1 <- Name -> DsM (Core Name)
lookupOcc Name
SrcSpanLess (Located Name)
n
                       Core Name -> DsM (Core TypeQ)
repNamedTyCon Core Name
tc1
  where
    occ :: OccName
occ = Name -> OccName
nameOccName Name
SrcSpanLess (Located Name)
n

repTy (HsAppTy _ f :: LHsType GhcRn
f a :: LHsType GhcRn
a)       = do
                                Core TypeQ
f1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
f
                                Core TypeQ
a1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
a
                                Core TypeQ -> Core TypeQ -> DsM (Core TypeQ)
repTapp Core TypeQ
f1 Core TypeQ
a1
repTy (HsAppKindTy _ ty :: LHsType GhcRn
ty ki :: LHsType GhcRn
ki) = do
                                Core TypeQ
ty1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ty
                                Core TypeQ
ki1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
ki
                                Core TypeQ -> Core TypeQ -> DsM (Core TypeQ)
repTappKind Core TypeQ
ty1 Core TypeQ
ki1
repTy (HsFunTy _ f :: LHsType GhcRn
f a :: LHsType GhcRn
a)       = do
                                Core TypeQ
f1   <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
f
                                Core TypeQ
a1   <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
a
                                Core TypeQ
tcon <- DsM (Core TypeQ)
repArrowTyCon
                                Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
tcon [Core TypeQ
f1, Core TypeQ
a1]
repTy (HsListTy _ t :: LHsType GhcRn
t)        = do
                                Core TypeQ
t1   <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t
                                Core TypeQ
tcon <- DsM (Core TypeQ)
repListTyCon
                                Core TypeQ -> Core TypeQ -> DsM (Core TypeQ)
repTapp Core TypeQ
tcon Core TypeQ
t1
repTy (HsTupleTy _ HsUnboxedTuple tys :: [LHsType GhcRn]
tys) = do
                                [Core TypeQ]
tys1 <- [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys [LHsType GhcRn]
tys
                                Core TypeQ
tcon <- Int -> DsM (Core TypeQ)
repUnboxedTupleTyCon ([LHsType GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
tys)
                                Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
tcon [Core TypeQ]
tys1
repTy (HsTupleTy _ _ tys :: [LHsType GhcRn]
tys)   = do [Core TypeQ]
tys1 <- [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys [LHsType GhcRn]
tys
                                 Core TypeQ
tcon <- Int -> DsM (Core TypeQ)
repTupleTyCon ([LHsType GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
tys)
                                 Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
tcon [Core TypeQ]
tys1
repTy (HsSumTy _ tys :: [LHsType GhcRn]
tys)       = do [Core TypeQ]
tys1 <- [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys [LHsType GhcRn]
tys
                                 Core TypeQ
tcon <- Int -> DsM (Core TypeQ)
repUnboxedSumTyCon ([LHsType GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
tys)
                                 Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
tcon [Core TypeQ]
tys1
repTy (HsOpTy _ ty1 :: LHsType GhcRn
ty1 n :: Located (IdP GhcRn)
n ty2 :: LHsType GhcRn
ty2)  = LHsType GhcRn -> DsM (Core TypeQ)
repLTy ((IdP GhcRn -> LHsType GhcRn
forall (p :: Pass). IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar (Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
Located (IdP GhcRn)
n) LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
`nlHsAppTy` LHsType GhcRn
ty1)
                                   LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
`nlHsAppTy` LHsType GhcRn
ty2)
repTy (HsParTy _ t :: LHsType GhcRn
t)         = LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t
repTy (HsStarTy _ _) =  DsM (Core TypeQ)
repTStar
repTy (HsKindSig _ t :: LHsType GhcRn
t k :: LHsType GhcRn
k)     = do
                                Core TypeQ
t1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t
                                Core TypeQ
k1 <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
k
                                Core TypeQ -> Core TypeQ -> DsM (Core TypeQ)
repTSig Core TypeQ
t1 Core TypeQ
k1
repTy (HsSpliceTy _ splice :: HsSplice GhcRn
splice)      = HsSplice GhcRn -> DsM (Core TypeQ)
forall a. HsSplice GhcRn -> DsM (Core a)
repSplice HsSplice GhcRn
splice
repTy (HsExplicitListTy _ _ tys :: [LHsType GhcRn]
tys) = do
                                    [Core TypeQ]
tys1 <- [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys [LHsType GhcRn]
tys
                                    [Core TypeQ] -> DsM (Core TypeQ)
repTPromotedList [Core TypeQ]
tys1
repTy (HsExplicitTupleTy _ tys :: [LHsType GhcRn]
tys) = do
                                    [Core TypeQ]
tys1 <- [LHsType GhcRn] -> DsM [Core TypeQ]
repLTys [LHsType GhcRn]
tys
                                    Core TypeQ
tcon <- Int -> DsM (Core TypeQ)
repPromotedTupleTyCon ([LHsType GhcRn] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
tys)
                                    Core TypeQ -> [Core TypeQ] -> DsM (Core TypeQ)
repTapps Core TypeQ
tcon [Core TypeQ]
tys1
repTy (HsTyLit _ lit :: HsTyLit
lit) = do
                          Core TyLitQ
lit' <- HsTyLit -> DsM (Core TyLitQ)
repTyLit HsTyLit
lit
                          Core TyLitQ -> DsM (Core TypeQ)
repTLit Core TyLitQ
lit'
repTy (HsWildCardTy _) = DsM (Core TypeQ)
repTWildCard
repTy (HsIParamTy _ n :: Located HsIPName
n t :: LHsType GhcRn
t) = do
                             Core String
n' <- HsIPName -> DsM (Core String)
rep_implicit_param_name (Located HsIPName -> SrcSpanLess (Located HsIPName)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located HsIPName
n)
                             Core TypeQ
t' <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy LHsType GhcRn
t
                             Core String -> Core TypeQ -> DsM (Core TypeQ)
repTImplicitParam Core String
n' Core TypeQ
t'

repTy ty :: HsType GhcRn
ty                      = String -> SDoc -> DsM (Core TypeQ)
forall a. String -> SDoc -> DsM a
notHandled "Exotic form of type" (HsType GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsType GhcRn
ty)

repTyLit :: HsTyLit -> DsM (Core TH.TyLitQ)
repTyLit :: HsTyLit -> DsM (Core TyLitQ)
repTyLit (HsNumTy _ i :: Integer
i) = do CoreExpr
iExpr <- Integer -> DsM CoreExpr
forall (m :: * -> *). MonadThings m => Integer -> m CoreExpr
mkIntegerExpr Integer
i
                            Name -> [CoreExpr] -> DsM (Core TyLitQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
numTyLitName [CoreExpr
iExpr]
repTyLit (HsStrTy _ s :: CLabelString
s) = do { CoreExpr
s' <- CLabelString -> DsM CoreExpr
forall (m :: * -> *). MonadThings m => CLabelString -> m CoreExpr
mkStringExprFS CLabelString
s
                            ; Name -> [CoreExpr] -> DsM (Core TyLitQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
strTyLitName [CoreExpr
s']
                            }

-- | Represent a type wrapped in a Maybe
repMaybeLTy :: Maybe (LHsKind GhcRn)
            -> DsM (Core (Maybe TH.TypeQ))
repMaybeLTy :: Maybe (LHsType GhcRn) -> DsM (Core (Maybe TypeQ))
repMaybeLTy = Name
-> (LHsType GhcRn -> DsM (Core TypeQ))
-> Maybe (LHsType GhcRn)
-> DsM (Core (Maybe TypeQ))
forall a b.
Name -> (a -> DsM (Core b)) -> Maybe a -> DsM (Core (Maybe b))
repMaybe Name
kindQTyConName LHsType GhcRn -> DsM (Core TypeQ)
repLTy

repRole :: Located (Maybe Role) -> DsM (Core TH.Role)
repRole :: Located (Maybe Role) -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
repRole (Located (Maybe Role)
-> Located (SrcSpanLess (Located (Maybe Role)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Just Nominal))          = Name -> [CoreExpr] -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
nominalRName []
repRole (Located (Maybe Role)
-> Located (SrcSpanLess (Located (Maybe Role)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Just Representational)) = Name -> [CoreExpr] -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
representationalRName []
repRole (Located (Maybe Role)
-> Located (SrcSpanLess (Located (Maybe Role)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Just Phantom))          = Name -> [CoreExpr] -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
phantomRName []
repRole (Located (Maybe Role)
-> Located (SrcSpanLess (Located (Maybe Role)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ Nothing)                 = Name -> [CoreExpr] -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
inferRName []
repRole _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (Core Role)
forall a. String -> a
panic "repRole: Impossible Match" -- due to #15884

-----------------------------------------------------------------------------
--              Splices
-----------------------------------------------------------------------------

repSplice :: HsSplice GhcRn -> DsM (Core a)
-- See Note [How brackets and nested splices are handled] in TcSplice
-- We return a CoreExpr of any old type; the context should know
repSplice :: HsSplice GhcRn -> DsM (Core a)
repSplice (HsTypedSplice   _ _ n :: IdP GhcRn
n _) = Name -> DsM (Core a)
forall a. Name -> DsM (Core a)
rep_splice Name
IdP GhcRn
n
repSplice (HsUntypedSplice _ _ n :: IdP GhcRn
n _) = Name -> DsM (Core a)
forall a. Name -> DsM (Core a)
rep_splice Name
IdP GhcRn
n
repSplice (HsQuasiQuote _ n :: IdP GhcRn
n _ _ _)  = Name -> DsM (Core a)
forall a. Name -> DsM (Core a)
rep_splice Name
IdP GhcRn
n
repSplice e :: HsSplice GhcRn
e@(HsSpliced {})          = String -> SDoc -> DsM (Core a)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "repSplice" (HsSplice GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsSplice GhcRn
e)
repSplice e :: HsSplice GhcRn
e@(HsSplicedT {})         = String -> SDoc -> DsM (Core a)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "repSpliceT" (HsSplice GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsSplice GhcRn
e)
repSplice e :: HsSplice GhcRn
e@(XSplice {})            = String -> SDoc -> DsM (Core a)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "repSplice" (HsSplice GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsSplice GhcRn
e)

rep_splice :: Name -> DsM (Core a)
rep_splice :: Name -> DsM (Core a)
rep_splice splice_name :: Name
splice_name
 = do { Maybe DsMetaVal
mb_val <- Name -> DsM (Maybe DsMetaVal)
dsLookupMetaEnv Name
splice_name
       ; case Maybe DsMetaVal
mb_val of
           Just (DsSplice e :: HsExpr GhcTc
e) -> do { CoreExpr
e' <- HsExpr GhcTc -> DsM CoreExpr
dsExpr HsExpr GhcTc
e
                                   ; Core a -> DsM (Core a)
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> Core a
forall a. CoreExpr -> Core a
MkC CoreExpr
e') }
           _ -> String -> SDoc -> DsM (Core a)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "HsSplice" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
splice_name) }
                        -- Should not happen; statically checked

-----------------------------------------------------------------------------
--              Expressions
-----------------------------------------------------------------------------

repLEs :: [LHsExpr GhcRn] -> DsM (Core [TH.ExpQ])
repLEs :: [LHsExpr GhcRn] -> DsM (Core [ExpQ])
repLEs es :: [LHsExpr GhcRn]
es = Name
-> (LHsExpr GhcRn -> DsM (Core ExpQ))
-> [LHsExpr GhcRn]
-> DsM (Core [ExpQ])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
expQTyConName LHsExpr GhcRn -> DsM (Core ExpQ)
repLE [LHsExpr GhcRn]
es

-- FIXME: some of these panics should be converted into proper error messages
--        unless we can make sure that constructs, which are plainly not
--        supported in TH already lead to error messages at an earlier stage
repLE :: LHsExpr GhcRn -> DsM (Core TH.ExpQ)
repLE :: LHsExpr GhcRn -> DsM (Core ExpQ)
repLE (LHsExpr GhcRn -> Located (SrcSpanLess (LHsExpr GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc e :: SrcSpanLess (LHsExpr GhcRn)
e) = SrcSpan -> DsM (Core ExpQ) -> DsM (Core ExpQ)
forall a. SrcSpan -> DsM a -> DsM a
putSrcSpanDs SrcSpan
loc (HsExpr GhcRn -> DsM (Core ExpQ)
repE SrcSpanLess (LHsExpr GhcRn)
HsExpr GhcRn
e)

repE :: HsExpr GhcRn -> DsM (Core TH.ExpQ)
repE :: HsExpr GhcRn -> DsM (Core ExpQ)
repE (HsVar _ (Located (IdP GhcRn) -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ x :: SrcSpanLess (Located Name)
x)) =
  do { Maybe DsMetaVal
mb_val <- Name -> DsM (Maybe DsMetaVal)
dsLookupMetaEnv Name
SrcSpanLess (Located Name)
x
     ; case Maybe DsMetaVal
mb_val of
        Nothing            -> do { Core Name
str <- Name -> DsM (Core Name)
globalVar Name
SrcSpanLess (Located Name)
x
                                 ; Name -> Core Name -> DsM (Core ExpQ)
repVarOrCon Name
SrcSpanLess (Located Name)
x Core Name
str }
        Just (DsBound y :: Id
y)   -> Name -> Core Name -> DsM (Core ExpQ)
repVarOrCon Name
SrcSpanLess (Located Name)
x (Id -> Core Name
coreVar Id
y)
        Just (DsSplice e :: HsExpr GhcTc
e)  -> do { CoreExpr
e' <- HsExpr GhcTc -> DsM CoreExpr
dsExpr HsExpr GhcTc
e
                                 ; Core ExpQ -> DsM (Core ExpQ)
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> Core ExpQ
forall a. CoreExpr -> Core a
MkC CoreExpr
e') } }
repE (HsIPVar _ n :: HsIPName
n) = HsIPName -> DsM (Core String)
rep_implicit_param_name HsIPName
n DsM (Core String)
-> (Core String -> DsM (Core ExpQ)) -> DsM (Core ExpQ)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Core String -> DsM (Core ExpQ)
repImplicitParamVar
repE (HsOverLabel _ _ s :: CLabelString
s) = CLabelString -> DsM (Core ExpQ)
repOverLabel CLabelString
s

repE e :: HsExpr GhcRn
e@(HsRecFld _ f :: AmbiguousFieldOcc GhcRn
f) = case AmbiguousFieldOcc GhcRn
f of
  Unambiguous x :: XUnambiguous GhcRn
x _ -> HsExpr GhcRn -> DsM (Core ExpQ)
repE (XVar GhcRn -> Located (IdP GhcRn) -> HsExpr GhcRn
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar XVar GhcRn
NoExt
noExt (SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located Name)
XUnambiguous GhcRn
x))
  Ambiguous{}     -> String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "Ambiguous record selectors" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)
  XAmbiguousFieldOcc{} -> String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "XAmbiguous record selectors" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)

        -- Remember, we're desugaring renamer output here, so
        -- HsOverlit can definitely occur
repE (HsOverLit _ l :: HsOverLit GhcRn
l) = do { Core Lit
a <- HsOverLit GhcRn -> DsM (Core Lit)
repOverloadedLiteral HsOverLit GhcRn
l; Core Lit -> DsM (Core ExpQ)
repLit Core Lit
a }
repE (HsLit _ l :: HsLit GhcRn
l)     = do { Core Lit
a <- HsLit GhcRn -> DsM (Core Lit)
repLiteral HsLit GhcRn
l;           Core Lit -> DsM (Core ExpQ)
repLit Core Lit
a }
repE (HsLam _ (MG { mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = (Located [LMatch GhcRn (LHsExpr GhcRn)]
-> Located (SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ [m]) })) = LMatch GhcRn (LHsExpr GhcRn) -> DsM (Core ExpQ)
repLambda LMatch GhcRn (LHsExpr GhcRn)
m
repE (HsLamCase _ (MG { mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = (Located [LMatch GhcRn (LHsExpr GhcRn)]
-> Located (SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ ms :: SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)])
ms) }))
                   = do { [Core MatchQ]
ms' <- (LMatch GhcRn (LHsExpr GhcRn)
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ))
-> [LMatch GhcRn (LHsExpr GhcRn)]
-> IOEnv (Env DsGblEnv DsLclEnv) [Core MatchQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LMatch GhcRn (LHsExpr GhcRn)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
repMatchTup [LMatch GhcRn (LHsExpr GhcRn)]
SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)])
ms
                        ; Core [MatchQ]
core_ms <- Name -> [Core MatchQ] -> DsM (Core [MatchQ])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
matchQTyConName [Core MatchQ]
ms'
                        ; Core [MatchQ] -> DsM (Core ExpQ)
repLamCase Core [MatchQ]
core_ms }
repE (HsApp _ x :: LHsExpr GhcRn
x y :: LHsExpr GhcRn
y)   = do {Core ExpQ
a <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
x; Core ExpQ
b <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
y; Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repApp Core ExpQ
a Core ExpQ
b}
repE (HsAppType _ e :: LHsExpr GhcRn
e t :: LHsWcType (NoGhcTc GhcRn)
t) = do { Core ExpQ
a <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e
                            ; Core TypeQ
s <- LHsType GhcRn -> DsM (Core TypeQ)
repLTy (HsWildCardBndrs GhcRn (LHsType GhcRn) -> LHsType GhcRn
forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body LHsWcType (NoGhcTc GhcRn)
HsWildCardBndrs GhcRn (LHsType GhcRn)
t)
                            ; Core ExpQ -> Core TypeQ -> DsM (Core ExpQ)
repAppType Core ExpQ
a Core TypeQ
s }

repE (OpApp _ e1 :: LHsExpr GhcRn
e1 op :: LHsExpr GhcRn
op e2 :: LHsExpr GhcRn
e2) =
  do { Core ExpQ
arg1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e1;
       Core ExpQ
arg2 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e2;
       Core ExpQ
the_op <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
op ;
       Core ExpQ -> Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repInfixApp Core ExpQ
arg1 Core ExpQ
the_op Core ExpQ
arg2 }
repE (NegApp _ x :: LHsExpr GhcRn
x _)      = do
                              Core ExpQ
a         <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
x
                              Core ExpQ
negateVar <- Name -> DsM (Core Name)
lookupOcc Name
negateName DsM (Core Name)
-> (Core Name -> DsM (Core ExpQ)) -> DsM (Core ExpQ)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Core Name -> DsM (Core ExpQ)
repVar
                              Core ExpQ
negateVar Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
`repApp` Core ExpQ
a
repE (HsPar _ x :: LHsExpr GhcRn
x)            = LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
x
repE (SectionL _ x :: LHsExpr GhcRn
x y :: LHsExpr GhcRn
y)       = do { Core ExpQ
a <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
x; Core ExpQ
b <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
y; Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repSectionL Core ExpQ
a Core ExpQ
b }
repE (SectionR _ x :: LHsExpr GhcRn
x y :: LHsExpr GhcRn
y)       = do { Core ExpQ
a <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
x; Core ExpQ
b <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
y; Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repSectionR Core ExpQ
a Core ExpQ
b }
repE (HsCase _ e :: LHsExpr GhcRn
e (MG { mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = (Located [LMatch GhcRn (LHsExpr GhcRn)]
-> Located (SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ ms :: SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)])
ms) }))
                          = do { Core ExpQ
arg <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e
                               ; [Core MatchQ]
ms2 <- (LMatch GhcRn (LHsExpr GhcRn)
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ))
-> [LMatch GhcRn (LHsExpr GhcRn)]
-> IOEnv (Env DsGblEnv DsLclEnv) [Core MatchQ]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LMatch GhcRn (LHsExpr GhcRn)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
repMatchTup [LMatch GhcRn (LHsExpr GhcRn)]
SrcSpanLess (Located [LMatch GhcRn (LHsExpr GhcRn)])
ms
                               ; Core [MatchQ]
core_ms2 <- Name -> [Core MatchQ] -> DsM (Core [MatchQ])
forall a. Name -> [Core a] -> DsM (Core [a])
coreList Name
matchQTyConName [Core MatchQ]
ms2
                               ; Core ExpQ -> Core [MatchQ] -> DsM (Core ExpQ)
repCaseE Core ExpQ
arg Core [MatchQ]
core_ms2 }
repE (HsIf _ _ x :: LHsExpr GhcRn
x y :: LHsExpr GhcRn
y z :: LHsExpr GhcRn
z)       = do
                              Core ExpQ
a <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
x
                              Core ExpQ
b <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
y
                              Core ExpQ
c <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
z
                              Core ExpQ -> Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repCond Core ExpQ
a Core ExpQ
b Core ExpQ
c
repE (HsMultiIf _ alts :: [LGRHS GhcRn (LHsExpr GhcRn)]
alts)
  = do { (binds :: [[GenSymBind]]
binds, alts' :: [Core (Q (Guard, Exp))]
alts') <- ([([GenSymBind], Core (Q (Guard, Exp)))]
 -> ([[GenSymBind]], [Core (Q (Guard, Exp))]))
-> IOEnv
     (Env DsGblEnv DsLclEnv) [([GenSymBind], Core (Q (Guard, Exp)))]
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([[GenSymBind]], [Core (Q (Guard, Exp))])
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [([GenSymBind], Core (Q (Guard, Exp)))]
-> ([[GenSymBind]], [Core (Q (Guard, Exp))])
forall a b. [(a, b)] -> ([a], [b])
unzip (IOEnv
   (Env DsGblEnv DsLclEnv) [([GenSymBind], Core (Q (Guard, Exp)))]
 -> IOEnv
      (Env DsGblEnv DsLclEnv) ([[GenSymBind]], [Core (Q (Guard, Exp))]))
-> IOEnv
     (Env DsGblEnv DsLclEnv) [([GenSymBind], Core (Q (Guard, Exp)))]
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([[GenSymBind]], [Core (Q (Guard, Exp))])
forall a b. (a -> b) -> a -> b
$ (LGRHS GhcRn (LHsExpr GhcRn)
 -> IOEnv
      (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp))))
-> [LGRHS GhcRn (LHsExpr GhcRn)]
-> IOEnv
     (Env DsGblEnv DsLclEnv) [([GenSymBind], Core (Q (Guard, Exp)))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LGRHS GhcRn (LHsExpr GhcRn)
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp)))
repLGRHS [LGRHS GhcRn (LHsExpr GhcRn)]
alts
       ; Core ExpQ
expr' <- Core [Q (Guard, Exp)] -> DsM (Core ExpQ)
repMultiIf ([Core (Q (Guard, Exp))] -> Core [Q (Guard, Exp)]
forall a. [Core a] -> Core [a]
nonEmptyCoreList [Core (Q (Guard, Exp))]
alts')
       ; [GenSymBind] -> Core ExpQ -> DsM (Core ExpQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms ([[GenSymBind]] -> [GenSymBind]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[GenSymBind]]
binds) Core ExpQ
expr' }
repE (HsLet _ (LHsLocalBinds GhcRn -> Located (SrcSpanLess (LHsLocalBinds GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ bs :: SrcSpanLess (LHsLocalBinds GhcRn)
bs) e :: LHsExpr GhcRn
e)       = do { (ss :: [GenSymBind]
ss,ds :: Core [DecQ]
ds) <- HsLocalBinds GhcRn -> DsM ([GenSymBind], Core [DecQ])
repBinds SrcSpanLess (LHsLocalBinds GhcRn)
HsLocalBinds GhcRn
bs
                                     ; Core ExpQ
e2 <- [GenSymBind] -> DsM (Core ExpQ) -> DsM (Core ExpQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss (LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e)
                                     ; Core ExpQ
z <- Core [DecQ] -> Core ExpQ -> DsM (Core ExpQ)
repLetE Core [DecQ]
ds Core ExpQ
e2
                                     ; [GenSymBind] -> Core ExpQ -> DsM (Core ExpQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core ExpQ
z }

-- FIXME: I haven't got the types here right yet
repE e :: HsExpr GhcRn
e@(HsDo _ ctxt :: HsStmtContext Name
ctxt (Located [ExprLStmt GhcRn]
-> Located (SrcSpanLess (Located [ExprLStmt GhcRn]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ sts :: SrcSpanLess (Located [ExprLStmt GhcRn])
sts))
 | case HsStmtContext Name
ctxt of { DoExpr -> Bool
True; GhciStmtCtxt -> Bool
True; _ -> Bool
False }
 = do { (ss :: [GenSymBind]
ss,zs :: [Core StmtQ]
zs) <- [ExprLStmt GhcRn] -> DsM ([GenSymBind], [Core StmtQ])
repLSts [ExprLStmt GhcRn]
SrcSpanLess (Located [ExprLStmt GhcRn])
sts;
        Core ExpQ
e'      <- Core [StmtQ] -> DsM (Core ExpQ)
repDoE ([Core StmtQ] -> Core [StmtQ]
forall a. [Core a] -> Core [a]
nonEmptyCoreList [Core StmtQ]
zs);
        [GenSymBind] -> Core ExpQ -> DsM (Core ExpQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core ExpQ
e' }

 | HsStmtContext Name
ListComp <- HsStmtContext Name
ctxt
 = do { (ss :: [GenSymBind]
ss,zs :: [Core StmtQ]
zs) <- [ExprLStmt GhcRn] -> DsM ([GenSymBind], [Core StmtQ])
repLSts [ExprLStmt GhcRn]
SrcSpanLess (Located [ExprLStmt GhcRn])
sts;
        Core ExpQ
e'      <- Core [StmtQ] -> DsM (Core ExpQ)
repComp ([Core StmtQ] -> Core [StmtQ]
forall a. [Core a] -> Core [a]
nonEmptyCoreList [Core StmtQ]
zs);
        [GenSymBind] -> Core ExpQ -> DsM (Core ExpQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core ExpQ
e' }

 | HsStmtContext Name
MDoExpr <- HsStmtContext Name
ctxt
 = do { (ss :: [GenSymBind]
ss,zs :: [Core StmtQ]
zs) <- [ExprLStmt GhcRn] -> DsM ([GenSymBind], [Core StmtQ])
repLSts [ExprLStmt GhcRn]
SrcSpanLess (Located [ExprLStmt GhcRn])
sts;
        Core ExpQ
e'      <- Core [StmtQ] -> DsM (Core ExpQ)
repMDoE ([Core StmtQ] -> Core [StmtQ]
forall a. [Core a] -> Core [a]
nonEmptyCoreList [Core StmtQ]
zs);
        [GenSymBind] -> Core ExpQ -> DsM (Core ExpQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms [GenSymBind]
ss Core ExpQ
e' }

  | Bool
otherwise
  = String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "monad comprehension and [: :]" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)

repE (ExplicitList _ _ es :: [LHsExpr GhcRn]
es) = do { Core [ExpQ]
xs <- [LHsExpr GhcRn] -> DsM (Core [ExpQ])
repLEs [LHsExpr GhcRn]
es; Core [ExpQ] -> DsM (Core ExpQ)
repListExp Core [ExpQ]
xs }
repE e :: HsExpr GhcRn
e@(ExplicitTuple _ es :: [LHsTupArg GhcRn]
es boxed :: Boxity
boxed)
  | Bool -> Bool
not ((LHsTupArg GhcRn -> Bool) -> [LHsTupArg GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all LHsTupArg GhcRn -> Bool
forall id. LHsTupArg id -> Bool
tupArgPresent [LHsTupArg GhcRn]
es) = String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "Tuple sections" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)
  | Boxity -> Bool
isBoxed Boxity
boxed = do { Core [ExpQ]
xs <- [LHsExpr GhcRn] -> DsM (Core [ExpQ])
repLEs [LHsExpr GhcRn
e | (LHsTupArg GhcRn -> Located (SrcSpanLess (LHsTupArg GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Present _ e)) <- [LHsTupArg GhcRn]
es]
                       ; Core [ExpQ] -> DsM (Core ExpQ)
repTup Core [ExpQ]
xs }
  | Bool
otherwise     = do { Core [ExpQ]
xs <- [LHsExpr GhcRn] -> DsM (Core [ExpQ])
repLEs [LHsExpr GhcRn
e | (LHsTupArg GhcRn -> Located (SrcSpanLess (LHsTupArg GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Present _ e)) <- [LHsTupArg GhcRn]
es]
                       ; Core [ExpQ] -> DsM (Core ExpQ)
repUnboxedTup Core [ExpQ]
xs }

repE (ExplicitSum _ alt :: Int
alt arity :: Int
arity e :: LHsExpr GhcRn
e)
 = do { Core ExpQ
e1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e
      ; Core ExpQ -> Int -> Int -> DsM (Core ExpQ)
repUnboxedSum Core ExpQ
e1 Int
alt Int
arity }

repE (RecordCon { rcon_con_name :: forall p. HsExpr p -> Located (IdP p)
rcon_con_name = Located (IdP GhcRn)
c, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds GhcRn
flds })
 = do { Core Name
x <- Located Name -> DsM (Core Name)
lookupLOcc Located Name
Located (IdP GhcRn)
c;
        Core [Q FieldExp]
fs <- HsRecordBinds GhcRn -> DsM (Core [Q FieldExp])
repFields HsRecordBinds GhcRn
flds;
        Core Name -> Core [Q FieldExp] -> DsM (Core ExpQ)
repRecCon Core Name
x Core [Q FieldExp]
fs }
repE (RecordUpd { rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr GhcRn
e, rupd_flds :: forall p. HsExpr p -> [LHsRecUpdField p]
rupd_flds = [LHsRecUpdField GhcRn]
flds })
 = do { Core ExpQ
x <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e;
        Core [Q FieldExp]
fs <- [LHsRecUpdField GhcRn] -> DsM (Core [Q FieldExp])
repUpdFields [LHsRecUpdField GhcRn]
flds;
        Core ExpQ -> Core [Q FieldExp] -> DsM (Core ExpQ)
repRecUpd Core ExpQ
x Core [Q FieldExp]
fs }

repE (ExprWithTySig _ e :: LHsExpr GhcRn
e ty :: LHsSigWcType (NoGhcTc GhcRn)
ty)
  = do { Core ExpQ
e1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e
       ; Core TypeQ
t1 <- HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
-> DsM (Core TypeQ)
repHsSigWcType LHsSigWcType (NoGhcTc GhcRn)
HsWildCardBndrs GhcRn (HsImplicitBndrs GhcRn (LHsType GhcRn))
ty
       ; Core ExpQ -> Core TypeQ -> DsM (Core ExpQ)
repSigExp Core ExpQ
e1 Core TypeQ
t1 }

repE (ArithSeq _ _ aseq :: ArithSeqInfo GhcRn
aseq) =
  case ArithSeqInfo GhcRn
aseq of
    From e :: LHsExpr GhcRn
e              -> do { Core ExpQ
ds1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e; Core ExpQ -> DsM (Core ExpQ)
repFrom Core ExpQ
ds1 }
    FromThen e1 :: LHsExpr GhcRn
e1 e2 :: LHsExpr GhcRn
e2      -> do
                             Core ExpQ
ds1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e1
                             Core ExpQ
ds2 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e2
                             Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repFromThen Core ExpQ
ds1 Core ExpQ
ds2
    FromTo   e1 :: LHsExpr GhcRn
e1 e2 :: LHsExpr GhcRn
e2      -> do
                             Core ExpQ
ds1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e1
                             Core ExpQ
ds2 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e2
                             Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repFromTo Core ExpQ
ds1 Core ExpQ
ds2
    FromThenTo e1 :: LHsExpr GhcRn
e1 e2 :: LHsExpr GhcRn
e2 e3 :: LHsExpr GhcRn
e3 -> do
                             Core ExpQ
ds1 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e1
                             Core ExpQ
ds2 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e2
                             Core ExpQ
ds3 <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e3
                             Core ExpQ -> Core ExpQ -> Core ExpQ -> DsM (Core ExpQ)
repFromThenTo Core ExpQ
ds1 Core ExpQ
ds2 Core ExpQ
ds3

repE (HsSpliceE _ splice :: HsSplice GhcRn
splice)  = HsSplice GhcRn -> DsM (Core ExpQ)
forall a. HsSplice GhcRn -> DsM (Core a)
repSplice HsSplice GhcRn
splice
repE (HsStatic _ e :: LHsExpr GhcRn
e)        = LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e DsM (Core ExpQ)
-> (Core ExpQ -> DsM (Core ExpQ)) -> DsM (Core ExpQ)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Name -> [CoreExpr] -> DsM (Core ExpQ)
forall a. Name -> [CoreExpr] -> DsM (Core a)
rep2 Name
staticEName ([CoreExpr] -> DsM (Core ExpQ))
-> (Core ExpQ -> [CoreExpr]) -> Core ExpQ -> DsM (Core ExpQ)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CoreExpr -> [CoreExpr] -> [CoreExpr]
forall a. a -> [a] -> [a]
:[]) (CoreExpr -> [CoreExpr])
-> (Core ExpQ -> CoreExpr) -> Core ExpQ -> [CoreExpr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Core ExpQ -> CoreExpr
forall a. Core a -> CoreExpr
unC
repE (HsUnboundVar _ uv :: UnboundVar
uv)   = do
                               Core String
occ   <- OccName -> DsM (Core String)
occNameLit (UnboundVar -> OccName
unboundVarOcc UnboundVar
uv)
                               Core Name
sname <- Core String -> DsM (Core Name)
repNameS Core String
occ
                               Core Name -> DsM (Core ExpQ)
repUnboundVar Core Name
sname

repE e :: HsExpr GhcRn
e@(HsCoreAnn {})      = String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "Core annotations" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)
repE e :: HsExpr GhcRn
e@(HsSCC {})          = String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "Cost centres" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)
repE e :: HsExpr GhcRn
e@(HsTickPragma {})   = String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "Tick Pragma" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)
repE e :: HsExpr GhcRn
e                     = String -> SDoc -> DsM (Core ExpQ)
forall a. String -> SDoc -> DsM a
notHandled "Expression form" (HsExpr GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e)

-----------------------------------------------------------------------------
-- Building representations of auxillary structures like Match, Clause, Stmt,

repMatchTup ::  LMatch GhcRn (LHsExpr GhcRn) -> DsM (Core TH.MatchQ)
repMatchTup :: LMatch GhcRn (LHsExpr GhcRn)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
repMatchTup (LMatch GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LMatch GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Match { m_pats = [p]
                            , m_grhss = GRHSs _ guards (dL->L _ wheres) })) =
  do { [GenSymBind]
ss1 <- [Name] -> DsM [GenSymBind]
mkGenSyms (LPat GhcRn -> [IdP GhcRn]
forall (p :: Pass). LPat (GhcPass p) -> [IdP (GhcPass p)]
collectPatBinders LPat GhcRn
p)
     ; [GenSymBind]
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss1 (IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ))
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
forall a b. (a -> b) -> a -> b
$ do {
     ; Core PatQ
p1 <- LPat GhcRn -> DsM (Core PatQ)
repLP LPat GhcRn
p
     ; (ss2 :: [GenSymBind]
ss2,ds :: Core [DecQ]
ds) <- HsLocalBinds GhcRn -> DsM ([GenSymBind], Core [DecQ])
repBinds SrcSpanLess (LHsLocalBinds GhcRn)
HsLocalBinds GhcRn
wheres
     ; [GenSymBind]
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss2 (IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
 -> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ))
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
forall a b. (a -> b) -> a -> b
$ do {
     ; Core BodyQ
gs    <- [LGRHS GhcRn (LHsExpr GhcRn)] -> DsM (Core BodyQ)
repGuards [LGRHS GhcRn (LHsExpr GhcRn)]
guards
     ; Core MatchQ
match <- Core PatQ
-> Core BodyQ
-> Core [DecQ]
-> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
repMatch Core PatQ
p1 Core BodyQ
gs Core [DecQ]
ds
     ; [GenSymBind]
-> Core MatchQ -> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms ([GenSymBind]
ss1[GenSymBind] -> [GenSymBind] -> [GenSymBind]
forall a. [a] -> [a] -> [a]
++[GenSymBind]
ss2) Core MatchQ
match }}}
repMatchTup _ = String -> IOEnv (Env DsGblEnv DsLclEnv) (Core MatchQ)
forall a. String -> a
panic "repMatchTup: case alt with more than one arg"

repClauseTup ::  LMatch GhcRn (LHsExpr GhcRn) -> DsM (Core TH.ClauseQ)
repClauseTup :: LMatch GhcRn (LHsExpr GhcRn) -> DsM (Core ClauseQ)
repClauseTup (LMatch GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LMatch GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Match { m_pats = ps
                             , m_grhss = GRHSs _ guards (dL->L _ wheres) })) =
  do { [GenSymBind]
ss1 <- [Name] -> DsM [GenSymBind]
mkGenSyms ([LPat GhcRn] -> [IdP GhcRn]
forall (p :: Pass). [LPat (GhcPass p)] -> [IdP (GhcPass p)]
collectPatsBinders [LPat GhcRn]
ps)
     ; [GenSymBind] -> DsM (Core ClauseQ) -> DsM (Core ClauseQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss1 (DsM (Core ClauseQ) -> DsM (Core ClauseQ))
-> DsM (Core ClauseQ) -> DsM (Core ClauseQ)
forall a b. (a -> b) -> a -> b
$ do {
       Core [PatQ]
ps1 <- [LPat GhcRn] -> DsM (Core [PatQ])
repLPs [LPat GhcRn]
ps
     ; (ss2 :: [GenSymBind]
ss2,ds :: Core [DecQ]
ds) <- HsLocalBinds GhcRn -> DsM ([GenSymBind], Core [DecQ])
repBinds SrcSpanLess (LHsLocalBinds GhcRn)
HsLocalBinds GhcRn
wheres
     ; [GenSymBind] -> DsM (Core ClauseQ) -> DsM (Core ClauseQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
ss2 (DsM (Core ClauseQ) -> DsM (Core ClauseQ))
-> DsM (Core ClauseQ) -> DsM (Core ClauseQ)
forall a b. (a -> b) -> a -> b
$ do {
       Core BodyQ
gs <- [LGRHS GhcRn (LHsExpr GhcRn)] -> DsM (Core BodyQ)
repGuards [LGRHS GhcRn (LHsExpr GhcRn)]
guards
     ; Core ClauseQ
clause <- Core [PatQ] -> Core BodyQ -> Core [DecQ] -> DsM (Core ClauseQ)
repClause Core [PatQ]
ps1 Core BodyQ
gs Core [DecQ]
ds
     ; [GenSymBind] -> Core ClauseQ -> DsM (Core ClauseQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms ([GenSymBind]
ss1[GenSymBind] -> [GenSymBind] -> [GenSymBind]
forall a. [a] -> [a] -> [a]
++[GenSymBind]
ss2) Core ClauseQ
clause }}}
repClauseTup (LMatch GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LMatch GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Match _ _ _ (XGRHSs _))) = String -> DsM (Core ClauseQ)
forall a. String -> a
panic "repClauseTup"
repClauseTup _ = String -> DsM (Core ClauseQ)
forall a. String -> a
panic "repClauseTup"

repGuards ::  [LGRHS GhcRn (LHsExpr GhcRn)] ->  DsM (Core TH.BodyQ)
repGuards :: [LGRHS GhcRn (LHsExpr GhcRn)] -> DsM (Core BodyQ)
repGuards [LGRHS GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LGRHS GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (GRHS _ [] e)]
  = do {Core ExpQ
a <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
e; Core ExpQ -> DsM (Core BodyQ)
repNormal Core ExpQ
a }
repGuards other :: [LGRHS GhcRn (LHsExpr GhcRn)]
other
  = do { [([GenSymBind], Core (Q (Guard, Exp)))]
zs <- (LGRHS GhcRn (LHsExpr GhcRn)
 -> IOEnv
      (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp))))
-> [LGRHS GhcRn (LHsExpr GhcRn)]
-> IOEnv
     (Env DsGblEnv DsLclEnv) [([GenSymBind], Core (Q (Guard, Exp)))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LGRHS GhcRn (LHsExpr GhcRn)
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp)))
repLGRHS [LGRHS GhcRn (LHsExpr GhcRn)]
other
       ; let (xs :: [[GenSymBind]]
xs, ys :: [Core (Q (Guard, Exp))]
ys) = [([GenSymBind], Core (Q (Guard, Exp)))]
-> ([[GenSymBind]], [Core (Q (Guard, Exp))])
forall a b. [(a, b)] -> ([a], [b])
unzip [([GenSymBind], Core (Q (Guard, Exp)))]
zs
       ; Core BodyQ
gd <- Core [Q (Guard, Exp)] -> DsM (Core BodyQ)
repGuarded ([Core (Q (Guard, Exp))] -> Core [Q (Guard, Exp)]
forall a. [Core a] -> Core [a]
nonEmptyCoreList [Core (Q (Guard, Exp))]
ys)
       ; [GenSymBind] -> Core BodyQ -> DsM (Core BodyQ)
forall a. [GenSymBind] -> Core (Q a) -> DsM (Core (Q a))
wrapGenSyms ([[GenSymBind]] -> [GenSymBind]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[GenSymBind]]
xs) Core BodyQ
gd }

repLGRHS :: LGRHS GhcRn (LHsExpr GhcRn)
         -> DsM ([GenSymBind], (Core (TH.Q (TH.Guard, TH.Exp))))
repLGRHS :: LGRHS GhcRn (LHsExpr GhcRn)
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp)))
repLGRHS (LGRHS GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LGRHS GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (GRHS _ [dL->L _ (BodyStmt _ e1 _ _)] e2))
  = do { Core (Q (Guard, Exp))
guarded <- LHsExpr GhcRn -> LHsExpr GhcRn -> DsM (Core (Q (Guard, Exp)))
repLNormalGE LHsExpr GhcRn
e1 LHsExpr GhcRn
e2
       ; ([GenSymBind], Core (Q (Guard, Exp)))
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp)))
forall (m :: * -> *) a. Monad m => a -> m a
return ([], Core (Q (Guard, Exp))
guarded) }
repLGRHS (LGRHS GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LGRHS GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (GRHS _ ss rhs))
  = do { (gs :: [GenSymBind]
gs, ss' :: [Core StmtQ]
ss') <- [ExprLStmt GhcRn] -> DsM ([GenSymBind], [Core StmtQ])
repLSts [ExprLStmt GhcRn]
ss
       ; Core ExpQ
rhs' <- [GenSymBind] -> DsM (Core ExpQ) -> DsM (Core ExpQ)
forall a. [GenSymBind] -> DsM a -> DsM a
addBinds [GenSymBind]
gs (DsM (Core ExpQ) -> DsM (Core ExpQ))
-> DsM (Core ExpQ) -> DsM (Core ExpQ)
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcRn -> DsM (Core ExpQ)
repLE LHsExpr GhcRn
rhs
       ; Core (Q (Guard, Exp))
guarded <- Core [StmtQ] -> Core ExpQ -> DsM (Core (Q (Guard, Exp)))
repPatGE ([Core StmtQ] -> Core [StmtQ]
forall a. [Core a] -> Core [a]
nonEmptyCoreList [Core StmtQ]
ss') Core ExpQ
rhs'
       ; ([GenSymBind], Core (Q (Guard, Exp)))
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp)))
forall (m :: * -> *) a. Monad m => a -> m a
return ([GenSymBind]
gs, Core (Q (Guard, Exp))
guarded) }
repLGRHS _ = String
-> IOEnv
     (Env DsGblEnv DsLclEnv) ([GenSymBind], Core (Q (Guard, Exp)))
forall a. String -> a
panic "repLGRHS"

repFields :: HsRecordBinds GhcRn -> DsM (Core [TH.Q TH.FieldExp])
repFields :: HsRecordBinds GhcRn -> DsM (Core [Q FieldExp])
repFields (HsRecFields { rec_flds :: forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds = [LHsRecField GhcRn (LHsExpr GhcRn)]
flds })
  = Name
-> (LHsRecField GhcRn (LHsExpr GhcRn) -> DsM (Core (Q FieldExp)))
-> [LHsRecField GhcRn (LHsExpr GhcRn)]
-> DsM (Core [Q FieldExp])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
fieldExpQTyConName LHsRecField GhcRn (LHsExpr GhcRn) -> DsM (Core (Q FieldExp))
rep_fld [LHsRecField GhcRn (LHsExpr GhcRn)]
flds
  where
    rep_fld :: LHsRecField GhcRn (LHsExpr GhcRn)
            -> DsM (Core (TH.Q TH.FieldExp))
    rep_fld :: LHsRecField GhcRn (LHsExpr GhcRn) -> DsM (Core (Q FieldExp))
rep_fld (LHsRecField GhcRn (LHsExpr GhcRn)
-> Located (SrcSpanLess (LHsRecField GhcRn (LHsExpr GhcRn)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ fld :: SrcSpanLess (LHsRecField GhcRn (LHsExpr GhcRn))
fld) = do { Core Name
fn <- Located Name -> DsM (Core Name)
lookupLOcc (HsRecField GhcRn (LHsExpr GhcRn) -> Located (XCFieldOcc GhcRn)
forall pass arg. HsRecField pass arg -> Located (XCFieldOcc pass)
hsRecFieldSel SrcSpanLess (LHsRecField GhcRn (LHsExpr GhcRn))
HsRecField GhcRn (LHsExpr GhcRn)
fld)
                               ; Core ExpQ
e  <- LHsExpr GhcRn -> DsM (Core ExpQ)
repLE (HsRecField GhcRn (LHsExpr GhcRn) -> LHsExpr GhcRn
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg SrcSpanLess (LHsRecField GhcRn (LHsExpr GhcRn))
HsRecField GhcRn (LHsExpr GhcRn)
fld)
                               ; Core Name -> Core ExpQ -> DsM (Core (Q FieldExp))
repFieldExp Core Name
fn Core ExpQ
e }

repUpdFields :: [LHsRecUpdField GhcRn] -> DsM (Core [TH.Q TH.FieldExp])
repUpdFields :: [LHsRecUpdField GhcRn] -> DsM (Core [Q FieldExp])
repUpdFields = Name
-> (LHsRecUpdField GhcRn -> DsM (Core (Q FieldExp)))
-> [LHsRecUpdField GhcRn]
-> DsM (Core [Q FieldExp])
forall a b. Name -> (a -> DsM (Core b)) -> [a] -> DsM (Core [b])
repList Name
fieldExpQTyConName LHsRecUpdField GhcRn -> DsM (Core (Q FieldExp))
rep_fld
  where
    rep_fld :: LHsRecUpdField GhcRn -> DsM (Core (TH.Q TH.FieldExp))
    rep_fld :: LHsRecUpdField GhcRn -> DsM (Core (Q FieldExp))
rep_fld (LHsRecUpdField GhcRn
-> Located (SrcSpanLess (LHsRecUpdField GhcRn))
forall a. HasSrcSpan a