{-# LANGUAGE CPP, TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module GHC.Tc.Utils.Zonk (
hsLitType, hsPatType, hsLPatType,
mkHsDictLet, mkHsApp,
mkHsAppTy, mkHsCaseAlt,
shortCutLit, hsOverLitName,
conLikeResTy,
TcId, TcIdSet,
zonkTopDecls, zonkTopExpr, zonkTopLExpr,
zonkTopBndrs,
ZonkEnv, ZonkFlexi(..), emptyZonkEnv, mkEmptyZonkEnv, initZonkEnv,
zonkTyVarBinders, zonkTyVarBindersX, zonkTyVarBinderX,
zonkTyBndrs, zonkTyBndrsX,
zonkTcTypeToType, zonkTcTypeToTypeX,
zonkTcTypesToTypes, zonkTcTypesToTypesX, zonkScaledTcTypesToTypesX,
zonkTyVarOcc,
zonkCoToCo,
zonkEvBinds, zonkTcEvBinds,
zonkTcMethInfoToMethInfoX,
lookupTyVarOcc
) where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Hs
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Core.Predicate
import GHC.Tc.Utils.Monad
import GHC.Builtin.Names
import GHC.Tc.TyCl.Build ( TcMethInfo, MethInfo )
import GHC.Tc.Utils.TcType
import GHC.Tc.Utils.TcMType
import GHC.Tc.Utils.Env ( tcLookupGlobalOnly )
import GHC.Tc.Types.Evidence
import GHC.Core.TyCo.Ppr ( pprTyVar )
import GHC.Builtin.Types.Prim
import GHC.Core.TyCon
import GHC.Builtin.Types
import GHC.Core.Type
import GHC.Core.Coercion
import GHC.Core.ConLike
import GHC.Core.DataCon
import GHC.Driver.Types
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Var
import GHC.Types.Var.Env
import GHC.Platform
import GHC.Types.Basic
import GHC.Data.Maybe
import GHC.Types.SrcLoc
import GHC.Data.Bag
import GHC.Utils.Outputable
import GHC.Utils.Misc
import GHC.Types.Unique.FM
import GHC.Core.Multiplicity
import GHC.Core
import {-# SOURCE #-} GHC.Tc.Gen.Splice (runTopSplice)
import Control.Monad
import Data.List ( partition )
import Control.Arrow ( second )
hsLPatType :: LPat GhcTc -> Type
hsLPatType :: LPat GhcTc -> Kind
hsLPatType (L SrcSpan
_ Pat GhcTc
p) = Pat GhcTc -> Kind
hsPatType Pat GhcTc
p
hsPatType :: Pat GhcTc -> Type
hsPatType :: Pat GhcTc -> Kind
hsPatType (ParPat XParPat GhcTc
_ LPat GhcTc
pat) = LPat GhcTc -> Kind
hsLPatType LPat GhcTc
pat
hsPatType (WildPat XWildPat GhcTc
ty) = Kind
XWildPat GhcTc
ty
hsPatType (VarPat XVarPat GhcTc
_ Located (IdP GhcTc)
lvar) = Id -> Kind
idType (GenLocated SrcSpan Id -> Id
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpan Id
Located (IdP GhcTc)
lvar)
hsPatType (BangPat XBangPat GhcTc
_ LPat GhcTc
pat) = LPat GhcTc -> Kind
hsLPatType LPat GhcTc
pat
hsPatType (LazyPat XLazyPat GhcTc
_ LPat GhcTc
pat) = LPat GhcTc -> Kind
hsLPatType LPat GhcTc
pat
hsPatType (LitPat XLitPat GhcTc
_ HsLit GhcTc
lit) = HsLit GhcTc -> Kind
forall (p :: Pass). HsLit (GhcPass p) -> Kind
hsLitType HsLit GhcTc
lit
hsPatType (AsPat XAsPat GhcTc
_ Located (IdP GhcTc)
var LPat GhcTc
_) = Id -> Kind
idType (GenLocated SrcSpan Id -> Id
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpan Id
Located (IdP GhcTc)
var)
hsPatType (ViewPat XViewPat GhcTc
ty LHsExpr GhcTc
_ LPat GhcTc
_) = Kind
XViewPat GhcTc
ty
hsPatType (ListPat (ListPatTc Kind
ty Maybe (Kind, SyntaxExpr GhcTc)
Nothing) [LPat GhcTc]
_) = Kind -> Kind
mkListTy Kind
ty
hsPatType (ListPat (ListPatTc Kind
_ (Just (Kind
ty,SyntaxExpr GhcTc
_))) [LPat GhcTc]
_) = Kind
ty
hsPatType (TuplePat XTuplePat GhcTc
tys [LPat GhcTc]
_ Boxity
bx) = Boxity -> [Kind] -> Kind
mkTupleTy1 Boxity
bx [Kind]
XTuplePat GhcTc
tys
hsPatType (SumPat XSumPat GhcTc
tys LPat GhcTc
_ ConTag
_ ConTag
_ ) = [Kind] -> Kind
mkSumTy [Kind]
XSumPat GhcTc
tys
hsPatType (ConPat { pat_con :: forall p. Pat p -> Located (ConLikeP p)
pat_con = Located (ConLikeP GhcTc)
lcon
, pat_con_ext :: forall p. Pat p -> XConPat p
pat_con_ext = ConPatTc
{ cpt_arg_tys :: ConPatTc -> [Kind]
cpt_arg_tys = [Kind]
tys
}
})
= ConLike -> [Kind] -> Kind
conLikeResTy (GenLocated SrcSpan ConLike -> ConLike
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpan ConLike
Located (ConLikeP GhcTc)
lcon) [Kind]
tys
hsPatType (SigPat XSigPat GhcTc
ty LPat GhcTc
_ HsPatSigType (NoGhcTc GhcTc)
_) = Kind
XSigPat GhcTc
ty
hsPatType (NPat XNPat GhcTc
ty Located (HsOverLit GhcTc)
_ Maybe (SyntaxExpr GhcTc)
_ SyntaxExpr GhcTc
_) = Kind
XNPat GhcTc
ty
hsPatType (NPlusKPat XNPlusKPat GhcTc
ty Located (IdP GhcTc)
_ Located (HsOverLit GhcTc)
_ HsOverLit GhcTc
_ SyntaxExpr GhcTc
_ SyntaxExpr GhcTc
_) = Kind
XNPlusKPat GhcTc
ty
hsPatType (XPat (CoPat HsWrapper
_ Pat GhcTc
_ Kind
ty)) = Kind
ty
hsPatType SplicePat{} = String -> Kind
forall a. String -> a
panic String
"hsPatType: SplicePat"
hsLitType :: HsLit (GhcPass p) -> TcType
hsLitType :: forall (p :: Pass). HsLit (GhcPass p) -> Kind
hsLitType (HsChar XHsChar (GhcPass p)
_ Char
_) = Kind
charTy
hsLitType (HsCharPrim XHsCharPrim (GhcPass p)
_ Char
_) = Kind
charPrimTy
hsLitType (HsString XHsString (GhcPass p)
_ FastString
_) = Kind
stringTy
hsLitType (HsStringPrim XHsStringPrim (GhcPass p)
_ ByteString
_) = Kind
addrPrimTy
hsLitType (HsInt XHsInt (GhcPass p)
_ IntegralLit
_) = Kind
intTy
hsLitType (HsIntPrim XHsIntPrim (GhcPass p)
_ Integer
_) = Kind
intPrimTy
hsLitType (HsWordPrim XHsWordPrim (GhcPass p)
_ Integer
_) = Kind
wordPrimTy
hsLitType (HsInt64Prim XHsInt64Prim (GhcPass p)
_ Integer
_) = Kind
int64PrimTy
hsLitType (HsWord64Prim XHsWord64Prim (GhcPass p)
_ Integer
_) = Kind
word64PrimTy
hsLitType (HsInteger XHsInteger (GhcPass p)
_ Integer
_ Kind
ty) = Kind
ty
hsLitType (HsRat XHsRat (GhcPass p)
_ FractionalLit
_ Kind
ty) = Kind
ty
hsLitType (HsFloatPrim XHsFloatPrim (GhcPass p)
_ FractionalLit
_) = Kind
floatPrimTy
hsLitType (HsDoublePrim XHsDoublePrim (GhcPass p)
_ FractionalLit
_) = Kind
doublePrimTy
shortCutLit :: Platform -> OverLitVal -> TcType -> Maybe (HsExpr GhcTc)
shortCutLit :: Platform -> OverLitVal -> Kind -> Maybe (HsExpr GhcTc)
shortCutLit Platform
platform (HsIntegral int :: IntegralLit
int@(IL SourceText
src Bool
neg Integer
i)) Kind
ty
| Kind -> Bool
isIntTy Kind
ty Bool -> Bool -> Bool
&& Platform -> Integer -> Bool
platformInIntRange Platform
platform Integer
i = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit NoExtField
XLitE GhcTc
noExtField (XHsInt GhcTc -> IntegralLit -> HsLit GhcTc
forall x. XHsInt x -> IntegralLit -> HsLit x
HsInt NoExtField
XHsInt GhcTc
noExtField IntegralLit
int))
| Kind -> Bool
isWordTy Kind
ty Bool -> Bool -> Bool
&& Platform -> Integer -> Bool
platformInWordRange Platform
platform Integer
i = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
wordDataCon (XHsWordPrim GhcTc -> Integer -> HsLit GhcTc
forall x. XHsWordPrim x -> Integer -> HsLit x
HsWordPrim SourceText
XHsWordPrim GhcTc
src Integer
i))
| Kind -> Bool
isIntegerTy Kind
ty = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit NoExtField
XLitE GhcTc
noExtField (XHsInteger GhcTc -> Integer -> Kind -> HsLit GhcTc
forall x. XHsInteger x -> Integer -> Kind -> HsLit x
HsInteger SourceText
XHsInteger GhcTc
src Integer
i Kind
ty))
| Bool
otherwise = Platform -> OverLitVal -> Kind -> Maybe (HsExpr GhcTc)
shortCutLit Platform
platform (FractionalLit -> OverLitVal
HsFractional (Bool -> Integer -> FractionalLit
integralFractionalLit Bool
neg Integer
i)) Kind
ty
shortCutLit Platform
_ (HsFractional FractionalLit
f) Kind
ty
| Kind -> Bool
isFloatTy Kind
ty = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
floatDataCon (XHsFloatPrim GhcTc -> FractionalLit -> HsLit GhcTc
forall x. XHsFloatPrim x -> FractionalLit -> HsLit x
HsFloatPrim NoExtField
XHsFloatPrim GhcTc
noExtField FractionalLit
f))
| Kind -> Bool
isDoubleTy Kind
ty = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
doubleDataCon (XHsDoublePrim GhcTc -> FractionalLit -> HsLit GhcTc
forall x. XHsDoublePrim x -> FractionalLit -> HsLit x
HsDoublePrim NoExtField
XHsDoublePrim GhcTc
noExtField FractionalLit
f))
| Bool
otherwise = Maybe (HsExpr GhcTc)
forall a. Maybe a
Nothing
shortCutLit Platform
_ (HsIsString SourceText
src FastString
s) Kind
ty
| Kind -> Bool
isStringTy Kind
ty = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit NoExtField
XLitE GhcTc
noExtField (XHsString GhcTc -> FastString -> HsLit GhcTc
forall x. XHsString x -> FastString -> HsLit x
HsString SourceText
XHsString GhcTc
src FastString
s))
| Bool
otherwise = Maybe (HsExpr GhcTc)
forall a. Maybe a
Nothing
mkLit :: DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit :: DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
con HsLit GhcTc
lit = XApp GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp NoExtField
XApp GhcTc
noExtField (DataCon -> LHsExpr GhcTc
nlHsDataCon DataCon
con) (HsLit GhcTc -> LHsExpr GhcTc
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit HsLit GhcTc
lit)
hsOverLitName :: OverLitVal -> Name
hsOverLitName :: OverLitVal -> Name
hsOverLitName (HsIntegral {}) = Name
fromIntegerName
hsOverLitName (HsFractional {}) = Name
fromRationalName
hsOverLitName (HsIsString {}) = Name
fromStringName
data ZonkEnv
= ZonkEnv { ZonkEnv -> ZonkFlexi
ze_flexi :: ZonkFlexi
, ZonkEnv -> TyCoVarEnv Id
ze_tv_env :: TyCoVarEnv TyCoVar
, ZonkEnv -> TyCoVarEnv Id
ze_id_env :: IdEnv Id
, ZonkEnv -> TcRef (TyVarEnv Kind)
ze_meta_tv_env :: TcRef (TyVarEnv Type) }
data ZonkFlexi
= DefaultFlexi
| SkolemiseFlexi
| RuntimeUnkFlexi
instance Outputable ZonkEnv where
ppr :: ZonkEnv -> SDoc
ppr (ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
tv_env
, ze_id_env :: ZonkEnv -> TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
id_env })
= String -> SDoc
text String
"ZE" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
braces ([SDoc] -> SDoc
vcat
[ String -> SDoc
text String
"ze_tv_env =" SDoc -> SDoc -> SDoc
<+> TyCoVarEnv Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVarEnv Id
tv_env
, String -> SDoc
text String
"ze_id_env =" SDoc -> SDoc -> SDoc
<+> TyCoVarEnv Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVarEnv Id
id_env ])
emptyZonkEnv :: TcM ZonkEnv
emptyZonkEnv :: TcM ZonkEnv
emptyZonkEnv = ZonkFlexi -> TcM ZonkEnv
mkEmptyZonkEnv ZonkFlexi
DefaultFlexi
mkEmptyZonkEnv :: ZonkFlexi -> TcM ZonkEnv
mkEmptyZonkEnv :: ZonkFlexi -> TcM ZonkEnv
mkEmptyZonkEnv ZonkFlexi
flexi
= do { TcRef (TyVarEnv Kind)
mtv_env_ref <- TyVarEnv Kind -> TcRnIf TcGblEnv TcLclEnv (TcRef (TyVarEnv Kind))
forall a gbl lcl. a -> TcRnIf gbl lcl (TcRef a)
newTcRef TyVarEnv Kind
forall a. VarEnv a
emptyVarEnv
; ZonkEnv -> TcM ZonkEnv
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv :: ZonkFlexi
-> TyCoVarEnv Id
-> TyCoVarEnv Id
-> TcRef (TyVarEnv Kind)
-> ZonkEnv
ZonkEnv { ze_flexi :: ZonkFlexi
ze_flexi = ZonkFlexi
flexi
, ze_tv_env :: TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
forall a. VarEnv a
emptyVarEnv
, ze_id_env :: TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
forall a. VarEnv a
emptyVarEnv
, ze_meta_tv_env :: TcRef (TyVarEnv Kind)
ze_meta_tv_env = TcRef (TyVarEnv Kind)
mtv_env_ref }) }
initZonkEnv :: (ZonkEnv -> TcM b) -> TcM b
initZonkEnv :: forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ZonkEnv -> TcM b
thing_inside = do { ZonkEnv
ze <- ZonkFlexi -> TcM ZonkEnv
mkEmptyZonkEnv ZonkFlexi
DefaultFlexi
; ZonkEnv -> TcM b
thing_inside ZonkEnv
ze }
extendIdZonkEnvRec :: ZonkEnv -> [Var] -> ZonkEnv
extendIdZonkEnvRec :: ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ze :: ZonkEnv
ze@(ZonkEnv { ze_id_env :: ZonkEnv -> TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
id_env }) [Id]
ids
= ZonkEnv
ze { ze_id_env :: TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id -> [(Id, Id)] -> TyCoVarEnv Id
forall a. VarEnv a -> [(Id, a)] -> VarEnv a
extendVarEnvList TyCoVarEnv Id
id_env [(Id
id,Id
id) | Id
id <- [Id]
ids] }
extendZonkEnv :: ZonkEnv -> [Var] -> ZonkEnv
extendZonkEnv :: ZonkEnv -> [Id] -> ZonkEnv
extendZonkEnv ze :: ZonkEnv
ze@(ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
tyco_env, ze_id_env :: ZonkEnv -> TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
id_env }) [Id]
vars
= ZonkEnv
ze { ze_tv_env :: TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id -> [(Id, Id)] -> TyCoVarEnv Id
forall a. VarEnv a -> [(Id, a)] -> VarEnv a
extendVarEnvList TyCoVarEnv Id
tyco_env [(Id
tv,Id
tv) | Id
tv <- [Id]
tycovars]
, ze_id_env :: TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id -> [(Id, Id)] -> TyCoVarEnv Id
forall a. VarEnv a -> [(Id, a)] -> VarEnv a
extendVarEnvList TyCoVarEnv Id
id_env [(Id
id,Id
id) | Id
id <- [Id]
ids] }
where
([Id]
tycovars, [Id]
ids) = (Id -> Bool) -> [Id] -> ([Id], [Id])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Id -> Bool
isTyCoVar [Id]
vars
extendIdZonkEnv :: ZonkEnv -> Var -> ZonkEnv
extendIdZonkEnv :: ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ze :: ZonkEnv
ze@(ZonkEnv { ze_id_env :: ZonkEnv -> TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
id_env }) Id
id
= ZonkEnv
ze { ze_id_env :: TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id -> Id -> Id -> TyCoVarEnv Id
forall a. VarEnv a -> Id -> a -> VarEnv a
extendVarEnv TyCoVarEnv Id
id_env Id
id Id
id }
extendTyZonkEnv :: ZonkEnv -> TyVar -> ZonkEnv
extendTyZonkEnv :: ZonkEnv -> Id -> ZonkEnv
extendTyZonkEnv ze :: ZonkEnv
ze@(ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
ty_env }) Id
tv
= ZonkEnv
ze { ze_tv_env :: TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id -> Id -> Id -> TyCoVarEnv Id
forall a. VarEnv a -> Id -> a -> VarEnv a
extendVarEnv TyCoVarEnv Id
ty_env Id
tv Id
tv }
setZonkType :: ZonkEnv -> ZonkFlexi -> ZonkEnv
setZonkType :: ZonkEnv -> ZonkFlexi -> ZonkEnv
setZonkType ZonkEnv
ze ZonkFlexi
flexi = ZonkEnv
ze { ze_flexi :: ZonkFlexi
ze_flexi = ZonkFlexi
flexi }
zonkEnvIds :: ZonkEnv -> TypeEnv
zonkEnvIds :: ZonkEnv -> TypeEnv
zonkEnvIds (ZonkEnv { ze_id_env :: ZonkEnv -> TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
id_env})
= [(Name, TyThing)] -> TypeEnv
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Id -> Name
forall a. NamedThing a => a -> Name
getName Id
id, Id -> TyThing
AnId Id
id) | Id
id <- TyCoVarEnv Id -> [Id]
forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM TyCoVarEnv Id
id_env]
zonkLIdOcc :: ZonkEnv -> Located TcId -> Located Id
zonkLIdOcc :: ZonkEnv -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
zonkLIdOcc ZonkEnv
env = (Id -> Id) -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
forall a b l. (a -> b) -> GenLocated l a -> GenLocated l b
mapLoc (ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env)
zonkIdOcc :: ZonkEnv -> TcId -> Id
zonkIdOcc :: ZonkEnv -> Id -> Id
zonkIdOcc (ZonkEnv { ze_id_env :: ZonkEnv -> TyCoVarEnv Id
ze_id_env = TyCoVarEnv Id
id_env}) Id
id
| Id -> Bool
isLocalVar Id
id = TyCoVarEnv Id -> Id -> Maybe Id
forall a. VarEnv a -> Id -> Maybe a
lookupVarEnv TyCoVarEnv Id
id_env Id
id Maybe Id -> Id -> Id
forall a. Maybe a -> a -> a
`orElse`
Id
id
| Bool
otherwise = Id
id
zonkIdOccs :: ZonkEnv -> [TcId] -> [Id]
zonkIdOccs :: ZonkEnv -> [Id] -> [Id]
zonkIdOccs ZonkEnv
env [Id]
ids = (Id -> Id) -> [Id] -> [Id]
forall a b. (a -> b) -> [a] -> [b]
map (ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env) [Id]
ids
zonkIdBndr :: ZonkEnv -> TcId -> TcM Id
zonkIdBndr :: ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
v
= do Scaled Kind
w' Kind
ty' <- ZonkEnv -> Scaled Kind -> TcM (Scaled Kind)
zonkScaledTcTypeToTypeX ZonkEnv
env (Id -> Scaled Kind
idScaledType Id
v)
Kind -> SDoc -> TcM ()
ensureNotLevPoly Kind
ty'
(String -> SDoc
text String
"In the type of binder" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr Id
v))
Id -> TcM Id
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => (IdInfo -> IdInfo) -> Id -> Id
(IdInfo -> IdInfo) -> Id -> Id
modifyIdInfo (IdInfo -> Kind -> IdInfo
`setLevityInfoWithType` Kind
ty') (Id -> Kind -> Id
setIdMult (Id -> Kind -> Id
setIdType Id
v Kind
ty') Kind
w'))
zonkIdBndrs :: ZonkEnv -> [TcId] -> TcM [Id]
zonkIdBndrs :: ZonkEnv -> [Id] -> TcM [Id]
zonkIdBndrs ZonkEnv
env [Id]
ids = (Id -> TcM Id) -> [Id] -> TcM [Id]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env) [Id]
ids
zonkTopBndrs :: [TcId] -> TcM [Id]
zonkTopBndrs :: [Id] -> TcM [Id]
zonkTopBndrs [Id]
ids = (ZonkEnv -> TcM [Id]) -> TcM [Id]
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> TcM [Id]) -> TcM [Id])
-> (ZonkEnv -> TcM [Id]) -> TcM [Id]
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> [Id] -> TcM [Id]
zonkIdBndrs ZonkEnv
ze [Id]
ids
zonkFieldOcc :: ZonkEnv -> FieldOcc GhcTc -> TcM (FieldOcc GhcTc)
zonkFieldOcc :: ZonkEnv -> FieldOcc GhcTc -> TcM (FieldOcc GhcTc)
zonkFieldOcc ZonkEnv
env (FieldOcc XCFieldOcc GhcTc
sel Located RdrName
lbl)
= (Id -> FieldOcc GhcTc) -> TcM Id -> TcM (FieldOcc GhcTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Id -> Located RdrName -> FieldOcc GhcTc)
-> Located RdrName -> Id -> FieldOcc GhcTc
forall a b c. (a -> b -> c) -> b -> a -> c
flip Id -> Located RdrName -> FieldOcc GhcTc
forall pass. XCFieldOcc pass -> Located RdrName -> FieldOcc pass
FieldOcc) Located RdrName
lbl) (TcM Id -> TcM (FieldOcc GhcTc)) -> TcM Id -> TcM (FieldOcc GhcTc)
forall a b. (a -> b) -> a -> b
$ ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
XCFieldOcc GhcTc
sel
zonkEvBndrsX :: ZonkEnv -> [EvVar] -> TcM (ZonkEnv, [Var])
zonkEvBndrsX :: ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkEvBndrsX = (ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id))
-> ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkEvBndrX
zonkEvBndrX :: ZonkEnv -> EvVar -> TcM (ZonkEnv, EvVar)
zonkEvBndrX :: ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkEvBndrX ZonkEnv
env Id
var
= do { Id
var' <- ZonkEnv -> Id -> TcM Id
zonkEvBndr ZonkEnv
env Id
var
; (ZonkEnv, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> [Id] -> ZonkEnv
extendZonkEnv ZonkEnv
env [Id
var'], Id
var') }
zonkEvBndr :: ZonkEnv -> EvVar -> TcM EvVar
zonkEvBndr :: ZonkEnv -> Id -> TcM Id
zonkEvBndr ZonkEnv
env Id
var
= (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind) -> Id -> TcM Id
forall (m :: * -> *). Monad m => (Kind -> m Kind) -> Id -> m Id
updateIdTypeAndMultM ({-# SCC "zonkEvBndr_zonkTcTypeToType" #-} ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) Id
var
zonkCoreBndrX :: ZonkEnv -> Var -> TcM (ZonkEnv, Var)
zonkCoreBndrX :: ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkCoreBndrX ZonkEnv
env Id
v
| Id -> Bool
isId Id
v = do { Id
v' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
v
; (ZonkEnv, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ZonkEnv
env Id
v', Id
v') }
| Bool
otherwise = ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX ZonkEnv
env Id
v
zonkCoreBndrsX :: ZonkEnv -> [Var] -> TcM (ZonkEnv, [Var])
zonkCoreBndrsX :: ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkCoreBndrsX = (ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id))
-> ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkCoreBndrX
zonkTyBndrs :: [TcTyVar] -> TcM (ZonkEnv, [TyVar])
zonkTyBndrs :: [Id] -> TcM (ZonkEnv, [Id])
zonkTyBndrs [Id]
tvs = (ZonkEnv -> TcM (ZonkEnv, [Id])) -> TcM (ZonkEnv, [Id])
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> TcM (ZonkEnv, [Id])) -> TcM (ZonkEnv, [Id]))
-> (ZonkEnv -> TcM (ZonkEnv, [Id])) -> TcM (ZonkEnv, [Id])
forall a b. (a -> b) -> a -> b
$ \ZonkEnv
ze -> ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkTyBndrsX ZonkEnv
ze [Id]
tvs
zonkTyBndrsX :: ZonkEnv -> [TcTyVar] -> TcM (ZonkEnv, [TyVar])
zonkTyBndrsX :: ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkTyBndrsX = (ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id))
-> ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX
zonkTyBndrX :: ZonkEnv -> TcTyVar -> TcM (ZonkEnv, TyVar)
zonkTyBndrX :: ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX ZonkEnv
env Id
tv
= ASSERT2( isImmutableTyVar tv, ppr tv <+> dcolon <+> ppr (tyVarKind tv) )
do { Kind
ki <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env (Id -> Kind
tyVarKind Id
tv)
; let tv' :: Id
tv' = Name -> Kind -> Id
mkTyVar (Id -> Name
tyVarName Id
tv) Kind
ki
; (ZonkEnv, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> Id -> ZonkEnv
extendTyZonkEnv ZonkEnv
env Id
tv', Id
tv') }
zonkTyVarBinders :: [VarBndr TcTyVar vis]
-> TcM (ZonkEnv, [VarBndr TyVar vis])
zonkTyVarBinders :: forall vis. [VarBndr Id vis] -> TcM (ZonkEnv, [VarBndr Id vis])
zonkTyVarBinders [VarBndr Id vis]
tvbs = (ZonkEnv -> TcM (ZonkEnv, [VarBndr Id vis]))
-> TcM (ZonkEnv, [VarBndr Id vis])
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> TcM (ZonkEnv, [VarBndr Id vis]))
-> TcM (ZonkEnv, [VarBndr Id vis]))
-> (ZonkEnv -> TcM (ZonkEnv, [VarBndr Id vis]))
-> TcM (ZonkEnv, [VarBndr Id vis])
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> [VarBndr Id vis] -> TcM (ZonkEnv, [VarBndr Id vis])
forall vis.
ZonkEnv -> [VarBndr Id vis] -> TcM (ZonkEnv, [VarBndr Id vis])
zonkTyVarBindersX ZonkEnv
ze [VarBndr Id vis]
tvbs
zonkTyVarBindersX :: ZonkEnv -> [VarBndr TcTyVar vis]
-> TcM (ZonkEnv, [VarBndr TyVar vis])
zonkTyVarBindersX :: forall vis.
ZonkEnv -> [VarBndr Id vis] -> TcM (ZonkEnv, [VarBndr Id vis])
zonkTyVarBindersX = (ZonkEnv
-> VarBndr Id vis
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, VarBndr Id vis))
-> ZonkEnv
-> [VarBndr Id vis]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [VarBndr Id vis])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv
-> VarBndr Id vis
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, VarBndr Id vis)
forall vis.
ZonkEnv -> VarBndr Id vis -> TcM (ZonkEnv, VarBndr Id vis)
zonkTyVarBinderX
zonkTyVarBinderX :: ZonkEnv -> VarBndr TcTyVar vis
-> TcM (ZonkEnv, VarBndr TyVar vis)
zonkTyVarBinderX :: forall vis.
ZonkEnv -> VarBndr Id vis -> TcM (ZonkEnv, VarBndr Id vis)
zonkTyVarBinderX ZonkEnv
env (Bndr Id
tv vis
vis)
= do { (ZonkEnv
env', Id
tv') <- ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX ZonkEnv
env Id
tv
; (ZonkEnv, VarBndr Id vis) -> TcM (ZonkEnv, VarBndr Id vis)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', Id -> vis -> VarBndr Id vis
forall var argf. var -> argf -> VarBndr var argf
Bndr Id
tv' vis
vis) }
zonkTopExpr :: HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkTopExpr :: HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkTopExpr HsExpr GhcTc
e = (ZonkEnv -> TcM (HsExpr GhcTc)) -> TcM (HsExpr GhcTc)
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> TcM (HsExpr GhcTc)) -> TcM (HsExpr GhcTc))
-> (ZonkEnv -> TcM (HsExpr GhcTc)) -> TcM (HsExpr GhcTc)
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
ze HsExpr GhcTc
e
zonkTopLExpr :: LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkTopLExpr :: LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkTopLExpr LHsExpr GhcTc
e = (ZonkEnv -> TcM (LHsExpr GhcTc)) -> TcM (LHsExpr GhcTc)
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> TcM (LHsExpr GhcTc)) -> TcM (LHsExpr GhcTc))
-> (ZonkEnv -> TcM (LHsExpr GhcTc)) -> TcM (LHsExpr GhcTc)
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
ze LHsExpr GhcTc
e
zonkTopDecls :: Bag EvBind
-> LHsBinds GhcTc
-> [LRuleDecl GhcTc] -> [LTcSpecPrag]
-> [LForeignDecl GhcTc]
-> TcM (TypeEnv,
Bag EvBind,
LHsBinds GhcTc,
[LForeignDecl GhcTc],
[LTcSpecPrag],
[LRuleDecl GhcTc])
zonkTopDecls :: Bag EvBind
-> LHsBinds GhcTc
-> [LRuleDecl GhcTc]
-> [LTcSpecPrag]
-> [LForeignDecl GhcTc]
-> TcM
(TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
zonkTopDecls Bag EvBind
ev_binds LHsBinds GhcTc
binds [LRuleDecl GhcTc]
rules [LTcSpecPrag]
imp_specs [LForeignDecl GhcTc]
fords
= do { (ZonkEnv
env1, Bag EvBind
ev_binds') <- (ZonkEnv -> TcM (ZonkEnv, Bag EvBind)) -> TcM (ZonkEnv, Bag EvBind)
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> TcM (ZonkEnv, Bag EvBind))
-> TcM (ZonkEnv, Bag EvBind))
-> (ZonkEnv -> TcM (ZonkEnv, Bag EvBind))
-> TcM (ZonkEnv, Bag EvBind)
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> Bag EvBind -> TcM (ZonkEnv, Bag EvBind)
zonkEvBinds ZonkEnv
ze Bag EvBind
ev_binds
; (ZonkEnv
env2, LHsBinds GhcTc
binds') <- ZonkEnv -> LHsBinds GhcTc -> TcM (ZonkEnv, LHsBinds GhcTc)
zonkRecMonoBinds ZonkEnv
env1 LHsBinds GhcTc
binds
; [LRuleDecl GhcTc]
rules' <- ZonkEnv -> [LRuleDecl GhcTc] -> TcM [LRuleDecl GhcTc]
zonkRules ZonkEnv
env2 [LRuleDecl GhcTc]
rules
; [LTcSpecPrag]
specs' <- ZonkEnv -> [LTcSpecPrag] -> TcM [LTcSpecPrag]
zonkLTcSpecPrags ZonkEnv
env2 [LTcSpecPrag]
imp_specs
; [LForeignDecl GhcTc]
fords' <- ZonkEnv -> [LForeignDecl GhcTc] -> TcM [LForeignDecl GhcTc]
zonkForeignExports ZonkEnv
env2 [LForeignDecl GhcTc]
fords
; (TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
-> TcM
(TypeEnv, Bag EvBind, LHsBinds GhcTc, [LForeignDecl GhcTc],
[LTcSpecPrag], [LRuleDecl GhcTc])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> TypeEnv
zonkEnvIds ZonkEnv
env2, Bag EvBind
ev_binds', LHsBinds GhcTc
binds', [LForeignDecl GhcTc]
fords', [LTcSpecPrag]
specs', [LRuleDecl GhcTc]
rules') }
zonkLocalBinds :: ZonkEnv -> HsLocalBinds GhcTc
-> TcM (ZonkEnv, HsLocalBinds GhcTc)
zonkLocalBinds :: ZonkEnv -> HsLocalBinds GhcTc -> TcM (ZonkEnv, HsLocalBinds GhcTc)
zonkLocalBinds ZonkEnv
env (EmptyLocalBinds XEmptyLocalBinds GhcTc GhcTc
x)
= (ZonkEnv, HsLocalBinds GhcTc) -> TcM (ZonkEnv, HsLocalBinds GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, (XEmptyLocalBinds GhcTc GhcTc -> HsLocalBinds GhcTc
forall idL idR. XEmptyLocalBinds idL idR -> HsLocalBindsLR idL idR
EmptyLocalBinds XEmptyLocalBinds GhcTc GhcTc
x))
zonkLocalBinds ZonkEnv
_ (HsValBinds XHsValBinds GhcTc GhcTc
_ (ValBinds {}))
= String -> TcM (ZonkEnv, HsLocalBinds GhcTc)
forall a. String -> a
panic String
"zonkLocalBinds"
zonkLocalBinds ZonkEnv
env (HsValBinds XHsValBinds GhcTc GhcTc
x (XValBindsLR (NValBinds [(RecFlag, LHsBinds GhcTc)]
binds [LSig GhcRn]
sigs)))
= do { (ZonkEnv
env1, [(RecFlag, LHsBinds GhcTc)]
new_binds) <- ZonkEnv
-> [(RecFlag, LHsBinds GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv) (ZonkEnv, [(RecFlag, LHsBinds GhcTc)])
forall {a}.
ZonkEnv
-> [(a, LHsBinds GhcTc)]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(a, LHsBinds GhcTc)])
go ZonkEnv
env [(RecFlag, LHsBinds GhcTc)]
binds
; (ZonkEnv, HsLocalBinds GhcTc) -> TcM (ZonkEnv, HsLocalBinds GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, XHsValBinds GhcTc GhcTc
-> HsValBindsLR GhcTc GhcTc -> HsLocalBinds GhcTc
forall idL idR.
XHsValBinds idL idR
-> HsValBindsLR idL idR -> HsLocalBindsLR idL idR
HsValBinds XHsValBinds GhcTc GhcTc
x (XXValBindsLR GhcTc GhcTc -> HsValBindsLR GhcTc GhcTc
forall idL idR. XXValBindsLR idL idR -> HsValBindsLR idL idR
XValBindsLR ([(RecFlag, LHsBinds GhcTc)] -> [LSig GhcRn] -> NHsValBindsLR GhcTc
forall idL.
[(RecFlag, LHsBinds idL)] -> [LSig GhcRn] -> NHsValBindsLR idL
NValBinds [(RecFlag, LHsBinds GhcTc)]
new_binds [LSig GhcRn]
sigs))) }
where
go :: ZonkEnv
-> [(a, LHsBinds GhcTc)]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(a, LHsBinds GhcTc)])
go ZonkEnv
env []
= (ZonkEnv, [(a, LHsBinds GhcTc)])
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(a, LHsBinds GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, [])
go ZonkEnv
env ((a
r,LHsBinds GhcTc
b):[(a, LHsBinds GhcTc)]
bs)
= do { (ZonkEnv
env1, LHsBinds GhcTc
b') <- ZonkEnv -> LHsBinds GhcTc -> TcM (ZonkEnv, LHsBinds GhcTc)
zonkRecMonoBinds ZonkEnv
env LHsBinds GhcTc
b
; (ZonkEnv
env2, [(a, LHsBinds GhcTc)]
bs') <- ZonkEnv
-> [(a, LHsBinds GhcTc)]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(a, LHsBinds GhcTc)])
go ZonkEnv
env1 [(a, LHsBinds GhcTc)]
bs
; (ZonkEnv, [(a, LHsBinds GhcTc)])
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(a, LHsBinds GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, (a
r,LHsBinds GhcTc
b')(a, LHsBinds GhcTc)
-> [(a, LHsBinds GhcTc)] -> [(a, LHsBinds GhcTc)]
forall a. a -> [a] -> [a]
:[(a, LHsBinds GhcTc)]
bs') }
zonkLocalBinds ZonkEnv
env (HsIPBinds XHsIPBinds GhcTc GhcTc
x (IPBinds XIPBinds GhcTc
dict_binds [LIPBind GhcTc]
binds )) = do
[LIPBind GhcTc]
new_binds <- (LIPBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LIPBind GhcTc))
-> [LIPBind GhcTc] -> IOEnv (Env TcGblEnv TcLclEnv) [LIPBind GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((IPBind GhcTc -> TcM (IPBind GhcTc))
-> LIPBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LIPBind GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM IPBind GhcTc -> TcM (IPBind GhcTc)
zonk_ip_bind) [LIPBind GhcTc]
binds
let
env1 :: ZonkEnv
env1 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env
[ Id
IdP GhcTc
n | (L SrcSpan
_ (IPBind XCIPBind GhcTc
_ (Right IdP GhcTc
n) LHsExpr GhcTc
_)) <- [LIPBind GhcTc]
new_binds]
(ZonkEnv
env2, TcEvBinds
new_dict_binds) <- ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, TcEvBinds)
zonkTcEvBinds ZonkEnv
env1 XIPBinds GhcTc
TcEvBinds
dict_binds
(ZonkEnv, HsLocalBinds GhcTc) -> TcM (ZonkEnv, HsLocalBinds GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, XHsIPBinds GhcTc GhcTc -> HsIPBinds GhcTc -> HsLocalBinds GhcTc
forall idL idR.
XHsIPBinds idL idR -> HsIPBinds idR -> HsLocalBindsLR idL idR
HsIPBinds XHsIPBinds GhcTc GhcTc
x (XIPBinds GhcTc -> [LIPBind GhcTc] -> HsIPBinds GhcTc
forall id. XIPBinds id -> [LIPBind id] -> HsIPBinds id
IPBinds XIPBinds GhcTc
TcEvBinds
new_dict_binds [LIPBind GhcTc]
new_binds))
where
zonk_ip_bind :: IPBind GhcTc -> TcM (IPBind GhcTc)
zonk_ip_bind (IPBind XCIPBind GhcTc
x Either (Located HsIPName) (IdP GhcTc)
n LHsExpr GhcTc
e)
= do Either (Located HsIPName) Id
n' <- (Id -> TcM Id)
-> Either (Located HsIPName) Id
-> TcM (Either (Located HsIPName) Id)
forall a b.
(a -> TcM b)
-> Either (Located HsIPName) a -> TcM (Either (Located HsIPName) b)
mapIPNameTc (ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env) Either (Located HsIPName) Id
Either (Located HsIPName) (IdP GhcTc)
n
LHsExpr GhcTc
e' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
IPBind GhcTc -> TcM (IPBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCIPBind GhcTc
-> Either (Located HsIPName) (IdP GhcTc)
-> LHsExpr GhcTc
-> IPBind GhcTc
forall id.
XCIPBind id
-> Either (Located HsIPName) (IdP id) -> LHsExpr id -> IPBind id
IPBind XCIPBind GhcTc
x Either (Located HsIPName) Id
Either (Located HsIPName) (IdP GhcTc)
n' LHsExpr GhcTc
e')
zonkRecMonoBinds :: ZonkEnv -> LHsBinds GhcTc -> TcM (ZonkEnv, LHsBinds GhcTc)
zonkRecMonoBinds :: ZonkEnv -> LHsBinds GhcTc -> TcM (ZonkEnv, LHsBinds GhcTc)
zonkRecMonoBinds ZonkEnv
env LHsBinds GhcTc
binds
= ((ZonkEnv, LHsBinds GhcTc) -> TcM (ZonkEnv, LHsBinds GhcTc))
-> TcM (ZonkEnv, LHsBinds GhcTc)
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM (\ ~(ZonkEnv
_, LHsBinds GhcTc
new_binds) -> do
{ let env1 :: ZonkEnv
env1 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env (LHsBinds GhcTc -> [IdP GhcTc]
forall p idR. CollectPass p => LHsBindsLR p idR -> [IdP p]
collectHsBindsBinders LHsBinds GhcTc
new_binds)
; LHsBinds GhcTc
binds' <- ZonkEnv -> LHsBinds GhcTc -> TcM (LHsBinds GhcTc)
zonkMonoBinds ZonkEnv
env1 LHsBinds GhcTc
binds
; (ZonkEnv, LHsBinds GhcTc) -> TcM (ZonkEnv, LHsBinds GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, LHsBinds GhcTc
binds') })
zonkMonoBinds :: ZonkEnv -> LHsBinds GhcTc -> TcM (LHsBinds GhcTc)
zonkMonoBinds :: ZonkEnv -> LHsBinds GhcTc -> TcM (LHsBinds GhcTc)
zonkMonoBinds ZonkEnv
env LHsBinds GhcTc
binds = (LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc))
-> LHsBinds GhcTc -> TcM (LHsBinds GhcTc)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM (ZonkEnv
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
zonk_lbind ZonkEnv
env) LHsBinds GhcTc
binds
zonk_lbind :: ZonkEnv -> LHsBind GhcTc -> TcM (LHsBind GhcTc)
zonk_lbind :: ZonkEnv
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
zonk_lbind ZonkEnv
env = (HsBind GhcTc -> TcM (HsBind GhcTc))
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> HsBind GhcTc -> TcM (HsBind GhcTc)
zonk_bind ZonkEnv
env)
zonk_bind :: ZonkEnv -> HsBind GhcTc -> TcM (HsBind GhcTc)
zonk_bind :: ZonkEnv -> HsBind GhcTc -> TcM (HsBind GhcTc)
zonk_bind ZonkEnv
env bind :: HsBind GhcTc
bind@(PatBind { pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = LPat GhcTc
pat, pat_rhs :: forall idL idR. HsBindLR idL idR -> GRHSs idR (LHsExpr idR)
pat_rhs = GRHSs GhcTc (LHsExpr GhcTc)
grhss
, pat_ext :: forall idL idR. HsBindLR idL idR -> XPatBind idL idR
pat_ext = NPatBindTc NameSet
fvs Kind
ty})
= do { (ZonkEnv
_env, GenLocated SrcSpan (Pat GhcTc)
new_pat) <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; GRHSs GhcTc (LHsExpr GhcTc)
new_grhss <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> GRHSs GhcTc (LHsExpr GhcTc)
-> TcM (GRHSs GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> GRHSs GhcTc (Located (body GhcTc))
-> TcM (GRHSs GhcTc (Located (body GhcTc)))
zonkGRHSs ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr GRHSs GhcTc (LHsExpr GhcTc)
grhss
; Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
; HsBind GhcTc -> TcM (HsBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBind GhcTc
bind { pat_lhs :: LPat GhcTc
pat_lhs = GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
new_pat, pat_rhs :: GRHSs GhcTc (LHsExpr GhcTc)
pat_rhs = GRHSs GhcTc (LHsExpr GhcTc)
new_grhss
, pat_ext :: XPatBind GhcTc GhcTc
pat_ext = NameSet -> Kind -> NPatBindTc
NPatBindTc NameSet
fvs Kind
new_ty }) }
zonk_bind ZonkEnv
env (VarBind { var_ext :: forall idL idR. HsBindLR idL idR -> XVarBind idL idR
var_ext = XVarBind GhcTc GhcTc
x
, var_id :: forall idL idR. HsBindLR idL idR -> IdP idL
var_id = IdP GhcTc
var, var_rhs :: forall idL idR. HsBindLR idL idR -> LHsExpr idR
var_rhs = LHsExpr GhcTc
expr })
= do { Id
new_var <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
IdP GhcTc
var
; LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
; HsBind GhcTc -> TcM (HsBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (VarBind :: forall idL idR.
XVarBind idL idR -> IdP idL -> LHsExpr idR -> HsBindLR idL idR
VarBind { var_ext :: XVarBind GhcTc GhcTc
var_ext = XVarBind GhcTc GhcTc
x
, var_id :: IdP GhcTc
var_id = Id
IdP GhcTc
new_var
, var_rhs :: LHsExpr GhcTc
var_rhs = LHsExpr GhcTc
new_expr }) }
zonk_bind ZonkEnv
env bind :: HsBind GhcTc
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = L SrcSpan
loc IdP GhcTc
var
, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup GhcTc (LHsExpr GhcTc)
ms
, fun_ext :: forall idL idR. HsBindLR idL idR -> XFunBind idL idR
fun_ext = XFunBind GhcTc GhcTc
co_fn })
= do { Id
new_var <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
IdP GhcTc
var
; (ZonkEnv
env1, HsWrapper
new_co_fn) <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env XFunBind GhcTc GhcTc
HsWrapper
co_fn
; MatchGroup GhcTc (LHsExpr GhcTc)
new_ms <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> TcM (MatchGroup GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env1 ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr MatchGroup GhcTc (LHsExpr GhcTc)
ms
; HsBind GhcTc -> TcM (HsBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBind GhcTc
bind { fun_id :: Located (IdP GhcTc)
fun_id = SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc Id
new_var
, fun_matches :: MatchGroup GhcTc (LHsExpr GhcTc)
fun_matches = MatchGroup GhcTc (LHsExpr GhcTc)
new_ms
, fun_ext :: XFunBind GhcTc GhcTc
fun_ext = XFunBind GhcTc GhcTc
HsWrapper
new_co_fn }) }
zonk_bind ZonkEnv
env (AbsBinds { abs_tvs :: forall idL idR. HsBindLR idL idR -> [Id]
abs_tvs = [Id]
tyvars, abs_ev_vars :: forall idL idR. HsBindLR idL idR -> [Id]
abs_ev_vars = [Id]
evs
, abs_ev_binds :: forall idL idR. HsBindLR idL idR -> [TcEvBinds]
abs_ev_binds = [TcEvBinds]
ev_binds
, abs_exports :: forall idL idR. HsBindLR idL idR -> [ABExport idL]
abs_exports = [ABExport GhcTc]
exports
, abs_binds :: forall idL idR. HsBindLR idL idR -> LHsBinds idL
abs_binds = LHsBinds GhcTc
val_binds
, abs_sig :: forall idL idR. HsBindLR idL idR -> Bool
abs_sig = Bool
has_sig })
= ASSERT( all isImmutableTyVar tyvars )
do { (ZonkEnv
env0, [Id]
new_tyvars) <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkTyBndrsX ZonkEnv
env [Id]
tyvars
; (ZonkEnv
env1, [Id]
new_evs) <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkEvBndrsX ZonkEnv
env0 [Id]
evs
; (ZonkEnv
env2, [TcEvBinds]
new_ev_binds) <- ZonkEnv -> [TcEvBinds] -> TcM (ZonkEnv, [TcEvBinds])
zonkTcEvBinds_s ZonkEnv
env1 [TcEvBinds]
ev_binds
; (LHsBinds GhcTc
new_val_bind, [ABExport GhcTc]
new_exports) <- ((LHsBinds GhcTc, [ABExport GhcTc])
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc]))
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc])
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM (((LHsBinds GhcTc, [ABExport GhcTc])
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc]))
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc]))
-> ((LHsBinds GhcTc, [ABExport GhcTc])
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc]))
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc])
forall a b. (a -> b) -> a -> b
$ \ ~(LHsBinds GhcTc
new_val_binds, [ABExport GhcTc]
_) ->
do { let env3 :: ZonkEnv
env3 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env2 ([Id] -> ZonkEnv) -> [Id] -> ZonkEnv
forall a b. (a -> b) -> a -> b
$
LHsBinds GhcTc -> [IdP GhcTc]
forall p idR. CollectPass p => LHsBindsLR p idR -> [IdP p]
collectHsBindsBinders LHsBinds GhcTc
new_val_binds
; LHsBinds GhcTc
new_val_binds <- (LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc))
-> LHsBinds GhcTc -> TcM (LHsBinds GhcTc)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM (ZonkEnv
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
zonk_val_bind ZonkEnv
env3) LHsBinds GhcTc
val_binds
; [ABExport GhcTc]
new_exports <- (ABExport GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (ABExport GhcTc))
-> [ABExport GhcTc]
-> IOEnv (Env TcGblEnv TcLclEnv) [ABExport GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv
-> ABExport GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (ABExport GhcTc)
zonk_export ZonkEnv
env3) [ABExport GhcTc]
exports
; (LHsBinds GhcTc, [ABExport GhcTc])
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsBinds GhcTc, [ABExport GhcTc])
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsBinds GhcTc
new_val_binds, [ABExport GhcTc]
new_exports) }
; HsBind GhcTc -> TcM (HsBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (AbsBinds :: forall idL idR.
XAbsBinds idL idR
-> [Id]
-> [Id]
-> [ABExport idL]
-> [TcEvBinds]
-> LHsBinds idL
-> Bool
-> HsBindLR idL idR
AbsBinds { abs_ext :: XAbsBinds GhcTc GhcTc
abs_ext = NoExtField
XAbsBinds GhcTc GhcTc
noExtField
, abs_tvs :: [Id]
abs_tvs = [Id]
new_tyvars, abs_ev_vars :: [Id]
abs_ev_vars = [Id]
new_evs
, abs_ev_binds :: [TcEvBinds]
abs_ev_binds = [TcEvBinds]
new_ev_binds
, abs_exports :: [ABExport GhcTc]
abs_exports = [ABExport GhcTc]
new_exports, abs_binds :: LHsBinds GhcTc
abs_binds = LHsBinds GhcTc
new_val_bind
, abs_sig :: Bool
abs_sig = Bool
has_sig }) }
where
zonk_val_bind :: ZonkEnv
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
zonk_val_bind ZonkEnv
env LHsBind GhcTc
lbind
| Bool
has_sig
, (L SrcSpan
loc bind :: HsBind GhcTc
bind@(FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> Located (IdP idL)
fun_id = (L SrcSpan
mloc IdP GhcTc
mono_id)
, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches = MatchGroup GhcTc (LHsExpr GhcTc)
ms
, fun_ext :: forall idL idR. HsBindLR idL idR -> XFunBind idL idR
fun_ext = XFunBind GhcTc GhcTc
co_fn })) <- LHsBind GhcTc
lbind
= do { Id
new_mono_id <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind) -> Id -> TcM Id
forall (m :: * -> *). Monad m => (Kind -> m Kind) -> Id -> m Id
updateIdTypeAndMultM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) Id
IdP GhcTc
mono_id
; (ZonkEnv
env', HsWrapper
new_co_fn) <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env XFunBind GhcTc GhcTc
HsWrapper
co_fn
; MatchGroup GhcTc (LHsExpr GhcTc)
new_ms <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> TcM (MatchGroup GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env' ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr MatchGroup GhcTc (LHsExpr GhcTc)
ms
; LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc))
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsBind GhcTc -> LHsBind GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (HsBind GhcTc -> LHsBind GhcTc) -> HsBind GhcTc -> LHsBind GhcTc
forall a b. (a -> b) -> a -> b
$
HsBind GhcTc
bind { fun_id :: Located (IdP GhcTc)
fun_id = SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
mloc Id
new_mono_id
, fun_matches :: MatchGroup GhcTc (LHsExpr GhcTc)
fun_matches = MatchGroup GhcTc (LHsExpr GhcTc)
new_ms
, fun_ext :: XFunBind GhcTc GhcTc
fun_ext = XFunBind GhcTc GhcTc
HsWrapper
new_co_fn } }
| Bool
otherwise
= ZonkEnv
-> LHsBind GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcTc)
zonk_lbind ZonkEnv
env LHsBind GhcTc
lbind
zonk_export :: ZonkEnv -> ABExport GhcTc -> TcM (ABExport GhcTc)
zonk_export :: ZonkEnv
-> ABExport GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (ABExport GhcTc)
zonk_export ZonkEnv
env (ABE{ abe_ext :: forall p. ABExport p -> XABE p
abe_ext = XABE GhcTc
x
, abe_wrap :: forall p. ABExport p -> HsWrapper
abe_wrap = HsWrapper
wrap
, abe_poly :: forall p. ABExport p -> IdP p
abe_poly = IdP GhcTc
poly_id
, abe_mono :: forall p. ABExport p -> IdP p
abe_mono = IdP GhcTc
mono_id
, abe_prags :: forall p. ABExport p -> TcSpecPrags
abe_prags = TcSpecPrags
prags })
= do Id
new_poly_id <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
IdP GhcTc
poly_id
(ZonkEnv
_, HsWrapper
new_wrap) <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
wrap
TcSpecPrags
new_prags <- ZonkEnv -> TcSpecPrags -> TcM TcSpecPrags
zonkSpecPrags ZonkEnv
env TcSpecPrags
prags
ABExport GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (ABExport GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ABE :: forall p.
XABE p -> IdP p -> IdP p -> HsWrapper -> TcSpecPrags -> ABExport p
ABE{ abe_ext :: XABE GhcTc
abe_ext = XABE GhcTc
x
, abe_wrap :: HsWrapper
abe_wrap = HsWrapper
new_wrap
, abe_poly :: IdP GhcTc
abe_poly = Id
IdP GhcTc
new_poly_id
, abe_mono :: IdP GhcTc
abe_mono = ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env Id
IdP GhcTc
mono_id
, abe_prags :: TcSpecPrags
abe_prags = TcSpecPrags
new_prags })
zonk_bind ZonkEnv
env (PatSynBind XPatSynBind GhcTc GhcTc
x bind :: PatSynBind GhcTc GhcTc
bind@(PSB { psb_id :: forall idL idR. PatSynBind idL idR -> Located (IdP idL)
psb_id = L SrcSpan
loc IdP GhcTc
id
, psb_args :: forall idL idR.
PatSynBind idL idR -> HsPatSynDetails (Located (IdP idR))
psb_args = HsPatSynDetails (Located (IdP GhcTc))
details
, psb_def :: forall idL idR. PatSynBind idL idR -> LPat idR
psb_def = LPat GhcTc
lpat
, psb_dir :: forall idL idR. PatSynBind idL idR -> HsPatSynDir idR
psb_dir = HsPatSynDir GhcTc
dir }))
= do { Id
id' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
IdP GhcTc
id
; (ZonkEnv
env1, GenLocated SrcSpan (Pat GhcTc)
lpat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
lpat
; let details' :: HsPatSynDetails (GenLocated SrcSpan Id)
details' = ZonkEnv
-> HsPatSynDetails (GenLocated SrcSpan Id)
-> HsPatSynDetails (GenLocated SrcSpan Id)
zonkPatSynDetails ZonkEnv
env1 HsPatSynDetails (GenLocated SrcSpan Id)
HsPatSynDetails (Located (IdP GhcTc))
details
; (ZonkEnv
_env2, HsPatSynDir GhcTc
dir') <- ZonkEnv -> HsPatSynDir GhcTc -> TcM (ZonkEnv, HsPatSynDir GhcTc)
zonkPatSynDir ZonkEnv
env1 HsPatSynDir GhcTc
dir
; HsBind GhcTc -> TcM (HsBind GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsBind GhcTc -> TcM (HsBind GhcTc))
-> HsBind GhcTc -> TcM (HsBind GhcTc)
forall a b. (a -> b) -> a -> b
$ XPatSynBind GhcTc GhcTc -> PatSynBind GhcTc GhcTc -> HsBind GhcTc
forall idL idR.
XPatSynBind idL idR -> PatSynBind idL idR -> HsBindLR idL idR
PatSynBind XPatSynBind GhcTc GhcTc
x (PatSynBind GhcTc GhcTc -> HsBind GhcTc)
-> PatSynBind GhcTc GhcTc -> HsBind GhcTc
forall a b. (a -> b) -> a -> b
$
PatSynBind GhcTc GhcTc
bind { psb_id :: Located (IdP GhcTc)
psb_id = SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc Id
id'
, psb_args :: HsPatSynDetails (Located (IdP GhcTc))
psb_args = HsPatSynDetails (GenLocated SrcSpan Id)
HsPatSynDetails (Located (IdP GhcTc))
details'
, psb_def :: LPat GhcTc
psb_def = GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
lpat'
, psb_dir :: HsPatSynDir GhcTc
psb_dir = HsPatSynDir GhcTc
dir' } }
zonkPatSynDetails :: ZonkEnv
-> HsPatSynDetails (Located TcId)
-> HsPatSynDetails (Located Id)
zonkPatSynDetails :: ZonkEnv
-> HsPatSynDetails (GenLocated SrcSpan Id)
-> HsPatSynDetails (GenLocated SrcSpan Id)
zonkPatSynDetails ZonkEnv
env (PrefixCon [GenLocated SrcSpan Id]
as)
= [GenLocated SrcSpan Id] -> HsPatSynDetails (GenLocated SrcSpan Id)
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon ((GenLocated SrcSpan Id -> GenLocated SrcSpan Id)
-> [GenLocated SrcSpan Id] -> [GenLocated SrcSpan Id]
forall a b. (a -> b) -> [a] -> [b]
map (ZonkEnv -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
zonkLIdOcc ZonkEnv
env) [GenLocated SrcSpan Id]
as)
zonkPatSynDetails ZonkEnv
env (InfixCon GenLocated SrcSpan Id
a1 GenLocated SrcSpan Id
a2)
= GenLocated SrcSpan Id
-> GenLocated SrcSpan Id -> HsPatSynDetails (GenLocated SrcSpan Id)
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon (ZonkEnv -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
zonkLIdOcc ZonkEnv
env GenLocated SrcSpan Id
a1) (ZonkEnv -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
zonkLIdOcc ZonkEnv
env GenLocated SrcSpan Id
a2)
zonkPatSynDetails ZonkEnv
env (RecCon [RecordPatSynField (GenLocated SrcSpan Id)]
flds)
= [RecordPatSynField (GenLocated SrcSpan Id)]
-> HsPatSynDetails (GenLocated SrcSpan Id)
forall arg rec. rec -> HsConDetails arg rec
RecCon ((RecordPatSynField (GenLocated SrcSpan Id)
-> RecordPatSynField (GenLocated SrcSpan Id))
-> [RecordPatSynField (GenLocated SrcSpan Id)]
-> [RecordPatSynField (GenLocated SrcSpan Id)]
forall a b. (a -> b) -> [a] -> [b]
map ((GenLocated SrcSpan Id -> GenLocated SrcSpan Id)
-> RecordPatSynField (GenLocated SrcSpan Id)
-> RecordPatSynField (GenLocated SrcSpan Id)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ZonkEnv -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
zonkLIdOcc ZonkEnv
env)) [RecordPatSynField (GenLocated SrcSpan Id)]
flds)
zonkPatSynDir :: ZonkEnv -> HsPatSynDir GhcTc
-> TcM (ZonkEnv, HsPatSynDir GhcTc)
zonkPatSynDir :: ZonkEnv -> HsPatSynDir GhcTc -> TcM (ZonkEnv, HsPatSynDir GhcTc)
zonkPatSynDir ZonkEnv
env HsPatSynDir GhcTc
Unidirectional = (ZonkEnv, HsPatSynDir GhcTc) -> TcM (ZonkEnv, HsPatSynDir GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, HsPatSynDir GhcTc
forall id. HsPatSynDir id
Unidirectional)
zonkPatSynDir ZonkEnv
env HsPatSynDir GhcTc
ImplicitBidirectional = (ZonkEnv, HsPatSynDir GhcTc) -> TcM (ZonkEnv, HsPatSynDir GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, HsPatSynDir GhcTc
forall id. HsPatSynDir id
ImplicitBidirectional)
zonkPatSynDir ZonkEnv
env (ExplicitBidirectional MatchGroup GhcTc (LHsExpr GhcTc)
mg) = do
MatchGroup GhcTc (LHsExpr GhcTc)
mg' <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> TcM (MatchGroup GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr MatchGroup GhcTc (LHsExpr GhcTc)
mg
(ZonkEnv, HsPatSynDir GhcTc) -> TcM (ZonkEnv, HsPatSynDir GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, MatchGroup GhcTc (LHsExpr GhcTc) -> HsPatSynDir GhcTc
forall id. MatchGroup id (LHsExpr id) -> HsPatSynDir id
ExplicitBidirectional MatchGroup GhcTc (LHsExpr GhcTc)
mg')
zonkSpecPrags :: ZonkEnv -> TcSpecPrags -> TcM TcSpecPrags
zonkSpecPrags :: ZonkEnv -> TcSpecPrags -> TcM TcSpecPrags
zonkSpecPrags ZonkEnv
_ TcSpecPrags
IsDefaultMethod = TcSpecPrags -> TcM TcSpecPrags
forall (m :: * -> *) a. Monad m => a -> m a
return TcSpecPrags
IsDefaultMethod
zonkSpecPrags ZonkEnv
env (SpecPrags [LTcSpecPrag]
ps) = do { [LTcSpecPrag]
ps' <- ZonkEnv -> [LTcSpecPrag] -> TcM [LTcSpecPrag]
zonkLTcSpecPrags ZonkEnv
env [LTcSpecPrag]
ps
; TcSpecPrags -> TcM TcSpecPrags
forall (m :: * -> *) a. Monad m => a -> m a
return ([LTcSpecPrag] -> TcSpecPrags
SpecPrags [LTcSpecPrag]
ps') }
zonkLTcSpecPrags :: ZonkEnv -> [LTcSpecPrag] -> TcM [LTcSpecPrag]
zonkLTcSpecPrags :: ZonkEnv -> [LTcSpecPrag] -> TcM [LTcSpecPrag]
zonkLTcSpecPrags ZonkEnv
env [LTcSpecPrag]
ps
= (LTcSpecPrag -> IOEnv (Env TcGblEnv TcLclEnv) LTcSpecPrag)
-> [LTcSpecPrag] -> TcM [LTcSpecPrag]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LTcSpecPrag -> IOEnv (Env TcGblEnv TcLclEnv) LTcSpecPrag
zonk_prag [LTcSpecPrag]
ps
where
zonk_prag :: LTcSpecPrag -> IOEnv (Env TcGblEnv TcLclEnv) LTcSpecPrag
zonk_prag (L SrcSpan
loc (SpecPrag Id
id HsWrapper
co_fn InlinePragma
inl))
= do { (ZonkEnv
_, HsWrapper
co_fn') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
co_fn
; LTcSpecPrag -> IOEnv (Env TcGblEnv TcLclEnv) LTcSpecPrag
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> TcSpecPrag -> LTcSpecPrag
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (Id -> HsWrapper -> InlinePragma -> TcSpecPrag
SpecPrag (ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env Id
id) HsWrapper
co_fn' InlinePragma
inl)) }
zonkMatchGroup :: ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup :: forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (MG { mg_alts :: forall p body. MatchGroup p body -> Located [LMatch p body]
mg_alts = L SrcSpan
l [LMatch GhcTc (Located (body GhcTc))]
ms
, mg_ext :: forall p body. MatchGroup p body -> XMG p body
mg_ext = MatchGroupTc [Scaled Kind]
arg_tys Kind
res_ty
, mg_origin :: forall p body. MatchGroup p body -> Origin
mg_origin = Origin
origin })
= do { [LMatch GhcTc (Located (body GhcTc))]
ms' <- (LMatch GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (LMatch GhcTc (Located (body GhcTc))))
-> [LMatch GhcTc (Located (body GhcTc))]
-> IOEnv
(Env TcGblEnv TcLclEnv) [LMatch GhcTc (Located (body GhcTc))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> LMatch GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (LMatch GhcTc (Located (body GhcTc)))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> LMatch GhcTc (Located (body GhcTc))
-> TcM (LMatch GhcTc (Located (body GhcTc)))
zonkMatch ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody) [LMatch GhcTc (Located (body GhcTc))]
ms
; [Scaled Kind]
arg_tys' <- ZonkEnv -> [Scaled Kind] -> TcM [Scaled Kind]
zonkScaledTcTypesToTypesX ZonkEnv
env [Scaled Kind]
arg_tys
; Kind
res_ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
res_ty
; MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (MG :: forall p body.
XMG p body
-> Located [LMatch p body] -> Origin -> MatchGroup p body
MG { mg_alts :: GenLocated SrcSpan [LMatch GhcTc (Located (body GhcTc))]
mg_alts = SrcSpan
-> [LMatch GhcTc (Located (body GhcTc))]
-> GenLocated SrcSpan [LMatch GhcTc (Located (body GhcTc))]
forall l e. l -> e -> GenLocated l e
L SrcSpan
l [LMatch GhcTc (Located (body GhcTc))]
ms'
, mg_ext :: XMG GhcTc (Located (body GhcTc))
mg_ext = [Scaled Kind] -> Kind -> MatchGroupTc
MatchGroupTc [Scaled Kind]
arg_tys' Kind
res_ty'
, mg_origin :: Origin
mg_origin = Origin
origin }) }
zonkMatch :: ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> LMatch GhcTc (Located (body GhcTc))
-> TcM (LMatch GhcTc (Located (body GhcTc)))
zonkMatch :: forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> LMatch GhcTc (Located (body GhcTc))
-> TcM (LMatch GhcTc (Located (body GhcTc)))
zonkMatch ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (L SrcSpan
loc match :: Match GhcTc (Located (body GhcTc))
match@(Match { m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat GhcTc]
pats
, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs GhcTc (Located (body GhcTc))
grhss }))
= do { (ZonkEnv
env1, [GenLocated SrcSpan (Pat GhcTc)]
new_pats) <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env [LPat GhcTc]
pats
; GRHSs GhcTc (Located (body GhcTc))
new_grhss <- ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> GRHSs GhcTc (Located (body GhcTc))
-> TcM (GRHSs GhcTc (Located (body GhcTc)))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> GRHSs GhcTc (Located (body GhcTc))
-> TcM (GRHSs GhcTc (Located (body GhcTc)))
zonkGRHSs ZonkEnv
env1 ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody GRHSs GhcTc (Located (body GhcTc))
grhss
; GenLocated SrcSpan (Match GhcTc (Located (body GhcTc)))
-> TcM (GenLocated SrcSpan (Match GhcTc (Located (body GhcTc))))
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> Match GhcTc (Located (body GhcTc))
-> GenLocated SrcSpan (Match GhcTc (Located (body GhcTc)))
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (Match GhcTc (Located (body GhcTc))
match { m_pats :: [LPat GhcTc]
m_pats = [GenLocated SrcSpan (Pat GhcTc)]
[LPat GhcTc]
new_pats, m_grhss :: GRHSs GhcTc (Located (body GhcTc))
m_grhss = GRHSs GhcTc (Located (body GhcTc))
new_grhss })) }
zonkGRHSs :: ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> GRHSs GhcTc (Located (body GhcTc))
-> TcM (GRHSs GhcTc (Located (body GhcTc)))
zonkGRHSs :: forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> GRHSs GhcTc (Located (body GhcTc))
-> TcM (GRHSs GhcTc (Located (body GhcTc)))
zonkGRHSs ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (GRHSs XCGRHSs GhcTc (Located (body GhcTc))
x [LGRHS GhcTc (Located (body GhcTc))]
grhss (L SrcSpan
l HsLocalBinds GhcTc
binds)) = do
(ZonkEnv
new_env, HsLocalBinds GhcTc
new_binds) <- ZonkEnv -> HsLocalBinds GhcTc -> TcM (ZonkEnv, HsLocalBinds GhcTc)
zonkLocalBinds ZonkEnv
env HsLocalBinds GhcTc
binds
let
zonk_grhs :: GRHS GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GRHS GhcTc (Located (body GhcTc)))
zonk_grhs (GRHS XCGRHS GhcTc (Located (body GhcTc))
xx [GuardLStmt GhcTc]
guarded Located (body GhcTc)
rhs)
= do (ZonkEnv
env2, [GuardLStmt GhcTc]
new_guarded) <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [GuardLStmt GhcTc]
-> TcM (ZonkEnv, [GuardLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
new_env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr [GuardLStmt GhcTc]
guarded
Located (body GhcTc)
new_rhs <- ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody ZonkEnv
env2 Located (body GhcTc)
rhs
GRHS GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GRHS GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (XCGRHS GhcTc (Located (body GhcTc))
-> [GuardLStmt GhcTc]
-> Located (body GhcTc)
-> GRHS GhcTc (Located (body GhcTc))
forall p body.
XCGRHS p body -> [GuardLStmt p] -> body -> GRHS p body
GRHS XCGRHS GhcTc (Located (body GhcTc))
xx [GuardLStmt GhcTc]
new_guarded Located (body GhcTc)
new_rhs)
[LGRHS GhcTc (Located (body GhcTc))]
new_grhss <- (LGRHS GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (LGRHS GhcTc (Located (body GhcTc))))
-> [LGRHS GhcTc (Located (body GhcTc))]
-> IOEnv
(Env TcGblEnv TcLclEnv) [LGRHS GhcTc (Located (body GhcTc))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((GRHS GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GRHS GhcTc (Located (body GhcTc))))
-> LGRHS GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (LGRHS GhcTc (Located (body GhcTc)))
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM GRHS GhcTc (Located (body GhcTc))
-> IOEnv
(Env TcGblEnv TcLclEnv) (GRHS GhcTc (Located (body GhcTc)))
zonk_grhs) [LGRHS GhcTc (Located (body GhcTc))]
grhss
GRHSs GhcTc (Located (body GhcTc))
-> TcM (GRHSs GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (XCGRHSs GhcTc (Located (body GhcTc))
-> [LGRHS GhcTc (Located (body GhcTc))]
-> GenLocated SrcSpan (HsLocalBinds GhcTc)
-> GRHSs GhcTc (Located (body GhcTc))
forall p body.
XCGRHSs p body -> [LGRHS p body] -> LHsLocalBinds p -> GRHSs p body
GRHSs XCGRHSs GhcTc (Located (body GhcTc))
x [LGRHS GhcTc (Located (body GhcTc))]
new_grhss (SrcSpan
-> HsLocalBinds GhcTc -> GenLocated SrcSpan (HsLocalBinds GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsLocalBinds GhcTc
new_binds))
zonkLExprs :: ZonkEnv -> [LHsExpr GhcTc] -> TcM [LHsExpr GhcTc]
zonkLExpr :: ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkExpr :: ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkLExprs :: ZonkEnv -> [LHsExpr GhcTc] -> TcM [LHsExpr GhcTc]
zonkLExprs ZonkEnv
env [LHsExpr GhcTc]
exprs = (LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [LHsExpr GhcTc] -> TcM [LHsExpr GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env) [LHsExpr GhcTc]
exprs
zonkLExpr :: ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr = (HsExpr GhcTc -> TcM (HsExpr GhcTc))
-> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env) LHsExpr GhcTc
expr
zonkExpr :: ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env (HsVar XVar GhcTc
x (L SrcSpan
l IdP GhcTc
id))
= ASSERT2( isNothing (isDataConId_maybe id), ppr id )
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XVar GhcTc -> Located (IdP GhcTc) -> HsExpr GhcTc
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar XVar GhcTc
x (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env Id
IdP GhcTc
id)))
zonkExpr ZonkEnv
_ e :: HsExpr GhcTc
e@(HsConLikeOut {}) = HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return HsExpr GhcTc
e
zonkExpr ZonkEnv
_ (HsIPVar XIPVar GhcTc
x HsIPName
id)
= HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XIPVar GhcTc -> HsIPName -> HsExpr GhcTc
forall p. XIPVar p -> HsIPName -> HsExpr p
HsIPVar XIPVar GhcTc
x HsIPName
id)
zonkExpr ZonkEnv
_ e :: HsExpr GhcTc
e@HsOverLabel{} = HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return HsExpr GhcTc
e
zonkExpr ZonkEnv
env (HsLit XLitE GhcTc
x (HsRat XHsRat GhcTc
e FractionalLit
f Kind
ty))
= do Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcTc
x (XHsRat GhcTc -> FractionalLit -> Kind -> HsLit GhcTc
forall x. XHsRat x -> FractionalLit -> Kind -> HsLit x
HsRat XHsRat GhcTc
e FractionalLit
f Kind
new_ty))
zonkExpr ZonkEnv
_ (HsLit XLitE GhcTc
x HsLit GhcTc
lit)
= HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcTc
x HsLit GhcTc
lit)
zonkExpr ZonkEnv
env (HsOverLit XOverLitE GhcTc
x HsOverLit GhcTc
lit)
= do { HsOverLit GhcTc
lit' <- ZonkEnv -> HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
zonkOverLit ZonkEnv
env HsOverLit GhcTc
lit
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XOverLitE GhcTc -> HsOverLit GhcTc -> HsExpr GhcTc
forall p. XOverLitE p -> HsOverLit p -> HsExpr p
HsOverLit XOverLitE GhcTc
x HsOverLit GhcTc
lit') }
zonkExpr ZonkEnv
env (HsLam XLam GhcTc
x MatchGroup GhcTc (LHsExpr GhcTc)
matches)
= do MatchGroup GhcTc (LHsExpr GhcTc)
new_matches <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> TcM (MatchGroup GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr MatchGroup GhcTc (LHsExpr GhcTc)
matches
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLam GhcTc -> MatchGroup GhcTc (LHsExpr GhcTc) -> HsExpr GhcTc
forall p. XLam p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsLam XLam GhcTc
x MatchGroup GhcTc (LHsExpr GhcTc)
new_matches)
zonkExpr ZonkEnv
env (HsLamCase XLamCase GhcTc
x MatchGroup GhcTc (LHsExpr GhcTc)
matches)
= do MatchGroup GhcTc (LHsExpr GhcTc)
new_matches <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> TcM (MatchGroup GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr MatchGroup GhcTc (LHsExpr GhcTc)
matches
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLamCase GhcTc -> MatchGroup GhcTc (LHsExpr GhcTc) -> HsExpr GhcTc
forall p. XLamCase p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsLamCase XLamCase GhcTc
x MatchGroup GhcTc (LHsExpr GhcTc)
new_matches)
zonkExpr ZonkEnv
env (HsApp XApp GhcTc
x LHsExpr GhcTc
e1 LHsExpr GhcTc
e2)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XApp GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcTc
x LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_e2)
zonkExpr ZonkEnv
env (HsAppType XAppTypeE GhcTc
ty LHsExpr GhcTc
e LHsWcType (NoGhcTc GhcTc)
t)
= do LHsExpr GhcTc
new_e <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XAppTypeE GhcTc
ty
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XAppTypeE GhcTc
-> LHsExpr GhcTc -> LHsWcType (NoGhcTc GhcTc) -> HsExpr GhcTc
forall p.
XAppTypeE p -> LHsExpr p -> LHsWcType (NoGhcTc p) -> HsExpr p
HsAppType Kind
XAppTypeE GhcTc
new_ty LHsExpr GhcTc
new_e LHsWcType (NoGhcTc GhcTc)
t)
zonkExpr ZonkEnv
_ e :: HsExpr GhcTc
e@(HsRnBracketOut XRnBracketOut GhcTc
_ HsBracket GhcRn
_ [PendingRnSplice]
_)
= String -> SDoc -> TcM (HsExpr GhcTc)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"zonkExpr: HsRnBracketOut" (HsExpr GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
e)
zonkExpr ZonkEnv
env (HsTcBracketOut XTcBracketOut GhcTc
x Maybe QuoteWrapper
wrap HsBracket GhcRn
body [PendingTcSplice]
bs)
= do Maybe QuoteWrapper
wrap' <- (QuoteWrapper -> IOEnv (Env TcGblEnv TcLclEnv) QuoteWrapper)
-> Maybe QuoteWrapper
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe QuoteWrapper)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse QuoteWrapper -> IOEnv (Env TcGblEnv TcLclEnv) QuoteWrapper
zonkQuoteWrap Maybe QuoteWrapper
wrap
[PendingTcSplice]
bs' <- (PendingTcSplice -> IOEnv (Env TcGblEnv TcLclEnv) PendingTcSplice)
-> [PendingTcSplice]
-> IOEnv (Env TcGblEnv TcLclEnv) [PendingTcSplice]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv
-> PendingTcSplice -> IOEnv (Env TcGblEnv TcLclEnv) PendingTcSplice
zonk_b ZonkEnv
env) [PendingTcSplice]
bs
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XTcBracketOut GhcTc
-> Maybe QuoteWrapper
-> HsBracket GhcRn
-> [PendingTcSplice]
-> HsExpr GhcTc
forall p.
XTcBracketOut p
-> Maybe QuoteWrapper
-> HsBracket GhcRn
-> [PendingTcSplice]
-> HsExpr p
HsTcBracketOut XTcBracketOut GhcTc
x Maybe QuoteWrapper
wrap' HsBracket GhcRn
body [PendingTcSplice]
bs')
where
zonkQuoteWrap :: QuoteWrapper -> IOEnv (Env TcGblEnv TcLclEnv) QuoteWrapper
zonkQuoteWrap (QuoteWrapper Id
ev Kind
ty) = do
let ev' :: Id
ev' = ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env Id
ev
Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
QuoteWrapper -> IOEnv (Env TcGblEnv TcLclEnv) QuoteWrapper
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Kind -> QuoteWrapper
QuoteWrapper Id
ev' Kind
ty')
zonk_b :: ZonkEnv
-> PendingTcSplice -> IOEnv (Env TcGblEnv TcLclEnv) PendingTcSplice
zonk_b ZonkEnv
env' (PendingTcSplice Name
n LHsExpr GhcTc
e) = do LHsExpr GhcTc
e' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env' LHsExpr GhcTc
e
PendingTcSplice -> IOEnv (Env TcGblEnv TcLclEnv) PendingTcSplice
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> LHsExpr GhcTc -> PendingTcSplice
PendingTcSplice Name
n LHsExpr GhcTc
e')
zonkExpr ZonkEnv
env (HsSpliceE XSpliceE GhcTc
_ (XSplice (HsSplicedT DelayedSplice
s))) =
DelayedSplice -> TcM (HsExpr GhcTc)
runTopSplice DelayedSplice
s TcM (HsExpr GhcTc)
-> (HsExpr GhcTc -> TcM (HsExpr GhcTc)) -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env
zonkExpr ZonkEnv
_ e :: HsExpr GhcTc
e@(HsSpliceE XSpliceE GhcTc
_ HsSplice GhcTc
_) = String -> SDoc -> TcM (HsExpr GhcTc)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"zonkExpr: HsSpliceE" (HsExpr GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
e)
zonkExpr ZonkEnv
env (OpApp XOpApp GhcTc
fixity LHsExpr GhcTc
e1 LHsExpr GhcTc
op LHsExpr GhcTc
e2)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_op <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
op
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XOpApp GhcTc
-> LHsExpr GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p.
XOpApp p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
OpApp XOpApp GhcTc
fixity LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_op LHsExpr GhcTc
new_e2)
zonkExpr ZonkEnv
env (NegApp XNegApp GhcTc
x LHsExpr GhcTc
expr SyntaxExpr GhcTc
op)
= do (ZonkEnv
env', SyntaxExprTc
new_op) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
op
LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env' LHsExpr GhcTc
expr
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XNegApp GhcTc -> LHsExpr GhcTc -> SyntaxExpr GhcTc -> HsExpr GhcTc
forall p. XNegApp p -> LHsExpr p -> SyntaxExpr p -> HsExpr p
NegApp XNegApp GhcTc
x LHsExpr GhcTc
new_expr SyntaxExpr GhcTc
SyntaxExprTc
new_op)
zonkExpr ZonkEnv
env (HsPar XPar GhcTc
x LHsExpr GhcTc
e)
= do LHsExpr GhcTc
new_e <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPar GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XPar p -> LHsExpr p -> HsExpr p
HsPar XPar GhcTc
x LHsExpr GhcTc
new_e)
zonkExpr ZonkEnv
env (SectionL XSectionL GhcTc
x LHsExpr GhcTc
expr LHsExpr GhcTc
op)
= do LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
LHsExpr GhcTc
new_op <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
op
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSectionL GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XSectionL p -> LHsExpr p -> LHsExpr p -> HsExpr p
SectionL XSectionL GhcTc
x LHsExpr GhcTc
new_expr LHsExpr GhcTc
new_op)
zonkExpr ZonkEnv
env (SectionR XSectionR GhcTc
x LHsExpr GhcTc
op LHsExpr GhcTc
expr)
= do LHsExpr GhcTc
new_op <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
op
LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XSectionR GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XSectionR p -> LHsExpr p -> LHsExpr p -> HsExpr p
SectionR XSectionR GhcTc
x LHsExpr GhcTc
new_op LHsExpr GhcTc
new_expr)
zonkExpr ZonkEnv
env (ExplicitTuple XExplicitTuple GhcTc
x [LHsTupArg GhcTc]
tup_args Boxity
boxed)
= do { [LHsTupArg GhcTc]
new_tup_args <- (LHsTupArg GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsTupArg GhcTc))
-> [LHsTupArg GhcTc]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsTupArg GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LHsTupArg GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsTupArg GhcTc)
zonk_tup_arg [LHsTupArg GhcTc]
tup_args
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XExplicitTuple GhcTc -> [LHsTupArg GhcTc] -> Boxity -> HsExpr GhcTc
forall p. XExplicitTuple p -> [LHsTupArg p] -> Boxity -> HsExpr p
ExplicitTuple XExplicitTuple GhcTc
x [LHsTupArg GhcTc]
new_tup_args Boxity
boxed) }
where
zonk_tup_arg :: LHsTupArg GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsTupArg GhcTc)
zonk_tup_arg (L SrcSpan
l (Present XPresent GhcTc
x LHsExpr GhcTc
e)) = do { LHsExpr GhcTc
e' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
; LHsTupArg GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsTupArg GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> HsTupArg GhcTc -> LHsTupArg GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (XPresent GhcTc -> LHsExpr GhcTc -> HsTupArg GhcTc
forall id. XPresent id -> LHsExpr id -> HsTupArg id
Present XPresent GhcTc
x LHsExpr GhcTc
e')) }
zonk_tup_arg (L SrcSpan
l (Missing XMissing GhcTc
t)) = do { Scaled Kind
t' <- ZonkEnv -> Scaled Kind -> TcM (Scaled Kind)
zonkScaledTcTypeToTypeX ZonkEnv
env Scaled Kind
XMissing GhcTc
t
; LHsTupArg GhcTc -> IOEnv (Env TcGblEnv TcLclEnv) (LHsTupArg GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan -> HsTupArg GhcTc -> LHsTupArg GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (XMissing GhcTc -> HsTupArg GhcTc
forall id. XMissing id -> HsTupArg id
Missing Scaled Kind
XMissing GhcTc
t')) }
zonkExpr ZonkEnv
env (ExplicitSum XExplicitSum GhcTc
args ConTag
alt ConTag
arity LHsExpr GhcTc
expr)
= do [Kind]
new_args <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) [Kind]
XExplicitSum GhcTc
args
LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XExplicitSum GhcTc
-> ConTag -> ConTag -> LHsExpr GhcTc -> HsExpr GhcTc
forall p.
XExplicitSum p -> ConTag -> ConTag -> LHsExpr p -> HsExpr p
ExplicitSum [Kind]
XExplicitSum GhcTc
new_args ConTag
alt ConTag
arity LHsExpr GhcTc
new_expr)
zonkExpr ZonkEnv
env (HsCase XCase GhcTc
x LHsExpr GhcTc
expr MatchGroup GhcTc (LHsExpr GhcTc)
ms)
= do LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
MatchGroup GhcTc (LHsExpr GhcTc)
new_ms <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> TcM (MatchGroup GhcTc (LHsExpr GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr MatchGroup GhcTc (LHsExpr GhcTc)
ms
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCase GhcTc
-> LHsExpr GhcTc
-> MatchGroup GhcTc (LHsExpr GhcTc)
-> HsExpr GhcTc
forall p.
XCase p -> LHsExpr p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsCase XCase GhcTc
x LHsExpr GhcTc
new_expr MatchGroup GhcTc (LHsExpr GhcTc)
new_ms)
zonkExpr ZonkEnv
env (HsIf XIf GhcTc
x LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 LHsExpr GhcTc
e3)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
LHsExpr GhcTc
new_e3 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e3
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XIf GhcTc
-> LHsExpr GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XIf p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsIf XIf GhcTc
x LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_e2 LHsExpr GhcTc
new_e3)
zonkExpr ZonkEnv
env (HsMultiIf XMultiIf GhcTc
ty [LGRHS GhcTc (LHsExpr GhcTc)]
alts)
= do { [LGRHS GhcTc (LHsExpr GhcTc)]
alts' <- (LGRHS GhcTc (LHsExpr GhcTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (LGRHS GhcTc (LHsExpr GhcTc)))
-> [LGRHS GhcTc (LHsExpr GhcTc)]
-> IOEnv (Env TcGblEnv TcLclEnv) [LGRHS GhcTc (LHsExpr GhcTc)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((GRHS GhcTc (LHsExpr GhcTc) -> TcM (GRHS GhcTc (LHsExpr GhcTc)))
-> LGRHS GhcTc (LHsExpr GhcTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (LGRHS GhcTc (LHsExpr GhcTc))
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM GRHS GhcTc (LHsExpr GhcTc) -> TcM (GRHS GhcTc (LHsExpr GhcTc))
zonk_alt) [LGRHS GhcTc (LHsExpr GhcTc)]
alts
; Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XMultiIf GhcTc
ty
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsExpr GhcTc -> TcM (HsExpr GhcTc))
-> HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall a b. (a -> b) -> a -> b
$ XMultiIf GhcTc -> [LGRHS GhcTc (LHsExpr GhcTc)] -> HsExpr GhcTc
forall p. XMultiIf p -> [LGRHS p (LHsExpr p)] -> HsExpr p
HsMultiIf Kind
XMultiIf GhcTc
ty' [LGRHS GhcTc (LHsExpr GhcTc)]
alts' }
where zonk_alt :: GRHS GhcTc (LHsExpr GhcTc) -> TcM (GRHS GhcTc (LHsExpr GhcTc))
zonk_alt (GRHS XCGRHS GhcTc (LHsExpr GhcTc)
x [GuardLStmt GhcTc]
guard LHsExpr GhcTc
expr)
= do { (ZonkEnv
env', [GuardLStmt GhcTc]
guard') <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [GuardLStmt GhcTc]
-> TcM (ZonkEnv, [GuardLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr [GuardLStmt GhcTc]
guard
; LHsExpr GhcTc
expr' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env' LHsExpr GhcTc
expr
; GRHS GhcTc (LHsExpr GhcTc) -> TcM (GRHS GhcTc (LHsExpr GhcTc))
forall (m :: * -> *) a. Monad m => a -> m a
return (GRHS GhcTc (LHsExpr GhcTc) -> TcM (GRHS GhcTc (LHsExpr GhcTc)))
-> GRHS GhcTc (LHsExpr GhcTc) -> TcM (GRHS GhcTc (LHsExpr GhcTc))
forall a b. (a -> b) -> a -> b
$ XCGRHS GhcTc (LHsExpr GhcTc)
-> [GuardLStmt GhcTc]
-> LHsExpr GhcTc
-> GRHS GhcTc (LHsExpr GhcTc)
forall p body.
XCGRHS p body -> [GuardLStmt p] -> body -> GRHS p body
GRHS XCGRHS GhcTc (LHsExpr GhcTc)
x [GuardLStmt GhcTc]
guard' LHsExpr GhcTc
expr' }
zonkExpr ZonkEnv
env (HsLet XLet GhcTc
x (L SrcSpan
l HsLocalBinds GhcTc
binds) LHsExpr GhcTc
expr)
= do (ZonkEnv
new_env, HsLocalBinds GhcTc
new_binds) <- ZonkEnv -> HsLocalBinds GhcTc -> TcM (ZonkEnv, HsLocalBinds GhcTc)
zonkLocalBinds ZonkEnv
env HsLocalBinds GhcTc
binds
LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
new_env LHsExpr GhcTc
expr
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XLet GhcTc
-> GenLocated SrcSpan (HsLocalBinds GhcTc)
-> LHsExpr GhcTc
-> HsExpr GhcTc
forall p. XLet p -> LHsLocalBinds p -> LHsExpr p -> HsExpr p
HsLet XLet GhcTc
x (SrcSpan
-> HsLocalBinds GhcTc -> GenLocated SrcSpan (HsLocalBinds GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsLocalBinds GhcTc
new_binds) LHsExpr GhcTc
new_expr)
zonkExpr ZonkEnv
env (HsDo XDo GhcTc
ty HsStmtContext GhcRn
do_or_lc (L SrcSpan
l [GuardLStmt GhcTc]
stmts))
= do (ZonkEnv
_, [GuardLStmt GhcTc]
new_stmts) <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [GuardLStmt GhcTc]
-> TcM (ZonkEnv, [GuardLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr [GuardLStmt GhcTc]
stmts
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XDo GhcTc
ty
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XDo GhcTc
-> HsStmtContext GhcRn
-> GenLocated SrcSpan [GuardLStmt GhcTc]
-> HsExpr GhcTc
forall p.
XDo p -> HsStmtContext GhcRn -> Located [ExprLStmt p] -> HsExpr p
HsDo Kind
XDo GhcTc
new_ty HsStmtContext GhcRn
do_or_lc (SrcSpan
-> [GuardLStmt GhcTc] -> GenLocated SrcSpan [GuardLStmt GhcTc]
forall l e. l -> e -> GenLocated l e
L SrcSpan
l [GuardLStmt GhcTc]
new_stmts))
zonkExpr ZonkEnv
env (ExplicitList XExplicitList GhcTc
ty Maybe (SyntaxExpr GhcTc)
wit [LHsExpr GhcTc]
exprs)
= do (ZonkEnv
env1, Maybe SyntaxExprTc
new_wit) <- ZonkEnv
-> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
zonkWit ZonkEnv
env Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
wit
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env1 Kind
XExplicitList GhcTc
ty
[LHsExpr GhcTc]
new_exprs <- ZonkEnv -> [LHsExpr GhcTc] -> TcM [LHsExpr GhcTc]
zonkLExprs ZonkEnv
env1 [LHsExpr GhcTc]
exprs
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XExplicitList GhcTc
-> Maybe (SyntaxExpr GhcTc) -> [LHsExpr GhcTc] -> HsExpr GhcTc
forall p.
XExplicitList p -> Maybe (SyntaxExpr p) -> [LHsExpr p] -> HsExpr p
ExplicitList Kind
XExplicitList GhcTc
new_ty Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
new_wit [LHsExpr GhcTc]
new_exprs)
where zonkWit :: ZonkEnv
-> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
zonkWit ZonkEnv
env Maybe SyntaxExprTc
Nothing = (ZonkEnv, Maybe SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, Maybe SyntaxExprTc
forall a. Maybe a
Nothing)
zonkWit ZonkEnv
env (Just SyntaxExprTc
fln) = (SyntaxExprTc -> Maybe SyntaxExprTc)
-> (ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just ((ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
SyntaxExprTc
fln
zonkExpr ZonkEnv
env expr :: HsExpr GhcTc
expr@(RecordCon { rcon_ext :: forall p. HsExpr p -> XRecordCon p
rcon_ext = XRecordCon GhcTc
ext, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds GhcTc
rbinds })
= do { HsExpr GhcTc
new_con_expr <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env (RecordConTc -> HsExpr GhcTc
rcon_con_expr XRecordCon GhcTc
RecordConTc
ext)
; HsRecordBinds GhcTc
new_rbinds <- ZonkEnv -> HsRecordBinds GhcTc -> TcM (HsRecordBinds GhcTc)
zonkRecFields ZonkEnv
env HsRecordBinds GhcTc
rbinds
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsExpr GhcTc
expr { rcon_ext :: XRecordCon GhcTc
rcon_ext = XRecordCon GhcTc
RecordConTc
ext { rcon_con_expr :: HsExpr GhcTc
rcon_con_expr = HsExpr GhcTc
new_con_expr }
, rcon_flds :: HsRecordBinds GhcTc
rcon_flds = HsRecordBinds GhcTc
new_rbinds }) }
zonkExpr ZonkEnv
env (RecordUpd { rupd_flds :: forall p. HsExpr p -> [LHsRecUpdField p]
rupd_flds = [LHsRecUpdField GhcTc]
rbinds
, rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = LHsExpr GhcTc
expr
, rupd_ext :: forall p. HsExpr p -> XRecordUpd p
rupd_ext = RecordUpdTc
{ rupd_cons :: RecordUpdTc -> [ConLike]
rupd_cons = [ConLike]
cons, rupd_in_tys :: RecordUpdTc -> [Kind]
rupd_in_tys = [Kind]
in_tys
, rupd_out_tys :: RecordUpdTc -> [Kind]
rupd_out_tys = [Kind]
out_tys, rupd_wrap :: RecordUpdTc -> HsWrapper
rupd_wrap = HsWrapper
req_wrap }})
= do { LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
; [Kind]
new_in_tys <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) [Kind]
in_tys
; [Kind]
new_out_tys <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) [Kind]
out_tys
; [LHsRecUpdField GhcTc]
new_rbinds <- ZonkEnv -> [LHsRecUpdField GhcTc] -> TcM [LHsRecUpdField GhcTc]
zonkRecUpdFields ZonkEnv
env [LHsRecUpdField GhcTc]
rbinds
; (ZonkEnv
_, HsWrapper
new_recwrap) <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
req_wrap
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (RecordUpd :: forall p.
XRecordUpd p -> LHsExpr p -> [LHsRecUpdField p] -> HsExpr p
RecordUpd { rupd_expr :: LHsExpr GhcTc
rupd_expr = LHsExpr GhcTc
new_expr, rupd_flds :: [LHsRecUpdField GhcTc]
rupd_flds = [LHsRecUpdField GhcTc]
new_rbinds
, rupd_ext :: XRecordUpd GhcTc
rupd_ext = RecordUpdTc :: [ConLike] -> [Kind] -> [Kind] -> HsWrapper -> RecordUpdTc
RecordUpdTc
{ rupd_cons :: [ConLike]
rupd_cons = [ConLike]
cons, rupd_in_tys :: [Kind]
rupd_in_tys = [Kind]
new_in_tys
, rupd_out_tys :: [Kind]
rupd_out_tys = [Kind]
new_out_tys
, rupd_wrap :: HsWrapper
rupd_wrap = HsWrapper
new_recwrap }}) }
zonkExpr ZonkEnv
env (ExprWithTySig XExprWithTySig GhcTc
_ LHsExpr GhcTc
e LHsSigWcType (NoGhcTc GhcTc)
ty)
= do { LHsExpr GhcTc
e' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XExprWithTySig GhcTc
-> LHsExpr GhcTc -> LHsSigWcType (NoGhcTc GhcTc) -> HsExpr GhcTc
forall p.
XExprWithTySig p
-> LHsExpr p -> LHsSigWcType (NoGhcTc p) -> HsExpr p
ExprWithTySig NoExtField
XExprWithTySig GhcTc
noExtField LHsExpr GhcTc
e' LHsSigWcType (NoGhcTc GhcTc)
ty) }
zonkExpr ZonkEnv
env (ArithSeq XArithSeq GhcTc
expr Maybe (SyntaxExpr GhcTc)
wit ArithSeqInfo GhcTc
info)
= do (ZonkEnv
env1, Maybe SyntaxExprTc
new_wit) <- ZonkEnv
-> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
zonkWit ZonkEnv
env Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
wit
HsExpr GhcTc
new_expr <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env XArithSeq GhcTc
HsExpr GhcTc
expr
ArithSeqInfo GhcTc
new_info <- ZonkEnv -> ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
zonkArithSeq ZonkEnv
env1 ArithSeqInfo GhcTc
info
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XArithSeq GhcTc
-> Maybe (SyntaxExpr GhcTc) -> ArithSeqInfo GhcTc -> HsExpr GhcTc
forall p.
XArithSeq p -> Maybe (SyntaxExpr p) -> ArithSeqInfo p -> HsExpr p
ArithSeq XArithSeq GhcTc
HsExpr GhcTc
new_expr Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
new_wit ArithSeqInfo GhcTc
new_info)
where zonkWit :: ZonkEnv
-> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
zonkWit ZonkEnv
env Maybe SyntaxExprTc
Nothing = (ZonkEnv, Maybe SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, Maybe SyntaxExprTc
forall a. Maybe a
Nothing)
zonkWit ZonkEnv
env (Just SyntaxExprTc
fln) = (SyntaxExprTc -> Maybe SyntaxExprTc)
-> (ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just ((ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
SyntaxExprTc
fln
zonkExpr ZonkEnv
env (HsPragE XPragE GhcTc
x HsPragE GhcTc
prag LHsExpr GhcTc
expr)
= do LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XPragE GhcTc -> HsPragE GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XPragE p -> HsPragE p -> LHsExpr p -> HsExpr p
HsPragE XPragE GhcTc
x HsPragE GhcTc
prag LHsExpr GhcTc
new_expr)
zonkExpr ZonkEnv
env (HsProc XProc GhcTc
x LPat GhcTc
pat LHsCmdTop GhcTc
body)
= do { (ZonkEnv
env1, GenLocated SrcSpan (Pat GhcTc)
new_pat) <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; LHsCmdTop GhcTc
new_body <- ZonkEnv -> LHsCmdTop GhcTc -> TcM (LHsCmdTop GhcTc)
zonkCmdTop ZonkEnv
env1 LHsCmdTop GhcTc
body
; HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XProc GhcTc -> LPat GhcTc -> LHsCmdTop GhcTc -> HsExpr GhcTc
forall p. XProc p -> LPat p -> LHsCmdTop p -> HsExpr p
HsProc XProc GhcTc
x GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
new_pat LHsCmdTop GhcTc
new_body) }
zonkExpr ZonkEnv
env (HsStatic XStatic GhcTc
fvs LHsExpr GhcTc
expr)
= XStatic GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XStatic p -> LHsExpr p -> HsExpr p
HsStatic XStatic GhcTc
fvs (LHsExpr GhcTc -> HsExpr GhcTc)
-> TcM (LHsExpr GhcTc) -> TcM (HsExpr GhcTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
zonkExpr ZonkEnv
env (XExpr (WrapExpr (HsWrap HsWrapper
co_fn HsExpr GhcTc
expr)))
= do (ZonkEnv
env1, HsWrapper
new_co_fn) <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
co_fn
HsExpr GhcTc
new_expr <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env1 HsExpr GhcTc
expr
HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XXExpr GhcTc -> HsExpr GhcTc
forall p. XXExpr p -> HsExpr p
XExpr (HsWrap HsExpr -> XXExprGhcTc
WrapExpr (HsWrapper -> HsExpr GhcTc -> HsWrap HsExpr
forall (hs_syn :: * -> *).
HsWrapper -> hs_syn GhcTc -> HsWrap hs_syn
HsWrap HsWrapper
new_co_fn HsExpr GhcTc
new_expr)))
zonkExpr ZonkEnv
env (XExpr (ExpansionExpr (HsExpanded HsExpr GhcRn
a HsExpr GhcTc
b)))
= XXExprGhcTc -> HsExpr GhcTc
forall p. XXExpr p -> HsExpr p
XExpr (XXExprGhcTc -> HsExpr GhcTc)
-> (HsExpr GhcTc -> XXExprGhcTc) -> HsExpr GhcTc -> HsExpr GhcTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpansion (HsExpr GhcRn) (HsExpr GhcTc) -> XXExprGhcTc
ExpansionExpr (HsExpansion (HsExpr GhcRn) (HsExpr GhcTc) -> XXExprGhcTc)
-> (HsExpr GhcTc -> HsExpansion (HsExpr GhcRn) (HsExpr GhcTc))
-> HsExpr GhcTc
-> XXExprGhcTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr GhcRn
-> HsExpr GhcTc -> HsExpansion (HsExpr GhcRn) (HsExpr GhcTc)
forall a b. a -> b -> HsExpansion a b
HsExpanded HsExpr GhcRn
a (HsExpr GhcTc -> HsExpr GhcTc)
-> TcM (HsExpr GhcTc) -> TcM (HsExpr GhcTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env HsExpr GhcTc
b
zonkExpr ZonkEnv
_ e :: HsExpr GhcTc
e@(HsUnboundVar {})
= HsExpr GhcTc -> TcM (HsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return HsExpr GhcTc
e
zonkExpr ZonkEnv
_ HsExpr GhcTc
expr = String -> SDoc -> TcM (HsExpr GhcTc)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"zonkExpr" (HsExpr GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
expr)
zonkSyntaxExpr :: ZonkEnv -> SyntaxExpr GhcTc
-> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr :: ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env (SyntaxExprTc { syn_expr :: SyntaxExprTc -> HsExpr GhcTc
syn_expr = HsExpr GhcTc
expr
, syn_arg_wraps :: SyntaxExprTc -> [HsWrapper]
syn_arg_wraps = [HsWrapper]
arg_wraps
, syn_res_wrap :: SyntaxExprTc -> HsWrapper
syn_res_wrap = HsWrapper
res_wrap })
= do { (ZonkEnv
env0, HsWrapper
res_wrap') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
res_wrap
; HsExpr GhcTc
expr' <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env0 HsExpr GhcTc
expr
; (ZonkEnv
env1, [HsWrapper]
arg_wraps') <- (ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper))
-> ZonkEnv
-> [HsWrapper]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [HsWrapper])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env0 [HsWrapper]
arg_wraps
; (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, SyntaxExprTc :: HsExpr GhcTc -> [HsWrapper] -> HsWrapper -> SyntaxExprTc
SyntaxExprTc { syn_expr :: HsExpr GhcTc
syn_expr = HsExpr GhcTc
expr'
, syn_arg_wraps :: [HsWrapper]
syn_arg_wraps = [HsWrapper]
arg_wraps'
, syn_res_wrap :: HsWrapper
syn_res_wrap = HsWrapper
res_wrap' }) }
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
SyntaxExprTc
NoSyntaxExprTc = (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, SyntaxExprTc
NoSyntaxExprTc)
zonkLCmd :: ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkCmd :: ZonkEnv -> HsCmd GhcTc -> TcM (HsCmd GhcTc)
zonkLCmd :: ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
env LHsCmd GhcTc
cmd = (HsCmd GhcTc -> TcM (HsCmd GhcTc))
-> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> HsCmd GhcTc -> TcM (HsCmd GhcTc)
zonkCmd ZonkEnv
env) LHsCmd GhcTc
cmd
zonkCmd :: ZonkEnv -> HsCmd GhcTc -> TcM (HsCmd GhcTc)
zonkCmd ZonkEnv
env (XCmd (HsWrap HsWrapper
w HsCmd GhcTc
cmd))
= do { (ZonkEnv
env1, HsWrapper
w') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
w
; HsCmd GhcTc
cmd' <- ZonkEnv -> HsCmd GhcTc -> TcM (HsCmd GhcTc)
zonkCmd ZonkEnv
env1 HsCmd GhcTc
cmd
; HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XXCmd GhcTc -> HsCmd GhcTc
forall id. XXCmd id -> HsCmd id
XCmd (HsWrapper -> HsCmd GhcTc -> HsWrap HsCmd
forall (hs_syn :: * -> *).
HsWrapper -> hs_syn GhcTc -> HsWrap hs_syn
HsWrap HsWrapper
w' HsCmd GhcTc
cmd')) }
zonkCmd ZonkEnv
env (HsCmdArrApp XCmdArrApp GhcTc
ty LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 HsArrAppType
ho Bool
rl)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XCmdArrApp GhcTc
ty
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdArrApp GhcTc
-> LHsExpr GhcTc
-> LHsExpr GhcTc
-> HsArrAppType
-> Bool
-> HsCmd GhcTc
forall id.
XCmdArrApp id
-> LHsExpr id -> LHsExpr id -> HsArrAppType -> Bool -> HsCmd id
HsCmdArrApp Kind
XCmdArrApp GhcTc
new_ty LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_e2 HsArrAppType
ho Bool
rl)
zonkCmd ZonkEnv
env (HsCmdArrForm XCmdArrForm GhcTc
x LHsExpr GhcTc
op LexicalFixity
f Maybe Fixity
fixity [LHsCmdTop GhcTc]
args)
= do LHsExpr GhcTc
new_op <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
op
[LHsCmdTop GhcTc]
new_args <- (LHsCmdTop GhcTc -> TcM (LHsCmdTop GhcTc))
-> [LHsCmdTop GhcTc]
-> IOEnv (Env TcGblEnv TcLclEnv) [LHsCmdTop GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> LHsCmdTop GhcTc -> TcM (LHsCmdTop GhcTc)
zonkCmdTop ZonkEnv
env) [LHsCmdTop GhcTc]
args
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdArrForm GhcTc
-> LHsExpr GhcTc
-> LexicalFixity
-> Maybe Fixity
-> [LHsCmdTop GhcTc]
-> HsCmd GhcTc
forall id.
XCmdArrForm id
-> LHsExpr id
-> LexicalFixity
-> Maybe Fixity
-> [LHsCmdTop id]
-> HsCmd id
HsCmdArrForm XCmdArrForm GhcTc
x LHsExpr GhcTc
new_op LexicalFixity
f Maybe Fixity
fixity [LHsCmdTop GhcTc]
new_args)
zonkCmd ZonkEnv
env (HsCmdApp XCmdApp GhcTc
x LHsCmd GhcTc
c LHsExpr GhcTc
e)
= do LHsCmd GhcTc
new_c <- ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
env LHsCmd GhcTc
c
LHsExpr GhcTc
new_e <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdApp GhcTc -> LHsCmd GhcTc -> LHsExpr GhcTc -> HsCmd GhcTc
forall id. XCmdApp id -> LHsCmd id -> LHsExpr id -> HsCmd id
HsCmdApp XCmdApp GhcTc
x LHsCmd GhcTc
new_c LHsExpr GhcTc
new_e)
zonkCmd ZonkEnv
env (HsCmdLam XCmdLam GhcTc
x MatchGroup GhcTc (LHsCmd GhcTc)
matches)
= do MatchGroup GhcTc (LHsCmd GhcTc)
new_matches <- ZonkEnv
-> (ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc))
-> MatchGroup GhcTc (LHsCmd GhcTc)
-> TcM (MatchGroup GhcTc (LHsCmd GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd MatchGroup GhcTc (LHsCmd GhcTc)
matches
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdLam GhcTc -> MatchGroup GhcTc (LHsCmd GhcTc) -> HsCmd GhcTc
forall id. XCmdLam id -> MatchGroup id (LHsCmd id) -> HsCmd id
HsCmdLam XCmdLam GhcTc
x MatchGroup GhcTc (LHsCmd GhcTc)
new_matches)
zonkCmd ZonkEnv
env (HsCmdPar XCmdPar GhcTc
x LHsCmd GhcTc
c)
= do LHsCmd GhcTc
new_c <- ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
env LHsCmd GhcTc
c
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdPar GhcTc -> LHsCmd GhcTc -> HsCmd GhcTc
forall id. XCmdPar id -> LHsCmd id -> HsCmd id
HsCmdPar XCmdPar GhcTc
x LHsCmd GhcTc
new_c)
zonkCmd ZonkEnv
env (HsCmdCase XCmdCase GhcTc
x LHsExpr GhcTc
expr MatchGroup GhcTc (LHsCmd GhcTc)
ms)
= do LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
MatchGroup GhcTc (LHsCmd GhcTc)
new_ms <- ZonkEnv
-> (ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc))
-> MatchGroup GhcTc (LHsCmd GhcTc)
-> TcM (MatchGroup GhcTc (LHsCmd GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd MatchGroup GhcTc (LHsCmd GhcTc)
ms
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdCase GhcTc
-> LHsExpr GhcTc -> MatchGroup GhcTc (LHsCmd GhcTc) -> HsCmd GhcTc
forall id.
XCmdCase id -> LHsExpr id -> MatchGroup id (LHsCmd id) -> HsCmd id
HsCmdCase XCmdCase GhcTc
x LHsExpr GhcTc
new_expr MatchGroup GhcTc (LHsCmd GhcTc)
new_ms)
zonkCmd ZonkEnv
env (HsCmdLamCase XCmdLamCase GhcTc
x MatchGroup GhcTc (LHsCmd GhcTc)
ms)
= do MatchGroup GhcTc (LHsCmd GhcTc)
new_ms <- ZonkEnv
-> (ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc))
-> MatchGroup GhcTc (LHsCmd GhcTc)
-> TcM (MatchGroup GhcTc (LHsCmd GhcTc))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> MatchGroup GhcTc (Located (body GhcTc))
-> TcM (MatchGroup GhcTc (Located (body GhcTc)))
zonkMatchGroup ZonkEnv
env ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd MatchGroup GhcTc (LHsCmd GhcTc)
ms
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdLamCase GhcTc -> MatchGroup GhcTc (LHsCmd GhcTc) -> HsCmd GhcTc
forall id. XCmdLamCase id -> MatchGroup id (LHsCmd id) -> HsCmd id
HsCmdLamCase XCmdLamCase GhcTc
x MatchGroup GhcTc (LHsCmd GhcTc)
new_ms)
zonkCmd ZonkEnv
env (HsCmdIf XCmdIf GhcTc
x SyntaxExpr GhcTc
eCond LHsExpr GhcTc
ePred LHsCmd GhcTc
cThen LHsCmd GhcTc
cElse)
= do { (ZonkEnv
env1, SyntaxExprTc
new_eCond) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
eCond
; LHsExpr GhcTc
new_ePred <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env1 LHsExpr GhcTc
ePred
; LHsCmd GhcTc
new_cThen <- ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
env1 LHsCmd GhcTc
cThen
; LHsCmd GhcTc
new_cElse <- ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
env1 LHsCmd GhcTc
cElse
; HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdIf GhcTc
-> SyntaxExpr GhcTc
-> LHsExpr GhcTc
-> LHsCmd GhcTc
-> LHsCmd GhcTc
-> HsCmd GhcTc
forall id.
XCmdIf id
-> SyntaxExpr id
-> LHsExpr id
-> LHsCmd id
-> LHsCmd id
-> HsCmd id
HsCmdIf XCmdIf GhcTc
x SyntaxExpr GhcTc
SyntaxExprTc
new_eCond LHsExpr GhcTc
new_ePred LHsCmd GhcTc
new_cThen LHsCmd GhcTc
new_cElse) }
zonkCmd ZonkEnv
env (HsCmdLet XCmdLet GhcTc
x (L SrcSpan
l HsLocalBinds GhcTc
binds) LHsCmd GhcTc
cmd)
= do (ZonkEnv
new_env, HsLocalBinds GhcTc
new_binds) <- ZonkEnv -> HsLocalBinds GhcTc -> TcM (ZonkEnv, HsLocalBinds GhcTc)
zonkLocalBinds ZonkEnv
env HsLocalBinds GhcTc
binds
LHsCmd GhcTc
new_cmd <- ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
new_env LHsCmd GhcTc
cmd
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdLet GhcTc
-> GenLocated SrcSpan (HsLocalBinds GhcTc)
-> LHsCmd GhcTc
-> HsCmd GhcTc
forall id. XCmdLet id -> LHsLocalBinds id -> LHsCmd id -> HsCmd id
HsCmdLet XCmdLet GhcTc
x (SrcSpan
-> HsLocalBinds GhcTc -> GenLocated SrcSpan (HsLocalBinds GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsLocalBinds GhcTc
new_binds) LHsCmd GhcTc
new_cmd)
zonkCmd ZonkEnv
env (HsCmdDo XCmdDo GhcTc
ty (L SrcSpan
l [CmdLStmt GhcTc]
stmts))
= do (ZonkEnv
_, [CmdLStmt GhcTc]
new_stmts) <- ZonkEnv
-> (ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc))
-> [CmdLStmt GhcTc]
-> TcM (ZonkEnv, [CmdLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd [CmdLStmt GhcTc]
stmts
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XCmdDo GhcTc
ty
HsCmd GhcTc -> TcM (HsCmd GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdDo GhcTc -> GenLocated SrcSpan [CmdLStmt GhcTc] -> HsCmd GhcTc
forall id. XCmdDo id -> Located [CmdLStmt id] -> HsCmd id
HsCmdDo Kind
XCmdDo GhcTc
new_ty (SrcSpan -> [CmdLStmt GhcTc] -> GenLocated SrcSpan [CmdLStmt GhcTc]
forall l e. l -> e -> GenLocated l e
L SrcSpan
l [CmdLStmt GhcTc]
new_stmts))
zonkCmdTop :: ZonkEnv -> LHsCmdTop GhcTc -> TcM (LHsCmdTop GhcTc)
zonkCmdTop :: ZonkEnv -> LHsCmdTop GhcTc -> TcM (LHsCmdTop GhcTc)
zonkCmdTop ZonkEnv
env LHsCmdTop GhcTc
cmd = (HsCmdTop GhcTc -> TcM (HsCmdTop GhcTc))
-> LHsCmdTop GhcTc -> TcM (LHsCmdTop GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> HsCmdTop GhcTc -> TcM (HsCmdTop GhcTc)
zonk_cmd_top ZonkEnv
env) LHsCmdTop GhcTc
cmd
zonk_cmd_top :: ZonkEnv -> HsCmdTop GhcTc -> TcM (HsCmdTop GhcTc)
zonk_cmd_top :: ZonkEnv -> HsCmdTop GhcTc -> TcM (HsCmdTop GhcTc)
zonk_cmd_top ZonkEnv
env (HsCmdTop (CmdTopTc Kind
stack_tys Kind
ty CmdSyntaxTable GhcTc
ids) LHsCmd GhcTc
cmd)
= do LHsCmd GhcTc
new_cmd <- ZonkEnv -> LHsCmd GhcTc -> TcM (LHsCmd GhcTc)
zonkLCmd ZonkEnv
env LHsCmd GhcTc
cmd
Kind
new_stack_tys <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
stack_tys
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
CmdSyntaxTable GhcTc
new_ids <- (HsExpr GhcTc -> TcM (HsExpr GhcTc))
-> CmdSyntaxTable GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (CmdSyntaxTable GhcTc)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> [(a, b)] -> m [(a, c)]
mapSndM (ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env) CmdSyntaxTable GhcTc
ids
MASSERT( isLiftedTypeKind (tcTypeKind new_stack_tys) )
HsCmdTop GhcTc -> TcM (HsCmdTop GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XCmdTop GhcTc -> LHsCmd GhcTc -> HsCmdTop GhcTc
forall p. XCmdTop p -> LHsCmd p -> HsCmdTop p
HsCmdTop (Kind -> Kind -> CmdSyntaxTable GhcTc -> CmdTopTc
CmdTopTc Kind
new_stack_tys Kind
new_ty CmdSyntaxTable GhcTc
new_ids) LHsCmd GhcTc
new_cmd)
zonkCoFn :: ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn :: ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
WpHole = (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, HsWrapper
WpHole)
zonkCoFn ZonkEnv
env (WpCompose HsWrapper
c1 HsWrapper
c2) = do { (ZonkEnv
env1, HsWrapper
c1') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
c1
; (ZonkEnv
env2, HsWrapper
c2') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env1 HsWrapper
c2
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, HsWrapper -> HsWrapper -> HsWrapper
WpCompose HsWrapper
c1' HsWrapper
c2') }
zonkCoFn ZonkEnv
env (WpFun HsWrapper
c1 HsWrapper
c2 Scaled Kind
t1 SDoc
d) = do { (ZonkEnv
env1, HsWrapper
c1') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
c1
; (ZonkEnv
env2, HsWrapper
c2') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env1 HsWrapper
c2
; Scaled Kind
t1' <- ZonkEnv -> Scaled Kind -> TcM (Scaled Kind)
zonkScaledTcTypeToTypeX ZonkEnv
env2 Scaled Kind
t1
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, HsWrapper -> HsWrapper -> Scaled Kind -> SDoc -> HsWrapper
WpFun HsWrapper
c1' HsWrapper
c2' Scaled Kind
t1' SDoc
d) }
zonkCoFn ZonkEnv
env (WpCast TcCoercionR
co) = do { TcCoercionR
co' <- ZonkEnv -> TcCoercionR -> TcM TcCoercionR
zonkCoToCo ZonkEnv
env TcCoercionR
co
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, TcCoercionR -> HsWrapper
WpCast TcCoercionR
co') }
zonkCoFn ZonkEnv
env (WpEvLam Id
ev) = do { (ZonkEnv
env', Id
ev') <- ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkEvBndrX ZonkEnv
env Id
ev
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', Id -> HsWrapper
WpEvLam Id
ev') }
zonkCoFn ZonkEnv
env (WpEvApp EvTerm
arg) = do { EvTerm
arg' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
arg
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, EvTerm -> HsWrapper
WpEvApp EvTerm
arg') }
zonkCoFn ZonkEnv
env (WpTyLam Id
tv) = ASSERT( isImmutableTyVar tv )
do { (ZonkEnv
env', Id
tv') <- ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX ZonkEnv
env Id
tv
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', Id -> HsWrapper
WpTyLam Id
tv') }
zonkCoFn ZonkEnv
env (WpTyApp Kind
ty) = do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, Kind -> HsWrapper
WpTyApp Kind
ty') }
zonkCoFn ZonkEnv
env (WpLet TcEvBinds
bs) = do { (ZonkEnv
env1, TcEvBinds
bs') <- ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, TcEvBinds)
zonkTcEvBinds ZonkEnv
env TcEvBinds
bs
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, TcEvBinds -> HsWrapper
WpLet TcEvBinds
bs') }
zonkCoFn ZonkEnv
env (WpMultCoercion TcCoercionR
co) = do { TcCoercionR
co' <- ZonkEnv -> TcCoercionR -> TcM TcCoercionR
zonkCoToCo ZonkEnv
env TcCoercionR
co
; (ZonkEnv, HsWrapper) -> TcM (ZonkEnv, HsWrapper)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, TcCoercionR -> HsWrapper
WpMultCoercion TcCoercionR
co') }
zonkOverLit :: ZonkEnv -> HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
zonkOverLit :: ZonkEnv -> HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
zonkOverLit ZonkEnv
env lit :: HsOverLit GhcTc
lit@(OverLit {ol_ext :: forall p. HsOverLit p -> XOverLit p
ol_ext = OverLitTc Bool
r Kind
ty, ol_witness :: forall p. HsOverLit p -> HsExpr p
ol_witness = HsExpr GhcTc
e })
= do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
; HsExpr GhcTc
e' <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env HsExpr GhcTc
e
; HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (HsOverLit GhcTc
lit { ol_witness :: HsExpr GhcTc
ol_witness = HsExpr GhcTc
e', ol_ext :: XOverLit GhcTc
ol_ext = Bool -> Kind -> OverLitTc
OverLitTc Bool
r Kind
ty' }) }
zonkArithSeq :: ZonkEnv -> ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
zonkArithSeq :: ZonkEnv -> ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
zonkArithSeq ZonkEnv
env (From LHsExpr GhcTc
e)
= do LHsExpr GhcTc
new_e <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e
ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr GhcTc -> ArithSeqInfo GhcTc
forall id. LHsExpr id -> ArithSeqInfo id
From LHsExpr GhcTc
new_e)
zonkArithSeq ZonkEnv
env (FromThen LHsExpr GhcTc
e1 LHsExpr GhcTc
e2)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr GhcTc -> LHsExpr GhcTc -> ArithSeqInfo GhcTc
forall id. LHsExpr id -> LHsExpr id -> ArithSeqInfo id
FromThen LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_e2)
zonkArithSeq ZonkEnv
env (FromTo LHsExpr GhcTc
e1 LHsExpr GhcTc
e2)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr GhcTc -> LHsExpr GhcTc -> ArithSeqInfo GhcTc
forall id. LHsExpr id -> LHsExpr id -> ArithSeqInfo id
FromTo LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_e2)
zonkArithSeq ZonkEnv
env (FromThenTo LHsExpr GhcTc
e1 LHsExpr GhcTc
e2 LHsExpr GhcTc
e3)
= do LHsExpr GhcTc
new_e1 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e1
LHsExpr GhcTc
new_e2 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e2
LHsExpr GhcTc
new_e3 <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
e3
ArithSeqInfo GhcTc -> TcM (ArithSeqInfo GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsExpr GhcTc
-> LHsExpr GhcTc -> LHsExpr GhcTc -> ArithSeqInfo GhcTc
forall id.
LHsExpr id -> LHsExpr id -> LHsExpr id -> ArithSeqInfo id
FromThenTo LHsExpr GhcTc
new_e1 LHsExpr GhcTc
new_e2 LHsExpr GhcTc
new_e3)
zonkStmts :: ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts :: forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
_ [] = (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, [])
zonkStmts ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (LStmt GhcTc (Located (body GhcTc))
s:[LStmt GhcTc (Located (body GhcTc))]
ss) = do { (ZonkEnv
env1, LStmt GhcTc (Located (body GhcTc))
s') <- (Stmt GhcTc (Located (body GhcTc))
-> TcM (ZonkEnv, Stmt GhcTc (Located (body GhcTc))))
-> LStmt GhcTc (Located (body GhcTc))
-> TcM (ZonkEnv, LStmt GhcTc (Located (body GhcTc)))
forall a b c. (a -> TcM (b, c)) -> Located a -> TcM (b, Located c)
wrapLocSndM (ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> Stmt GhcTc (Located (body GhcTc))
-> TcM (ZonkEnv, Stmt GhcTc (Located (body GhcTc)))
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> Stmt GhcTc (Located (body GhcTc))
-> TcM (ZonkEnv, Stmt GhcTc (Located (body GhcTc)))
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody) LStmt GhcTc (Located (body GhcTc))
s
; (ZonkEnv
env2, [LStmt GhcTc (Located (body GhcTc))]
ss') <- ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env1 ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody [LStmt GhcTc (Located (body GhcTc))]
ss
; (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, LStmt GhcTc (Located (body GhcTc))
s' LStmt GhcTc (Located (body GhcTc))
-> [LStmt GhcTc (Located (body GhcTc))]
-> [LStmt GhcTc (Located (body GhcTc))]
forall a. a -> [a] -> [a]
: [LStmt GhcTc (Located (body GhcTc))]
ss') }
zonkStmt :: ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> Stmt GhcTc (Located (body GhcTc))
-> TcM (ZonkEnv, Stmt GhcTc (Located (body GhcTc)))
zonkStmt :: forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> Stmt GhcTc (Located (body GhcTc))
-> TcM (ZonkEnv, Stmt GhcTc (Located (body GhcTc)))
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
_ (ParStmt XParStmt GhcTc GhcTc (Located (body GhcTc))
bind_ty [ParStmtBlock GhcTc GhcTc]
stmts_w_bndrs HsExpr GhcTc
mzip_op SyntaxExpr GhcTc
bind_op)
= do { (ZonkEnv
env1, SyntaxExprTc
new_bind_op) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
bind_op
; Kind
new_bind_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env1 Kind
XParStmt GhcTc GhcTc (Located (body GhcTc))
bind_ty
; [ParStmtBlock GhcTc GhcTc]
new_stmts_w_bndrs <- (ParStmtBlock GhcTc GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ParStmtBlock GhcTc GhcTc))
-> [ParStmtBlock GhcTc GhcTc]
-> IOEnv (Env TcGblEnv TcLclEnv) [ParStmtBlock GhcTc GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv
-> ParStmtBlock GhcTc GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ParStmtBlock GhcTc GhcTc)
zonk_branch ZonkEnv
env1) [ParStmtBlock GhcTc GhcTc]
stmts_w_bndrs
; let new_binders :: [Id]
new_binders = [Id
b | ParStmtBlock XParStmtBlock GhcTc GhcTc
_ [GuardLStmt GhcTc]
_ [IdP GhcTc]
bs SyntaxExpr GhcTc
_ <- [ParStmtBlock GhcTc GhcTc]
new_stmts_w_bndrs
, Id
b <- [Id]
[IdP GhcTc]
bs]
env2 :: ZonkEnv
env2 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env1 [Id]
new_binders
; HsExpr GhcTc
new_mzip <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env2 HsExpr GhcTc
mzip_op
; (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2
, XParStmt GhcTc GhcTc (Located (body GhcTc))
-> [ParStmtBlock GhcTc GhcTc]
-> HsExpr GhcTc
-> SyntaxExpr GhcTc
-> StmtLR GhcTc GhcTc (Located (body GhcTc))
forall idL idR body.
XParStmt idL idR body
-> [ParStmtBlock idL idR]
-> HsExpr idR
-> SyntaxExpr idR
-> StmtLR idL idR body
ParStmt Kind
XParStmt GhcTc GhcTc (Located (body GhcTc))
new_bind_ty [ParStmtBlock GhcTc GhcTc]
new_stmts_w_bndrs HsExpr GhcTc
new_mzip SyntaxExpr GhcTc
SyntaxExprTc
new_bind_op)}
where
zonk_branch :: ZonkEnv -> ParStmtBlock GhcTc GhcTc
-> TcM (ParStmtBlock GhcTc GhcTc)
zonk_branch :: ZonkEnv
-> ParStmtBlock GhcTc GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ParStmtBlock GhcTc GhcTc)
zonk_branch ZonkEnv
env1 (ParStmtBlock XParStmtBlock GhcTc GhcTc
x [GuardLStmt GhcTc]
stmts [IdP GhcTc]
bndrs SyntaxExpr GhcTc
return_op)
= do { (ZonkEnv
env2, [GuardLStmt GhcTc]
new_stmts) <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [GuardLStmt GhcTc]
-> TcM (ZonkEnv, [GuardLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env1 ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr [GuardLStmt GhcTc]
stmts
; (ZonkEnv
env3, SyntaxExprTc
new_return) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env2 SyntaxExpr GhcTc
return_op
; ParStmtBlock GhcTc GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ParStmtBlock GhcTc GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XParStmtBlock GhcTc GhcTc
-> [GuardLStmt GhcTc]
-> [IdP GhcTc]
-> SyntaxExpr GhcTc
-> ParStmtBlock GhcTc GhcTc
forall idL idR.
XParStmtBlock idL idR
-> [ExprLStmt idL]
-> [IdP idR]
-> SyntaxExpr idR
-> ParStmtBlock idL idR
ParStmtBlock XParStmtBlock GhcTc GhcTc
x [GuardLStmt GhcTc]
new_stmts (ZonkEnv -> [Id] -> [Id]
zonkIdOccs ZonkEnv
env3 [Id]
[IdP GhcTc]
bndrs)
SyntaxExpr GhcTc
SyntaxExprTc
new_return) }
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (RecStmt { recS_stmts :: forall idL idR body. StmtLR idL idR body -> [LStmtLR idL idR body]
recS_stmts = [LStmtLR GhcTc GhcTc (Located (body GhcTc))]
segStmts, recS_later_ids :: forall idL idR body. StmtLR idL idR body -> [IdP idR]
recS_later_ids = [IdP GhcTc]
lvs, recS_rec_ids :: forall idL idR body. StmtLR idL idR body -> [IdP idR]
recS_rec_ids = [IdP GhcTc]
rvs
, recS_ret_fn :: forall idL idR body. StmtLR idL idR body -> SyntaxExpr idR
recS_ret_fn = SyntaxExpr GhcTc
ret_id, recS_mfix_fn :: forall idL idR body. StmtLR idL idR body -> SyntaxExpr idR
recS_mfix_fn = SyntaxExpr GhcTc
mfix_id
, recS_bind_fn :: forall idL idR body. StmtLR idL idR body -> SyntaxExpr idR
recS_bind_fn = SyntaxExpr GhcTc
bind_id
, recS_ext :: forall idL idR body. StmtLR idL idR body -> XRecStmt idL idR body
recS_ext =
RecStmtTc { recS_bind_ty :: RecStmtTc -> Kind
recS_bind_ty = Kind
bind_ty
, recS_later_rets :: RecStmtTc -> [HsExpr GhcTc]
recS_later_rets = [HsExpr GhcTc]
later_rets
, recS_rec_rets :: RecStmtTc -> [HsExpr GhcTc]
recS_rec_rets = [HsExpr GhcTc]
rec_rets
, recS_ret_ty :: RecStmtTc -> Kind
recS_ret_ty = Kind
ret_ty} })
= do { (ZonkEnv
env1, SyntaxExprTc
new_bind_id) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
bind_id
; (ZonkEnv
env2, SyntaxExprTc
new_mfix_id) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env1 SyntaxExpr GhcTc
mfix_id
; (ZonkEnv
env3, SyntaxExprTc
new_ret_id) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env2 SyntaxExpr GhcTc
ret_id
; Kind
new_bind_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env3 Kind
bind_ty
; [Id]
new_rvs <- ZonkEnv -> [Id] -> TcM [Id]
zonkIdBndrs ZonkEnv
env3 [Id]
[IdP GhcTc]
rvs
; [Id]
new_lvs <- ZonkEnv -> [Id] -> TcM [Id]
zonkIdBndrs ZonkEnv
env3 [Id]
[IdP GhcTc]
lvs
; Kind
new_ret_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env3 Kind
ret_ty
; let env4 :: ZonkEnv
env4 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env3 [Id]
new_rvs
; (ZonkEnv
env5, [LStmtLR GhcTc GhcTc (Located (body GhcTc))]
new_segStmts) <- ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmtLR GhcTc GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmtLR GhcTc GhcTc (Located (body GhcTc))])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env4 ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody [LStmtLR GhcTc GhcTc (Located (body GhcTc))]
segStmts
; [HsExpr GhcTc]
new_later_rets <- (HsExpr GhcTc -> TcM (HsExpr GhcTc))
-> [HsExpr GhcTc] -> IOEnv (Env TcGblEnv TcLclEnv) [HsExpr GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env5) [HsExpr GhcTc]
later_rets
; [HsExpr GhcTc]
new_rec_rets <- (HsExpr GhcTc -> TcM (HsExpr GhcTc))
-> [HsExpr GhcTc] -> IOEnv (Env TcGblEnv TcLclEnv) [HsExpr GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env5) [HsExpr GhcTc]
rec_rets
; (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env3 [Id]
new_lvs,
RecStmt :: forall idL idR body.
XRecStmt idL idR body
-> [LStmtLR idL idR body]
-> [IdP idR]
-> [IdP idR]
-> SyntaxExpr idR
-> SyntaxExpr idR
-> SyntaxExpr idR
-> StmtLR idL idR body
RecStmt { recS_stmts :: [LStmtLR GhcTc GhcTc (Located (body GhcTc))]
recS_stmts = [LStmtLR GhcTc GhcTc (Located (body GhcTc))]
new_segStmts, recS_later_ids :: [IdP GhcTc]
recS_later_ids = [Id]
[IdP GhcTc]
new_lvs
, recS_rec_ids :: [IdP GhcTc]
recS_rec_ids = [Id]
[IdP GhcTc]
new_rvs, recS_ret_fn :: SyntaxExpr GhcTc
recS_ret_fn = SyntaxExpr GhcTc
SyntaxExprTc
new_ret_id
, recS_mfix_fn :: SyntaxExpr GhcTc
recS_mfix_fn = SyntaxExpr GhcTc
SyntaxExprTc
new_mfix_id, recS_bind_fn :: SyntaxExpr GhcTc
recS_bind_fn = SyntaxExpr GhcTc
SyntaxExprTc
new_bind_id
, recS_ext :: XRecStmt GhcTc GhcTc (Located (body GhcTc))
recS_ext = RecStmtTc :: Kind -> [HsExpr GhcTc] -> [HsExpr GhcTc] -> Kind -> RecStmtTc
RecStmtTc
{ recS_bind_ty :: Kind
recS_bind_ty = Kind
new_bind_ty
, recS_later_rets :: [HsExpr GhcTc]
recS_later_rets = [HsExpr GhcTc]
new_later_rets
, recS_rec_rets :: [HsExpr GhcTc]
recS_rec_rets = [HsExpr GhcTc]
new_rec_rets
, recS_ret_ty :: Kind
recS_ret_ty = Kind
new_ret_ty } }) }
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (BodyStmt XBodyStmt GhcTc GhcTc (Located (body GhcTc))
ty Located (body GhcTc)
body SyntaxExpr GhcTc
then_op SyntaxExpr GhcTc
guard_op)
= do (ZonkEnv
env1, SyntaxExprTc
new_then_op) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
then_op
(ZonkEnv
env2, SyntaxExprTc
new_guard_op) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env1 SyntaxExpr GhcTc
guard_op
Located (body GhcTc)
new_body <- ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody ZonkEnv
env2 Located (body GhcTc)
body
Kind
new_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env2 Kind
XBodyStmt GhcTc GhcTc (Located (body GhcTc))
ty
(ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, XBodyStmt GhcTc GhcTc (Located (body GhcTc))
-> Located (body GhcTc)
-> SyntaxExpr GhcTc
-> SyntaxExpr GhcTc
-> StmtLR GhcTc GhcTc (Located (body GhcTc))
forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt Kind
XBodyStmt GhcTc GhcTc (Located (body GhcTc))
new_ty Located (body GhcTc)
new_body SyntaxExpr GhcTc
SyntaxExprTc
new_then_op SyntaxExpr GhcTc
SyntaxExprTc
new_guard_op)
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (LastStmt XLastStmt GhcTc GhcTc (Located (body GhcTc))
x Located (body GhcTc)
body Maybe Bool
noret SyntaxExpr GhcTc
ret_op)
= do (ZonkEnv
env1, SyntaxExprTc
new_ret) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
ret_op
Located (body GhcTc)
new_body <- ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody ZonkEnv
env1 Located (body GhcTc)
body
(ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, XLastStmt GhcTc GhcTc (Located (body GhcTc))
-> Located (body GhcTc)
-> Maybe Bool
-> SyntaxExpr GhcTc
-> StmtLR GhcTc GhcTc (Located (body GhcTc))
forall idL idR body.
XLastStmt idL idR body
-> body -> Maybe Bool -> SyntaxExpr idR -> StmtLR idL idR body
LastStmt XLastStmt GhcTc GhcTc (Located (body GhcTc))
x Located (body GhcTc)
new_body Maybe Bool
noret SyntaxExpr GhcTc
SyntaxExprTc
new_ret)
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
_ (TransStmt { trS_stmts :: forall idL idR body. StmtLR idL idR body -> [ExprLStmt idL]
trS_stmts = [GuardLStmt GhcTc]
stmts, trS_bndrs :: forall idL idR body. StmtLR idL idR body -> [(IdP idR, IdP idR)]
trS_bndrs = [(IdP GhcTc, IdP GhcTc)]
binderMap
, trS_by :: forall idL idR body. StmtLR idL idR body -> Maybe (LHsExpr idR)
trS_by = Maybe (LHsExpr GhcTc)
by, trS_form :: forall idL idR body. StmtLR idL idR body -> TransForm
trS_form = TransForm
form, trS_using :: forall idL idR body. StmtLR idL idR body -> LHsExpr idR
trS_using = LHsExpr GhcTc
using
, trS_ret :: forall idL idR body. StmtLR idL idR body -> SyntaxExpr idR
trS_ret = SyntaxExpr GhcTc
return_op, trS_bind :: forall idL idR body. StmtLR idL idR body -> SyntaxExpr idR
trS_bind = SyntaxExpr GhcTc
bind_op
, trS_ext :: forall idL idR body. StmtLR idL idR body -> XTransStmt idL idR body
trS_ext = XTransStmt GhcTc GhcTc (Located (body GhcTc))
bind_arg_ty
, trS_fmap :: forall idL idR body. StmtLR idL idR body -> HsExpr idR
trS_fmap = HsExpr GhcTc
liftM_op })
= do {
; (ZonkEnv
env1, SyntaxExprTc
bind_op') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
bind_op
; Kind
bind_arg_ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env1 Kind
XTransStmt GhcTc GhcTc (Located (body GhcTc))
bind_arg_ty
; (ZonkEnv
env2, [GuardLStmt GhcTc]
stmts') <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [GuardLStmt GhcTc]
-> TcM (ZonkEnv, [GuardLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env1 ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr [GuardLStmt GhcTc]
stmts
; Maybe (LHsExpr GhcTc)
by' <- (LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> Maybe (LHsExpr GhcTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe (LHsExpr GhcTc))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
fmapMaybeM (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env2) Maybe (LHsExpr GhcTc)
by
; LHsExpr GhcTc
using' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env2 LHsExpr GhcTc
using
; (ZonkEnv
env3, SyntaxExprTc
return_op') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env2 SyntaxExpr GhcTc
return_op
; [(Id, Id)]
binderMap' <- ((Id, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, Id))
-> [(Id, Id)] -> IOEnv (Env TcGblEnv TcLclEnv) [(Id, Id)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> (Id, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, Id)
zonkBinderMapEntry ZonkEnv
env3) [(Id, Id)]
[(IdP GhcTc, IdP GhcTc)]
binderMap
; HsExpr GhcTc
liftM_op' <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env3 HsExpr GhcTc
liftM_op
; let env3' :: ZonkEnv
env3' = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env3 (((Id, Id) -> Id) -> [(Id, Id)] -> [Id]
forall a b. (a -> b) -> [a] -> [b]
map (Id, Id) -> Id
forall a b. (a, b) -> b
snd [(Id, Id)]
binderMap')
; (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env3', TransStmt :: forall idL idR body.
XTransStmt idL idR body
-> TransForm
-> [ExprLStmt idL]
-> [(IdP idR, IdP idR)]
-> LHsExpr idR
-> Maybe (LHsExpr idR)
-> SyntaxExpr idR
-> SyntaxExpr idR
-> HsExpr idR
-> StmtLR idL idR body
TransStmt { trS_stmts :: [GuardLStmt GhcTc]
trS_stmts = [GuardLStmt GhcTc]
stmts', trS_bndrs :: [(IdP GhcTc, IdP GhcTc)]
trS_bndrs = [(Id, Id)]
[(IdP GhcTc, IdP GhcTc)]
binderMap'
, trS_by :: Maybe (LHsExpr GhcTc)
trS_by = Maybe (LHsExpr GhcTc)
by', trS_form :: TransForm
trS_form = TransForm
form, trS_using :: LHsExpr GhcTc
trS_using = LHsExpr GhcTc
using'
, trS_ret :: SyntaxExpr GhcTc
trS_ret = SyntaxExpr GhcTc
SyntaxExprTc
return_op', trS_bind :: SyntaxExpr GhcTc
trS_bind = SyntaxExpr GhcTc
SyntaxExprTc
bind_op'
, trS_ext :: XTransStmt GhcTc GhcTc (Located (body GhcTc))
trS_ext = Kind
XTransStmt GhcTc GhcTc (Located (body GhcTc))
bind_arg_ty'
, trS_fmap :: HsExpr GhcTc
trS_fmap = HsExpr GhcTc
liftM_op' }) }
where
zonkBinderMapEntry :: ZonkEnv -> (Id, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, Id)
zonkBinderMapEntry ZonkEnv
env (Id
oldBinder, Id
newBinder) = do
let oldBinder' :: Id
oldBinder' = ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env Id
oldBinder
Id
newBinder' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
newBinder
(Id, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (Id
oldBinder', Id
newBinder')
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
_ (LetStmt XLetStmt GhcTc GhcTc (Located (body GhcTc))
x (L SrcSpan
l HsLocalBinds GhcTc
binds))
= do (ZonkEnv
env1, HsLocalBinds GhcTc
new_binds) <- ZonkEnv -> HsLocalBinds GhcTc -> TcM (ZonkEnv, HsLocalBinds GhcTc)
zonkLocalBinds ZonkEnv
env HsLocalBinds GhcTc
binds
(ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, XLetStmt GhcTc GhcTc (Located (body GhcTc))
-> GenLocated SrcSpan (HsLocalBinds GhcTc)
-> StmtLR GhcTc GhcTc (Located (body GhcTc))
forall idL idR body.
XLetStmt idL idR body
-> LHsLocalBindsLR idL idR -> StmtLR idL idR body
LetStmt XLetStmt GhcTc GhcTc (Located (body GhcTc))
x (SrcSpan
-> HsLocalBinds GhcTc -> GenLocated SrcSpan (HsLocalBinds GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsLocalBinds GhcTc
new_binds))
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody (BindStmt XBindStmt GhcTc GhcTc (Located (body GhcTc))
xbs LPat GhcTc
pat Located (body GhcTc)
body)
= do { (ZonkEnv
env1, SyntaxExprTc
new_bind) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env (XBindStmtTc -> SyntaxExpr GhcTc
xbstc_bindOp XBindStmt GhcTc GhcTc (Located (body GhcTc))
XBindStmtTc
xbs)
; Kind
new_w <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env1 (XBindStmtTc -> Kind
xbstc_boundResultMult XBindStmt GhcTc GhcTc (Located (body GhcTc))
XBindStmtTc
xbs)
; Kind
new_bind_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env1 (XBindStmtTc -> Kind
xbstc_boundResultType XBindStmt GhcTc GhcTc (Located (body GhcTc))
XBindStmtTc
xbs)
; Located (body GhcTc)
new_body <- ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
zBody ZonkEnv
env1 Located (body GhcTc)
body
; (ZonkEnv
env2, GenLocated SrcSpan (Pat GhcTc)
new_pat) <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env1 LPat GhcTc
pat
; Maybe SyntaxExprTc
new_fail <- case XBindStmtTc -> Maybe (SyntaxExpr GhcTc)
xbstc_failOp XBindStmt GhcTc GhcTc (Located (body GhcTc))
XBindStmtTc
xbs of
Maybe (SyntaxExpr GhcTc)
Nothing -> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe SyntaxExprTc
forall a. Maybe a
Nothing
Just SyntaxExpr GhcTc
f -> ((ZonkEnv, SyntaxExprTc) -> Maybe SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just (SyntaxExprTc -> Maybe SyntaxExprTc)
-> ((ZonkEnv, SyntaxExprTc) -> SyntaxExprTc)
-> (ZonkEnv, SyntaxExprTc)
-> Maybe SyntaxExprTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ZonkEnv, SyntaxExprTc) -> SyntaxExprTc
forall a b. (a, b) -> b
snd) (ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env1 SyntaxExpr GhcTc
f)
; (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return ( ZonkEnv
env2
, XBindStmt GhcTc GhcTc (Located (body GhcTc))
-> LPat GhcTc
-> Located (body GhcTc)
-> StmtLR GhcTc GhcTc (Located (body GhcTc))
forall idL idR body.
XBindStmt idL idR body -> LPat idL -> body -> StmtLR idL idR body
BindStmt (XBindStmtTc :: SyntaxExpr GhcTc
-> Kind -> Kind -> Maybe (SyntaxExpr GhcTc) -> XBindStmtTc
XBindStmtTc
{ xbstc_bindOp :: SyntaxExpr GhcTc
xbstc_bindOp = SyntaxExpr GhcTc
SyntaxExprTc
new_bind
, xbstc_boundResultType :: Kind
xbstc_boundResultType = Kind
new_bind_ty
, xbstc_boundResultMult :: Kind
xbstc_boundResultMult = Kind
new_w
, xbstc_failOp :: Maybe (SyntaxExpr GhcTc)
xbstc_failOp = Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
new_fail
})
GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
new_pat Located (body GhcTc)
new_body) }
zonkStmt ZonkEnv
env ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc))
_zBody (ApplicativeStmt XApplicativeStmt GhcTc GhcTc (Located (body GhcTc))
body_ty [(SyntaxExpr GhcTc, ApplicativeArg GhcTc)]
args Maybe (SyntaxExpr GhcTc)
mb_join)
= do { (ZonkEnv
env1, Maybe SyntaxExprTc
new_mb_join) <- ZonkEnv
-> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
zonk_join ZonkEnv
env Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
mb_join
; (ZonkEnv
env2, [(SyntaxExprTc, ApplicativeArg GhcTc)]
new_args) <- ZonkEnv
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
zonk_args ZonkEnv
env1 [(SyntaxExpr GhcTc, ApplicativeArg GhcTc)]
[(SyntaxExprTc, ApplicativeArg GhcTc)]
args
; Kind
new_body_ty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env2 Kind
XApplicativeStmt GhcTc GhcTc (Located (body GhcTc))
body_ty
; (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
-> TcM (ZonkEnv, StmtLR GhcTc GhcTc (Located (body GhcTc)))
forall (m :: * -> *) a. Monad m => a -> m a
return ( ZonkEnv
env2
, XApplicativeStmt GhcTc GhcTc (Located (body GhcTc))
-> [(SyntaxExpr GhcTc, ApplicativeArg GhcTc)]
-> Maybe (SyntaxExpr GhcTc)
-> StmtLR GhcTc GhcTc (Located (body GhcTc))
forall idL idR body.
XApplicativeStmt idL idR body
-> [(SyntaxExpr idR, ApplicativeArg idL)]
-> Maybe (SyntaxExpr idR)
-> StmtLR idL idR body
ApplicativeStmt Kind
XApplicativeStmt GhcTc GhcTc (Located (body GhcTc))
new_body_ty [(SyntaxExpr GhcTc, ApplicativeArg GhcTc)]
[(SyntaxExprTc, ApplicativeArg GhcTc)]
new_args Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
new_mb_join) }
where
zonk_join :: ZonkEnv
-> Maybe SyntaxExprTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
zonk_join ZonkEnv
env Maybe SyntaxExprTc
Nothing = (ZonkEnv, Maybe SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, Maybe SyntaxExprTc
forall a. Maybe a
Nothing)
zonk_join ZonkEnv
env (Just SyntaxExprTc
j) = (SyntaxExprTc -> Maybe SyntaxExprTc)
-> (ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just ((ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
SyntaxExprTc
j
get_pat :: (SyntaxExpr GhcTc, ApplicativeArg GhcTc) -> LPat GhcTc
get_pat :: (SyntaxExpr GhcTc, ApplicativeArg GhcTc) -> LPat GhcTc
get_pat (SyntaxExpr GhcTc
_, ApplicativeArgOne XApplicativeArgOne GhcTc
_ LPat GhcTc
pat LHsExpr GhcTc
_ Bool
_) = LPat GhcTc
pat
get_pat (SyntaxExpr GhcTc
_, ApplicativeArgMany XApplicativeArgMany GhcTc
_ [GuardLStmt GhcTc]
_ HsExpr GhcTc
_ LPat GhcTc
pat HsStmtContext GhcRn
_) = LPat GhcTc
pat
replace_pat :: LPat GhcTc
-> (SyntaxExpr GhcTc, ApplicativeArg GhcTc)
-> (SyntaxExpr GhcTc, ApplicativeArg GhcTc)
replace_pat :: LPat GhcTc
-> (SyntaxExpr GhcTc, ApplicativeArg GhcTc)
-> (SyntaxExpr GhcTc, ApplicativeArg GhcTc)
replace_pat LPat GhcTc
pat (SyntaxExpr GhcTc
op, ApplicativeArgOne XApplicativeArgOne GhcTc
fail_op LPat GhcTc
_ LHsExpr GhcTc
a Bool
isBody)
= (SyntaxExpr GhcTc
op, XApplicativeArgOne GhcTc
-> LPat GhcTc -> LHsExpr GhcTc -> Bool -> ApplicativeArg GhcTc
forall idL.
XApplicativeArgOne idL
-> LPat idL -> LHsExpr idL -> Bool -> ApplicativeArg idL
ApplicativeArgOne XApplicativeArgOne GhcTc
fail_op LPat GhcTc
pat LHsExpr GhcTc
a Bool
isBody)
replace_pat LPat GhcTc
pat (SyntaxExpr GhcTc
op, ApplicativeArgMany XApplicativeArgMany GhcTc
x [GuardLStmt GhcTc]
a HsExpr GhcTc
b LPat GhcTc
_ HsStmtContext GhcRn
c)
= (SyntaxExpr GhcTc
op, XApplicativeArgMany GhcTc
-> [GuardLStmt GhcTc]
-> HsExpr GhcTc
-> LPat GhcTc
-> HsStmtContext GhcRn
-> ApplicativeArg GhcTc
forall idL.
XApplicativeArgMany idL
-> [ExprLStmt idL]
-> HsExpr idL
-> LPat idL
-> HsStmtContext GhcRn
-> ApplicativeArg idL
ApplicativeArgMany XApplicativeArgMany GhcTc
x [GuardLStmt GhcTc]
a HsExpr GhcTc
b LPat GhcTc
pat HsStmtContext GhcRn
c)
zonk_args :: ZonkEnv
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
zonk_args ZonkEnv
env [(SyntaxExprTc, ApplicativeArg GhcTc)]
args
= do { (ZonkEnv
env1, [(SyntaxExprTc, ApplicativeArg GhcTc)]
new_args_rev) <- ZonkEnv
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
zonk_args_rev ZonkEnv
env ([(SyntaxExprTc, ApplicativeArg GhcTc)]
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
forall a. [a] -> [a]
reverse [(SyntaxExprTc, ApplicativeArg GhcTc)]
args)
; (ZonkEnv
env2, [GenLocated SrcSpan (Pat GhcTc)]
new_pats) <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env1 (((SyntaxExprTc, ApplicativeArg GhcTc)
-> GenLocated SrcSpan (Pat GhcTc))
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> [GenLocated SrcSpan (Pat GhcTc)]
forall a b. (a -> b) -> [a] -> [b]
map (SyntaxExpr GhcTc, ApplicativeArg GhcTc) -> LPat GhcTc
(SyntaxExprTc, ApplicativeArg GhcTc)
-> GenLocated SrcSpan (Pat GhcTc)
get_pat [(SyntaxExprTc, ApplicativeArg GhcTc)]
args)
; (ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, String
-> (GenLocated SrcSpan (Pat GhcTc)
-> (SyntaxExprTc, ApplicativeArg GhcTc)
-> (SyntaxExprTc, ApplicativeArg GhcTc))
-> [GenLocated SrcSpan (Pat GhcTc)]
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
forall a b c. String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual String
"zonkStmt" GenLocated SrcSpan (Pat GhcTc)
-> (SyntaxExprTc, ApplicativeArg GhcTc)
-> (SyntaxExprTc, ApplicativeArg GhcTc)
LPat GhcTc
-> (SyntaxExpr GhcTc, ApplicativeArg GhcTc)
-> (SyntaxExpr GhcTc, ApplicativeArg GhcTc)
replace_pat
[GenLocated SrcSpan (Pat GhcTc)]
new_pats ([(SyntaxExprTc, ApplicativeArg GhcTc)]
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
forall a. [a] -> [a]
reverse [(SyntaxExprTc, ApplicativeArg GhcTc)]
new_args_rev)) }
zonk_args_rev :: ZonkEnv
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
zonk_args_rev ZonkEnv
env ((SyntaxExprTc
op, ApplicativeArg GhcTc
arg) : [(SyntaxExprTc, ApplicativeArg GhcTc)]
args)
= do { (ZonkEnv
env1, SyntaxExprTc
new_op) <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
SyntaxExprTc
op
; ApplicativeArg GhcTc
new_arg <- ZonkEnv
-> ApplicativeArg GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ApplicativeArg GhcTc)
zonk_arg ZonkEnv
env1 ApplicativeArg GhcTc
arg
; (ZonkEnv
env2, [(SyntaxExprTc, ApplicativeArg GhcTc)]
new_args) <- ZonkEnv
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
zonk_args_rev ZonkEnv
env1 [(SyntaxExprTc, ApplicativeArg GhcTc)]
args
; (ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, (SyntaxExprTc
new_op, ApplicativeArg GhcTc
new_arg) (SyntaxExprTc, ApplicativeArg GhcTc)
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
-> [(SyntaxExprTc, ApplicativeArg GhcTc)]
forall a. a -> [a] -> [a]
: [(SyntaxExprTc, ApplicativeArg GhcTc)]
new_args) }
zonk_args_rev ZonkEnv
env [] = (ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv, [(SyntaxExprTc, ApplicativeArg GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, [])
zonk_arg :: ZonkEnv
-> ApplicativeArg GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ApplicativeArg GhcTc)
zonk_arg ZonkEnv
env (ApplicativeArgOne XApplicativeArgOne GhcTc
fail_op LPat GhcTc
pat LHsExpr GhcTc
expr Bool
isBody)
= do { LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
; Maybe SyntaxExprTc
new_fail <- Maybe SyntaxExprTc
-> (SyntaxExprTc -> IOEnv (Env TcGblEnv TcLclEnv) SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe SyntaxExprTc)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM Maybe SyntaxExprTc
XApplicativeArgOne GhcTc
fail_op ((SyntaxExprTc -> IOEnv (Env TcGblEnv TcLclEnv) SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe SyntaxExprTc))
-> (SyntaxExprTc -> IOEnv (Env TcGblEnv TcLclEnv) SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe SyntaxExprTc)
forall a b. (a -> b) -> a -> b
$ \SyntaxExprTc
old_fail ->
do { (ZonkEnv
_, SyntaxExprTc
fail') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
SyntaxExprTc
old_fail
; SyntaxExprTc -> IOEnv (Env TcGblEnv TcLclEnv) SyntaxExprTc
forall (m :: * -> *) a. Monad m => a -> m a
return SyntaxExprTc
fail'
}
; ApplicativeArg GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ApplicativeArg GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XApplicativeArgOne GhcTc
-> LPat GhcTc -> LHsExpr GhcTc -> Bool -> ApplicativeArg GhcTc
forall idL.
XApplicativeArgOne idL
-> LPat idL -> LHsExpr idL -> Bool -> ApplicativeArg idL
ApplicativeArgOne Maybe SyntaxExprTc
XApplicativeArgOne GhcTc
new_fail LPat GhcTc
pat LHsExpr GhcTc
new_expr Bool
isBody) }
zonk_arg ZonkEnv
env (ApplicativeArgMany XApplicativeArgMany GhcTc
x [GuardLStmt GhcTc]
stmts HsExpr GhcTc
ret LPat GhcTc
pat HsStmtContext GhcRn
ctxt)
= do { (ZonkEnv
env1, [GuardLStmt GhcTc]
new_stmts) <- ZonkEnv
-> (ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc))
-> [GuardLStmt GhcTc]
-> TcM (ZonkEnv, [GuardLStmt GhcTc])
forall (body :: * -> *).
ZonkEnv
-> (ZonkEnv -> Located (body GhcTc) -> TcM (Located (body GhcTc)))
-> [LStmt GhcTc (Located (body GhcTc))]
-> TcM (ZonkEnv, [LStmt GhcTc (Located (body GhcTc))])
zonkStmts ZonkEnv
env ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr [GuardLStmt GhcTc]
stmts
; HsExpr GhcTc
new_ret <- ZonkEnv -> HsExpr GhcTc -> TcM (HsExpr GhcTc)
zonkExpr ZonkEnv
env1 HsExpr GhcTc
ret
; ApplicativeArg GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ApplicativeArg GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (XApplicativeArgMany GhcTc
-> [GuardLStmt GhcTc]
-> HsExpr GhcTc
-> LPat GhcTc
-> HsStmtContext GhcRn
-> ApplicativeArg GhcTc
forall idL.
XApplicativeArgMany idL
-> [ExprLStmt idL]
-> HsExpr idL
-> LPat idL
-> HsStmtContext GhcRn
-> ApplicativeArg idL
ApplicativeArgMany XApplicativeArgMany GhcTc
x [GuardLStmt GhcTc]
new_stmts HsExpr GhcTc
new_ret LPat GhcTc
pat HsStmtContext GhcRn
ctxt) }
zonkRecFields :: ZonkEnv -> HsRecordBinds GhcTc -> TcM (HsRecordBinds GhcTc)
zonkRecFields :: ZonkEnv -> HsRecordBinds GhcTc -> TcM (HsRecordBinds GhcTc)
zonkRecFields ZonkEnv
env (HsRecFields [LHsRecField GhcTc (LHsExpr GhcTc)]
flds Maybe (Located ConTag)
dd)
= do { [LHsRecField GhcTc (LHsExpr GhcTc)]
flds' <- (LHsRecField GhcTc (LHsExpr GhcTc)
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsRecField GhcTc (LHsExpr GhcTc)))
-> [LHsRecField GhcTc (LHsExpr GhcTc)]
-> IOEnv
(Env TcGblEnv TcLclEnv) [LHsRecField GhcTc (LHsExpr GhcTc)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LHsRecField GhcTc (LHsExpr GhcTc)
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsRecField GhcTc (LHsExpr GhcTc))
zonk_rbind [LHsRecField GhcTc (LHsExpr GhcTc)]
flds
; HsRecordBinds GhcTc -> TcM (HsRecordBinds GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsRecField GhcTc (LHsExpr GhcTc)]
-> Maybe (Located ConTag) -> HsRecordBinds GhcTc
forall p arg.
[LHsRecField p arg] -> Maybe (Located ConTag) -> HsRecFields p arg
HsRecFields [LHsRecField GhcTc (LHsExpr GhcTc)]
flds' Maybe (Located ConTag)
dd) }
where
zonk_rbind :: LHsRecField GhcTc (LHsExpr GhcTc)
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsRecField GhcTc (LHsExpr GhcTc))
zonk_rbind (L SrcSpan
l HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc)
fld)
= do { Located (FieldOcc GhcTc)
new_id <- (FieldOcc GhcTc -> TcM (FieldOcc GhcTc))
-> Located (FieldOcc GhcTc) -> TcM (Located (FieldOcc GhcTc))
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> FieldOcc GhcTc -> TcM (FieldOcc GhcTc)
zonkFieldOcc ZonkEnv
env) (HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc)
-> Located (FieldOcc GhcTc)
forall id arg. HsRecField' id arg -> Located id
hsRecFieldLbl HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc)
fld)
; LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env (HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc) -> LHsExpr GhcTc
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc)
fld)
; LHsRecField GhcTc (LHsExpr GhcTc)
-> IOEnv
(Env TcGblEnv TcLclEnv) (LHsRecField GhcTc (LHsExpr GhcTc))
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc)
-> LHsRecField GhcTc (LHsExpr GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (HsRecField' (FieldOcc GhcTc) (LHsExpr GhcTc)
fld { hsRecFieldLbl :: Located (FieldOcc GhcTc)
hsRecFieldLbl = Located (FieldOcc GhcTc)
new_id
, hsRecFieldArg :: LHsExpr GhcTc
hsRecFieldArg = LHsExpr GhcTc
new_expr })) }
zonkRecUpdFields :: ZonkEnv -> [LHsRecUpdField GhcTc]
-> TcM [LHsRecUpdField GhcTc]
zonkRecUpdFields :: ZonkEnv -> [LHsRecUpdField GhcTc] -> TcM [LHsRecUpdField GhcTc]
zonkRecUpdFields ZonkEnv
env = (LHsRecUpdField GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcTc))
-> [LHsRecUpdField GhcTc] -> TcM [LHsRecUpdField GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LHsRecUpdField GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcTc)
zonk_rbind
where
zonk_rbind :: LHsRecUpdField GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcTc)
zonk_rbind (L SrcSpan
l HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
fld)
= do { Located (FieldOcc GhcTc)
new_id <- (FieldOcc GhcTc -> TcM (FieldOcc GhcTc))
-> Located (FieldOcc GhcTc) -> TcM (Located (FieldOcc GhcTc))
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> FieldOcc GhcTc -> TcM (FieldOcc GhcTc)
zonkFieldOcc ZonkEnv
env) (HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
-> Located (FieldOcc GhcTc)
forall arg.
HsRecField' (AmbiguousFieldOcc GhcTc) arg
-> Located (FieldOcc GhcTc)
hsRecUpdFieldOcc HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
fld)
; LHsExpr GhcTc
new_expr <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env (HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
-> LHsExpr GhcTc
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
fld)
; LHsRecUpdField GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LHsRecUpdField GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpan
-> HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
-> LHsRecUpdField GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (HsRecField' (AmbiguousFieldOcc GhcTc) (LHsExpr GhcTc)
fld { hsRecFieldLbl :: Located (AmbiguousFieldOcc GhcTc)
hsRecFieldLbl = (FieldOcc GhcTc -> AmbiguousFieldOcc GhcTc)
-> Located (FieldOcc GhcTc) -> Located (AmbiguousFieldOcc GhcTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FieldOcc GhcTc -> AmbiguousFieldOcc GhcTc
ambiguousFieldOcc Located (FieldOcc GhcTc)
new_id
, hsRecFieldArg :: LHsExpr GhcTc
hsRecFieldArg = LHsExpr GhcTc
new_expr })) }
mapIPNameTc :: (a -> TcM b) -> Either (Located HsIPName) a
-> TcM (Either (Located HsIPName) b)
mapIPNameTc :: forall a b.
(a -> TcM b)
-> Either (Located HsIPName) a -> TcM (Either (Located HsIPName) b)
mapIPNameTc a -> TcM b
_ (Left Located HsIPName
x) = Either (Located HsIPName) b
-> IOEnv (Env TcGblEnv TcLclEnv) (Either (Located HsIPName) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Located HsIPName -> Either (Located HsIPName) b
forall a b. a -> Either a b
Left Located HsIPName
x)
mapIPNameTc a -> TcM b
f (Right a
x) = do b
r <- a -> TcM b
f a
x
Either (Located HsIPName) b
-> IOEnv (Env TcGblEnv TcLclEnv) (Either (Located HsIPName) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> Either (Located HsIPName) b
forall a b. b -> Either a b
Right b
r)
zonkPat :: ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat :: ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat = (Pat GhcTc -> TcM (ZonkEnv, Pat GhcTc))
-> GenLocated SrcSpan (Pat GhcTc)
-> IOEnv
(Env TcGblEnv TcLclEnv) (ZonkEnv, GenLocated SrcSpan (Pat GhcTc))
forall a b c. (a -> TcM (b, c)) -> Located a -> TcM (b, Located c)
wrapLocSndM (ZonkEnv -> Pat GhcTc -> TcM (ZonkEnv, Pat GhcTc)
zonk_pat ZonkEnv
env) GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat
zonk_pat :: ZonkEnv -> Pat GhcTc -> TcM (ZonkEnv, Pat GhcTc)
zonk_pat :: ZonkEnv -> Pat GhcTc -> TcM (ZonkEnv, Pat GhcTc)
zonk_pat ZonkEnv
env (ParPat XParPat GhcTc
x LPat GhcTc
p)
= do { (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
p') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
p
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XParPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XParPat p -> LPat p -> Pat p
ParPat XParPat GhcTc
x GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
p') }
zonk_pat ZonkEnv
env (WildPat XWildPat GhcTc
ty)
= do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XWildPat GhcTc
ty
; Kind -> SDoc -> TcM ()
ensureNotLevPoly Kind
ty'
(String -> SDoc
text String
"In a wildcard pattern")
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, XWildPat GhcTc -> Pat GhcTc
forall p. XWildPat p -> Pat p
WildPat Kind
XWildPat GhcTc
ty') }
zonk_pat ZonkEnv
env (VarPat XVarPat GhcTc
x (L SrcSpan
l IdP GhcTc
v))
= do { Id
v' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
IdP GhcTc
v
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ZonkEnv
env Id
v', XVarPat GhcTc -> Located (IdP GhcTc) -> Pat GhcTc
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat GhcTc
x (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
l Id
v')) }
zonk_pat ZonkEnv
env (LazyPat XLazyPat GhcTc
x LPat GhcTc
pat)
= do { (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XLazyPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XLazyPat p -> LPat p -> Pat p
LazyPat XLazyPat GhcTc
x GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat') }
zonk_pat ZonkEnv
env (BangPat XBangPat GhcTc
x LPat GhcTc
pat)
= do { (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XBangPat GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XBangPat p -> LPat p -> Pat p
BangPat XBangPat GhcTc
x GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat') }
zonk_pat ZonkEnv
env (AsPat XAsPat GhcTc
x (L SrcSpan
loc IdP GhcTc
v) LPat GhcTc
pat)
= do { Id
v' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
IdP GhcTc
v
; (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat (ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ZonkEnv
env Id
v') LPat GhcTc
pat
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XAsPat GhcTc -> Located (IdP GhcTc) -> LPat GhcTc -> Pat GhcTc
forall p. XAsPat p -> Located (IdP p) -> LPat p -> Pat p
AsPat XAsPat GhcTc
x (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc Id
v') GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat') }
zonk_pat ZonkEnv
env (ViewPat XViewPat GhcTc
ty LHsExpr GhcTc
expr LPat GhcTc
pat)
= do { LHsExpr GhcTc
expr' <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env LHsExpr GhcTc
expr
; (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XViewPat GhcTc
ty
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XViewPat GhcTc -> LHsExpr GhcTc -> LPat GhcTc -> Pat GhcTc
forall p. XViewPat p -> LHsExpr p -> LPat p -> Pat p
ViewPat Kind
XViewPat GhcTc
ty' LHsExpr GhcTc
expr' GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat') }
zonk_pat ZonkEnv
env (ListPat (ListPatTc Kind
ty Maybe (Kind, SyntaxExpr GhcTc)
Nothing) [LPat GhcTc]
pats)
= do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
; (ZonkEnv
env', [GenLocated SrcSpan (Pat GhcTc)]
pats') <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env [LPat GhcTc]
pats
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XListPat GhcTc -> [LPat GhcTc] -> Pat GhcTc
forall p. XListPat p -> [LPat p] -> Pat p
ListPat (Kind -> Maybe (Kind, SyntaxExpr GhcTc) -> ListPatTc
ListPatTc Kind
ty' Maybe (Kind, SyntaxExpr GhcTc)
forall a. Maybe a
Nothing) [GenLocated SrcSpan (Pat GhcTc)]
[LPat GhcTc]
pats') }
zonk_pat ZonkEnv
env (ListPat (ListPatTc Kind
ty (Just (Kind
ty2,SyntaxExpr GhcTc
wit))) [LPat GhcTc]
pats)
= do { (ZonkEnv
env', SyntaxExprTc
wit') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
wit
; Kind
ty2' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env' Kind
ty2
; Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env' Kind
ty
; (ZonkEnv
env'', [GenLocated SrcSpan (Pat GhcTc)]
pats') <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env' [LPat GhcTc]
pats
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env'', XListPat GhcTc -> [LPat GhcTc] -> Pat GhcTc
forall p. XListPat p -> [LPat p] -> Pat p
ListPat (Kind -> Maybe (Kind, SyntaxExpr GhcTc) -> ListPatTc
ListPatTc Kind
ty' ((Kind, SyntaxExprTc) -> Maybe (Kind, SyntaxExprTc)
forall a. a -> Maybe a
Just (Kind
ty2',SyntaxExprTc
wit'))) [GenLocated SrcSpan (Pat GhcTc)]
[LPat GhcTc]
pats') }
zonk_pat ZonkEnv
env (TuplePat XTuplePat GhcTc
tys [LPat GhcTc]
pats Boxity
boxed)
= do { [Kind]
tys' <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) [Kind]
XTuplePat GhcTc
tys
; (ZonkEnv
env', [GenLocated SrcSpan (Pat GhcTc)]
pats') <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env [LPat GhcTc]
pats
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XTuplePat GhcTc -> [LPat GhcTc] -> Boxity -> Pat GhcTc
forall p. XTuplePat p -> [LPat p] -> Boxity -> Pat p
TuplePat [Kind]
XTuplePat GhcTc
tys' [GenLocated SrcSpan (Pat GhcTc)]
[LPat GhcTc]
pats' Boxity
boxed) }
zonk_pat ZonkEnv
env (SumPat XSumPat GhcTc
tys LPat GhcTc
pat ConTag
alt ConTag
arity )
= do { [Kind]
tys' <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) [Kind]
XSumPat GhcTc
tys
; (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XSumPat GhcTc -> LPat GhcTc -> ConTag -> ConTag -> Pat GhcTc
forall p. XSumPat p -> LPat p -> ConTag -> ConTag -> Pat p
SumPat [Kind]
XSumPat GhcTc
tys' GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat' ConTag
alt ConTag
arity) }
zonk_pat ZonkEnv
env p :: Pat GhcTc
p@(ConPat { pat_con :: forall p. Pat p -> Located (ConLikeP p)
pat_con = L SrcSpan
_ ConLikeP GhcTc
con
, pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = HsConPatDetails GhcTc
args
, pat_con_ext :: forall p. Pat p -> XConPat p
pat_con_ext = p' :: XConPat GhcTc
p'@(ConPatTc
{ cpt_tvs :: ConPatTc -> [Id]
cpt_tvs = [Id]
tyvars
, cpt_dicts :: ConPatTc -> [Id]
cpt_dicts = [Id]
evs
, cpt_binds :: ConPatTc -> TcEvBinds
cpt_binds = TcEvBinds
binds
, cpt_wrap :: ConPatTc -> HsWrapper
cpt_wrap = HsWrapper
wrapper
, cpt_arg_tys :: ConPatTc -> [Kind]
cpt_arg_tys = [Kind]
tys
})
})
= ASSERT( all isImmutableTyVar tyvars )
do { [Kind]
new_tys <- (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) [Kind]
tys
; case ConLikeP GhcTc
con of
RealDataCon DataCon
dc
| TcTyCon -> Bool
isUnboxedTupleTyCon (DataCon -> TcTyCon
dataConTyCon DataCon
dc)
-> (Kind -> TcM ()) -> [Kind] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (SDoc -> Kind -> TcM ()
checkForLevPoly SDoc
doc) ([Kind] -> [Kind]
dropRuntimeRepArgs [Kind]
new_tys)
ConLikeP GhcTc
_ -> () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
; (ZonkEnv
env0, [Id]
new_tyvars) <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkTyBndrsX ZonkEnv
env [Id]
tyvars
; (ZonkEnv
env1, [Id]
new_evs) <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkEvBndrsX ZonkEnv
env0 [Id]
evs
; (ZonkEnv
env2, TcEvBinds
new_binds) <- ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, TcEvBinds)
zonkTcEvBinds ZonkEnv
env1 TcEvBinds
binds
; (ZonkEnv
env3, HsWrapper
new_wrapper) <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env2 HsWrapper
wrapper
; (ZonkEnv
env', HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpan (Pat GhcTc)))
new_args) <- ZonkEnv
-> HsConPatDetails GhcTc -> TcM (ZonkEnv, HsConPatDetails GhcTc)
forall id.
ZonkEnv
-> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))
-> TcM
(ZonkEnv, HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)))
zonkConStuff ZonkEnv
env3 HsConPatDetails GhcTc
args
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ( ZonkEnv
env'
, Pat GhcTc
p
{ pat_args :: HsConPatDetails GhcTc
pat_args = HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields GhcTc (GenLocated SrcSpan (Pat GhcTc)))
HsConPatDetails GhcTc
new_args
, pat_con_ext :: XConPat GhcTc
pat_con_ext = XConPat GhcTc
ConPatTc
p'
{ cpt_arg_tys :: [Kind]
cpt_arg_tys = [Kind]
new_tys
, cpt_tvs :: [Id]
cpt_tvs = [Id]
new_tyvars
, cpt_dicts :: [Id]
cpt_dicts = [Id]
new_evs
, cpt_binds :: TcEvBinds
cpt_binds = TcEvBinds
new_binds
, cpt_wrap :: HsWrapper
cpt_wrap = HsWrapper
new_wrapper
}
}
)
}
where
doc :: SDoc
doc = String -> SDoc
text String
"In the type of an element of an unboxed tuple pattern:" SDoc -> SDoc -> SDoc
$$ Pat GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr Pat GhcTc
p
zonk_pat ZonkEnv
env (LitPat XLitPat GhcTc
x HsLit GhcTc
lit) = (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, XLitPat GhcTc -> HsLit GhcTc -> Pat GhcTc
forall p. XLitPat p -> HsLit p -> Pat p
LitPat XLitPat GhcTc
x HsLit GhcTc
lit)
zonk_pat ZonkEnv
env (SigPat XSigPat GhcTc
ty LPat GhcTc
pat HsPatSigType (NoGhcTc GhcTc)
hs_ty)
= do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
XSigPat GhcTc
ty
; (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', XSigPat GhcTc
-> LPat GhcTc -> HsPatSigType (NoGhcTc GhcTc) -> Pat GhcTc
forall p. XSigPat p -> LPat p -> HsPatSigType (NoGhcTc p) -> Pat p
SigPat Kind
XSigPat GhcTc
ty' GenLocated SrcSpan (Pat GhcTc)
LPat GhcTc
pat' HsPatSigType (NoGhcTc GhcTc)
hs_ty) }
zonk_pat ZonkEnv
env (NPat XNPat GhcTc
ty (L SrcSpan
l HsOverLit GhcTc
lit) Maybe (SyntaxExpr GhcTc)
mb_neg SyntaxExpr GhcTc
eq_expr)
= do { (ZonkEnv
env1, SyntaxExprTc
eq_expr') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
eq_expr
; (ZonkEnv
env2, Maybe SyntaxExprTc
mb_neg') <- case Maybe (SyntaxExpr GhcTc)
mb_neg of
Maybe (SyntaxExpr GhcTc)
Nothing -> (ZonkEnv, Maybe SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, Maybe SyntaxExprTc
forall a. Maybe a
Nothing)
Just SyntaxExpr GhcTc
n -> (SyntaxExprTc -> Maybe SyntaxExprTc)
-> (ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second SyntaxExprTc -> Maybe SyntaxExprTc
forall a. a -> Maybe a
Just ((ZonkEnv, SyntaxExprTc) -> (ZonkEnv, Maybe SyntaxExprTc))
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, SyntaxExprTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Maybe SyntaxExprTc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env1 SyntaxExpr GhcTc
n
; HsOverLit GhcTc
lit' <- ZonkEnv -> HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
zonkOverLit ZonkEnv
env2 HsOverLit GhcTc
lit
; Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env2 Kind
XNPat GhcTc
ty
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env2, XNPat GhcTc
-> Located (HsOverLit GhcTc)
-> Maybe (SyntaxExpr GhcTc)
-> SyntaxExpr GhcTc
-> Pat GhcTc
forall p.
XNPat p
-> Located (HsOverLit p)
-> Maybe (SyntaxExpr p)
-> SyntaxExpr p
-> Pat p
NPat Kind
XNPat GhcTc
ty' (SrcSpan -> HsOverLit GhcTc -> Located (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsOverLit GhcTc
lit') Maybe (SyntaxExpr GhcTc)
Maybe SyntaxExprTc
mb_neg' SyntaxExpr GhcTc
SyntaxExprTc
eq_expr') }
zonk_pat ZonkEnv
env (NPlusKPat XNPlusKPat GhcTc
ty (L SrcSpan
loc IdP GhcTc
n) (L SrcSpan
l HsOverLit GhcTc
lit1) HsOverLit GhcTc
lit2 SyntaxExpr GhcTc
e1 SyntaxExpr GhcTc
e2)
= do { (ZonkEnv
env1, SyntaxExprTc
e1') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env SyntaxExpr GhcTc
e1
; (ZonkEnv
env2, SyntaxExprTc
e2') <- ZonkEnv -> SyntaxExpr GhcTc -> TcM (ZonkEnv, SyntaxExpr GhcTc)
zonkSyntaxExpr ZonkEnv
env1 SyntaxExpr GhcTc
e2
; Id
n' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env2 Id
IdP GhcTc
n
; HsOverLit GhcTc
lit1' <- ZonkEnv -> HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
zonkOverLit ZonkEnv
env2 HsOverLit GhcTc
lit1
; HsOverLit GhcTc
lit2' <- ZonkEnv -> HsOverLit GhcTc -> TcM (HsOverLit GhcTc)
zonkOverLit ZonkEnv
env2 HsOverLit GhcTc
lit2
; Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env2 Kind
XNPlusKPat GhcTc
ty
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ZonkEnv
env2 Id
n',
XNPlusKPat GhcTc
-> Located (IdP GhcTc)
-> Located (HsOverLit GhcTc)
-> HsOverLit GhcTc
-> SyntaxExpr GhcTc
-> SyntaxExpr GhcTc
-> Pat GhcTc
forall p.
XNPlusKPat p
-> Located (IdP p)
-> Located (HsOverLit p)
-> HsOverLit p
-> SyntaxExpr p
-> SyntaxExpr p
-> Pat p
NPlusKPat Kind
XNPlusKPat GhcTc
ty' (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc Id
n') (SrcSpan -> HsOverLit GhcTc -> Located (HsOverLit GhcTc)
forall l e. l -> e -> GenLocated l e
L SrcSpan
l HsOverLit GhcTc
lit1') HsOverLit GhcTc
lit2' SyntaxExpr GhcTc
SyntaxExprTc
e1' SyntaxExpr GhcTc
SyntaxExprTc
e2') }
zonk_pat ZonkEnv
env (XPat (CoPat HsWrapper
co_fn Pat GhcTc
pat Kind
ty))
= do { (ZonkEnv
env', HsWrapper
co_fn') <- ZonkEnv -> HsWrapper -> TcM (ZonkEnv, HsWrapper)
zonkCoFn ZonkEnv
env HsWrapper
co_fn
; (ZonkEnv
env'', GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env' (Pat GhcTc -> GenLocated SrcSpan (Pat GhcTc)
forall e. e -> Located e
noLoc Pat GhcTc
pat)
; Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env'' Kind
ty
; (ZonkEnv, Pat GhcTc) -> TcM (ZonkEnv, Pat GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env'', XXPat GhcTc -> Pat GhcTc
forall p. XXPat p -> Pat p
XPat (XXPat GhcTc -> Pat GhcTc) -> XXPat GhcTc -> Pat GhcTc
forall a b. (a -> b) -> a -> b
$ HsWrapper -> Pat GhcTc -> Kind -> CoPat
CoPat HsWrapper
co_fn' (GenLocated SrcSpan (Pat GhcTc) -> Pat GhcTc
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpan (Pat GhcTc)
pat') Kind
ty')
}
zonk_pat ZonkEnv
_ Pat GhcTc
pat = String -> SDoc -> TcM (ZonkEnv, Pat GhcTc)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"zonk_pat" (Pat GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr Pat GhcTc
pat)
zonkConStuff :: ZonkEnv
-> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))
-> TcM (ZonkEnv,
HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)))
zonkConStuff :: forall id.
ZonkEnv
-> HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc))
-> TcM
(ZonkEnv, HsConDetails (LPat GhcTc) (HsRecFields id (LPat GhcTc)))
zonkConStuff ZonkEnv
env (PrefixCon [LPat GhcTc]
pats)
= do { (ZonkEnv
env', [GenLocated SrcSpan (Pat GhcTc)]
pats') <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env [LPat GhcTc]
pats
; (ZonkEnv,
HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc))))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv,
HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc))))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', [GenLocated SrcSpan (Pat GhcTc)]
-> HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc)))
forall arg rec. [arg] -> HsConDetails arg rec
PrefixCon [GenLocated SrcSpan (Pat GhcTc)]
pats') }
zonkConStuff ZonkEnv
env (InfixCon LPat GhcTc
p1 LPat GhcTc
p2)
= do { (ZonkEnv
env1, GenLocated SrcSpan (Pat GhcTc)
p1') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
p1
; (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
p2') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env1 LPat GhcTc
p2
; (ZonkEnv,
HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc))))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv,
HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc))))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
-> GenLocated SrcSpan (Pat GhcTc)
-> HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc)))
forall arg rec. arg -> arg -> HsConDetails arg rec
InfixCon GenLocated SrcSpan (Pat GhcTc)
p1' GenLocated SrcSpan (Pat GhcTc)
p2') }
zonkConStuff ZonkEnv
env (RecCon (HsRecFields [LHsRecField id (LPat GhcTc)]
rpats Maybe (Located ConTag)
dd))
= do { (ZonkEnv
env', [GenLocated SrcSpan (Pat GhcTc)]
pats') <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env ((GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
-> GenLocated SrcSpan (Pat GhcTc))
-> [GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
-> [GenLocated SrcSpan (Pat GhcTc)]
forall a b. (a -> b) -> [a] -> [b]
map (HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))
-> GenLocated SrcSpan (Pat GhcTc)
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg (HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))
-> GenLocated SrcSpan (Pat GhcTc))
-> (GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
-> HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
-> GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
-> GenLocated SrcSpan (Pat GhcTc)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
-> HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))
forall l e. GenLocated l e -> e
unLoc) [GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
[LHsRecField id (LPat GhcTc)]
rpats)
; let rpats' :: [GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
rpats' = (GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
-> GenLocated SrcSpan (Pat GhcTc)
-> GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))))
-> [GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
-> [GenLocated SrcSpan (Pat GhcTc)]
-> [GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\(L SrcSpan
l HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))
rp) GenLocated SrcSpan (Pat GhcTc)
p' ->
SrcSpan
-> HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))
-> GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc))
rp { hsRecFieldArg :: GenLocated SrcSpan (Pat GhcTc)
hsRecFieldArg = GenLocated SrcSpan (Pat GhcTc)
p' }))
[GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
[LHsRecField id (LPat GhcTc)]
rpats [GenLocated SrcSpan (Pat GhcTc)]
pats'
; (ZonkEnv,
HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc))))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(ZonkEnv,
HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc))))
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', HsRecFields id (GenLocated SrcSpan (Pat GhcTc))
-> HsConDetails
(GenLocated SrcSpan (Pat GhcTc))
(HsRecFields id (GenLocated SrcSpan (Pat GhcTc)))
forall arg rec. rec -> HsConDetails arg rec
RecCon ([GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
-> Maybe (Located ConTag)
-> HsRecFields id (GenLocated SrcSpan (Pat GhcTc))
forall p arg.
[LHsRecField p arg] -> Maybe (Located ConTag) -> HsRecFields p arg
HsRecFields [GenLocated
SrcSpan
(HsRecField' (FieldOcc id) (GenLocated SrcSpan (Pat GhcTc)))]
rpats' Maybe (Located ConTag)
dd)) }
zonkPats :: ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats :: ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env [] = (ZonkEnv, [GenLocated SrcSpan (Pat GhcTc)])
-> IOEnv
(Env TcGblEnv TcLclEnv) (ZonkEnv, [GenLocated SrcSpan (Pat GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, [])
zonkPats ZonkEnv
env (LPat GhcTc
pat:[LPat GhcTc]
pats) = do { (ZonkEnv
env1, GenLocated SrcSpan (Pat GhcTc)
pat') <- ZonkEnv -> LPat GhcTc -> TcM (ZonkEnv, LPat GhcTc)
zonkPat ZonkEnv
env LPat GhcTc
pat
; (ZonkEnv
env', [GenLocated SrcSpan (Pat GhcTc)]
pats') <- ZonkEnv -> [LPat GhcTc] -> TcM (ZonkEnv, [LPat GhcTc])
zonkPats ZonkEnv
env1 [LPat GhcTc]
pats
; (ZonkEnv, [GenLocated SrcSpan (Pat GhcTc)])
-> IOEnv
(Env TcGblEnv TcLclEnv) (ZonkEnv, [GenLocated SrcSpan (Pat GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', GenLocated SrcSpan (Pat GhcTc)
pat'GenLocated SrcSpan (Pat GhcTc)
-> [GenLocated SrcSpan (Pat GhcTc)]
-> [GenLocated SrcSpan (Pat GhcTc)]
forall a. a -> [a] -> [a]
:[GenLocated SrcSpan (Pat GhcTc)]
pats') }
zonkForeignExports :: ZonkEnv -> [LForeignDecl GhcTc]
-> TcM [LForeignDecl GhcTc]
zonkForeignExports :: ZonkEnv -> [LForeignDecl GhcTc] -> TcM [LForeignDecl GhcTc]
zonkForeignExports ZonkEnv
env [LForeignDecl GhcTc]
ls = (LForeignDecl GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LForeignDecl GhcTc))
-> [LForeignDecl GhcTc] -> TcM [LForeignDecl GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((ForeignDecl GhcTc -> TcM (ForeignDecl GhcTc))
-> LForeignDecl GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LForeignDecl GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> ForeignDecl GhcTc -> TcM (ForeignDecl GhcTc)
zonkForeignExport ZonkEnv
env)) [LForeignDecl GhcTc]
ls
zonkForeignExport :: ZonkEnv -> ForeignDecl GhcTc -> TcM (ForeignDecl GhcTc)
zonkForeignExport :: ZonkEnv -> ForeignDecl GhcTc -> TcM (ForeignDecl GhcTc)
zonkForeignExport ZonkEnv
env (ForeignExport { fd_name :: forall pass. ForeignDecl pass -> Located (IdP pass)
fd_name = Located (IdP GhcTc)
i, fd_e_ext :: forall pass. ForeignDecl pass -> XForeignExport pass
fd_e_ext = XForeignExport GhcTc
co
, fd_fe :: forall pass. ForeignDecl pass -> ForeignExport
fd_fe = ForeignExport
spec })
= ForeignDecl GhcTc -> TcM (ForeignDecl GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignExport :: forall pass.
XForeignExport pass
-> Located (IdP pass)
-> LHsSigType pass
-> ForeignExport
-> ForeignDecl pass
ForeignExport { fd_name :: Located (IdP GhcTc)
fd_name = ZonkEnv -> GenLocated SrcSpan Id -> GenLocated SrcSpan Id
zonkLIdOcc ZonkEnv
env GenLocated SrcSpan Id
Located (IdP GhcTc)
i
, fd_sig_ty :: LHsSigType GhcTc
fd_sig_ty = LHsSigType GhcTc
forall a. HasCallStack => a
undefined, fd_e_ext :: XForeignExport GhcTc
fd_e_ext = XForeignExport GhcTc
co
, fd_fe :: ForeignExport
fd_fe = ForeignExport
spec })
zonkForeignExport ZonkEnv
_ ForeignDecl GhcTc
for_imp
= ForeignDecl GhcTc -> TcM (ForeignDecl GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignDecl GhcTc
for_imp
zonkRules :: ZonkEnv -> [LRuleDecl GhcTc] -> TcM [LRuleDecl GhcTc]
zonkRules :: ZonkEnv -> [LRuleDecl GhcTc] -> TcM [LRuleDecl GhcTc]
zonkRules ZonkEnv
env [LRuleDecl GhcTc]
rs = (LRuleDecl GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LRuleDecl GhcTc))
-> [LRuleDecl GhcTc] -> TcM [LRuleDecl GhcTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((RuleDecl GhcTc -> TcM (RuleDecl GhcTc))
-> LRuleDecl GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (LRuleDecl GhcTc)
forall a b. (a -> TcM b) -> Located a -> TcM (Located b)
wrapLocM (ZonkEnv -> RuleDecl GhcTc -> TcM (RuleDecl GhcTc)
zonkRule ZonkEnv
env)) [LRuleDecl GhcTc]
rs
zonkRule :: ZonkEnv -> RuleDecl GhcTc -> TcM (RuleDecl GhcTc)
zonkRule :: ZonkEnv -> RuleDecl GhcTc -> TcM (RuleDecl GhcTc)
zonkRule ZonkEnv
env rule :: RuleDecl GhcTc
rule@(HsRule { rd_tmvs :: forall pass. RuleDecl pass -> [LRuleBndr pass]
rd_tmvs = [LRuleBndr GhcTc]
tm_bndrs
, rd_lhs :: forall pass. RuleDecl pass -> Located (HsExpr pass)
rd_lhs = LHsExpr GhcTc
lhs
, rd_rhs :: forall pass. RuleDecl pass -> Located (HsExpr pass)
rd_rhs = LHsExpr GhcTc
rhs })
= do { (ZonkEnv
env_inside, [LRuleBndr GhcTc]
new_tm_bndrs) <- (ZonkEnv
-> LRuleBndr GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, LRuleBndr GhcTc))
-> ZonkEnv
-> [LRuleBndr GhcTc]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [LRuleBndr GhcTc])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv
-> LRuleBndr GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, LRuleBndr GhcTc)
zonk_tm_bndr ZonkEnv
env [LRuleBndr GhcTc]
tm_bndrs
; let env_lhs :: ZonkEnv
env_lhs = ZonkEnv -> ZonkFlexi -> ZonkEnv
setZonkType ZonkEnv
env_inside ZonkFlexi
SkolemiseFlexi
; LHsExpr GhcTc
new_lhs <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env_lhs LHsExpr GhcTc
lhs
; LHsExpr GhcTc
new_rhs <- ZonkEnv -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc)
zonkLExpr ZonkEnv
env_inside LHsExpr GhcTc
rhs
; RuleDecl GhcTc -> TcM (RuleDecl GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (RuleDecl GhcTc -> TcM (RuleDecl GhcTc))
-> RuleDecl GhcTc -> TcM (RuleDecl GhcTc)
forall a b. (a -> b) -> a -> b
$ RuleDecl GhcTc
rule { rd_tmvs :: [LRuleBndr GhcTc]
rd_tmvs = [LRuleBndr GhcTc]
new_tm_bndrs
, rd_lhs :: LHsExpr GhcTc
rd_lhs = LHsExpr GhcTc
new_lhs
, rd_rhs :: LHsExpr GhcTc
rd_rhs = LHsExpr GhcTc
new_rhs } }
where
zonk_tm_bndr :: ZonkEnv -> LRuleBndr GhcTc -> TcM (ZonkEnv, LRuleBndr GhcTc)
zonk_tm_bndr :: ZonkEnv
-> LRuleBndr GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, LRuleBndr GhcTc)
zonk_tm_bndr ZonkEnv
env (L SrcSpan
l (RuleBndr XCRuleBndr GhcTc
x (L SrcSpan
loc IdP GhcTc
v)))
= do { (ZonkEnv
env', Id
v') <- ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonk_it ZonkEnv
env Id
IdP GhcTc
v
; (ZonkEnv, LRuleBndr GhcTc)
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, LRuleBndr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', SrcSpan -> RuleBndr GhcTc -> LRuleBndr GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (XCRuleBndr GhcTc -> Located (IdP GhcTc) -> RuleBndr GhcTc
forall pass. XCRuleBndr pass -> Located (IdP pass) -> RuleBndr pass
RuleBndr XCRuleBndr GhcTc
x (SrcSpan -> Id -> GenLocated SrcSpan Id
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc Id
v'))) }
zonk_tm_bndr ZonkEnv
_ (L SrcSpan
_ (RuleBndrSig {})) = String -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, LRuleBndr GhcTc)
forall a. String -> a
panic String
"zonk_tm_bndr RuleBndrSig"
zonk_it :: ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonk_it ZonkEnv
env Id
v
| Id -> Bool
isId Id
v = do { Id
v' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
v
; (ZonkEnv, Id) -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env [Id
v'], Id
v') }
| Bool
otherwise = ASSERT( isImmutableTyVar v)
ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX ZonkEnv
env Id
v
zonkEvTerm :: ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm :: ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env (EvExpr EvExpr
e)
= EvExpr -> EvTerm
EvExpr (EvExpr -> EvTerm)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr -> TcM EvTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e
zonkEvTerm ZonkEnv
env (EvTypeable Kind
ty EvTypeable
ev)
= Kind -> EvTypeable -> EvTerm
EvTypeable (Kind -> EvTypeable -> EvTerm)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind
-> IOEnv (Env TcGblEnv TcLclEnv) (EvTypeable -> EvTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty IOEnv (Env TcGblEnv TcLclEnv) (EvTypeable -> EvTerm)
-> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable -> TcM EvTerm
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ZonkEnv -> EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
zonkEvTypeable ZonkEnv
env EvTypeable
ev
zonkEvTerm ZonkEnv
env (EvFun { et_tvs :: EvTerm -> [Id]
et_tvs = [Id]
tvs, et_given :: EvTerm -> [Id]
et_given = [Id]
evs
, et_binds :: EvTerm -> TcEvBinds
et_binds = TcEvBinds
ev_binds, et_body :: EvTerm -> Id
et_body = Id
body_id })
= do { (ZonkEnv
env0, [Id]
new_tvs) <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkTyBndrsX ZonkEnv
env [Id]
tvs
; (ZonkEnv
env1, [Id]
new_evs) <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkEvBndrsX ZonkEnv
env0 [Id]
evs
; (ZonkEnv
env2, TcEvBinds
new_ev_binds) <- ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, TcEvBinds)
zonkTcEvBinds ZonkEnv
env1 TcEvBinds
ev_binds
; let new_body_id :: Id
new_body_id = ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env2 Id
body_id
; EvTerm -> TcM EvTerm
forall (m :: * -> *) a. Monad m => a -> m a
return (EvFun :: [Id] -> [Id] -> TcEvBinds -> Id -> EvTerm
EvFun { et_tvs :: [Id]
et_tvs = [Id]
new_tvs, et_given :: [Id]
et_given = [Id]
new_evs
, et_binds :: TcEvBinds
et_binds = TcEvBinds
new_ev_binds, et_body :: Id
et_body = Id
new_body_id }) }
zonkCoreExpr :: ZonkEnv -> CoreExpr -> TcM CoreExpr
zonkCoreExpr :: ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env (Var Id
v)
| Id -> Bool
isCoVar Id
v
= TcCoercionR -> EvExpr
forall b. TcCoercionR -> Expr b
Coercion (TcCoercionR -> EvExpr)
-> TcM TcCoercionR -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> Id -> TcM TcCoercionR
zonkCoVarOcc ZonkEnv
env Id
v
| Bool
otherwise
= EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> EvExpr
forall b. Id -> Expr b
Var (Id -> EvExpr) -> Id -> EvExpr
forall a b. (a -> b) -> a -> b
$ ZonkEnv -> Id -> Id
zonkIdOcc ZonkEnv
env Id
v)
zonkCoreExpr ZonkEnv
_ (Lit Literal
l)
= EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr)
-> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall a b. (a -> b) -> a -> b
$ Literal -> EvExpr
forall b. Literal -> Expr b
Lit Literal
l
zonkCoreExpr ZonkEnv
env (Coercion TcCoercionR
co)
= TcCoercionR -> EvExpr
forall b. TcCoercionR -> Expr b
Coercion (TcCoercionR -> EvExpr)
-> TcM TcCoercionR -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> TcCoercionR -> TcM TcCoercionR
zonkCoToCo ZonkEnv
env TcCoercionR
co
zonkCoreExpr ZonkEnv
env (Type Kind
ty)
= Kind -> EvExpr
forall b. Kind -> Expr b
Type (Kind -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
zonkCoreExpr ZonkEnv
env (Cast EvExpr
e TcCoercionR
co)
= EvExpr -> TcCoercionR -> EvExpr
forall b. Expr b -> TcCoercionR -> Expr b
Cast (EvExpr -> TcCoercionR -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionR -> EvExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e IOEnv (Env TcGblEnv TcLclEnv) (TcCoercionR -> EvExpr)
-> TcM TcCoercionR -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ZonkEnv -> TcCoercionR -> TcM TcCoercionR
zonkCoToCo ZonkEnv
env TcCoercionR
co
zonkCoreExpr ZonkEnv
env (Tick Tickish Id
t EvExpr
e)
= Tickish Id -> EvExpr -> EvExpr
forall b. Tickish Id -> Expr b -> Expr b
Tick Tickish Id
t (EvExpr -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e
zonkCoreExpr ZonkEnv
env (App EvExpr
e1 EvExpr
e2)
= EvExpr -> EvExpr -> EvExpr
forall b. Expr b -> Expr b -> Expr b
App (EvExpr -> EvExpr -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) (EvExpr -> EvExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e1 IOEnv (Env TcGblEnv TcLclEnv) (EvExpr -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e2
zonkCoreExpr ZonkEnv
env (Lam Id
v EvExpr
e)
= do { (ZonkEnv
env1, Id
v') <- ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkCoreBndrX ZonkEnv
env Id
v
; Id -> EvExpr -> EvExpr
forall b. b -> Expr b -> Expr b
Lam Id
v' (EvExpr -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env1 EvExpr
e }
zonkCoreExpr ZonkEnv
env (Let Bind Id
bind EvExpr
e)
= do (ZonkEnv
env1, Bind Id
bind') <- ZonkEnv -> Bind Id -> TcM (ZonkEnv, Bind Id)
zonkCoreBind ZonkEnv
env Bind Id
bind
Bind Id -> EvExpr -> EvExpr
forall b. Bind b -> Expr b -> Expr b
Let Bind Id
bind'(EvExpr -> EvExpr)
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env1 EvExpr
e
zonkCoreExpr ZonkEnv
env (Case EvExpr
scrut Id
b Kind
ty [Alt Id]
alts)
= do EvExpr
scrut' <- ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
scrut
Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
Id
b' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
b
let env1 :: ZonkEnv
env1 = ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ZonkEnv
env Id
b'
[Alt Id]
alts' <- (Alt Id -> IOEnv (Env TcGblEnv TcLclEnv) (Alt Id))
-> [Alt Id] -> IOEnv (Env TcGblEnv TcLclEnv) [Alt Id]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Alt Id -> IOEnv (Env TcGblEnv TcLclEnv) (Alt Id)
zonkCoreAlt ZonkEnv
env1) [Alt Id]
alts
EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr)
-> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
forall a b. (a -> b) -> a -> b
$ EvExpr -> Id -> Kind -> [Alt Id] -> EvExpr
forall b. Expr b -> b -> Kind -> [Alt b] -> Expr b
Case EvExpr
scrut' Id
b' Kind
ty' [Alt Id]
alts'
zonkCoreAlt :: ZonkEnv -> CoreAlt -> TcM CoreAlt
zonkCoreAlt :: ZonkEnv -> Alt Id -> IOEnv (Env TcGblEnv TcLclEnv) (Alt Id)
zonkCoreAlt ZonkEnv
env (AltCon
dc, [Id]
bndrs, EvExpr
rhs)
= do (ZonkEnv
env1, [Id]
bndrs') <- ZonkEnv -> [Id] -> TcM (ZonkEnv, [Id])
zonkCoreBndrsX ZonkEnv
env [Id]
bndrs
EvExpr
rhs' <- ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env1 EvExpr
rhs
Alt Id -> IOEnv (Env TcGblEnv TcLclEnv) (Alt Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (Alt Id -> IOEnv (Env TcGblEnv TcLclEnv) (Alt Id))
-> Alt Id -> IOEnv (Env TcGblEnv TcLclEnv) (Alt Id)
forall a b. (a -> b) -> a -> b
$ (AltCon
dc, [Id]
bndrs', EvExpr
rhs')
zonkCoreBind :: ZonkEnv -> CoreBind -> TcM (ZonkEnv, CoreBind)
zonkCoreBind :: ZonkEnv -> Bind Id -> TcM (ZonkEnv, Bind Id)
zonkCoreBind ZonkEnv
env (NonRec Id
v EvExpr
e)
= do Id
v' <- ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
v
EvExpr
e' <- ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e
let env1 :: ZonkEnv
env1 = ZonkEnv -> Id -> ZonkEnv
extendIdZonkEnv ZonkEnv
env Id
v'
(ZonkEnv, Bind Id) -> TcM (ZonkEnv, Bind Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, Id -> EvExpr -> Bind Id
forall b. b -> Expr b -> Bind b
NonRec Id
v' EvExpr
e')
zonkCoreBind ZonkEnv
env (Rec [(Id, EvExpr)]
pairs)
= do (ZonkEnv
env1, [(Id, EvExpr)]
pairs') <- ((ZonkEnv, [(Id, EvExpr)])
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(Id, EvExpr)]))
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(Id, EvExpr)])
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM (ZonkEnv, [(Id, EvExpr)])
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(Id, EvExpr)])
go
(ZonkEnv, Bind Id) -> TcM (ZonkEnv, Bind Id)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, [(Id, EvExpr)] -> Bind Id
forall b. [(b, Expr b)] -> Bind b
Rec [(Id, EvExpr)]
pairs')
where
go :: (ZonkEnv, [(Id, EvExpr)])
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(Id, EvExpr)])
go ~(ZonkEnv
_, [(Id, EvExpr)]
new_pairs) = do
let env1 :: ZonkEnv
env1 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env (((Id, EvExpr) -> Id) -> [(Id, EvExpr)] -> [Id]
forall a b. (a -> b) -> [a] -> [b]
map (Id, EvExpr) -> Id
forall a b. (a, b) -> a
fst [(Id, EvExpr)]
new_pairs)
[(Id, EvExpr)]
pairs' <- ((Id, EvExpr) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, EvExpr))
-> [(Id, EvExpr)] -> IOEnv (Env TcGblEnv TcLclEnv) [(Id, EvExpr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv
-> (Id, EvExpr) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, EvExpr)
zonkCorePair ZonkEnv
env1) [(Id, EvExpr)]
pairs
(ZonkEnv, [(Id, EvExpr)])
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [(Id, EvExpr)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, [(Id, EvExpr)]
pairs')
zonkCorePair :: ZonkEnv -> (CoreBndr, CoreExpr) -> TcM (CoreBndr, CoreExpr)
zonkCorePair :: ZonkEnv
-> (Id, EvExpr) -> IOEnv (Env TcGblEnv TcLclEnv) (Id, EvExpr)
zonkCorePair ZonkEnv
env (Id
v,EvExpr
e) = (,) (Id -> EvExpr -> (Id, EvExpr))
-> TcM Id -> IOEnv (Env TcGblEnv TcLclEnv) (EvExpr -> (Id, EvExpr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> Id -> TcM Id
zonkIdBndr ZonkEnv
env Id
v IOEnv (Env TcGblEnv TcLclEnv) (EvExpr -> (Id, EvExpr))
-> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
-> IOEnv (Env TcGblEnv TcLclEnv) (Id, EvExpr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ZonkEnv -> EvExpr -> IOEnv (Env TcGblEnv TcLclEnv) EvExpr
zonkCoreExpr ZonkEnv
env EvExpr
e
zonkEvTypeable :: ZonkEnv -> EvTypeable -> TcM EvTypeable
zonkEvTypeable :: ZonkEnv -> EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
zonkEvTypeable ZonkEnv
env (EvTypeableTyCon TcTyCon
tycon [EvTerm]
e)
= do { [EvTerm]
e' <- (EvTerm -> TcM EvTerm)
-> [EvTerm] -> IOEnv (Env TcGblEnv TcLclEnv) [EvTerm]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env) [EvTerm]
e
; EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
forall (m :: * -> *) a. Monad m => a -> m a
return (EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable)
-> EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
forall a b. (a -> b) -> a -> b
$ TcTyCon -> [EvTerm] -> EvTypeable
EvTypeableTyCon TcTyCon
tycon [EvTerm]
e' }
zonkEvTypeable ZonkEnv
env (EvTypeableTyApp EvTerm
t1 EvTerm
t2)
= do { EvTerm
t1' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
t1
; EvTerm
t2' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
t2
; EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
forall (m :: * -> *) a. Monad m => a -> m a
return (EvTerm -> EvTerm -> EvTypeable
EvTypeableTyApp EvTerm
t1' EvTerm
t2') }
zonkEvTypeable ZonkEnv
env (EvTypeableTrFun EvTerm
tm EvTerm
t1 EvTerm
t2)
= do { EvTerm
tm' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
tm
; EvTerm
t1' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
t1
; EvTerm
t2' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
t2
; EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
forall (m :: * -> *) a. Monad m => a -> m a
return (EvTerm -> EvTerm -> EvTerm -> EvTypeable
EvTypeableTrFun EvTerm
tm' EvTerm
t1' EvTerm
t2') }
zonkEvTypeable ZonkEnv
env (EvTypeableTyLit EvTerm
t1)
= do { EvTerm
t1' <- ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
t1
; EvTypeable -> IOEnv (Env TcGblEnv TcLclEnv) EvTypeable
forall (m :: * -> *) a. Monad m => a -> m a
return (EvTerm -> EvTypeable
EvTypeableTyLit EvTerm
t1') }
zonkTcEvBinds_s :: ZonkEnv -> [TcEvBinds] -> TcM (ZonkEnv, [TcEvBinds])
zonkTcEvBinds_s :: ZonkEnv -> [TcEvBinds] -> TcM (ZonkEnv, [TcEvBinds])
zonkTcEvBinds_s ZonkEnv
env [TcEvBinds]
bs = do { (ZonkEnv
env, [Bag EvBind]
bs') <- (ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, Bag EvBind))
-> ZonkEnv
-> [TcEvBinds]
-> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, [Bag EvBind])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, Bag EvBind)
zonk_tc_ev_binds ZonkEnv
env [TcEvBinds]
bs
; (ZonkEnv, [TcEvBinds]) -> TcM (ZonkEnv, [TcEvBinds])
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, [Bag EvBind -> TcEvBinds
EvBinds ([Bag EvBind] -> Bag EvBind
forall a. [Bag a] -> Bag a
unionManyBags [Bag EvBind]
bs')]) }
zonkTcEvBinds :: ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, TcEvBinds)
zonkTcEvBinds :: ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, TcEvBinds)
zonkTcEvBinds ZonkEnv
env TcEvBinds
bs = do { (ZonkEnv
env', Bag EvBind
bs') <- ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, Bag EvBind)
zonk_tc_ev_binds ZonkEnv
env TcEvBinds
bs
; (ZonkEnv, TcEvBinds) -> TcM (ZonkEnv, TcEvBinds)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env', Bag EvBind -> TcEvBinds
EvBinds Bag EvBind
bs') }
zonk_tc_ev_binds :: ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, Bag EvBind)
zonk_tc_ev_binds :: ZonkEnv -> TcEvBinds -> TcM (ZonkEnv, Bag EvBind)
zonk_tc_ev_binds ZonkEnv
env (TcEvBinds EvBindsVar
var) = ZonkEnv -> EvBindsVar -> TcM (ZonkEnv, Bag EvBind)
zonkEvBindsVar ZonkEnv
env EvBindsVar
var
zonk_tc_ev_binds ZonkEnv
env (EvBinds Bag EvBind
bs) = ZonkEnv -> Bag EvBind -> TcM (ZonkEnv, Bag EvBind)
zonkEvBinds ZonkEnv
env Bag EvBind
bs
zonkEvBindsVar :: ZonkEnv -> EvBindsVar -> TcM (ZonkEnv, Bag EvBind)
zonkEvBindsVar :: ZonkEnv -> EvBindsVar -> TcM (ZonkEnv, Bag EvBind)
zonkEvBindsVar ZonkEnv
env (EvBindsVar { ebv_binds :: EvBindsVar -> IORef EvBindMap
ebv_binds = IORef EvBindMap
ref })
= do { EvBindMap
bs <- IORef EvBindMap -> IOEnv (Env TcGblEnv TcLclEnv) EvBindMap
forall a env. IORef a -> IOEnv env a
readMutVar IORef EvBindMap
ref
; ZonkEnv -> Bag EvBind -> TcM (ZonkEnv, Bag EvBind)
zonkEvBinds ZonkEnv
env (EvBindMap -> Bag EvBind
evBindMapBinds EvBindMap
bs) }
zonkEvBindsVar ZonkEnv
env (CoEvBindsVar {}) = (ZonkEnv, Bag EvBind) -> TcM (ZonkEnv, Bag EvBind)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env, Bag EvBind
forall a. Bag a
emptyBag)
zonkEvBinds :: ZonkEnv -> Bag EvBind -> TcM (ZonkEnv, Bag EvBind)
zonkEvBinds :: ZonkEnv -> Bag EvBind -> TcM (ZonkEnv, Bag EvBind)
zonkEvBinds ZonkEnv
env Bag EvBind
binds
= {-# SCC "zonkEvBinds" #-}
((ZonkEnv, Bag EvBind) -> TcM (ZonkEnv, Bag EvBind))
-> TcM (ZonkEnv, Bag EvBind)
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM (\ ~( ZonkEnv
_, Bag EvBind
new_binds) -> do
{ let env1 :: ZonkEnv
env1 = ZonkEnv -> [Id] -> ZonkEnv
extendIdZonkEnvRec ZonkEnv
env (Bag EvBind -> [Id]
collect_ev_bndrs Bag EvBind
new_binds)
; Bag EvBind
binds' <- (EvBind -> IOEnv (Env TcGblEnv TcLclEnv) EvBind)
-> Bag EvBind -> IOEnv (Env TcGblEnv TcLclEnv) (Bag EvBind)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM (ZonkEnv -> EvBind -> IOEnv (Env TcGblEnv TcLclEnv) EvBind
zonkEvBind ZonkEnv
env1) Bag EvBind
binds
; (ZonkEnv, Bag EvBind) -> TcM (ZonkEnv, Bag EvBind)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonkEnv
env1, Bag EvBind
binds') })
where
collect_ev_bndrs :: Bag EvBind -> [EvVar]
collect_ev_bndrs :: Bag EvBind -> [Id]
collect_ev_bndrs = (EvBind -> [Id] -> [Id]) -> [Id] -> Bag EvBind -> [Id]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr EvBind -> [Id] -> [Id]
add []
add :: EvBind -> [Id] -> [Id]
add (EvBind { eb_lhs :: EvBind -> Id
eb_lhs = Id
var }) [Id]
vars = Id
var Id -> [Id] -> [Id]
forall a. a -> [a] -> [a]
: [Id]
vars
zonkEvBind :: ZonkEnv -> EvBind -> TcM EvBind
zonkEvBind :: ZonkEnv -> EvBind -> IOEnv (Env TcGblEnv TcLclEnv) EvBind
zonkEvBind ZonkEnv
env bind :: EvBind
bind@(EvBind { eb_lhs :: EvBind -> Id
eb_lhs = Id
var, eb_rhs :: EvBind -> EvTerm
eb_rhs = EvTerm
term })
= do { Id
var' <- {-# SCC "zonkEvBndr" #-} ZonkEnv -> Id -> TcM Id
zonkEvBndr ZonkEnv
env Id
var
; EvTerm
term' <- case Kind -> Maybe (Role, Kind, Kind)
getEqPredTys_maybe (Id -> Kind
idType Id
var') of
Just (Role
r, Kind
ty1, Kind
ty2) | Kind
ty1 Kind -> Kind -> Bool
`eqType` Kind
ty2
-> EvTerm -> TcM EvTerm
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionR -> EvTerm
evCoercion (Role -> Kind -> TcCoercionR
mkTcReflCo Role
r Kind
ty1))
Maybe (Role, Kind, Kind)
_other -> ZonkEnv -> EvTerm -> TcM EvTerm
zonkEvTerm ZonkEnv
env EvTerm
term
; EvBind -> IOEnv (Env TcGblEnv TcLclEnv) EvBind
forall (m :: * -> *) a. Monad m => a -> m a
return (EvBind
bind { eb_lhs :: Id
eb_lhs = Id
var', eb_rhs :: EvTerm
eb_rhs = EvTerm
term' }) }
zonkTyVarOcc :: ZonkEnv -> TyVar -> TcM TcType
zonkTyVarOcc :: ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTyVarOcc env :: ZonkEnv
env@(ZonkEnv { ze_flexi :: ZonkEnv -> ZonkFlexi
ze_flexi = ZonkFlexi
flexi
, ze_tv_env :: ZonkEnv -> TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
tv_env
, ze_meta_tv_env :: ZonkEnv -> TcRef (TyVarEnv Kind)
ze_meta_tv_env = TcRef (TyVarEnv Kind)
mtv_env_ref }) Id
tv
| Id -> Bool
isTcTyVar Id
tv
= case Id -> TcTyVarDetails
tcTyVarDetails Id
tv of
SkolemTv {} -> IOEnv (Env TcGblEnv TcLclEnv) Kind
lookup_in_tv_env
RuntimeUnk {} -> IOEnv (Env TcGblEnv TcLclEnv) Kind
lookup_in_tv_env
MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref }
-> do { TyVarEnv Kind
mtv_env <- TcRef (TyVarEnv Kind) -> TcRnIf TcGblEnv TcLclEnv (TyVarEnv Kind)
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef TcRef (TyVarEnv Kind)
mtv_env_ref
; case TyVarEnv Kind -> Id -> Maybe Kind
forall a. VarEnv a -> Id -> Maybe a
lookupVarEnv TyVarEnv Kind
mtv_env Id
tv of
Just Kind
ty -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return Kind
ty
Maybe Kind
Nothing -> do { MetaDetails
mtv_details <- IORef MetaDetails -> TcRnIf TcGblEnv TcLclEnv MetaDetails
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef IORef MetaDetails
ref
; IORef MetaDetails
-> MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonk_meta IORef MetaDetails
ref MetaDetails
mtv_details } }
| Bool
otherwise
= IOEnv (Env TcGblEnv TcLclEnv) Kind
lookup_in_tv_env
where
lookup_in_tv_env :: IOEnv (Env TcGblEnv TcLclEnv) Kind
lookup_in_tv_env
= case TyCoVarEnv Id -> Id -> Maybe Id
forall a. VarEnv a -> Id -> Maybe a
lookupVarEnv TyCoVarEnv Id
tv_env Id
tv of
Maybe Id
Nothing -> Id -> Kind
mkTyVarTy (Id -> Kind) -> TcM Id -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind) -> Id -> TcM Id
forall (m :: * -> *). Monad m => (Kind -> m Kind) -> Id -> m Id
updateTyVarKindM (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env) Id
tv
Just Id
tv' -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Kind
mkTyVarTy Id
tv')
zonk_meta :: IORef MetaDetails
-> MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonk_meta IORef MetaDetails
ref MetaDetails
Flexi
= do { Kind
kind <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env (Id -> Kind
tyVarKind Id
tv)
; Kind
ty <- ZonkFlexi -> Id -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
commitFlexi ZonkFlexi
flexi Id
tv Kind
kind
; Id -> IORef MetaDetails -> Kind -> TcM ()
writeMetaTyVarRef Id
tv IORef MetaDetails
ref Kind
ty
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
finish_meta Kind
ty }
zonk_meta IORef MetaDetails
_ (Indirect Kind
ty)
= do { Kind
zty <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
finish_meta Kind
zty }
finish_meta :: Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
finish_meta Kind
ty
= do { TcRef (TyVarEnv Kind) -> (TyVarEnv Kind -> TyVarEnv Kind) -> TcM ()
forall a gbl lcl. TcRef a -> (a -> a) -> TcRnIf gbl lcl ()
updTcRef TcRef (TyVarEnv Kind)
mtv_env_ref (\TyVarEnv Kind
env -> TyVarEnv Kind -> Id -> Kind -> TyVarEnv Kind
forall a. VarEnv a -> Id -> a -> VarEnv a
extendVarEnv TyVarEnv Kind
env Id
tv Kind
ty)
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return Kind
ty }
lookupTyVarOcc :: ZonkEnv -> TcTyVar -> Maybe TyVar
lookupTyVarOcc :: ZonkEnv -> Id -> Maybe Id
lookupTyVarOcc (ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
tv_env }) Id
tv
= TyCoVarEnv Id -> Id -> Maybe Id
forall a. VarEnv a -> Id -> Maybe a
lookupVarEnv TyCoVarEnv Id
tv_env Id
tv
commitFlexi :: ZonkFlexi -> TcTyVar -> Kind -> TcM Type
commitFlexi :: ZonkFlexi -> Id -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
commitFlexi ZonkFlexi
flexi Id
tv Kind
zonked_kind
= case ZonkFlexi
flexi of
ZonkFlexi
SkolemiseFlexi -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Kind
mkTyVarTy (Name -> Kind -> Id
mkTyVar Name
name Kind
zonked_kind))
ZonkFlexi
DefaultFlexi
| Kind -> Bool
isRuntimeRepTy Kind
zonked_kind
-> do { String -> SDoc -> TcM ()
traceTc String
"Defaulting flexi tyvar to LiftedRep:" (Id -> SDoc
pprTyVar Id
tv)
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return Kind
liftedRepTy }
| Kind -> Bool
isMultiplicityTy Kind
zonked_kind
-> do { String -> SDoc -> TcM ()
traceTc String
"Defaulting flexi tyvar to Many:" (Id -> SDoc
pprTyVar Id
tv)
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return Kind
manyDataConTy }
| Bool
otherwise
-> do { String -> SDoc -> TcM ()
traceTc String
"Defaulting flexi tyvar to Any:" (Id -> SDoc
pprTyVar Id
tv)
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return (Kind -> Kind
anyTypeOfKind Kind
zonked_kind) }
ZonkFlexi
RuntimeUnkFlexi
-> do { String -> SDoc -> TcM ()
traceTc String
"Defaulting flexi tyvar to RuntimeUnk:" (Id -> SDoc
pprTyVar Id
tv)
; Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Kind
mkTyVarTy (Name -> Kind -> TcTyVarDetails -> Id
mkTcTyVar Name
name Kind
zonked_kind TcTyVarDetails
RuntimeUnk)) }
where
name :: Name
name = Id -> Name
tyVarName Id
tv
zonkCoVarOcc :: ZonkEnv -> CoVar -> TcM Coercion
zonkCoVarOcc :: ZonkEnv -> Id -> TcM TcCoercionR
zonkCoVarOcc (ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv Id
ze_tv_env = TyCoVarEnv Id
tyco_env }) Id
cv
| Just Id
cv' <- TyCoVarEnv Id -> Id -> Maybe Id
forall a. VarEnv a -> Id -> Maybe a
lookupVarEnv TyCoVarEnv Id
tyco_env Id
cv
= TcCoercionR -> TcM TcCoercionR
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionR -> TcM TcCoercionR) -> TcCoercionR -> TcM TcCoercionR
forall a b. (a -> b) -> a -> b
$ Id -> TcCoercionR
mkCoVarCo Id
cv'
| Bool
otherwise
= do { Id
cv' <- Id -> TcM Id
zonkCoVar Id
cv; TcCoercionR -> TcM TcCoercionR
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> TcCoercionR
mkCoVarCo Id
cv') }
zonkCoHole :: ZonkEnv -> CoercionHole -> TcM Coercion
zonkCoHole :: ZonkEnv -> CoercionHole -> TcM TcCoercionR
zonkCoHole ZonkEnv
env hole :: CoercionHole
hole@(CoercionHole { ch_ref :: CoercionHole -> IORef (Maybe TcCoercionR)
ch_ref = IORef (Maybe TcCoercionR)
ref, ch_co_var :: CoercionHole -> Id
ch_co_var = Id
cv })
= do { Maybe TcCoercionR
contents <- IORef (Maybe TcCoercionR)
-> TcRnIf TcGblEnv TcLclEnv (Maybe TcCoercionR)
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef IORef (Maybe TcCoercionR)
ref
; case Maybe TcCoercionR
contents of
Just TcCoercionR
co -> do { TcCoercionR
co' <- ZonkEnv -> TcCoercionR -> TcM TcCoercionR
zonkCoToCo ZonkEnv
env TcCoercionR
co
; Id -> TcCoercionR -> TcM TcCoercionR
checkCoercionHole Id
cv TcCoercionR
co' }
Maybe TcCoercionR
Nothing -> do { String -> SDoc -> TcM ()
traceTc String
"Zonking unfilled coercion hole" (CoercionHole -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoercionHole
hole)
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
TcM () -> TcM ()
whenNoErrs (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
MASSERT2( False
, text "Type-correct unfilled coercion hole"
<+> ppr hole )
; Id
cv' <- Id -> TcM Id
zonkCoVar Id
cv
; TcCoercionR -> TcM TcCoercionR
forall (m :: * -> *) a. Monad m => a -> m a
return (TcCoercionR -> TcM TcCoercionR) -> TcCoercionR -> TcM TcCoercionR
forall a b. (a -> b) -> a -> b
$ Id -> TcCoercionR
mkCoVarCo Id
cv' } }
zonk_tycomapper :: TyCoMapper ZonkEnv TcM
zonk_tycomapper :: TyCoMapper ZonkEnv (IOEnv (Env TcGblEnv TcLclEnv))
zonk_tycomapper = TyCoMapper :: forall env (m :: * -> *).
(env -> Id -> m Kind)
-> (env -> Id -> m TcCoercionR)
-> (env -> CoercionHole -> m TcCoercionR)
-> (env -> Id -> ArgFlag -> m (env, Id))
-> (TcTyCon -> m TcTyCon)
-> TyCoMapper env m
TyCoMapper
{ tcm_tyvar :: ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) Kind
tcm_tyvar = ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTyVarOcc
, tcm_covar :: ZonkEnv -> Id -> TcM TcCoercionR
tcm_covar = ZonkEnv -> Id -> TcM TcCoercionR
zonkCoVarOcc
, tcm_hole :: ZonkEnv -> CoercionHole -> TcM TcCoercionR
tcm_hole = ZonkEnv -> CoercionHole -> TcM TcCoercionR
zonkCoHole
, tcm_tycobinder :: ZonkEnv
-> Id -> ArgFlag -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
tcm_tycobinder = \ZonkEnv
env Id
tv ArgFlag
_vis -> ZonkEnv -> Id -> IOEnv (Env TcGblEnv TcLclEnv) (ZonkEnv, Id)
zonkTyBndrX ZonkEnv
env Id
tv
, tcm_tycon :: TcTyCon -> IOEnv (Env TcGblEnv TcLclEnv) TcTyCon
tcm_tycon = TcTyCon -> IOEnv (Env TcGblEnv TcLclEnv) TcTyCon
zonkTcTyConToTyCon }
zonkTcTyConToTyCon :: TcTyCon -> TcM TyCon
zonkTcTyConToTyCon :: TcTyCon -> IOEnv (Env TcGblEnv TcLclEnv) TcTyCon
zonkTcTyConToTyCon TcTyCon
tc
| TcTyCon -> Bool
isTcTyCon TcTyCon
tc = do { TyThing
thing <- Name -> TcM TyThing
tcLookupGlobalOnly (TcTyCon -> Name
forall a. NamedThing a => a -> Name
getName TcTyCon
tc)
; case TyThing
thing of
ATyCon TcTyCon
real_tc -> TcTyCon -> IOEnv (Env TcGblEnv TcLclEnv) TcTyCon
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyCon
real_tc
TyThing
_ -> String -> SDoc -> IOEnv (Env TcGblEnv TcLclEnv) TcTyCon
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"zonkTcTyCon" (TcTyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyCon
tc SDoc -> SDoc -> SDoc
$$ TyThing -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyThing
thing) }
| Bool
otherwise = TcTyCon -> IOEnv (Env TcGblEnv TcLclEnv) TcTyCon
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyCon
tc
zonkTcTypeToType :: TcType -> TcM Type
zonkTcTypeToType :: Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToType Kind
ty = (ZonkEnv -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> (ZonkEnv -> IOEnv (Env TcGblEnv TcLclEnv) Kind)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
ze Kind
ty
zonkTcTypesToTypes :: [TcType] -> TcM [Type]
zonkTcTypesToTypes :: [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
zonkTcTypesToTypes [Kind]
tys = (ZonkEnv -> IOEnv (Env TcGblEnv TcLclEnv) [Kind])
-> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall b. (ZonkEnv -> TcM b) -> TcM b
initZonkEnv ((ZonkEnv -> IOEnv (Env TcGblEnv TcLclEnv) [Kind])
-> IOEnv (Env TcGblEnv TcLclEnv) [Kind])
-> (ZonkEnv -> IOEnv (Env TcGblEnv TcLclEnv) [Kind])
-> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze -> ZonkEnv -> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
zonkTcTypesToTypesX ZonkEnv
ze [Kind]
tys
zonkScaledTcTypeToTypeX :: ZonkEnv -> Scaled TcType -> TcM (Scaled TcType)
zonkScaledTcTypeToTypeX :: ZonkEnv -> Scaled Kind -> TcM (Scaled Kind)
zonkScaledTcTypeToTypeX ZonkEnv
env (Scaled Kind
m Kind
ty) = Kind -> Kind -> Scaled Kind
forall a. Kind -> a -> Scaled a
Scaled (Kind -> Kind -> Scaled Kind)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind
-> IOEnv (Env TcGblEnv TcLclEnv) (Kind -> Scaled Kind)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
m
IOEnv (Env TcGblEnv TcLclEnv) (Kind -> Scaled Kind)
-> IOEnv (Env TcGblEnv TcLclEnv) Kind -> TcM (Scaled Kind)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
env Kind
ty
zonkTcTypeToTypeX :: ZonkEnv -> TcType -> TcM Type
zonkTcTypesToTypesX :: ZonkEnv -> [TcType] -> TcM [Type]
zonkCoToCo :: ZonkEnv -> Coercion -> TcM Coercion
(ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX, ZonkEnv -> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind]
zonkTcTypesToTypesX, ZonkEnv -> TcCoercionR -> TcM TcCoercionR
zonkCoToCo, ZonkEnv -> [TcCoercionR] -> TcM [TcCoercionR]
_)
= TyCoMapper ZonkEnv (IOEnv (Env TcGblEnv TcLclEnv))
-> (ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind,
ZonkEnv -> [Kind] -> IOEnv (Env TcGblEnv TcLclEnv) [Kind],
ZonkEnv -> TcCoercionR -> TcM TcCoercionR,
ZonkEnv -> [TcCoercionR] -> TcM [TcCoercionR])
forall (m :: * -> *) env.
Monad m =>
TyCoMapper env m
-> (env -> Kind -> m Kind, env -> [Kind] -> m [Kind],
env -> TcCoercionR -> m TcCoercionR,
env -> [TcCoercionR] -> m [TcCoercionR])
mapTyCoX TyCoMapper ZonkEnv (IOEnv (Env TcGblEnv TcLclEnv))
zonk_tycomapper
zonkScaledTcTypesToTypesX :: ZonkEnv -> [Scaled TcType] -> TcM [Scaled Type]
zonkScaledTcTypesToTypesX :: ZonkEnv -> [Scaled Kind] -> TcM [Scaled Kind]
zonkScaledTcTypesToTypesX ZonkEnv
env [Scaled Kind]
scaled_tys =
(Scaled Kind -> TcM (Scaled Kind))
-> [Scaled Kind] -> TcM [Scaled Kind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZonkEnv -> Scaled Kind -> TcM (Scaled Kind)
zonkScaledTcTypeToTypeX ZonkEnv
env) [Scaled Kind]
scaled_tys
zonkTcMethInfoToMethInfoX :: ZonkEnv -> TcMethInfo -> TcM MethInfo
zonkTcMethInfoToMethInfoX :: ZonkEnv -> TcMethInfo -> TcM TcMethInfo
zonkTcMethInfoToMethInfoX ZonkEnv
ze (Name
name, Kind
ty, Maybe (DefMethSpec (SrcSpan, Kind))
gdm_spec)
= do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
ze Kind
ty
; Maybe (DefMethSpec (SrcSpan, Kind))
gdm_spec' <- Maybe (DefMethSpec (SrcSpan, Kind))
-> TcM (Maybe (DefMethSpec (SrcSpan, Kind)))
zonk_gdm Maybe (DefMethSpec (SrcSpan, Kind))
gdm_spec
; TcMethInfo -> TcM TcMethInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
name, Kind
ty', Maybe (DefMethSpec (SrcSpan, Kind))
gdm_spec') }
where
zonk_gdm :: Maybe (DefMethSpec (SrcSpan, TcType))
-> TcM (Maybe (DefMethSpec (SrcSpan, Type)))
zonk_gdm :: Maybe (DefMethSpec (SrcSpan, Kind))
-> TcM (Maybe (DefMethSpec (SrcSpan, Kind)))
zonk_gdm Maybe (DefMethSpec (SrcSpan, Kind))
Nothing = Maybe (DefMethSpec (SrcSpan, Kind))
-> TcM (Maybe (DefMethSpec (SrcSpan, Kind)))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (DefMethSpec (SrcSpan, Kind))
forall a. Maybe a
Nothing
zonk_gdm (Just DefMethSpec (SrcSpan, Kind)
VanillaDM) = Maybe (DefMethSpec (SrcSpan, Kind))
-> TcM (Maybe (DefMethSpec (SrcSpan, Kind)))
forall (m :: * -> *) a. Monad m => a -> m a
return (DefMethSpec (SrcSpan, Kind) -> Maybe (DefMethSpec (SrcSpan, Kind))
forall a. a -> Maybe a
Just DefMethSpec (SrcSpan, Kind)
forall ty. DefMethSpec ty
VanillaDM)
zonk_gdm (Just (GenericDM (SrcSpan
loc, Kind
ty)))
= do { Kind
ty' <- ZonkEnv -> Kind -> IOEnv (Env TcGblEnv TcLclEnv) Kind
zonkTcTypeToTypeX ZonkEnv
ze Kind
ty
; Maybe (DefMethSpec (SrcSpan, Kind))
-> TcM (Maybe (DefMethSpec (SrcSpan, Kind)))
forall (m :: * -> *) a. Monad m => a -> m a
return (DefMethSpec (SrcSpan, Kind) -> Maybe (DefMethSpec (SrcSpan, Kind))
forall a. a -> Maybe a
Just ((SrcSpan, Kind) -> DefMethSpec (SrcSpan, Kind)
forall ty. ty -> DefMethSpec ty
GenericDM (SrcSpan
loc, Kind
ty'))) }