{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module GHC.Rename.Splice (
rnTopSpliceDecls,
rnSpliceType, rnSpliceExpr, rnSplicePat, rnSpliceDecl,
rnBracket,
checkThLocalName
, traceSplice, SpliceInfo(..)
) where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Types.Name
import GHC.Types.Name.Set
import GHC.Hs
import GHC.Types.Name.Reader
import GHC.Tc.Utils.Monad
import GHC.Rename.Env
import GHC.Rename.Utils ( HsDocContext(..), newLocalBndrRn )
import GHC.Rename.Unbound ( isUnboundName )
import GHC.Rename.Module ( rnSrcDecls, findSplice )
import GHC.Rename.Pat ( rnPat )
import GHC.Types.Basic ( TopLevelFlag, isTopLevel, SourceText(..) )
import GHC.Utils.Outputable
import GHC.Unit.Module
import GHC.Types.SrcLoc
import GHC.Rename.HsType ( rnLHsType )
import Control.Monad ( unless, when )
import {-# SOURCE #-} GHC.Rename.Expr ( rnLExpr )
import GHC.Tc.Utils.Env ( checkWellStaged )
import GHC.Builtin.Names.TH ( liftName )
import GHC.Driver.Session
import GHC.Data.FastString
import GHC.Utils.Error ( dumpIfSet_dyn_printer, DumpFormat (..) )
import GHC.Tc.Utils.Env ( tcMetaTy )
import GHC.Driver.Hooks
import GHC.Builtin.Names.TH ( quoteExpName, quotePatName, quoteDecName, quoteTypeName
, decsQTyConName, expQTyConName, patQTyConName, typeQTyConName, )
import {-# SOURCE #-} GHC.Tc.Gen.Expr ( tcCheckPolyExpr )
import {-# SOURCE #-} GHC.Tc.Gen.Splice
( runMetaD
, runMetaE
, runMetaP
, runMetaT
, tcTopSpliceExpr
)
import GHC.Tc.Utils.Zonk
import GHCi.RemoteTypes ( ForeignRef )
import qualified Language.Haskell.TH as TH (Q)
import qualified GHC.LanguageExtensions as LangExt
rnBracket :: HsExpr GhcPs -> HsBracket GhcPs -> RnM (HsExpr GhcRn, FreeVars)
rnBracket :: HsExpr GhcPs
-> HsBracket GhcPs -> RnM (HsExpr (GhcPass 'Renamed), Uses)
rnBracket HsExpr GhcPs
e HsBracket GhcPs
br_body
= MsgDoc
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (HsBracket GhcPs -> MsgDoc
quotationCtxtDoc HsBracket GhcPs
br_body) (RnM (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses))
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
do {
Bool
thQuotesEnabled <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.TemplateHaskellQuotes
; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
thQuotesEnabled (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. MsgDoc -> TcRn a
failWith ( [MsgDoc] -> MsgDoc
vcat
[ String -> MsgDoc
text String
"Syntax error on" MsgDoc -> MsgDoc -> MsgDoc
<+> HsExpr GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsExpr GhcPs
e
, String -> MsgDoc
text (String
"Perhaps you intended to use TemplateHaskell"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" or TemplateHaskellQuotes") ] )
; ThStage
cur_stage <- TcM ThStage
getStage
; case ThStage
cur_stage of
{ Splice SpliceType
Typed -> Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTc (HsBracket GhcPs -> Bool
forall id. HsBracket id -> Bool
isTypedBracket HsBracket GhcPs
br_body)
MsgDoc
illegalUntypedBracket
; Splice SpliceType
Untyped -> Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTc (Bool -> Bool
not (HsBracket GhcPs -> Bool
forall id. HsBracket id -> Bool
isTypedBracket HsBracket GhcPs
br_body))
MsgDoc
illegalTypedBracket
; RunSplice TcRef [ForeignRef (Q ())]
_ ->
String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"rnBracket: Renaming bracket when running a splice"
(HsExpr GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsExpr GhcPs
e)
; ThStage
Comp -> () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
; Brack {} -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. MsgDoc -> TcRn a
failWithTc MsgDoc
illegalBracket
}
; IOEnv (Env TcGblEnv TcLclEnv) ()
recordThUse
; case HsBracket GhcPs -> Bool
forall id. HsBracket id -> Bool
isTypedBracket HsBracket GhcPs
br_body of
Bool
True -> do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"Renaming typed TH bracket" MsgDoc
empty
; (HsBracket (GhcPass 'Renamed)
body', Uses
fvs_e) <-
ThStage
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a. ThStage -> TcM a -> TcM a
setStage (ThStage -> PendingStuff -> ThStage
Brack ThStage
cur_stage PendingStuff
RnPendingTyped) (TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
ThStage
-> HsBracket GhcPs -> TcM (HsBracket (GhcPass 'Renamed), Uses)
rn_bracket ThStage
cur_stage HsBracket GhcPs
br_body
; (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XBracket (GhcPass 'Renamed)
-> HsBracket (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall p. XBracket p -> HsBracket p -> HsExpr p
HsBracket NoExtField
XBracket (GhcPass 'Renamed)
noExtField HsBracket (GhcPass 'Renamed)
body', Uses
fvs_e) }
Bool
False -> do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"Renaming untyped TH bracket" MsgDoc
empty
; IORef [PendingRnSplice]
ps_var <- [PendingRnSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) (IORef [PendingRnSplice])
forall a env. a -> IOEnv env (IORef a)
newMutVar []
; (HsBracket (GhcPass 'Renamed)
body', Uses
fvs_e) <-
Extension
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall gbl lcl a. Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetXOptM Extension
LangExt.RebindableSyntax (TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
ThStage
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a. ThStage -> TcM a -> TcM a
setStage (ThStage -> PendingStuff -> ThStage
Brack ThStage
cur_stage (IORef [PendingRnSplice] -> PendingStuff
RnPendingUntyped IORef [PendingRnSplice]
ps_var)) (TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
ThStage
-> HsBracket GhcPs -> TcM (HsBracket (GhcPass 'Renamed), Uses)
rn_bracket ThStage
cur_stage HsBracket GhcPs
br_body
; [PendingRnSplice]
pendings <- IORef [PendingRnSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) [PendingRnSplice]
forall a env. IORef a -> IOEnv env a
readMutVar IORef [PendingRnSplice]
ps_var
; (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XRnBracketOut (GhcPass 'Renamed)
-> HsBracket (GhcPass 'Renamed)
-> [PendingRnSplice]
-> HsExpr (GhcPass 'Renamed)
forall p.
XRnBracketOut p
-> HsBracket (GhcPass 'Renamed) -> [PendingRnSplice] -> HsExpr p
HsRnBracketOut NoExtField
XRnBracketOut (GhcPass 'Renamed)
noExtField HsBracket (GhcPass 'Renamed)
body' [PendingRnSplice]
pendings, Uses
fvs_e) }
}
rn_bracket :: ThStage -> HsBracket GhcPs -> RnM (HsBracket GhcRn, FreeVars)
rn_bracket :: ThStage
-> HsBracket GhcPs -> TcM (HsBracket (GhcPass 'Renamed), Uses)
rn_bracket ThStage
outer_stage br :: HsBracket GhcPs
br@(VarBr XVarBr GhcPs
x Bool
flg IdP GhcPs
rdr_name)
= do { Name
name <- RdrName -> RnM Name
lookupOccRn RdrName
IdP GhcPs
rdr_name
; Module
this_mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
flg Bool -> Bool -> Bool
&& Module -> Name -> Bool
nameIsLocalOrFrom Module
this_mod Name
name) (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
do { Maybe (TopLevelFlag, ThLevel)
mb_bind_lvl <- Name -> RnM (Maybe (TopLevelFlag, ThLevel))
lookupLocalOccThLvl_maybe Name
name
; case Maybe (TopLevelFlag, ThLevel)
mb_bind_lvl of
{ Maybe (TopLevelFlag, ThLevel)
Nothing -> () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
; Just (TopLevelFlag
top_lvl, ThLevel
bind_lvl)
| TopLevelFlag -> Bool
isTopLevel TopLevelFlag
top_lvl
-> Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Name -> Bool
isExternalName Name
name) (Name -> IOEnv (Env TcGblEnv TcLclEnv) ()
keepAlive Name
name)
| Bool
otherwise
-> do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rn_bracket VarBr"
(Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Name
name MsgDoc -> MsgDoc -> MsgDoc
<+> ThLevel -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ThLevel
bind_lvl
MsgDoc -> MsgDoc -> MsgDoc
<+> ThStage -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ThStage
outer_stage)
; Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTc (ThStage -> ThLevel
thLevel ThStage
outer_stage ThLevel -> ThLevel -> ThLevel
forall a. Num a => a -> a -> a
+ ThLevel
1 ThLevel -> ThLevel -> Bool
forall a. Eq a => a -> a -> Bool
== ThLevel
bind_lvl)
(HsBracket GhcPs -> MsgDoc
quotedNameStageErr HsBracket GhcPs
br) }
}
}
; (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XVarBr (GhcPass 'Renamed)
-> Bool -> IdP (GhcPass 'Renamed) -> HsBracket (GhcPass 'Renamed)
forall p. XVarBr p -> Bool -> IdP p -> HsBracket p
VarBr XVarBr GhcPs
XVarBr (GhcPass 'Renamed)
x Bool
flg Name
IdP (GhcPass 'Renamed)
name, Name -> Uses
unitFV Name
name) }
rn_bracket ThStage
_ (ExpBr XExpBr GhcPs
x LHsExpr GhcPs
e) = do { (LHsExpr (GhcPass 'Renamed)
e', Uses
fvs) <- LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), Uses)
rnLExpr LHsExpr GhcPs
e
; (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XExpBr (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed) -> HsBracket (GhcPass 'Renamed)
forall p. XExpBr p -> LHsExpr p -> HsBracket p
ExpBr XExpBr GhcPs
XExpBr (GhcPass 'Renamed)
x LHsExpr (GhcPass 'Renamed)
e', Uses
fvs) }
rn_bracket ThStage
_ (PatBr XPatBr GhcPs
x LPat GhcPs
p)
= HsMatchContext (GhcPass 'Renamed)
-> LPat GhcPs
-> (LPat (GhcPass 'Renamed)
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a.
HsMatchContext (GhcPass 'Renamed)
-> LPat GhcPs
-> (LPat (GhcPass 'Renamed) -> RnM (a, Uses))
-> RnM (a, Uses)
rnPat HsMatchContext (GhcPass 'Renamed)
forall p. HsMatchContext p
ThPatQuote LPat GhcPs
p ((LPat (GhcPass 'Renamed)
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> (LPat (GhcPass 'Renamed)
-> TcM (HsBracket (GhcPass 'Renamed), Uses))
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$ \ LPat (GhcPass 'Renamed)
p' -> (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPatBr (GhcPass 'Renamed)
-> LPat (GhcPass 'Renamed) -> HsBracket (GhcPass 'Renamed)
forall p. XPatBr p -> LPat p -> HsBracket p
PatBr XPatBr GhcPs
XPatBr (GhcPass 'Renamed)
x LPat (GhcPass 'Renamed)
p', Uses
emptyFVs)
rn_bracket ThStage
_ (TypBr XTypBr GhcPs
x LHsType GhcPs
t) = do { (LHsType (GhcPass 'Renamed)
t', Uses
fvs) <- HsDocContext
-> LHsType GhcPs -> RnM (LHsType (GhcPass 'Renamed), Uses)
rnLHsType HsDocContext
TypBrCtx LHsType GhcPs
t
; (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XTypBr (GhcPass 'Renamed)
-> LHsType (GhcPass 'Renamed) -> HsBracket (GhcPass 'Renamed)
forall p. XTypBr p -> LHsType p -> HsBracket p
TypBr XTypBr GhcPs
XTypBr (GhcPass 'Renamed)
x LHsType (GhcPass 'Renamed)
t', Uses
fvs) }
rn_bracket ThStage
_ (DecBrL XDecBrL GhcPs
x [LHsDecl GhcPs]
decls)
= do { HsGroup GhcPs
group <- [LHsDecl GhcPs] -> RnM (HsGroup GhcPs)
groupDecls [LHsDecl GhcPs]
decls
; TcGblEnv
gbl_env <- TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; let new_gbl_env :: TcGblEnv
new_gbl_env = TcGblEnv
gbl_env { tcg_dus :: DefUses
tcg_dus = DefUses
emptyDUs }
; (TcGblEnv
tcg_env, HsGroup (GhcPass 'Renamed)
group') <- TcGblEnv
-> TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed))
-> TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed))
forall gbl lcl a. gbl -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setGblEnv TcGblEnv
new_gbl_env (TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed))
-> TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed)))
-> TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed))
-> TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$
HsGroup GhcPs
-> TcRnIf TcGblEnv TcLclEnv (TcGblEnv, HsGroup (GhcPass 'Renamed))
rnSrcDecls HsGroup GhcPs
group
; String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rn_bracket dec" (DefUses -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr (TcGblEnv -> DefUses
tcg_dus TcGblEnv
tcg_env) MsgDoc -> MsgDoc -> MsgDoc
$$
Uses -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr (DefUses -> Uses
duUses (TcGblEnv -> DefUses
tcg_dus TcGblEnv
tcg_env)))
; (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XDecBrG (GhcPass 'Renamed)
-> HsGroup (GhcPass 'Renamed) -> HsBracket (GhcPass 'Renamed)
forall p. XDecBrG p -> HsGroup p -> HsBracket p
DecBrG XDecBrG (GhcPass 'Renamed)
XDecBrL GhcPs
x HsGroup (GhcPass 'Renamed)
group', DefUses -> Uses
duUses (TcGblEnv -> DefUses
tcg_dus TcGblEnv
tcg_env)) }
where
groupDecls :: [LHsDecl GhcPs] -> RnM (HsGroup GhcPs)
groupDecls :: [LHsDecl GhcPs] -> RnM (HsGroup GhcPs)
groupDecls [LHsDecl GhcPs]
decls
= do { (HsGroup GhcPs
group, Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs])
mb_splice) <- [LHsDecl GhcPs]
-> RnM (HsGroup GhcPs, Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs]))
findSplice [LHsDecl GhcPs]
decls
; case Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs])
mb_splice of
{ Maybe (SpliceDecl GhcPs, [LHsDecl GhcPs])
Nothing -> HsGroup GhcPs -> RnM (HsGroup GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return HsGroup GhcPs
group
; Just (SpliceDecl GhcPs
splice, [LHsDecl GhcPs]
rest) ->
do { HsGroup GhcPs
group' <- [LHsDecl GhcPs] -> RnM (HsGroup GhcPs)
groupDecls [LHsDecl GhcPs]
rest
; let group'' :: HsGroup GhcPs
group'' = HsGroup GhcPs -> HsGroup GhcPs -> HsGroup GhcPs
forall (p :: Pass).
HsGroup (GhcPass p) -> HsGroup (GhcPass p) -> HsGroup (GhcPass p)
appendGroups HsGroup GhcPs
group HsGroup GhcPs
group'
; HsGroup GhcPs -> RnM (HsGroup GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return HsGroup GhcPs
group'' { hs_splcds :: [LSpliceDecl GhcPs]
hs_splcds = SpliceDecl GhcPs -> LSpliceDecl GhcPs
forall e. e -> Located e
noLoc SpliceDecl GhcPs
splice LSpliceDecl GhcPs -> [LSpliceDecl GhcPs] -> [LSpliceDecl GhcPs]
forall a. a -> [a] -> [a]
: HsGroup GhcPs -> [LSpliceDecl GhcPs]
forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds HsGroup GhcPs
group' }
}
}}
rn_bracket ThStage
_ (DecBrG {}) = String -> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall a. String -> a
panic String
"rn_bracket: unexpected DecBrG"
rn_bracket ThStage
_ (TExpBr XTExpBr GhcPs
x LHsExpr GhcPs
e) = do { (LHsExpr (GhcPass 'Renamed)
e', Uses
fvs) <- LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), Uses)
rnLExpr LHsExpr GhcPs
e
; (HsBracket (GhcPass 'Renamed), Uses)
-> TcM (HsBracket (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XTExpBr (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed) -> HsBracket (GhcPass 'Renamed)
forall p. XTExpBr p -> LHsExpr p -> HsBracket p
TExpBr XTExpBr GhcPs
XTExpBr (GhcPass 'Renamed)
x LHsExpr (GhcPass 'Renamed)
e', Uses
fvs) }
quotationCtxtDoc :: HsBracket GhcPs -> SDoc
quotationCtxtDoc :: HsBracket GhcPs -> MsgDoc
quotationCtxtDoc HsBracket GhcPs
br_body
= MsgDoc -> ThLevel -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"In the Template Haskell quotation")
ThLevel
2 (HsBracket GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBracket GhcPs
br_body)
illegalBracket :: SDoc
illegalBracket :: MsgDoc
illegalBracket =
String -> MsgDoc
text String
"Template Haskell brackets cannot be nested" MsgDoc -> MsgDoc -> MsgDoc
<+>
String -> MsgDoc
text String
"(without intervening splices)"
illegalTypedBracket :: SDoc
illegalTypedBracket :: MsgDoc
illegalTypedBracket =
String -> MsgDoc
text String
"Typed brackets may only appear in typed splices."
illegalUntypedBracket :: SDoc
illegalUntypedBracket :: MsgDoc
illegalUntypedBracket =
String -> MsgDoc
text String
"Untyped brackets may only appear in untyped splices."
quotedNameStageErr :: HsBracket GhcPs -> SDoc
quotedNameStageErr :: HsBracket GhcPs -> MsgDoc
quotedNameStageErr HsBracket GhcPs
br
= [MsgDoc] -> MsgDoc
sep [ String -> MsgDoc
text String
"Stage error: the non-top-level quoted name" MsgDoc -> MsgDoc -> MsgDoc
<+> HsBracket GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsBracket GhcPs
br
, String -> MsgDoc
text String
"must be used at the same stage at which it is bound" ]
rnSpliceGen :: (HsSplice GhcRn -> RnM (a, FreeVars))
-> (HsSplice GhcRn -> (PendingRnSplice, a))
-> HsSplice GhcPs
-> RnM (a, FreeVars)
rnSpliceGen :: forall a.
(HsSplice (GhcPass 'Renamed) -> RnM (a, Uses))
-> (HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a))
-> HsSplice GhcPs
-> RnM (a, Uses)
rnSpliceGen HsSplice (GhcPass 'Renamed) -> RnM (a, Uses)
run_splice HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a)
pend_splice HsSplice GhcPs
splice
= MsgDoc -> RnM (a, Uses) -> RnM (a, Uses)
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (HsSplice GhcPs -> MsgDoc
spliceCtxt HsSplice GhcPs
splice) (RnM (a, Uses) -> RnM (a, Uses)) -> RnM (a, Uses) -> RnM (a, Uses)
forall a b. (a -> b) -> a -> b
$ do
{ ThStage
stage <- TcM ThStage
getStage
; case ThStage
stage of
Brack ThStage
pop_stage PendingStuff
RnPendingTyped
-> do { Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTc Bool
is_typed_splice MsgDoc
illegalUntypedSplice
; (HsSplice (GhcPass 'Renamed)
splice', Uses
fvs) <- ThStage
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a. ThStage -> TcM a -> TcM a
setStage ThStage
pop_stage (TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses))
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
HsSplice GhcPs -> TcM (HsSplice (GhcPass 'Renamed), Uses)
rnSplice HsSplice GhcPs
splice
; let (PendingRnSplice
_pending_splice, a
result) = HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a)
pend_splice HsSplice (GhcPass 'Renamed)
splice'
; (a, Uses) -> RnM (a, Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, Uses
fvs) }
Brack ThStage
pop_stage (RnPendingUntyped IORef [PendingRnSplice]
ps_var)
-> do { Bool -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTc (Bool -> Bool
not Bool
is_typed_splice) MsgDoc
illegalTypedSplice
; (HsSplice (GhcPass 'Renamed)
splice', Uses
fvs) <- ThStage
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a. ThStage -> TcM a -> TcM a
setStage ThStage
pop_stage (TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses))
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
HsSplice GhcPs -> TcM (HsSplice (GhcPass 'Renamed), Uses)
rnSplice HsSplice GhcPs
splice
; let (PendingRnSplice
pending_splice, a
result) = HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a)
pend_splice HsSplice (GhcPass 'Renamed)
splice'
; [PendingRnSplice]
ps <- IORef [PendingRnSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) [PendingRnSplice]
forall a env. IORef a -> IOEnv env a
readMutVar IORef [PendingRnSplice]
ps_var
; IORef [PendingRnSplice]
-> [PendingRnSplice] -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef [PendingRnSplice]
ps_var (PendingRnSplice
pending_splice PendingRnSplice -> [PendingRnSplice] -> [PendingRnSplice]
forall a. a -> [a] -> [a]
: [PendingRnSplice]
ps)
; (a, Uses) -> RnM (a, Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, Uses
fvs) }
ThStage
_ -> do { HsSplice GhcPs -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTopSpliceAllowed HsSplice GhcPs
splice
; (HsSplice (GhcPass 'Renamed)
splice', Uses
fvs1) <- TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall r. TcM r -> TcM r
checkNoErrs (TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses))
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
ThStage
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a. ThStage -> TcM a -> TcM a
setStage (SpliceType -> ThStage
Splice SpliceType
splice_type) (TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses))
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
HsSplice GhcPs -> TcM (HsSplice (GhcPass 'Renamed), Uses)
rnSplice HsSplice GhcPs
splice
; (a
result, Uses
fvs2) <- HsSplice (GhcPass 'Renamed) -> RnM (a, Uses)
run_splice HsSplice (GhcPass 'Renamed)
splice'
; (a, Uses) -> RnM (a, Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, Uses
fvs1 Uses -> Uses -> Uses
`plusFV` Uses
fvs2) } }
where
is_typed_splice :: Bool
is_typed_splice = HsSplice GhcPs -> Bool
forall id. HsSplice id -> Bool
isTypedSplice HsSplice GhcPs
splice
splice_type :: SpliceType
splice_type = if Bool
is_typed_splice
then SpliceType
Typed
else SpliceType
Untyped
checkTopSpliceAllowed :: HsSplice GhcPs -> RnM ()
checkTopSpliceAllowed :: HsSplice GhcPs -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTopSpliceAllowed HsSplice GhcPs
splice = do
let (String
herald, Extension
ext) = HsSplice GhcPs -> (String, Extension)
spliceExtension HsSplice GhcPs
splice
Bool
extEnabled <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
ext
Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
extEnabled
(MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. MsgDoc -> TcRn a
failWith (MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ String -> MsgDoc
text String
herald MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
"are not permitted without" MsgDoc -> MsgDoc -> MsgDoc
<+> Extension -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Extension
ext)
where
spliceExtension :: HsSplice GhcPs -> (String, LangExt.Extension)
spliceExtension :: HsSplice GhcPs -> (String, Extension)
spliceExtension (HsQuasiQuote {}) = (String
"Quasi-quotes", Extension
LangExt.QuasiQuotes)
spliceExtension (HsTypedSplice {}) = (String
"Top-level splices", Extension
LangExt.TemplateHaskell)
spliceExtension (HsUntypedSplice {}) = (String
"Top-level splices", Extension
LangExt.TemplateHaskell)
spliceExtension s :: HsSplice GhcPs
s@(HsSpliced {}) = String -> MsgDoc -> (String, Extension)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"spliceExtension" (HsSplice GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice GhcPs
s)
runRnSplice :: UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn res)
-> (res -> SDoc)
-> HsSplice GhcRn
-> TcRn (res, [ForeignRef (TH.Q ())])
runRnSplice :: forall res.
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn res)
-> (res -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (res, [ForeignRef (Q ())])
runRnSplice UntypedSpliceFlavour
flavour LHsExpr GhcTc -> TcRn res
run_meta res -> MsgDoc
ppr_res HsSplice (GhcPass 'Renamed)
splice
= do { HsSplice (GhcPass 'Renamed)
splice' <- (Hooks
-> Maybe
(HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed))))
-> (HsSplice (GhcPass 'Renamed)
-> RnM (HsSplice (GhcPass 'Renamed)))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed)))
forall (f :: * -> *) a.
(Functor f, HasDynFlags f) =>
(Hooks -> Maybe a) -> a -> f a
getHooked Hooks
-> Maybe
(HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed)))
runRnSpliceHook HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed))
forall (m :: * -> *) a. Monad m => a -> m a
return IOEnv
(Env TcGblEnv TcLclEnv)
(HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed)))
-> ((HsSplice (GhcPass 'Renamed)
-> RnM (HsSplice (GhcPass 'Renamed)))
-> RnM (HsSplice (GhcPass 'Renamed)))
-> RnM (HsSplice (GhcPass 'Renamed))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed)))
-> HsSplice (GhcPass 'Renamed) -> RnM (HsSplice (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ HsSplice (GhcPass 'Renamed)
splice)
; let the_expr :: LHsExpr (GhcPass 'Renamed)
the_expr = case HsSplice (GhcPass 'Renamed)
splice' of
HsUntypedSplice XUntypedSplice (GhcPass 'Renamed)
_ SpliceDecoration
_ IdP (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
e -> LHsExpr (GhcPass 'Renamed)
e
HsQuasiQuote XQuasiQuote (GhcPass 'Renamed)
_ IdP (GhcPass 'Renamed)
_ IdP (GhcPass 'Renamed)
q SrcSpan
qs FastString
str -> UntypedSpliceFlavour
-> Name -> SrcSpan -> FastString -> LHsExpr (GhcPass 'Renamed)
mkQuasiQuoteExpr UntypedSpliceFlavour
flavour Name
IdP (GhcPass 'Renamed)
q SrcSpan
qs FastString
str
HsTypedSplice {} -> String -> MsgDoc -> LHsExpr (GhcPass 'Renamed)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"runRnSplice" (HsSplice (GhcPass 'Renamed) -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
splice)
HsSpliced {} -> String -> MsgDoc -> LHsExpr (GhcPass 'Renamed)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"runRnSplice" (HsSplice (GhcPass 'Renamed) -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
splice)
; Type
meta_exp_ty <- Name -> TcM Type
tcMetaTy Name
meta_ty_name
; LHsExpr GhcTc
zonked_q_expr <- LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkTopLExpr (LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> TcM (LHsExpr GhcTc) -> TcM (LHsExpr GhcTc)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
SpliceType -> TcM (LHsExpr GhcTc) -> TcM (LHsExpr GhcTc)
tcTopSpliceExpr SpliceType
Untyped
(LHsExpr (GhcPass 'Renamed) -> Type -> TcM (LHsExpr GhcTc)
tcCheckPolyExpr LHsExpr (GhcPass 'Renamed)
the_expr Type
meta_exp_ty)
; TcRef [ForeignRef (Q ())]
mod_finalizers_ref <- [ForeignRef (Q ())]
-> TcRnIf TcGblEnv TcLclEnv (TcRef [ForeignRef (Q ())])
forall a gbl lcl. a -> TcRnIf gbl lcl (TcRef a)
newTcRef []
; res
result <- ThStage -> TcRn res -> TcRn res
forall a. ThStage -> TcM a -> TcM a
setStage (TcRef [ForeignRef (Q ())] -> ThStage
RunSplice TcRef [ForeignRef (Q ())]
mod_finalizers_ref) (TcRn res -> TcRn res) -> TcRn res -> TcRn res
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcTc -> TcRn res
run_meta LHsExpr GhcTc
zonked_q_expr
; [ForeignRef (Q ())]
mod_finalizers <- TcRef [ForeignRef (Q ())]
-> TcRnIf TcGblEnv TcLclEnv [ForeignRef (Q ())]
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef TcRef [ForeignRef (Q ())]
mod_finalizers_ref
; SpliceInfo -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceSplice (SpliceInfo :: String
-> Maybe (LHsExpr (GhcPass 'Renamed))
-> Bool
-> MsgDoc
-> SpliceInfo
SpliceInfo { spliceDescription :: String
spliceDescription = String
what
, spliceIsDecl :: Bool
spliceIsDecl = Bool
is_decl
, spliceSource :: Maybe (LHsExpr (GhcPass 'Renamed))
spliceSource = LHsExpr (GhcPass 'Renamed) -> Maybe (LHsExpr (GhcPass 'Renamed))
forall a. a -> Maybe a
Just LHsExpr (GhcPass 'Renamed)
the_expr
, spliceGenerated :: MsgDoc
spliceGenerated = res -> MsgDoc
ppr_res res
result })
; (res, [ForeignRef (Q ())]) -> TcRn (res, [ForeignRef (Q ())])
forall (m :: * -> *) a. Monad m => a -> m a
return (res
result, [ForeignRef (Q ())]
mod_finalizers) }
where
meta_ty_name :: Name
meta_ty_name = case UntypedSpliceFlavour
flavour of
UntypedSpliceFlavour
UntypedExpSplice -> Name
expQTyConName
UntypedSpliceFlavour
UntypedPatSplice -> Name
patQTyConName
UntypedSpliceFlavour
UntypedTypeSplice -> Name
typeQTyConName
UntypedSpliceFlavour
UntypedDeclSplice -> Name
decsQTyConName
what :: String
what = case UntypedSpliceFlavour
flavour of
UntypedSpliceFlavour
UntypedExpSplice -> String
"expression"
UntypedSpliceFlavour
UntypedPatSplice -> String
"pattern"
UntypedSpliceFlavour
UntypedTypeSplice -> String
"type"
UntypedSpliceFlavour
UntypedDeclSplice -> String
"declarations"
is_decl :: Bool
is_decl = case UntypedSpliceFlavour
flavour of
UntypedSpliceFlavour
UntypedDeclSplice -> Bool
True
UntypedSpliceFlavour
_ -> Bool
False
makePending :: UntypedSpliceFlavour
-> HsSplice GhcRn
-> PendingRnSplice
makePending :: UntypedSpliceFlavour
-> HsSplice (GhcPass 'Renamed) -> PendingRnSplice
makePending UntypedSpliceFlavour
flavour (HsUntypedSplice XUntypedSplice (GhcPass 'Renamed)
_ SpliceDecoration
_ IdP (GhcPass 'Renamed)
n LHsExpr (GhcPass 'Renamed)
e)
= UntypedSpliceFlavour
-> Name -> LHsExpr (GhcPass 'Renamed) -> PendingRnSplice
PendingRnSplice UntypedSpliceFlavour
flavour Name
IdP (GhcPass 'Renamed)
n LHsExpr (GhcPass 'Renamed)
e
makePending UntypedSpliceFlavour
flavour (HsQuasiQuote XQuasiQuote (GhcPass 'Renamed)
_ IdP (GhcPass 'Renamed)
n IdP (GhcPass 'Renamed)
quoter SrcSpan
q_span FastString
quote)
= UntypedSpliceFlavour
-> Name -> LHsExpr (GhcPass 'Renamed) -> PendingRnSplice
PendingRnSplice UntypedSpliceFlavour
flavour Name
IdP (GhcPass 'Renamed)
n (UntypedSpliceFlavour
-> Name -> SrcSpan -> FastString -> LHsExpr (GhcPass 'Renamed)
mkQuasiQuoteExpr UntypedSpliceFlavour
flavour Name
IdP (GhcPass 'Renamed)
quoter SrcSpan
q_span FastString
quote)
makePending UntypedSpliceFlavour
_ splice :: HsSplice (GhcPass 'Renamed)
splice@(HsTypedSplice {})
= String -> MsgDoc -> PendingRnSplice
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"makePending" (HsSplice (GhcPass 'Renamed) -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
splice)
makePending UntypedSpliceFlavour
_ splice :: HsSplice (GhcPass 'Renamed)
splice@(HsSpliced {})
= String -> MsgDoc -> PendingRnSplice
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"makePending" (HsSplice (GhcPass 'Renamed) -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
splice)
mkQuasiQuoteExpr :: UntypedSpliceFlavour -> Name -> SrcSpan -> FastString
-> LHsExpr GhcRn
mkQuasiQuoteExpr :: UntypedSpliceFlavour
-> Name -> SrcSpan -> FastString -> LHsExpr (GhcPass 'Renamed)
mkQuasiQuoteExpr UntypedSpliceFlavour
flavour Name
quoter SrcSpan
q_span FastString
quote
= SrcSpan -> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span (HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$ XApp (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed)
-> HsExpr (GhcPass 'Renamed)
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp NoExtField
XApp (GhcPass 'Renamed)
noExtField (SrcSpan -> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span
(HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$ XApp (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed)
-> HsExpr (GhcPass 'Renamed)
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp NoExtField
XApp (GhcPass 'Renamed)
noExtField (SrcSpan -> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span (XVar (GhcPass 'Renamed)
-> Located (IdP (GhcPass 'Renamed)) -> HsExpr (GhcPass 'Renamed)
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar NoExtField
XVar (GhcPass 'Renamed)
noExtField (SrcSpan -> Name -> GenLocated SrcSpan Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span Name
quote_selector)))
LHsExpr (GhcPass 'Renamed)
quoterExpr)
LHsExpr (GhcPass 'Renamed)
quoteExpr
where
quoterExpr :: LHsExpr (GhcPass 'Renamed)
quoterExpr = SrcSpan -> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span (HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$! XVar (GhcPass 'Renamed)
-> Located (IdP (GhcPass 'Renamed)) -> HsExpr (GhcPass 'Renamed)
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar NoExtField
XVar (GhcPass 'Renamed)
noExtField (GenLocated SrcSpan Name -> HsExpr (GhcPass 'Renamed))
-> GenLocated SrcSpan Name -> HsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$! (SrcSpan -> Name -> GenLocated SrcSpan Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span Name
quoter)
quoteExpr :: LHsExpr (GhcPass 'Renamed)
quoteExpr = SrcSpan -> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall l e. l -> e -> GenLocated l e
L SrcSpan
q_span (HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$! XLitE (GhcPass 'Renamed)
-> HsLit (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit NoExtField
XLitE (GhcPass 'Renamed)
noExtField (HsLit (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed))
-> HsLit (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$! XHsString (GhcPass 'Renamed)
-> FastString -> HsLit (GhcPass 'Renamed)
forall x. XHsString x -> FastString -> HsLit x
HsString SourceText
XHsString (GhcPass 'Renamed)
NoSourceText FastString
quote
quote_selector :: Name
quote_selector = case UntypedSpliceFlavour
flavour of
UntypedSpliceFlavour
UntypedExpSplice -> Name
quoteExpName
UntypedSpliceFlavour
UntypedPatSplice -> Name
quotePatName
UntypedSpliceFlavour
UntypedTypeSplice -> Name
quoteTypeName
UntypedSpliceFlavour
UntypedDeclSplice -> Name
quoteDecName
rnSplice :: HsSplice GhcPs -> RnM (HsSplice GhcRn, FreeVars)
rnSplice :: HsSplice GhcPs -> TcM (HsSplice (GhcPass 'Renamed), Uses)
rnSplice (HsTypedSplice XTypedSplice GhcPs
x SpliceDecoration
hasParen IdP GhcPs
splice_name LHsExpr GhcPs
expr)
= do { SrcSpan
loc <- TcRn SrcSpan
getSrcSpanM
; Name
n' <- Located RdrName -> RnM Name
newLocalBndrRn (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
IdP GhcPs
splice_name)
; (LHsExpr (GhcPass 'Renamed)
expr', Uses
fvs) <- LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), Uses)
rnLExpr LHsExpr GhcPs
expr
; (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XTypedSplice (GhcPass 'Renamed)
-> SpliceDecoration
-> IdP (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed)
forall id.
XTypedSplice id
-> SpliceDecoration -> IdP id -> LHsExpr id -> HsSplice id
HsTypedSplice XTypedSplice GhcPs
XTypedSplice (GhcPass 'Renamed)
x SpliceDecoration
hasParen Name
IdP (GhcPass 'Renamed)
n' LHsExpr (GhcPass 'Renamed)
expr', Uses
fvs) }
rnSplice (HsUntypedSplice XUntypedSplice GhcPs
x SpliceDecoration
hasParen IdP GhcPs
splice_name LHsExpr GhcPs
expr)
= do { SrcSpan
loc <- TcRn SrcSpan
getSrcSpanM
; Name
n' <- Located RdrName -> RnM Name
newLocalBndrRn (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
IdP GhcPs
splice_name)
; (LHsExpr (GhcPass 'Renamed)
expr', Uses
fvs) <- LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), Uses)
rnLExpr LHsExpr GhcPs
expr
; (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XUntypedSplice (GhcPass 'Renamed)
-> SpliceDecoration
-> IdP (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed)
forall id.
XUntypedSplice id
-> SpliceDecoration -> IdP id -> LHsExpr id -> HsSplice id
HsUntypedSplice XUntypedSplice GhcPs
XUntypedSplice (GhcPass 'Renamed)
x SpliceDecoration
hasParen Name
IdP (GhcPass 'Renamed)
n' LHsExpr (GhcPass 'Renamed)
expr', Uses
fvs) }
rnSplice (HsQuasiQuote XQuasiQuote GhcPs
x IdP GhcPs
splice_name IdP GhcPs
quoter SrcSpan
q_loc FastString
quote)
= do { SrcSpan
loc <- TcRn SrcSpan
getSrcSpanM
; Name
splice_name' <- Located RdrName -> RnM Name
newLocalBndrRn (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
IdP GhcPs
splice_name)
; Name
quoter' <- RdrName -> RnM Name
lookupOccRn RdrName
IdP GhcPs
quoter
; Module
this_mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Module -> Name -> Bool
nameIsLocalOrFrom Module
this_mod Name
quoter') (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
Name -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkThLocalName Name
quoter'
; (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XQuasiQuote (GhcPass 'Renamed)
-> IdP (GhcPass 'Renamed)
-> IdP (GhcPass 'Renamed)
-> SrcSpan
-> FastString
-> HsSplice (GhcPass 'Renamed)
forall id.
XQuasiQuote id
-> IdP id -> IdP id -> SrcSpan -> FastString -> HsSplice id
HsQuasiQuote XQuasiQuote GhcPs
XQuasiQuote (GhcPass 'Renamed)
x Name
IdP (GhcPass 'Renamed)
splice_name' Name
IdP (GhcPass 'Renamed)
quoter' SrcSpan
q_loc FastString
quote
, Name -> Uses
unitFV Name
quoter') }
rnSplice splice :: HsSplice GhcPs
splice@(HsSpliced {}) = String -> MsgDoc -> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"rnSplice" (HsSplice GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice GhcPs
splice)
rnSpliceExpr :: HsSplice GhcPs -> RnM (HsExpr GhcRn, FreeVars)
rnSpliceExpr :: HsSplice GhcPs -> RnM (HsExpr (GhcPass 'Renamed), Uses)
rnSpliceExpr HsSplice GhcPs
splice
= (HsSplice (GhcPass 'Renamed)
-> RnM (HsExpr (GhcPass 'Renamed), Uses))
-> (HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, HsExpr (GhcPass 'Renamed)))
-> HsSplice GhcPs
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall a.
(HsSplice (GhcPass 'Renamed) -> RnM (a, Uses))
-> (HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a))
-> HsSplice GhcPs
-> RnM (a, Uses)
rnSpliceGen HsSplice (GhcPass 'Renamed)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
run_expr_splice HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, HsExpr (GhcPass 'Renamed))
pend_expr_splice HsSplice GhcPs
splice
where
pend_expr_splice :: HsSplice GhcRn -> (PendingRnSplice, HsExpr GhcRn)
pend_expr_splice :: HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, HsExpr (GhcPass 'Renamed))
pend_expr_splice HsSplice (GhcPass 'Renamed)
rn_splice
= (UntypedSpliceFlavour
-> HsSplice (GhcPass 'Renamed) -> PendingRnSplice
makePending UntypedSpliceFlavour
UntypedExpSplice HsSplice (GhcPass 'Renamed)
rn_splice, XSpliceE (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall p. XSpliceE p -> HsSplice p -> HsExpr p
HsSpliceE NoExtField
XSpliceE (GhcPass 'Renamed)
noExtField HsSplice (GhcPass 'Renamed)
rn_splice)
run_expr_splice :: HsSplice GhcRn -> RnM (HsExpr GhcRn, FreeVars)
run_expr_splice :: HsSplice (GhcPass 'Renamed)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
run_expr_splice HsSplice (GhcPass 'Renamed)
rn_splice
| HsSplice (GhcPass 'Renamed) -> Bool
forall id. HsSplice id -> Bool
isTypedSplice HsSplice (GhcPass 'Renamed)
rn_splice
= do {
String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rnSpliceExpr: typed expression splice" MsgDoc
empty
; LocalRdrEnv
lcl_rdr <- RnM LocalRdrEnv
getLocalRdrEnv
; GlobalRdrEnv
gbl_rdr <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; let gbl_names :: Uses
gbl_names = [Name] -> Uses
mkNameSet [GlobalRdrElt -> Name
gre_name GlobalRdrElt
gre | GlobalRdrElt
gre <- GlobalRdrEnv -> [GlobalRdrElt]
globalRdrEnvElts GlobalRdrEnv
gbl_rdr
, GlobalRdrElt -> Bool
isLocalGRE GlobalRdrElt
gre]
lcl_names :: Uses
lcl_names = [Name] -> Uses
mkNameSet (LocalRdrEnv -> [Name]
localRdrEnvElts LocalRdrEnv
lcl_rdr)
; (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSpliceE (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall p. XSpliceE p -> HsSplice p -> HsExpr p
HsSpliceE NoExtField
XSpliceE (GhcPass 'Renamed)
noExtField HsSplice (GhcPass 'Renamed)
rn_splice, Uses
lcl_names Uses -> Uses -> Uses
`plusFV` Uses
gbl_names) }
| Bool
otherwise
= do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rnSpliceExpr: untyped expression splice" MsgDoc
empty
; (LHsExpr GhcPs
rn_expr, [ForeignRef (Q ())]
mod_finalizers) <-
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn (LHsExpr GhcPs))
-> (LHsExpr GhcPs -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (LHsExpr GhcPs, [ForeignRef (Q ())])
forall res.
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn res)
-> (res -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (res, [ForeignRef (Q ())])
runRnSplice UntypedSpliceFlavour
UntypedExpSplice LHsExpr GhcTc -> TcRn (LHsExpr GhcPs)
runMetaE LHsExpr GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
rn_splice
; (LHsExpr (GhcPass 'Renamed)
lexpr3, Uses
fvs) <- RnM (LHsExpr (GhcPass 'Renamed), Uses)
-> RnM (LHsExpr (GhcPass 'Renamed), Uses)
forall r. TcM r -> TcM r
checkNoErrs (LHsExpr GhcPs -> RnM (LHsExpr (GhcPass 'Renamed), Uses)
rnLExpr LHsExpr GhcPs
rn_expr)
; (HsExpr (GhcPass 'Renamed), Uses)
-> RnM (HsExpr (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return ( XPar (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall p. XPar p -> LHsExpr p -> HsExpr p
HsPar NoExtField
XPar (GhcPass 'Renamed)
noExtField (LHsExpr (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed))
-> LHsExpr (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$ XSpliceE (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall p. XSpliceE p -> HsSplice p -> HsExpr p
HsSpliceE NoExtField
XSpliceE (GhcPass 'Renamed)
noExtField
(HsSplice (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed))
-> (HsExpr (GhcPass 'Renamed) -> HsSplice (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed)
-> HsExpr (GhcPass 'Renamed)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XSpliced (GhcPass 'Renamed)
-> ThModFinalizers
-> HsSplicedThing (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed)
forall id.
XSpliced id -> ThModFinalizers -> HsSplicedThing id -> HsSplice id
HsSpliced NoExtField
XSpliced (GhcPass 'Renamed)
noExtField ([ForeignRef (Q ())] -> ThModFinalizers
ThModFinalizers [ForeignRef (Q ())]
mod_finalizers)
(HsSplicedThing (GhcPass 'Renamed) -> HsSplice (GhcPass 'Renamed))
-> (HsExpr (GhcPass 'Renamed) -> HsSplicedThing (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr (GhcPass 'Renamed) -> HsSplicedThing (GhcPass 'Renamed)
forall id. HsExpr id -> HsSplicedThing id
HsSplicedExpr (HsExpr (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed))
-> LHsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
LHsExpr (GhcPass 'Renamed)
lexpr3
, Uses
fvs)
}
rnSpliceType :: HsSplice GhcPs -> RnM (HsType GhcRn, FreeVars)
rnSpliceType :: HsSplice GhcPs -> RnM (HsType (GhcPass 'Renamed), Uses)
rnSpliceType HsSplice GhcPs
splice
= (HsSplice (GhcPass 'Renamed)
-> RnM (HsType (GhcPass 'Renamed), Uses))
-> (HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, HsType (GhcPass 'Renamed)))
-> HsSplice GhcPs
-> RnM (HsType (GhcPass 'Renamed), Uses)
forall a.
(HsSplice (GhcPass 'Renamed) -> RnM (a, Uses))
-> (HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a))
-> HsSplice GhcPs
-> RnM (a, Uses)
rnSpliceGen HsSplice (GhcPass 'Renamed)
-> RnM (HsType (GhcPass 'Renamed), Uses)
run_type_splice HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, HsType (GhcPass 'Renamed))
pend_type_splice HsSplice GhcPs
splice
where
pend_type_splice :: HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, HsType (GhcPass 'Renamed))
pend_type_splice HsSplice (GhcPass 'Renamed)
rn_splice
= ( UntypedSpliceFlavour
-> HsSplice (GhcPass 'Renamed) -> PendingRnSplice
makePending UntypedSpliceFlavour
UntypedTypeSplice HsSplice (GhcPass 'Renamed)
rn_splice
, XSpliceTy (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed)
forall pass. XSpliceTy pass -> HsSplice pass -> HsType pass
HsSpliceTy NoExtField
XSpliceTy (GhcPass 'Renamed)
noExtField HsSplice (GhcPass 'Renamed)
rn_splice)
run_type_splice :: HsSplice (GhcPass 'Renamed)
-> RnM (HsType (GhcPass 'Renamed), Uses)
run_type_splice HsSplice (GhcPass 'Renamed)
rn_splice
= do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rnSpliceType: untyped type splice" MsgDoc
empty
; (LHsType GhcPs
hs_ty2, [ForeignRef (Q ())]
mod_finalizers) <-
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn (LHsType GhcPs))
-> (LHsType GhcPs -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (LHsType GhcPs, [ForeignRef (Q ())])
forall res.
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn res)
-> (res -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (res, [ForeignRef (Q ())])
runRnSplice UntypedSpliceFlavour
UntypedTypeSplice LHsExpr GhcTc -> TcRn (LHsType GhcPs)
runMetaT LHsType GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
rn_splice
; (LHsType (GhcPass 'Renamed)
hs_ty3, Uses
fvs) <- do { let doc :: HsDocContext
doc = LHsType GhcPs -> HsDocContext
SpliceTypeCtx LHsType GhcPs
hs_ty2
; RnM (LHsType (GhcPass 'Renamed), Uses)
-> RnM (LHsType (GhcPass 'Renamed), Uses)
forall r. TcM r -> TcM r
checkNoErrs (RnM (LHsType (GhcPass 'Renamed), Uses)
-> RnM (LHsType (GhcPass 'Renamed), Uses))
-> RnM (LHsType (GhcPass 'Renamed), Uses)
-> RnM (LHsType (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$ HsDocContext
-> LHsType GhcPs -> RnM (LHsType (GhcPass 'Renamed), Uses)
rnLHsType HsDocContext
doc LHsType GhcPs
hs_ty2 }
; (HsType (GhcPass 'Renamed), Uses)
-> RnM (HsType (GhcPass 'Renamed), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return ( XParTy (GhcPass 'Renamed)
-> LHsType (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed)
forall pass. XParTy pass -> LHsType pass -> HsType pass
HsParTy NoExtField
XParTy (GhcPass 'Renamed)
noExtField
(LHsType (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed))
-> LHsType (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed)
forall a b. (a -> b) -> a -> b
$ XSpliceTy (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed)
forall pass. XSpliceTy pass -> HsSplice pass -> HsType pass
HsSpliceTy NoExtField
XSpliceTy (GhcPass 'Renamed)
noExtField
(HsSplice (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed))
-> (HsType (GhcPass 'Renamed) -> HsSplice (GhcPass 'Renamed))
-> HsType (GhcPass 'Renamed)
-> HsType (GhcPass 'Renamed)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XSpliced (GhcPass 'Renamed)
-> ThModFinalizers
-> HsSplicedThing (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed)
forall id.
XSpliced id -> ThModFinalizers -> HsSplicedThing id -> HsSplice id
HsSpliced NoExtField
XSpliced (GhcPass 'Renamed)
noExtField ([ForeignRef (Q ())] -> ThModFinalizers
ThModFinalizers [ForeignRef (Q ())]
mod_finalizers)
(HsSplicedThing (GhcPass 'Renamed) -> HsSplice (GhcPass 'Renamed))
-> (HsType (GhcPass 'Renamed) -> HsSplicedThing (GhcPass 'Renamed))
-> HsType (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsType (GhcPass 'Renamed) -> HsSplicedThing (GhcPass 'Renamed)
forall id. HsType id -> HsSplicedThing id
HsSplicedTy (HsType (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed))
-> LHsType (GhcPass 'Renamed) -> LHsType (GhcPass 'Renamed)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
LHsType (GhcPass 'Renamed)
hs_ty3
, Uses
fvs
) }
rnSplicePat :: HsSplice GhcPs -> RnM ( Either (Pat GhcPs) (Pat GhcRn)
, FreeVars)
rnSplicePat :: HsSplice GhcPs
-> RnM (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses)
rnSplicePat HsSplice GhcPs
splice
= (HsSplice (GhcPass 'Renamed)
-> RnM (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses))
-> (HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, Either (Pat GhcPs) (Pat (GhcPass 'Renamed))))
-> HsSplice GhcPs
-> RnM (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses)
forall a.
(HsSplice (GhcPass 'Renamed) -> RnM (a, Uses))
-> (HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a))
-> HsSplice GhcPs
-> RnM (a, Uses)
rnSpliceGen HsSplice (GhcPass 'Renamed)
-> RnM (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses)
run_pat_splice HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, Either (Pat GhcPs) (Pat (GhcPass 'Renamed)))
forall b.
HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, Either b (Pat (GhcPass 'Renamed)))
pend_pat_splice HsSplice GhcPs
splice
where
pend_pat_splice :: HsSplice GhcRn ->
(PendingRnSplice, Either b (Pat GhcRn))
pend_pat_splice :: forall b.
HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, Either b (Pat (GhcPass 'Renamed)))
pend_pat_splice HsSplice (GhcPass 'Renamed)
rn_splice
= (UntypedSpliceFlavour
-> HsSplice (GhcPass 'Renamed) -> PendingRnSplice
makePending UntypedSpliceFlavour
UntypedPatSplice HsSplice (GhcPass 'Renamed)
rn_splice
, Pat (GhcPass 'Renamed) -> Either b (Pat (GhcPass 'Renamed))
forall a b. b -> Either a b
Right (XSplicePat (GhcPass 'Renamed)
-> HsSplice (GhcPass 'Renamed) -> Pat (GhcPass 'Renamed)
forall p. XSplicePat p -> HsSplice p -> Pat p
SplicePat NoExtField
XSplicePat (GhcPass 'Renamed)
noExtField HsSplice (GhcPass 'Renamed)
rn_splice))
run_pat_splice :: HsSplice GhcRn ->
RnM (Either (Pat GhcPs) (Pat GhcRn), FreeVars)
run_pat_splice :: HsSplice (GhcPass 'Renamed)
-> RnM (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses)
run_pat_splice HsSplice (GhcPass 'Renamed)
rn_splice
= do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rnSplicePat: untyped pattern splice" MsgDoc
empty
; (GenLocated SrcSpan (Pat GhcPs)
pat, [ForeignRef (Q ())]
mod_finalizers) <-
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn (GenLocated SrcSpan (Pat GhcPs)))
-> (GenLocated SrcSpan (Pat GhcPs) -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (GenLocated SrcSpan (Pat GhcPs), [ForeignRef (Q ())])
forall res.
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn res)
-> (res -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (res, [ForeignRef (Q ())])
runRnSplice UntypedSpliceFlavour
UntypedPatSplice LHsExpr GhcTc -> TcRn (GenLocated SrcSpan (Pat GhcPs))
LHsExpr GhcTc -> TcM (LPat GhcPs)
runMetaP GenLocated SrcSpan (Pat GhcPs) -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice (GhcPass 'Renamed)
rn_splice
; (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses)
-> RnM (Either (Pat GhcPs) (Pat (GhcPass 'Renamed)), Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return ( Pat GhcPs -> Either (Pat GhcPs) (Pat (GhcPass 'Renamed))
forall a b. a -> Either a b
Left (Pat GhcPs -> Either (Pat GhcPs) (Pat (GhcPass 'Renamed)))
-> Pat GhcPs -> Either (Pat GhcPs) (Pat (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ XParPat GhcPs -> LPat GhcPs -> Pat GhcPs
forall p. XParPat p -> LPat p -> Pat p
ParPat NoExtField
XParPat GhcPs
noExtField (LPat GhcPs -> Pat GhcPs) -> LPat GhcPs -> Pat GhcPs
forall a b. (a -> b) -> a -> b
$ ((XSplicePat GhcPs -> HsSplice GhcPs -> Pat GhcPs
forall p. XSplicePat p -> HsSplice p -> Pat p
SplicePat NoExtField
XSplicePat GhcPs
noExtField)
(HsSplice GhcPs -> Pat GhcPs)
-> (Pat GhcPs -> HsSplice GhcPs) -> Pat GhcPs -> Pat GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XSpliced GhcPs
-> ThModFinalizers -> HsSplicedThing GhcPs -> HsSplice GhcPs
forall id.
XSpliced id -> ThModFinalizers -> HsSplicedThing id -> HsSplice id
HsSpliced NoExtField
XSpliced GhcPs
noExtField ([ForeignRef (Q ())] -> ThModFinalizers
ThModFinalizers [ForeignRef (Q ())]
mod_finalizers)
(HsSplicedThing GhcPs -> HsSplice GhcPs)
-> (Pat GhcPs -> HsSplicedThing GhcPs)
-> Pat GhcPs
-> HsSplice GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pat GhcPs -> HsSplicedThing GhcPs
forall id. Pat id -> HsSplicedThing id
HsSplicedPat) (Pat GhcPs -> Pat GhcPs)
-> GenLocated SrcSpan (Pat GhcPs) -> GenLocated SrcSpan (Pat GhcPs)
forall a b l. (a -> b) -> GenLocated l a -> GenLocated l b
`mapLoc`
GenLocated SrcSpan (Pat GhcPs)
pat
, Uses
emptyFVs
) }
rnSpliceDecl :: SpliceDecl GhcPs -> RnM (SpliceDecl GhcRn, FreeVars)
rnSpliceDecl :: SpliceDecl GhcPs -> RnM (SpliceDecl (GhcPass 'Renamed), Uses)
rnSpliceDecl (SpliceDecl XSpliceDecl GhcPs
_ (L SrcSpan
loc HsSplice GhcPs
splice) SpliceExplicitFlag
flg)
= (HsSplice (GhcPass 'Renamed)
-> RnM (SpliceDecl (GhcPass 'Renamed), Uses))
-> (HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, SpliceDecl (GhcPass 'Renamed)))
-> HsSplice GhcPs
-> RnM (SpliceDecl (GhcPass 'Renamed), Uses)
forall a.
(HsSplice (GhcPass 'Renamed) -> RnM (a, Uses))
-> (HsSplice (GhcPass 'Renamed) -> (PendingRnSplice, a))
-> HsSplice GhcPs
-> RnM (a, Uses)
rnSpliceGen HsSplice (GhcPass 'Renamed)
-> RnM (SpliceDecl (GhcPass 'Renamed), Uses)
forall {a} {a}. Outputable a => a -> a
run_decl_splice HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, SpliceDecl (GhcPass 'Renamed))
pend_decl_splice HsSplice GhcPs
splice
where
pend_decl_splice :: HsSplice (GhcPass 'Renamed)
-> (PendingRnSplice, SpliceDecl (GhcPass 'Renamed))
pend_decl_splice HsSplice (GhcPass 'Renamed)
rn_splice
= ( UntypedSpliceFlavour
-> HsSplice (GhcPass 'Renamed) -> PendingRnSplice
makePending UntypedSpliceFlavour
UntypedDeclSplice HsSplice (GhcPass 'Renamed)
rn_splice
, XSpliceDecl (GhcPass 'Renamed)
-> Located (HsSplice (GhcPass 'Renamed))
-> SpliceExplicitFlag
-> SpliceDecl (GhcPass 'Renamed)
forall p.
XSpliceDecl p
-> Located (HsSplice p) -> SpliceExplicitFlag -> SpliceDecl p
SpliceDecl NoExtField
XSpliceDecl (GhcPass 'Renamed)
noExtField (SrcSpan
-> HsSplice (GhcPass 'Renamed)
-> Located (HsSplice (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc HsSplice (GhcPass 'Renamed)
rn_splice) SpliceExplicitFlag
flg)
run_decl_splice :: a -> a
run_decl_splice a
rn_splice = String -> MsgDoc -> a
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"rnSpliceDecl" (a -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr a
rn_splice)
rnTopSpliceDecls :: HsSplice GhcPs -> RnM ([LHsDecl GhcPs], FreeVars)
rnTopSpliceDecls :: HsSplice GhcPs -> RnM ([LHsDecl GhcPs], Uses)
rnTopSpliceDecls HsSplice GhcPs
splice
= do { HsSplice GhcPs -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkTopSpliceAllowed HsSplice GhcPs
splice
; (HsSplice (GhcPass 'Renamed)
rn_splice, Uses
fvs) <- TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall r. TcM r -> TcM r
checkNoErrs (TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses))
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
ThStage
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a. ThStage -> TcM a -> TcM a
setStage (SpliceType -> ThStage
Splice SpliceType
Untyped) (TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses))
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
-> TcM (HsSplice (GhcPass 'Renamed), Uses)
forall a b. (a -> b) -> a -> b
$
HsSplice GhcPs -> TcM (HsSplice (GhcPass 'Renamed), Uses)
rnSplice HsSplice GhcPs
splice
; String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"rnTopSpliceDecls: untyped declaration splice" MsgDoc
empty
; ([LHsDecl GhcPs]
decls, [ForeignRef (Q ())]
mod_finalizers) <- TcM ([LHsDecl GhcPs], [ForeignRef (Q ())])
-> TcM ([LHsDecl GhcPs], [ForeignRef (Q ())])
forall r. TcM r -> TcM r
checkNoErrs (TcM ([LHsDecl GhcPs], [ForeignRef (Q ())])
-> TcM ([LHsDecl GhcPs], [ForeignRef (Q ())]))
-> TcM ([LHsDecl GhcPs], [ForeignRef (Q ())])
-> TcM ([LHsDecl GhcPs], [ForeignRef (Q ())])
forall a b. (a -> b) -> a -> b
$
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn [LHsDecl GhcPs])
-> ([LHsDecl GhcPs] -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcM ([LHsDecl GhcPs], [ForeignRef (Q ())])
forall res.
UntypedSpliceFlavour
-> (LHsExpr GhcTc -> TcRn res)
-> (res -> MsgDoc)
-> HsSplice (GhcPass 'Renamed)
-> TcRn (res, [ForeignRef (Q ())])
runRnSplice UntypedSpliceFlavour
UntypedDeclSplice LHsExpr GhcTc -> TcRn [LHsDecl GhcPs]
runMetaD [LHsDecl GhcPs] -> MsgDoc
ppr_decls HsSplice (GhcPass 'Renamed)
rn_splice
; [ForeignRef (Q ())] -> IOEnv (Env TcGblEnv TcLclEnv) ()
add_mod_finalizers_now [ForeignRef (Q ())]
mod_finalizers
; ([LHsDecl GhcPs], Uses) -> RnM ([LHsDecl GhcPs], Uses)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsDecl GhcPs]
decls,Uses
fvs) }
where
ppr_decls :: [LHsDecl GhcPs] -> SDoc
ppr_decls :: [LHsDecl GhcPs] -> MsgDoc
ppr_decls [LHsDecl GhcPs]
ds = [MsgDoc] -> MsgDoc
vcat ((LHsDecl GhcPs -> MsgDoc) -> [LHsDecl GhcPs] -> [MsgDoc]
forall a b. (a -> b) -> [a] -> [b]
map LHsDecl GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr [LHsDecl GhcPs]
ds)
add_mod_finalizers_now :: [ForeignRef (TH.Q ())] -> TcRn ()
add_mod_finalizers_now :: [ForeignRef (Q ())] -> IOEnv (Env TcGblEnv TcLclEnv) ()
add_mod_finalizers_now [] = () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
add_mod_finalizers_now [ForeignRef (Q ())]
mod_finalizers = do
TcRef [(TcLclEnv, ThModFinalizers)]
th_modfinalizers_var <- (TcGblEnv -> TcRef [(TcLclEnv, ThModFinalizers)])
-> TcRnIf TcGblEnv TcLclEnv TcGblEnv
-> IOEnv
(Env TcGblEnv TcLclEnv) (TcRef [(TcLclEnv, ThModFinalizers)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TcGblEnv -> TcRef [(TcLclEnv, ThModFinalizers)]
tcg_th_modfinalizers TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
TcLclEnv
env <- TcRnIf TcGblEnv TcLclEnv TcLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
TcRef [(TcLclEnv, ThModFinalizers)]
-> ([(TcLclEnv, ThModFinalizers)] -> [(TcLclEnv, ThModFinalizers)])
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a gbl lcl. TcRef a -> (a -> a) -> TcRnIf gbl lcl ()
updTcRef TcRef [(TcLclEnv, ThModFinalizers)]
th_modfinalizers_var (([(TcLclEnv, ThModFinalizers)] -> [(TcLclEnv, ThModFinalizers)])
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> ([(TcLclEnv, ThModFinalizers)] -> [(TcLclEnv, ThModFinalizers)])
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ \[(TcLclEnv, ThModFinalizers)]
fins ->
(TcLclEnv
env, [ForeignRef (Q ())] -> ThModFinalizers
ThModFinalizers [ForeignRef (Q ())]
mod_finalizers) (TcLclEnv, ThModFinalizers)
-> [(TcLclEnv, ThModFinalizers)] -> [(TcLclEnv, ThModFinalizers)]
forall a. a -> [a] -> [a]
: [(TcLclEnv, ThModFinalizers)]
fins
spliceCtxt :: HsSplice GhcPs -> SDoc
spliceCtxt :: HsSplice GhcPs -> MsgDoc
spliceCtxt HsSplice GhcPs
splice
= MsgDoc -> ThLevel -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"In the" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
what) ThLevel
2 (HsSplice GhcPs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr HsSplice GhcPs
splice)
where
what :: MsgDoc
what = case HsSplice GhcPs
splice of
HsUntypedSplice {} -> String -> MsgDoc
text String
"untyped splice:"
HsTypedSplice {} -> String -> MsgDoc
text String
"typed splice:"
HsQuasiQuote {} -> String -> MsgDoc
text String
"quasi-quotation:"
HsSpliced {} -> String -> MsgDoc
text String
"spliced expression:"
data SpliceInfo
= SpliceInfo
{ SpliceInfo -> String
spliceDescription :: String
, SpliceInfo -> Maybe (LHsExpr (GhcPass 'Renamed))
spliceSource :: Maybe (LHsExpr GhcRn)
, SpliceInfo -> Bool
spliceIsDecl :: Bool
, SpliceInfo -> MsgDoc
spliceGenerated :: SDoc
}
traceSplice :: SpliceInfo -> TcM ()
traceSplice :: SpliceInfo -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceSplice (SpliceInfo { spliceDescription :: SpliceInfo -> String
spliceDescription = String
sd, spliceSource :: SpliceInfo -> Maybe (LHsExpr (GhcPass 'Renamed))
spliceSource = Maybe (LHsExpr (GhcPass 'Renamed))
mb_src
, spliceGenerated :: SpliceInfo -> MsgDoc
spliceGenerated = MsgDoc
gen, spliceIsDecl :: SpliceInfo -> Bool
spliceIsDecl = Bool
is_decl })
= do { SrcSpan
loc <- case Maybe (LHsExpr (GhcPass 'Renamed))
mb_src of
Maybe (LHsExpr (GhcPass 'Renamed))
Nothing -> TcRn SrcSpan
getSrcSpanM
Just (L SrcSpan
loc HsExpr (GhcPass 'Renamed)
_) -> SrcSpan -> TcRn SrcSpan
forall (m :: * -> *) a. Monad m => a -> m a
return SrcSpan
loc
; DumpFlag -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceOptTcRn DumpFlag
Opt_D_dump_splices (SrcSpan -> MsgDoc
spliceDebugDoc SrcSpan
loc)
; Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
is_decl (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
do { DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; IO () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IO () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ PrintUnqualified
-> DynFlags -> DumpFlag -> String -> DumpFormat -> MsgDoc -> IO ()
dumpIfSet_dyn_printer PrintUnqualified
alwaysQualify DynFlags
dflags DumpFlag
Opt_D_th_dec_file
String
"" DumpFormat
FormatHaskell (SrcSpan -> MsgDoc
spliceCodeDoc SrcSpan
loc) } }
where
spliceDebugDoc :: SrcSpan -> SDoc
spliceDebugDoc :: SrcSpan -> MsgDoc
spliceDebugDoc SrcSpan
loc
= let code :: [MsgDoc]
code = case Maybe (LHsExpr (GhcPass 'Renamed))
mb_src of
Maybe (LHsExpr (GhcPass 'Renamed))
Nothing -> [MsgDoc]
ending
Just LHsExpr (GhcPass 'Renamed)
e -> ThLevel -> MsgDoc -> MsgDoc
nest ThLevel
2 (LHsExpr (GhcPass 'Renamed) -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr (LHsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall (p :: Pass). LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr LHsExpr (GhcPass 'Renamed)
e)) MsgDoc -> [MsgDoc] -> [MsgDoc]
forall a. a -> [a] -> [a]
: [MsgDoc]
ending
ending :: [MsgDoc]
ending = [ String -> MsgDoc
text String
"======>", ThLevel -> MsgDoc -> MsgDoc
nest ThLevel
2 MsgDoc
gen ]
in MsgDoc -> ThLevel -> MsgDoc -> MsgDoc
hang (SrcSpan -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr SrcSpan
loc MsgDoc -> MsgDoc -> MsgDoc
<> MsgDoc
colon MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
"Splicing" MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
sd)
ThLevel
2 ([MsgDoc] -> MsgDoc
sep [MsgDoc]
code)
spliceCodeDoc :: SrcSpan -> SDoc
spliceCodeDoc :: SrcSpan -> MsgDoc
spliceCodeDoc SrcSpan
loc
= [MsgDoc] -> MsgDoc
vcat [ String -> MsgDoc
text String
"--" MsgDoc -> MsgDoc -> MsgDoc
<+> SrcSpan -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr SrcSpan
loc MsgDoc -> MsgDoc -> MsgDoc
<> MsgDoc
colon MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
"Splicing" MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
sd
, MsgDoc
gen ]
illegalTypedSplice :: SDoc
illegalTypedSplice :: MsgDoc
illegalTypedSplice = String -> MsgDoc
text String
"Typed splices may not appear in untyped brackets"
illegalUntypedSplice :: SDoc
illegalUntypedSplice :: MsgDoc
illegalUntypedSplice = String -> MsgDoc
text String
"Untyped splices may not appear in typed brackets"
checkThLocalName :: Name -> RnM ()
checkThLocalName :: Name -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkThLocalName Name
name
| Name -> Bool
isUnboundName Name
name
= () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"checkThLocalName" (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Name
name)
; Maybe (TopLevelFlag, ThLevel, ThStage)
mb_local_use <- Name -> TcRn (Maybe (TopLevelFlag, ThLevel, ThStage))
getStageAndBindLevel Name
name
; case Maybe (TopLevelFlag, ThLevel, ThStage)
mb_local_use of {
Maybe (TopLevelFlag, ThLevel, ThStage)
Nothing -> () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return () ;
Just (TopLevelFlag
top_lvl, ThLevel
bind_lvl, ThStage
use_stage) ->
do { let use_lvl :: ThLevel
use_lvl = ThStage -> ThLevel
thLevel ThStage
use_stage
; MsgDoc -> ThLevel -> ThLevel -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkWellStaged (MsgDoc -> MsgDoc
quotes (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Name
name)) ThLevel
bind_lvl ThLevel
use_lvl
; String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"checkThLocalName" (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Name
name MsgDoc -> MsgDoc -> MsgDoc
<+> ThLevel -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ThLevel
bind_lvl
MsgDoc -> MsgDoc -> MsgDoc
<+> ThStage -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ThStage
use_stage
MsgDoc -> MsgDoc -> MsgDoc
<+> ThLevel -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr ThLevel
use_lvl)
; TopLevelFlag
-> ThLevel
-> ThStage
-> ThLevel
-> Name
-> IOEnv (Env TcGblEnv TcLclEnv) ()
checkCrossStageLifting TopLevelFlag
top_lvl ThLevel
bind_lvl ThStage
use_stage ThLevel
use_lvl Name
name } } }
checkCrossStageLifting :: TopLevelFlag -> ThLevel -> ThStage -> ThLevel
-> Name -> TcM ()
checkCrossStageLifting :: TopLevelFlag
-> ThLevel
-> ThStage
-> ThLevel
-> Name
-> IOEnv (Env TcGblEnv TcLclEnv) ()
checkCrossStageLifting TopLevelFlag
top_lvl ThLevel
bind_lvl ThStage
use_stage ThLevel
use_lvl Name
name
| Brack ThStage
_ (RnPendingUntyped IORef [PendingRnSplice]
ps_var) <- ThStage
use_stage
, ThLevel
use_lvl ThLevel -> ThLevel -> Bool
forall a. Ord a => a -> a -> Bool
> ThLevel
bind_lvl
= TopLevelFlag
-> Name
-> IORef [PendingRnSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) ()
check_cross_stage_lifting TopLevelFlag
top_lvl Name
name IORef [PendingRnSplice]
ps_var
| Bool
otherwise
= () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
check_cross_stage_lifting :: TopLevelFlag -> Name -> TcRef [PendingRnSplice] -> TcM ()
check_cross_stage_lifting :: TopLevelFlag
-> Name
-> IORef [PendingRnSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) ()
check_cross_stage_lifting TopLevelFlag
top_lvl Name
name IORef [PendingRnSplice]
ps_var
| TopLevelFlag -> Bool
isTopLevel TopLevelFlag
top_lvl
= Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Name -> Bool
isExternalName Name
name) (Name -> IOEnv (Env TcGblEnv TcLclEnv) ()
keepAlive Name
name)
| Bool
otherwise
=
do { String -> MsgDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
traceRn String
"checkCrossStageLifting" (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
ppr Name
name)
; let lift_expr :: LHsExpr (GhcPass 'Renamed)
lift_expr = LHsExpr (GhcPass 'Renamed)
-> LHsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall (id :: Pass).
IsPass id =>
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar Name
IdP (GhcPass 'Renamed)
liftName) (IdP (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar Name
IdP (GhcPass 'Renamed)
name)
pend_splice :: PendingRnSplice
pend_splice = UntypedSpliceFlavour
-> Name -> LHsExpr (GhcPass 'Renamed) -> PendingRnSplice
PendingRnSplice UntypedSpliceFlavour
UntypedExpSplice Name
name LHsExpr (GhcPass 'Renamed)
lift_expr
; [PendingRnSplice]
ps <- IORef [PendingRnSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) [PendingRnSplice]
forall a env. IORef a -> IOEnv env a
readMutVar IORef [PendingRnSplice]
ps_var
; IORef [PendingRnSplice]
-> [PendingRnSplice] -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef [PendingRnSplice]
ps_var (PendingRnSplice
pend_splice PendingRnSplice -> [PendingRnSplice] -> [PendingRnSplice]
forall a. a -> [a] -> [a]
: [PendingRnSplice]
ps) }