{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeApplications #-}
module GHC.Tc.Gen.App
( tcApp
, tcInferSigma
, tcExprPrag ) where
import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcPolyExpr )
import GHC.Types.Var
import GHC.Builtin.Types ( multiplicityTy )
import GHC.Tc.Gen.Head
import Language.Haskell.Syntax.Basic
import GHC.Hs
import GHC.Tc.Errors.Types
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.Unify
import GHC.Tc.Utils.Instantiate
import GHC.Tc.Instance.Family ( tcGetFamInstEnvs, tcLookupDataFamInst_maybe )
import GHC.Tc.Gen.HsType
import GHC.Tc.Utils.Concrete ( unifyConcrete, idConcreteTvs )
import GHC.Tc.Utils.TcMType
import GHC.Tc.Types.Evidence
import GHC.Tc.Types.Origin
import GHC.Tc.Utils.TcType as TcType
import GHC.Tc.Zonk.TcType
import GHC.Core.ConLike (ConLike(..))
import GHC.Core.DataCon (dataConConcreteTyVars)
import GHC.Core.TyCon
import GHC.Core.TyCo.Rep
import GHC.Core.TyCo.Ppr
import GHC.Core.TyCo.Subst (substTyWithInScope)
import GHC.Core.TyCo.FVs
import GHC.Core.Type
import GHC.Core.Coercion
import GHC.Types.Var.Set
import GHC.Builtin.PrimOps( tagToEnumKey )
import GHC.Builtin.Names
import GHC.Driver.DynFlags
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Name.Reader
import GHC.Types.SrcLoc
import GHC.Types.Var.Env ( emptyTidyEnv, mkInScopeSet )
import GHC.Types.SourceText
import GHC.Data.Maybe
import GHC.Utils.Misc
import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
import qualified GHC.LanguageExtensions as LangExt
import Control.Monad
import Data.Function
import GHC.Prelude
tcInferSigma :: Bool -> LHsExpr GhcRn -> TcM TcSigmaType
tcInferSigma :: Bool -> LHsExpr (GhcPass 'Renamed) -> TcM TcType
tcInferSigma Bool
inst (L SrcSpanAnnA
loc HsExpr (GhcPass 'Renamed)
rn_expr)
= HsExpr (GhcPass 'Renamed) -> TcM TcType -> TcM TcType
forall a. HsExpr (GhcPass 'Renamed) -> TcRn a -> TcRn a
addExprCtxt HsExpr (GhcPass 'Renamed)
rn_expr (TcM TcType -> TcM TcType) -> TcM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$
SrcSpanAnnA -> TcM TcType -> TcM TcType
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (TcM TcType -> TcM TcType) -> TcM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$
do { (fun@(rn_fun,fun_ctxt), rn_args) <- HsExpr (GhcPass 'Renamed)
-> TcM ((HsExpr (GhcPass 'Renamed), AppCtxt), [HsExprArg 'TcpRn])
splitHsApps HsExpr (GhcPass 'Renamed)
rn_expr
; do_ql <- wantQuickLook rn_fun
; (tc_fun, fun_sigma) <- tcInferAppHead fun
; (_delta, inst_args, app_res_sigma) <- tcInstFun do_ql inst (tc_fun, fun_ctxt) fun_sigma rn_args
; _tc_args <- tcValArgs do_ql inst_args
; return app_res_sigma }
tcApp :: HsExpr GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc)
tcApp :: HsExpr (GhcPass 'Renamed) -> ExpRhoType -> TcM (HsExpr GhcTc)
tcApp HsExpr (GhcPass 'Renamed)
rn_expr ExpRhoType
exp_res_ty
= do { (fun@(rn_fun, fun_ctxt), rn_args) <- HsExpr (GhcPass 'Renamed)
-> TcM ((HsExpr (GhcPass 'Renamed), AppCtxt), [HsExprArg 'TcpRn])
splitHsApps HsExpr (GhcPass 'Renamed)
rn_expr
; traceTc "tcApp {" $
vcat [ text "rn_expr:" <+> ppr rn_expr
, text "rn_fun:" <+> ppr rn_fun
, text "fun_ctxt:" <+> ppr fun_ctxt
, text "rn_args:" <+> ppr rn_args ]
; (tc_fun, fun_sigma) <- tcInferAppHead fun
; do_ql <- wantQuickLook rn_fun
; (delta, inst_args, app_res_rho) <- tcInstFun do_ql True (tc_fun, fun_ctxt) fun_sigma rn_args
; app_res_rho <- if do_ql
then quickLookResultType delta app_res_rho exp_res_ty
else return app_res_rho
; let perhaps_add_res_ty_ctxt TcM HsWrapper
thing_inside
| AppCtxt -> Bool
insideExpansion AppCtxt
fun_ctxt
= AppCtxt -> TcM HsWrapper -> TcM HsWrapper
forall a. AppCtxt -> TcM a -> TcM a
addHeadCtxt AppCtxt
fun_ctxt TcM HsWrapper
thing_inside
| Bool
otherwise
= HsExpr (GhcPass 'Renamed)
-> [HsExprArg 'TcpRn]
-> TcType
-> ExpRhoType
-> TcM HsWrapper
-> TcM HsWrapper
forall a.
HsExpr (GhcPass 'Renamed)
-> [HsExprArg 'TcpRn] -> TcType -> ExpRhoType -> TcM a -> TcM a
addFunResCtxt HsExpr (GhcPass 'Renamed)
rn_fun [HsExprArg 'TcpRn]
rn_args TcType
app_res_rho ExpRhoType
exp_res_ty (TcM HsWrapper -> TcM HsWrapper) -> TcM HsWrapper -> TcM HsWrapper
forall a b. (a -> b) -> a -> b
$
TcM HsWrapper
thing_inside
; do_ds <- xoptM LangExt.DeepSubsumption
; res_wrap <- perhaps_add_res_ty_ctxt $
if not do_ds
then
do { co <- unifyExpectedType rn_expr app_res_rho exp_res_ty
; return (mkWpCastN co) }
else
do { app_res_rho <- liftZonkM $ zonkQuickLook do_ql app_res_rho
; tcSubTypeDS rn_expr app_res_rho exp_res_ty }
; tc_args <- tcValArgs do_ql inst_args
; tc_expr <-
if isTagToEnum rn_fun
then tcTagToEnum tc_fun fun_ctxt tc_args app_res_rho
else do rebuildHsApps tc_fun fun_ctxt tc_args app_res_rho
; whenDOptM Opt_D_dump_tc_trace $
do { inst_args <- liftZonkM $ mapM zonkArg inst_args
; traceTc "tcApp }" (vcat [ text "rn_fun:" <+> ppr rn_fun
, text "rn_args:" <+> ppr rn_args
, text "inst_args" <+> brackets (pprWithCommas pprHsExprArgTc inst_args)
, text "do_ql: " <+> ppr do_ql
, text "fun_sigma: " <+> ppr fun_sigma
, text "delta: " <+> ppr delta
, text "app_res_rho:" <+> ppr app_res_rho
, text "exp_res_ty:" <+> ppr exp_res_ty
, text "rn_expr:" <+> ppr rn_expr
, text "tc_fun:" <+> ppr tc_fun
, text "tc_args:" <+> ppr tc_args
, text "tc_expr:" <+> ppr tc_expr ]) }
; return (mkHsWrap res_wrap tc_expr) }
wantQuickLook :: HsExpr GhcRn -> TcM Bool
wantQuickLook :: HsExpr (GhcPass 'Renamed) -> TcM Bool
wantQuickLook (HsVar XVar (GhcPass 'Renamed)
_ (L SrcSpanAnnN
_ Name
f))
| Name -> Unique
forall a. Uniquable a => a -> Unique
getUnique Name
f Unique -> [Unique] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Unique]
quickLookKeys = Bool -> TcM Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
wantQuickLook HsExpr (GhcPass 'Renamed)
_ = Extension -> TcM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.ImpredicativeTypes
quickLookKeys :: [Unique]
quickLookKeys :: [Unique]
quickLookKeys = [Unique
dollarIdKey, Unique
leftSectionKey, Unique
rightSectionKey]
zonkQuickLook :: Bool -> TcType -> ZonkM TcType
zonkQuickLook :: Bool -> TcType -> ZonkM TcType
zonkQuickLook Bool
do_ql TcType
ty
| Bool
do_ql = TcType -> ZonkM TcType
zonkTcType TcType
ty
| Bool
otherwise = TcType -> ZonkM TcType
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
ty
zonkArg :: HsExprArg 'TcpInst -> ZonkM (HsExprArg 'TcpInst)
zonkArg :: HsExprArg 'TcpInst -> ZonkM (HsExprArg 'TcpInst)
zonkArg eva :: HsExprArg 'TcpInst
eva@(EValArg { eva_arg_ty :: forall (p :: TcPass). HsExprArg p -> XEVAType p
eva_arg_ty = Scaled TcType
m TcType
ty })
= do { ty' <- TcType -> ZonkM TcType
zonkTcType TcType
ty
; return (eva { eva_arg_ty = Scaled m ty' }) }
zonkArg HsExprArg 'TcpInst
arg = HsExprArg 'TcpInst -> ZonkM (HsExprArg 'TcpInst)
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return HsExprArg 'TcpInst
arg
tcValArgs :: Bool
-> [HsExprArg 'TcpInst]
-> TcM [HsExprArg 'TcpTc]
tcValArgs :: Bool -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
tcValArgs Bool
do_ql [HsExprArg 'TcpInst]
args
= (HsExprArg 'TcpInst
-> IOEnv (Env TcGblEnv TcLclEnv) (HsExprArg 'TcpTc))
-> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM HsExprArg 'TcpInst
-> IOEnv (Env TcGblEnv TcLclEnv) (HsExprArg 'TcpTc)
tc_arg [HsExprArg 'TcpInst]
args
where
tc_arg :: HsExprArg 'TcpInst -> TcM (HsExprArg 'TcpTc)
tc_arg :: HsExprArg 'TcpInst
-> IOEnv (Env TcGblEnv TcLclEnv) (HsExprArg 'TcpTc)
tc_arg (EPrag AppCtxt
l HsPragE (GhcPass (XPass 'TcpInst))
p) = HsExprArg 'TcpTc
-> IOEnv (Env TcGblEnv TcLclEnv) (HsExprArg 'TcpTc)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (AppCtxt -> HsPragE (GhcPass (XPass 'TcpTc)) -> HsExprArg 'TcpTc
forall (p :: TcPass).
AppCtxt -> HsPragE (GhcPass (XPass p)) -> HsExprArg p
EPrag AppCtxt
l (HsPragE (GhcPass 'Renamed) -> HsPragE GhcTc
tcExprPrag HsPragE (GhcPass 'Renamed)
HsPragE (GhcPass (XPass 'TcpInst))
p))
tc_arg (EWrap EWrap
w) = HsExprArg 'TcpTc
-> IOEnv (Env TcGblEnv TcLclEnv) (HsExprArg 'TcpTc)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (EWrap -> HsExprArg 'TcpTc
forall (p :: TcPass). EWrap -> HsExprArg p
EWrap EWrap
w)
tc_arg (ETypeArg AppCtxt
l LHsWcType (GhcPass 'Renamed)
hs_ty XETAType 'TcpInst
ty) = HsExprArg 'TcpTc
-> IOEnv (Env TcGblEnv TcLclEnv) (HsExprArg 'TcpTc)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (AppCtxt
-> LHsWcType (GhcPass 'Renamed)
-> XETAType 'TcpTc
-> HsExprArg 'TcpTc
forall (p :: TcPass).
AppCtxt
-> LHsWcType (GhcPass 'Renamed) -> XETAType p -> HsExprArg p
ETypeArg AppCtxt
l LHsWcType (GhcPass 'Renamed)
hs_ty XETAType 'TcpInst
XETAType 'TcpTc
ty)
tc_arg eva :: HsExprArg 'TcpInst
eva@(EValArg { eva_arg :: forall (p :: TcPass). HsExprArg p -> EValArg p
eva_arg = EValArg 'TcpInst
arg, eva_arg_ty :: forall (p :: TcPass). HsExprArg p -> XEVAType p
eva_arg_ty = Scaled TcType
mult TcType
arg_ty
, eva_ctxt :: forall (p :: TcPass). HsExprArg p -> AppCtxt
eva_ctxt = AppCtxt
ctxt })
= do {
arg_ty <- ZonkM TcType -> TcM TcType
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TcType -> TcM TcType) -> ZonkM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ Bool -> TcType -> ZonkM TcType
zonkQuickLook Bool
do_ql TcType
arg_ty
; arg' <- tcScalingUsage mult $
do { traceTc "tcEValArg" $
vcat [ ppr ctxt
, text "arg type:" <+> ppr arg_ty
, text "arg:" <+> ppr arg ]
; tcEValArg ctxt arg arg_ty }
; return (eva { eva_arg = ValArg arg'
, eva_arg_ty = Scaled mult arg_ty }) }
tcEValArg :: AppCtxt -> EValArg 'TcpInst -> TcSigmaTypeFRR -> TcM (LHsExpr GhcTc)
tcEValArg :: AppCtxt -> EValArg 'TcpInst -> TcType -> TcM (LHsExpr GhcTc)
tcEValArg AppCtxt
ctxt (ValArg larg :: LHsExpr (GhcPass (XPass 'TcpInst))
larg@(L SrcSpanAnnA
arg_loc HsExpr (GhcPass 'Renamed)
arg)) TcType
exp_arg_sigma
= AppCtxt
-> LHsExpr (GhcPass 'Renamed)
-> TcM (LHsExpr GhcTc)
-> TcM (LHsExpr GhcTc)
forall a. AppCtxt -> LHsExpr (GhcPass 'Renamed) -> TcM a -> TcM a
addArgCtxt AppCtxt
ctxt LHsExpr (GhcPass 'Renamed)
LHsExpr (GhcPass (XPass 'TcpInst))
larg (TcM (LHsExpr GhcTc) -> TcM (LHsExpr GhcTc))
-> TcM (LHsExpr GhcTc) -> TcM (LHsExpr GhcTc)
forall a b. (a -> b) -> a -> b
$
do { arg' <- HsExpr (GhcPass 'Renamed) -> ExpRhoType -> TcM (HsExpr GhcTc)
tcPolyExpr HsExpr (GhcPass 'Renamed)
arg (TcType -> ExpRhoType
mkCheckExpType TcType
exp_arg_sigma)
; return (L arg_loc arg') }
tcEValArg AppCtxt
ctxt (ValArgQL { va_expr :: EValArg 'TcpInst -> LHsExpr (GhcPass 'Renamed)
va_expr = larg :: LHsExpr (GhcPass 'Renamed)
larg@(L SrcSpanAnnA
arg_loc HsExpr (GhcPass 'Renamed)
_)
, va_fun :: EValArg 'TcpInst -> (HsExpr GhcTc, AppCtxt)
va_fun = (HsExpr GhcTc
inner_fun, AppCtxt
fun_ctxt)
, va_args :: EValArg 'TcpInst -> [HsExprArg 'TcpInst]
va_args = [HsExprArg 'TcpInst]
inner_args
, va_ty :: EValArg 'TcpInst -> TcType
va_ty = TcType
app_res_rho }) TcType
exp_arg_sigma
= AppCtxt
-> LHsExpr (GhcPass 'Renamed)
-> TcM (LHsExpr GhcTc)
-> TcM (LHsExpr GhcTc)
forall a. AppCtxt -> LHsExpr (GhcPass 'Renamed) -> TcM a -> TcM a
addArgCtxt AppCtxt
ctxt LHsExpr (GhcPass 'Renamed)
larg (TcM (LHsExpr GhcTc) -> TcM (LHsExpr GhcTc))
-> TcM (LHsExpr GhcTc) -> TcM (LHsExpr GhcTc)
forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcRn ()
traceTc String
"tcEValArgQL {" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ HsExpr GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
inner_fun SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [HsExprArg 'TcpInst] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [HsExprArg 'TcpInst]
inner_args ])
; tc_args <- Bool -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
tcValArgs Bool
True [HsExprArg 'TcpInst]
inner_args
; co <- unifyType Nothing app_res_rho exp_arg_sigma
; arg' <- mkHsWrapCo co <$> rebuildHsApps inner_fun fun_ctxt tc_args app_res_rho
; traceTc "tcEValArgQL }" $
vcat [ text "inner_fun:" <+> ppr inner_fun
, text "app_res_rho:" <+> ppr app_res_rho
, text "exp_arg_sigma:" <+> ppr exp_arg_sigma ]
; return (L arg_loc arg') }
type Delta = TcTyVarSet
tcInstFun :: Bool
-> Bool
-> (HsExpr GhcTc, AppCtxt)
-> TcSigmaType -> [HsExprArg 'TcpRn]
-> TcM ( Delta
, [HsExprArg 'TcpInst]
, TcSigmaType )
tcInstFun :: Bool
-> Bool
-> (HsExpr GhcTc, AppCtxt)
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
tcInstFun Bool
do_ql Bool
inst_final (HsExpr GhcTc
tc_fun, AppCtxt
fun_ctxt) TcType
fun_sigma [HsExprArg 'TcpRn]
rn_args
= do { String -> SDoc -> TcRn ()
traceTc String
"tcInstFun" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tc_fun" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsExpr GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
tc_fun
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fun_sigma" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
fun_sigma
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fun_ctxt" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> AppCtxt -> SDoc
forall a. Outputable a => a -> SDoc
ppr AppCtxt
fun_ctxt
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"args:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [HsExprArg 'TcpRn] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [HsExprArg 'TcpRn]
rn_args
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"do_ql" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
do_ql ])
; Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go Delta
emptyVarSet [] [] TcType
fun_sigma [HsExprArg 'TcpRn]
rn_args }
where
fun_orig :: CtOrigin
fun_orig
| VAExpansion (OrigStmt{}) SrcSpan
_ SrcSpan
_ <- AppCtxt
fun_ctxt
= CtOrigin
DoOrigin
| VAExpansion (OrigPat LPat (GhcPass 'Renamed)
pat) SrcSpan
_ SrcSpan
_ <- AppCtxt
fun_ctxt
= LPat (GhcPass 'Renamed) -> CtOrigin
DoPatOrigin LPat (GhcPass 'Renamed)
pat
| VAExpansion (OrigExpr HsExpr (GhcPass 'Renamed)
e) SrcSpan
_ SrcSpan
_ <- AppCtxt
fun_ctxt
= HsExpr (GhcPass 'Renamed) -> CtOrigin
exprCtOrigin HsExpr (GhcPass 'Renamed)
e
| VACall HsExpr (GhcPass 'Renamed)
e Int
_ SrcSpan
_ <- AppCtxt
fun_ctxt
= HsExpr (GhcPass 'Renamed) -> CtOrigin
exprCtOrigin HsExpr (GhcPass 'Renamed)
e
fun_conc_tvs :: ConcreteTyVars
fun_conc_tvs
| HsVar XVar GhcTc
_ (L SrcSpanAnnN
_ TcTyVar
fun_id) <- HsExpr GhcTc
tc_fun
= TcTyVar -> ConcreteTyVars
idConcreteTvs TcTyVar
fun_id
| XExpr (ConLikeTc (RealDataCon DataCon
dc) [TcTyVar]
_ [Scaled TcType]
_) <- HsExpr GhcTc
tc_fun
= DataCon -> ConcreteTyVars
dataConConcreteTyVars DataCon
dc
| Bool
otherwise
= ConcreteTyVars
noConcreteTyVars
n_val_args :: Int
n_val_args = (HsExprArg 'TcpRn -> Bool) -> [HsExprArg 'TcpRn] -> Int
forall a. (a -> Bool) -> [a] -> Int
count HsExprArg 'TcpRn -> Bool
forall (id :: TcPass). HsExprArg id -> Bool
isHsValArg [HsExprArg 'TcpRn]
rn_args
fun_is_out_of_scope :: Bool
fun_is_out_of_scope
= case HsExpr GhcTc
tc_fun of
HsUnboundVar {} -> Bool
True
HsExpr GhcTc
_ -> Bool
False
inst_fun :: [HsExprArg 'TcpRn] -> ForAllTyFlag -> Bool
inst_fun :: [HsExprArg 'TcpRn] -> ForAllTyFlag -> Bool
inst_fun [] | Bool
inst_final = ForAllTyFlag -> Bool
isInvisibleForAllTyFlag
| Bool
otherwise = Bool -> ForAllTyFlag -> Bool
forall a b. a -> b -> a
const Bool
False
inst_fun (EValArg {} : [HsExprArg 'TcpRn]
_) = ForAllTyFlag -> Bool
isInvisibleForAllTyFlag
inst_fun [HsExprArg 'TcpRn]
_ = ForAllTyFlag -> Bool
isInferredForAllTyFlag
go, go1 :: Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcSigmaTypeFRR]
-> TcSigmaType -> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcSigmaType)
go :: Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
args
| Just TcTyVar
kappa <- TcType -> Maybe TcTyVar
getTyVar_maybe TcType
fun_ty
, TcTyVar
kappa TcTyVar -> Delta -> Bool
`elemVarSet` Delta
delta
= do { cts <- TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) MetaDetails
forall (m :: * -> *). MonadIO m => TcTyVar -> m MetaDetails
readMetaTyVar TcTyVar
kappa
; case cts of
Indirect TcType
fun_ty' -> Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty' [HsExprArg 'TcpRn]
args
MetaDetails
Flexi -> Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
args }
| Bool
otherwise
= Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
args
go1 :: Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty (HsExprArg 'TcpRn
arg : [HsExprArg 'TcpRn]
rest_args)
| Bool
fun_is_out_of_scope, HsExprArg 'TcpRn -> Bool
looks_like_type_arg HsExprArg 'TcpRn
arg
= Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
rest_args
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
args
| ([TcTyVar]
tvs, TcType
body1) <- (ForAllTyFlag -> Bool) -> TcType -> ([TcTyVar], TcType)
tcSplitSomeForAllTyVars ([HsExprArg 'TcpRn] -> ForAllTyFlag -> Bool
inst_fun [HsExprArg 'TcpRn]
args) TcType
fun_ty
, (ThetaType
theta, TcType
body2) <- if [HsExprArg 'TcpRn] -> ForAllTyFlag -> Bool
inst_fun [HsExprArg 'TcpRn]
args ForAllTyFlag
Inferred
then TcType -> (ThetaType, TcType)
tcSplitPhiTy TcType
body1
else ([], TcType
body1)
, Bool -> Bool
not ([TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
tvs Bool -> Bool -> Bool
&& ThetaType -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ThetaType
theta)
= do { (inst_tvs, wrap, fun_rho) <-
AppCtxt
-> TcM ([TcTyVar], HsWrapper, TcType)
-> TcM ([TcTyVar], HsWrapper, TcType)
forall a. AppCtxt -> TcM a -> TcM a
addHeadCtxt AppCtxt
fun_ctxt (TcM ([TcTyVar], HsWrapper, TcType)
-> TcM ([TcTyVar], HsWrapper, TcType))
-> TcM ([TcTyVar], HsWrapper, TcType)
-> TcM ([TcTyVar], HsWrapper, TcType)
forall a b. (a -> b) -> a -> b
$
CtOrigin
-> ConcreteTyVars
-> [TcTyVar]
-> ThetaType
-> TcType
-> TcM ([TcTyVar], HsWrapper, TcType)
instantiateSigma CtOrigin
fun_orig ConcreteTyVars
fun_conc_tvs [TcTyVar]
tvs ThetaType
theta TcType
body2
; go (delta `extendVarSetList` inst_tvs)
(addArgWrap wrap acc) so_far fun_rho args }
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty ((EValArg { eva_arg :: forall (p :: TcPass). HsExprArg p -> EValArg p
eva_arg = ValArg LHsExpr (GhcPass (XPass 'TcpRn))
arg }) : [HsExprArg 'TcpRn]
rest_args)
| Just (TyVarBinder
tvb, TcType
body) <- TcType -> Maybe (TyVarBinder, TcType)
tcSplitForAllTyVarBinder_maybe TcType
fun_ty
= Bool
-> SDoc
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TyVarBinder -> ForAllTyFlag
forall tv argf. VarBndr tv argf -> argf
binderFlag TyVarBinder
tvb ForAllTyFlag -> ForAllTyFlag -> Bool
forall a. Eq a => a -> a -> Bool
== ForAllTyFlag
Required) (TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
fun_ty SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass (XPass 'TcpRn))
GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
arg) (TcM (Delta, [HsExprArg 'TcpInst], TcType)
-> TcM (Delta, [HsExprArg 'TcpInst], TcType))
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
forall a b. (a -> b) -> a -> b
$
do { (ty_arg, inst_body) <- ConcreteTyVars
-> (TyVarBinder, TcType)
-> LHsExpr (GhcPass 'Renamed)
-> TcM (TcType, TcType)
tcVDQ ConcreteTyVars
fun_conc_tvs (TyVarBinder
tvb, TcType
body) LHsExpr (GhcPass 'Renamed)
LHsExpr (GhcPass (XPass 'TcpRn))
arg
; let wrap = ThetaType -> HsWrapper
mkWpTyApps [TcType
ty_arg]
; go delta (addArgWrap wrap acc) so_far inst_body rest_args }
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
_ TcType
fun_ty []
= do { String -> SDoc -> TcRn ()
traceTc String
"tcInstFun:ret" (TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
fun_ty)
; (Delta, [HsExprArg 'TcpInst], TcType)
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Delta
delta, [HsExprArg 'TcpInst] -> [HsExprArg 'TcpInst]
forall a. [a] -> [a]
reverse [HsExprArg 'TcpInst]
acc, TcType
fun_ty) }
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty (EWrap EWrap
w : [HsExprArg 'TcpRn]
args)
= Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go1 Delta
delta (EWrap -> HsExprArg 'TcpInst
forall (p :: TcPass). EWrap -> HsExprArg p
EWrap EWrap
w HsExprArg 'TcpInst -> [HsExprArg 'TcpInst] -> [HsExprArg 'TcpInst]
forall a. a -> [a] -> [a]
: [HsExprArg 'TcpInst]
acc) [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
args
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty (EPrag AppCtxt
sp HsPragE (GhcPass (XPass 'TcpRn))
prag : [HsExprArg 'TcpRn]
args)
= Delta
-> [HsExprArg 'TcpInst]
-> [Scaled TcType]
-> TcType
-> [HsExprArg 'TcpRn]
-> TcM (Delta, [HsExprArg 'TcpInst], TcType)
go1 Delta
delta (AppCtxt -> HsPragE (GhcPass (XPass 'TcpInst)) -> HsExprArg 'TcpInst
forall (p :: TcPass).
AppCtxt -> HsPragE (GhcPass (XPass p)) -> HsExprArg p
EPrag AppCtxt
sp HsPragE (GhcPass (XPass 'TcpRn))
HsPragE (GhcPass (XPass 'TcpInst))
prag HsExprArg 'TcpInst -> [HsExprArg 'TcpInst] -> [HsExprArg 'TcpInst]
forall a. a -> [a] -> [a]
: [HsExprArg 'TcpInst]
acc) [Scaled TcType]
so_far TcType
fun_ty [HsExprArg 'TcpRn]
args
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty ( ETypeArg { eva_ctxt :: forall (p :: TcPass). HsExprArg p -> AppCtxt
eva_ctxt = AppCtxt
ctxt, eva_hs_ty :: forall (p :: TcPass). HsExprArg p -> LHsWcType (GhcPass 'Renamed)
eva_hs_ty = LHsWcType (GhcPass 'Renamed)
hs_ty }
: [HsExprArg 'TcpRn]
rest_args )
= do { (ty_arg, inst_ty) <- ConcreteTyVars
-> TcType -> LHsWcType (GhcPass 'Renamed) -> TcM (TcType, TcType)
tcVTA ConcreteTyVars
fun_conc_tvs TcType
fun_ty LHsWcType (GhcPass 'Renamed)
hs_ty
; let arg' = ETypeArg { eva_ctxt :: AppCtxt
eva_ctxt = AppCtxt
ctxt, eva_hs_ty :: LHsWcType (GhcPass 'Renamed)
eva_hs_ty = LHsWcType (GhcPass 'Renamed)
hs_ty, eva_ty :: XETAType 'TcpInst
eva_ty = TcType
XETAType 'TcpInst
ty_arg }
; go delta (arg' : acc) so_far inst_ty rest_args }
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty args :: [HsExprArg 'TcpRn]
args@(EValArg {} : [HsExprArg 'TcpRn]
_)
| Just TcTyVar
kappa <- TcType -> Maybe TcTyVar
getTyVar_maybe TcType
fun_ty
, TcTyVar
kappa TcTyVar -> Delta -> Bool
`elemVarSet` Delta
delta
=
do { let val_args :: [EValArg 'TcpRn]
val_args = [HsExprArg 'TcpRn] -> [EValArg 'TcpRn]
forall (id :: TcPass). [HsExprArg id] -> [EValArg id]
leadingValArgs [HsExprArg 'TcpRn]
args
val_args_count :: Int
val_args_count = [EValArg 'TcpRn] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [EValArg 'TcpRn]
val_args
new_arg_tv :: EValArg 'TcpRn -> Int -> TcM TcTyVar
new_arg_tv (ValArg (L SrcSpanAnnA
_ HsExpr (GhcPass 'Renamed)
arg)) Int
i =
FixedRuntimeRepContext -> TcM TcTyVar
newOpenFlexiFRRTyVar (FixedRuntimeRepContext -> TcM TcTyVar)
-> FixedRuntimeRepContext -> TcM TcTyVar
forall a b. (a -> b) -> a -> b
$
ExpectedFunTyOrigin -> Int -> FixedRuntimeRepContext
FRRExpectedFunTy (TypedThing -> HsExpr (GhcPass 'Renamed) -> ExpectedFunTyOrigin
forall (p :: Pass).
Outputable (HsExpr (GhcPass p)) =>
TypedThing -> HsExpr (GhcPass p) -> ExpectedFunTyOrigin
ExpectedFunTyArg (HsExpr GhcTc -> TypedThing
HsExprTcThing HsExpr GhcTc
tc_fun) HsExpr (GhcPass 'Renamed)
arg) Int
i
; arg_nus <- (EValArg 'TcpRn -> Int -> TcM TcTyVar)
-> [EValArg 'TcpRn]
-> [Int]
-> IOEnv (Env TcGblEnv TcLclEnv) [TcTyVar]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM EValArg 'TcpRn -> Int -> TcM TcTyVar
new_arg_tv
[EValArg 'TcpRn]
val_args
[[Scaled TcType] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Scaled TcType]
so_far Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 ..]
; mults <- replicateM val_args_count (newFlexiTyVarTy multiplicityTy)
; res_nu <- newOpenFlexiTyVar
; kind_co <- unifyKind Nothing liftedTypeKind (tyVarKind kappa)
; let delta' = Delta
delta Delta -> [TcTyVar] -> Delta
`extendVarSetList` (TcTyVar
res_nuTcTyVar -> [TcTyVar] -> [TcTyVar]
forall a. a -> [a] -> [a]
:[TcTyVar]
arg_nus)
arg_tys = [TcTyVar] -> ThetaType
mkTyVarTys [TcTyVar]
arg_nus
res_ty = TcTyVar -> TcType
mkTyVarTy TcTyVar
res_nu
fun_ty' = [Scaled TcType] -> TcType -> TcType
HasDebugCallStack => [Scaled TcType] -> TcType -> TcType
mkScaledFunTys (String
-> (TcType -> TcType -> Scaled TcType)
-> ThetaType
-> ThetaType
-> [Scaled TcType]
forall a b c.
HasDebugCallStack =>
String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual String
"tcInstFun" TcType -> TcType -> Scaled TcType
forall a. TcType -> a -> Scaled a
mkScaled ThetaType
mults ThetaType
arg_tys) TcType
res_ty
co_wrap = TcCoercionN -> HsWrapper
mkWpCastN (Role -> TcType -> TcCoercionN -> TcCoercionN
mkGReflLeftCo Role
Nominal TcType
fun_ty' TcCoercionN
kind_co)
acc' = HsWrapper -> [HsExprArg 'TcpInst] -> [HsExprArg 'TcpInst]
forall (p :: TcPass). HsWrapper -> [HsExprArg p] -> [HsExprArg p]
addArgWrap HsWrapper
co_wrap [HsExprArg 'TcpInst]
acc
; liftZonkM $ writeMetaTyVar kappa (mkCastTy fun_ty' kind_co)
; go delta' acc' so_far fun_ty' args }
go1 Delta
delta [HsExprArg 'TcpInst]
acc [Scaled TcType]
so_far TcType
fun_ty
(eva :: HsExprArg 'TcpRn
eva@(EValArg { eva_arg :: forall (p :: TcPass). HsExprArg p -> EValArg p
eva_arg = ValArg LHsExpr (GhcPass (XPass 'TcpRn))
arg, eva_ctxt :: forall (p :: TcPass). HsExprArg p -> AppCtxt
eva_ctxt = AppCtxt
ctxt }) : [HsExprArg 'TcpRn]
rest_args)
= do { let herald :: ExpectedFunTyOrigin
herald = case AppCtxt
fun_ctxt of
VAExpansion (OrigStmt{}) SrcSpan
_ SrcSpan
_ -> CtOrigin -> HsExpr GhcTc -> ExpectedFunTyOrigin
forall (p :: Pass).
OutputableBndrId p =>
CtOrigin -> HsExpr (GhcPass p) -> ExpectedFunTyOrigin
ExpectedFunTySyntaxOp CtOrigin
DoOrigin HsExpr GhcTc
tc_fun
AppCtxt
_ -> TypedThing -> HsExpr (GhcPass 'Renamed) -> ExpectedFunTyOrigin
forall (p :: Pass).
Outputable (HsExpr (GhcPass p)) =>
TypedThing -> HsExpr (GhcPass p) -> ExpectedFunTyOrigin
ExpectedFunTyArg (HsExpr GhcTc -> TypedThing
HsExprTcThing HsExpr GhcTc
tc_fun) (GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
-> HsExpr (GhcPass 'Renamed)
forall l e. GenLocated l e -> e
unLoc LHsExpr (GhcPass (XPass 'TcpRn))
GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
arg)
; (wrap, arg_ty, res_ty) <-
ExpectedFunTyOrigin
-> Maybe TypedThing
-> (Int, TcType)
-> TcType
-> TcM (HsWrapper, Scaled TcType, TcType)
matchActualFunTy ExpectedFunTyOrigin
herald
(TypedThing -> Maybe TypedThing
forall a. a -> Maybe a
Just (TypedThing -> Maybe TypedThing) -> TypedThing -> Maybe TypedThing
forall a b. (a -> b) -> a -> b
$ HsExpr GhcTc -> TypedThing
HsExprTcThing HsExpr GhcTc
tc_fun)
(Int
n_val_args, TcType
fun_sigma) TcType
fun_ty
; (delta', arg') <- if do_ql
then addArgCtxt ctxt arg $
quickLookArg delta arg arg_ty
else return (delta, ValArg arg)
; let acc' = HsExprArg 'TcpRn
eva { eva_arg = arg', eva_arg_ty = arg_ty }
HsExprArg 'TcpInst -> [HsExprArg 'TcpInst] -> [HsExprArg 'TcpInst]
forall a. a -> [a] -> [a]
: HsWrapper -> [HsExprArg 'TcpInst] -> [HsExprArg 'TcpInst]
forall (p :: TcPass). HsWrapper -> [HsExprArg p] -> [HsExprArg p]
addArgWrap HsWrapper
wrap [HsExprArg 'TcpInst]
acc
; go delta' acc' (arg_ty:so_far) res_ty rest_args }
looks_like_type_arg :: HsExprArg 'TcpRn -> Bool
looks_like_type_arg :: HsExprArg 'TcpRn -> Bool
looks_like_type_arg ETypeArg{} =
Bool
True
looks_like_type_arg EValArg{ eva_arg :: forall (p :: TcPass). HsExprArg p -> EValArg p
eva_arg = ValArg (L SrcSpanAnnA
_ HsExpr (GhcPass 'Renamed)
e) } =
case HsExpr (GhcPass 'Renamed) -> HsExpr (GhcPass 'Renamed)
forall (p :: Pass). HsExpr (GhcPass p) -> HsExpr (GhcPass p)
stripParensHsExpr HsExpr (GhcPass 'Renamed)
e of
HsEmbTy XEmbTy (GhcPass 'Renamed)
_ LHsWcType (NoGhcTc (GhcPass 'Renamed))
_ -> Bool
True
HsExpr (GhcPass 'Renamed)
_ -> Bool
False
looks_like_type_arg HsExprArg 'TcpRn
_ = Bool
False
addArgCtxt :: AppCtxt -> LHsExpr GhcRn
-> TcM a -> TcM a
addArgCtxt :: forall a. AppCtxt -> LHsExpr (GhcPass 'Renamed) -> TcM a -> TcM a
addArgCtxt AppCtxt
ctxt (L SrcSpanAnnA
arg_loc HsExpr (GhcPass 'Renamed)
arg) TcM a
thing_inside
= do { in_generated_code <- TcM Bool
inGeneratedCode
; case ctxt of
VACall HsExpr (GhcPass 'Renamed)
fun Int
arg_no SrcSpan
_ | Bool -> Bool
not Bool
in_generated_code
-> do SrcSpanAnnA -> TcM a -> TcM a
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
arg_loc (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
SDoc -> TcM a -> TcM a
forall a. SDoc -> TcM a -> TcM a
addErrCtxt (HsExpr (GhcPass 'Renamed)
-> HsExpr (GhcPass 'Renamed) -> Int -> SDoc
forall fun arg.
(Outputable fun, Outputable arg) =>
fun -> arg -> Int -> SDoc
funAppCtxt HsExpr (GhcPass 'Renamed)
fun HsExpr (GhcPass 'Renamed)
arg Int
arg_no) (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
VAExpansion (OrigStmt (L SrcSpanAnnA
_ stmt :: StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
stmt@(BindStmt {}))) SrcSpan
_ SrcSpan
loc
| SrcSpan -> Bool
isGeneratedSrcSpan (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
arg_loc)
-> SrcSpan -> TcM a -> TcM a
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
ExprStmt (GhcPass 'Renamed) -> TcM a -> TcM a
forall a. ExprStmt (GhcPass 'Renamed) -> TcRn a -> TcRn a
addStmtCtxt ExprStmt (GhcPass 'Renamed)
StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
stmt (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
| Bool
otherwise
-> SrcSpanAnnA -> TcM a -> TcM a
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
arg_loc (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
ExprStmt (GhcPass 'Renamed) -> TcM a -> TcM a
forall a. ExprStmt (GhcPass 'Renamed) -> TcRn a -> TcRn a
addStmtCtxt ExprStmt (GhcPass 'Renamed)
StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
stmt (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
VAExpansion (OrigStmt (L SrcSpanAnnA
loc StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
stmt)) SrcSpan
_ SrcSpan
_
-> SrcSpanAnnA -> TcM a -> TcM a
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
ExprStmt (GhcPass 'Renamed) -> TcM a -> TcM a
forall a. ExprStmt (GhcPass 'Renamed) -> TcRn a -> TcRn a
addStmtCtxt ExprStmt (GhcPass 'Renamed)
StmtLR
(GhcPass 'Renamed)
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed)))
stmt (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
AppCtxt
_ -> SrcSpanAnnA -> TcM a -> TcM a
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
arg_loc (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
HsExpr (GhcPass 'Renamed) -> TcM a -> TcM a
forall a. HsExpr (GhcPass 'Renamed) -> TcRn a -> TcRn a
addExprCtxt HsExpr (GhcPass 'Renamed)
arg (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside }
tcVTA :: ConcreteTyVars
-> TcType
-> LHsWcType GhcRn
-> TcM (TcType, TcType)
tcVTA :: ConcreteTyVars
-> TcType -> LHsWcType (GhcPass 'Renamed) -> TcM (TcType, TcType)
tcVTA ConcreteTyVars
conc_tvs TcType
fun_ty LHsWcType (GhcPass 'Renamed)
hs_ty
| Just (TyVarBinder
tvb, TcType
inner_ty) <- TcType -> Maybe (TyVarBinder, TcType)
tcSplitForAllTyVarBinder_maybe TcType
fun_ty
, TyVarBinder -> ForAllTyFlag
forall tv argf. VarBndr tv argf -> argf
binderFlag TyVarBinder
tvb ForAllTyFlag -> ForAllTyFlag -> Bool
forall a. Eq a => a -> a -> Bool
== ForAllTyFlag
Specified
= do { ConcreteTyVars
-> (TyVarBinder, TcType)
-> LHsWcType (GhcPass 'Renamed)
-> TcM (TcType, TcType)
tc_inst_forall_arg ConcreteTyVars
conc_tvs (TyVarBinder
tvb, TcType
inner_ty) LHsWcType (GhcPass 'Renamed)
hs_ty }
| Bool
otherwise
= do { (_, fun_ty) <- ZonkM (TidyEnv, TcType) -> TcM (TidyEnv, TcType)
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM (TidyEnv, TcType) -> TcM (TidyEnv, TcType))
-> ZonkM (TidyEnv, TcType) -> TcM (TidyEnv, TcType)
forall a b. (a -> b) -> a -> b
$ TidyEnv -> TcType -> ZonkM (TidyEnv, TcType)
zonkTidyTcType TidyEnv
emptyTidyEnv TcType
fun_ty
; failWith $ TcRnInvalidTypeApplication fun_ty hs_ty }
tcVDQ :: ConcreteTyVars
-> (ForAllTyBinder, TcType)
-> LHsExpr GhcRn
-> TcM (TcType, TcType)
tcVDQ :: ConcreteTyVars
-> (TyVarBinder, TcType)
-> LHsExpr (GhcPass 'Renamed)
-> TcM (TcType, TcType)
tcVDQ ConcreteTyVars
conc_tvs (TyVarBinder
tvb, TcType
inner_ty) LHsExpr (GhcPass 'Renamed)
arg
= do { hs_wc_ty <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsWcType (GhcPass 'Renamed))
expr_to_type LHsExpr (GhcPass 'Renamed)
arg
; tc_inst_forall_arg conc_tvs (tvb, inner_ty) hs_wc_ty }
expr_to_type :: LHsExpr GhcRn -> TcM (LHsWcType GhcRn)
expr_to_type :: LHsExpr (GhcPass 'Renamed) -> TcM (LHsWcType (GhcPass 'Renamed))
expr_to_type LHsExpr (GhcPass 'Renamed)
earg =
case LHsExpr (GhcPass 'Renamed) -> LHsExpr (GhcPass 'Renamed)
forall (p :: Pass). LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr LHsExpr (GhcPass 'Renamed)
earg of
L SrcSpanAnnA
_ (HsEmbTy XEmbTy (GhcPass 'Renamed)
_ LHsWcType (NoGhcTc (GhcPass 'Renamed))
hs_ty) ->
HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return LHsWcType (NoGhcTc (GhcPass 'Renamed))
HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
hs_ty
LHsExpr (GhcPass 'Renamed)
e ->
XHsWC
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall pass thing.
XHsWC pass thing -> thing -> HsWildCardBndrs pass thing
HsWC [] (GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go LHsExpr (GhcPass 'Renamed)
e
where
go :: LHsExpr GhcRn -> TcM (LHsType GhcRn)
go :: LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go (L SrcSpanAnnA
_ (HsEmbTy XEmbTy (GhcPass 'Renamed)
_ LHsWcType (NoGhcTc (GhcPass 'Renamed))
t)) =
HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall t. HsWildCardBndrs (GhcPass 'Renamed) t -> TcM t
unwrap_wc LHsWcType (NoGhcTc (GhcPass 'Renamed))
HsWildCardBndrs
(GhcPass 'Renamed)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
t
go (L SrcSpanAnnA
l (HsVar XVar (GhcPass 'Renamed)
_ LIdP (GhcPass 'Renamed)
lname)) =
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> HsType (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (XTyVar (GhcPass 'Renamed)
-> PromotionFlag
-> LIdP (GhcPass 'Renamed)
-> HsType (GhcPass 'Renamed)
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar [AddEpAnn]
XTyVar (GhcPass 'Renamed)
forall a. NoAnn a => a
noAnn PromotionFlag
NotPromoted LIdP (GhcPass 'Renamed)
lname))
go (L SrcSpanAnnA
l (HsApp XApp (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
lhs LHsExpr (GhcPass 'Renamed)
rhs)) =
do { lhs' <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go LHsExpr (GhcPass 'Renamed)
lhs
; rhs' <- go rhs
; return (L l (HsAppTy noExtField lhs' rhs')) }
go (L SrcSpanAnnA
l (HsAppType XAppTypeE (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
lhs LHsWcType (NoGhcTc (GhcPass 'Renamed))
rhs)) =
do { lhs' <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go LHsExpr (GhcPass 'Renamed)
lhs
; rhs' <- unwrap_wc rhs
; return (L l (HsAppKindTy noExtField lhs' rhs')) }
go (L SrcSpanAnnA
l e :: HsExpr (GhcPass 'Renamed)
e@(OpApp XOpApp (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
lhs LHsExpr (GhcPass 'Renamed)
op LHsExpr (GhcPass 'Renamed)
rhs)) =
do { lhs' <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go LHsExpr (GhcPass 'Renamed)
lhs
; op' <- go op
; rhs' <- go rhs
; op_id <- unwrap_op_tv op'
; return (L l (HsOpTy noAnn NotPromoted lhs' op_id rhs')) }
where
unwrap_op_tv :: GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> IOEnv (Env TcGblEnv TcLclEnv) (LIdP (GhcPass 'Renamed))
unwrap_op_tv (L SrcSpanAnnA
_ (HsTyVar XTyVar (GhcPass 'Renamed)
_ PromotionFlag
_ LIdP (GhcPass 'Renamed)
op_id)) = LIdP (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (LIdP (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return LIdP (GhcPass 'Renamed)
op_id
unwrap_op_tv GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
_ = TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (LIdP (GhcPass 'Renamed))
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (LIdP (GhcPass 'Renamed)))
-> TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (LIdP (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Renamed) -> TcRnMessage
TcRnIllformedTypeArgument (SrcSpanAnnA
-> HsExpr (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l HsExpr (GhcPass 'Renamed)
e)
go (L SrcSpanAnnA
l e :: HsExpr (GhcPass 'Renamed)
e@(HsOverLit XOverLitE (GhcPass 'Renamed)
_ HsOverLit (GhcPass 'Renamed)
lit)) =
do { tylit <- case HsOverLit (GhcPass 'Renamed) -> OverLitVal
forall p. HsOverLit p -> OverLitVal
ol_val HsOverLit (GhcPass 'Renamed)
lit of
HsIntegral IntegralLit
n -> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed)))
-> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ XNumTy (GhcPass 'Renamed) -> Integer -> HsTyLit (GhcPass 'Renamed)
forall pass. XNumTy pass -> Integer -> HsTyLit pass
HsNumTy XNumTy (GhcPass 'Renamed)
SourceText
NoSourceText (IntegralLit -> Integer
il_value IntegralLit
n)
HsIsString SourceText
_ FastString
s -> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed)))
-> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ XStrTy (GhcPass 'Renamed)
-> FastString -> HsTyLit (GhcPass 'Renamed)
forall pass. XStrTy pass -> FastString -> HsTyLit pass
HsStrTy XStrTy (GhcPass 'Renamed)
SourceText
NoSourceText FastString
s
HsFractional FractionalLit
_ -> TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed)))
-> TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Renamed) -> TcRnMessage
TcRnIllformedTypeArgument (SrcSpanAnnA
-> HsExpr (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l HsExpr (GhcPass 'Renamed)
e)
; return (L l (HsTyLit noExtField tylit)) }
go (L SrcSpanAnnA
l e :: HsExpr (GhcPass 'Renamed)
e@(HsLit XLitE (GhcPass 'Renamed)
_ HsLit (GhcPass 'Renamed)
lit)) =
do { tylit <- case HsLit (GhcPass 'Renamed)
lit of
HsChar XHsChar (GhcPass 'Renamed)
_ Char
c -> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed)))
-> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ XCharTy (GhcPass 'Renamed) -> Char -> HsTyLit (GhcPass 'Renamed)
forall pass. XCharTy pass -> Char -> HsTyLit pass
HsCharTy XCharTy (GhcPass 'Renamed)
SourceText
NoSourceText Char
c
HsString XHsString (GhcPass 'Renamed)
_ FastString
s -> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed)))
-> HsTyLit (GhcPass 'Renamed)
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ XStrTy (GhcPass 'Renamed)
-> FastString -> HsTyLit (GhcPass 'Renamed)
forall pass. XStrTy pass -> FastString -> HsTyLit pass
HsStrTy XStrTy (GhcPass 'Renamed)
SourceText
NoSourceText FastString
s
HsLit (GhcPass 'Renamed)
_ -> TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed)))
-> TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) (HsTyLit (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Renamed) -> TcRnMessage
TcRnIllformedTypeArgument (SrcSpanAnnA
-> HsExpr (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l HsExpr (GhcPass 'Renamed)
e)
; return (L l (HsTyLit noExtField tylit)) }
go (L SrcSpanAnnA
l (ExplicitTuple XExplicitTuple (GhcPass 'Renamed)
_ [HsTupArg (GhcPass 'Renamed)]
tup_args Boxity
boxity))
| Boxity -> Bool
isBoxed Boxity
boxity
, Just [LHsExpr (GhcPass 'Renamed)]
es <- [HsTupArg (GhcPass 'Renamed)] -> Maybe [LHsExpr (GhcPass 'Renamed)]
forall (p :: Pass).
[HsTupArg (GhcPass p)] -> Maybe [LHsExpr (GhcPass p)]
tupArgsPresent_maybe [HsTupArg (GhcPass 'Renamed)]
tup_args
= do { ts <- (GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))]
-> IOEnv
(Env TcGblEnv TcLclEnv)
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
go [LHsExpr (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))]
es
; return (L l (HsExplicitTupleTy noExtField ts)) }
go (L SrcSpanAnnA
l (ExplicitList XExplicitList (GhcPass 'Renamed)
_ [LHsExpr (GhcPass 'Renamed)]
es)) =
do { ts <- (GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> [GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))]
-> IOEnv
(Env TcGblEnv TcLclEnv)
[GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
go [LHsExpr (GhcPass 'Renamed)]
[GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))]
es
; return (L l (HsExplicitListTy noExtField NotPromoted ts)) }
go (L SrcSpanAnnA
l (ExprWithTySig XExprWithTySig (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
e LHsSigWcType (NoGhcTc (GhcPass 'Renamed))
sig_ty)) =
do { t <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go LHsExpr (GhcPass 'Renamed)
e
; sig_ki <- (unwrap_sig <=< unwrap_wc) sig_ty
; return (L l (HsKindSig noAnn t sig_ki)) }
where
unwrap_sig :: LHsSigType GhcRn -> TcM (LHsType GhcRn)
unwrap_sig :: LHsSigType (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
unwrap_sig (L SrcSpanAnnA
_ (HsSig XHsSig (GhcPass 'Renamed)
_ HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit=XHsOuterImplicit (GhcPass 'Renamed)
bndrs} LHsType (GhcPass 'Renamed)
body))
| [Name] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
XHsOuterImplicit (GhcPass 'Renamed)
bndrs = GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return LHsType (GhcPass 'Renamed)
GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
body
| Bool
otherwise = [Name]
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall t. [Name] -> TcM t
illegal_implicit_tvs [Name]
XHsOuterImplicit (GhcPass 'Renamed)
bndrs
unwrap_sig (L SrcSpanAnnA
l (HsSig XHsSig (GhcPass 'Renamed)
_ HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs=[LHsTyVarBndr Specificity (NoGhcTc (GhcPass 'Renamed))]
bndrs} LHsType (GhcPass 'Renamed)
body)) =
LHsType (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsType (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed)))
-> LHsType (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> HsType (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (XForAllTy (GhcPass 'Renamed)
-> HsForAllTelescope (GhcPass 'Renamed)
-> LHsType (GhcPass 'Renamed)
-> HsType (GhcPass 'Renamed)
forall pass.
XForAllTy pass
-> HsForAllTelescope pass -> LHsType pass -> HsType pass
HsForAllTy XForAllTy (GhcPass 'Renamed)
NoExtField
noExtField (XHsForAllInvis (GhcPass 'Renamed)
-> [LHsTyVarBndr Specificity (GhcPass 'Renamed)]
-> HsForAllTelescope (GhcPass 'Renamed)
forall pass.
XHsForAllInvis pass
-> [LHsTyVarBndr Specificity pass] -> HsForAllTelescope pass
HsForAllInvis XHsForAllInvis (GhcPass 'Renamed)
EpAnnForallTy
forall a. NoAnn a => a
noAnn [LHsTyVarBndr Specificity (NoGhcTc (GhcPass 'Renamed))]
[LHsTyVarBndr Specificity (GhcPass 'Renamed)]
bndrs) LHsType (GhcPass 'Renamed)
body)
go (L SrcSpanAnnA
l (HsPar XPar (GhcPass 'Renamed)
_ LHsExpr (GhcPass 'Renamed)
e)) =
do { t <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go LHsExpr (GhcPass 'Renamed)
e
; return (L l (HsParTy noAnn t)) }
go (L SrcSpanAnnA
l (HsUntypedSplice XUntypedSplice (GhcPass 'Renamed)
splice_result HsUntypedSplice (GhcPass 'Renamed)
splice))
| HsUntypedSpliceTop ThModFinalizers
finalizers HsExpr (GhcPass 'Renamed)
e <- XUntypedSplice (GhcPass 'Renamed)
splice_result
= do { t <- LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go (SrcSpanAnnA
-> HsExpr (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l HsExpr (GhcPass 'Renamed)
e)
; let splice_result' = ThModFinalizers
-> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> HsUntypedSpliceResult
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall thing.
ThModFinalizers -> thing -> HsUntypedSpliceResult thing
HsUntypedSpliceTop ThModFinalizers
finalizers GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
t
; return (L l (HsSpliceTy splice_result' splice)) }
go (L SrcSpanAnnA
l (HsUnboundVar XUnboundVar (GhcPass 'Renamed)
_ RdrName
rdr))
| OccName -> Bool
isUnderscore OccName
occ = GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SrcSpanAnnA
-> HsType (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (XWildCardTy (GhcPass 'Renamed) -> HsType (GhcPass 'Renamed)
forall pass. XWildCardTy pass -> HsType pass
HsWildCardTy XWildCardTy (GhcPass 'Renamed)
NoExtField
noExtField))
| OccName -> Bool
startsWithUnderscore OccName
occ =
do { wildcards_enabled <- Extension -> TcM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.NamedWildCards
; if wildcards_enabled
then illegal_wc rdr
else not_in_scope }
| Bool
otherwise = TcM (LHsType (GhcPass 'Renamed))
IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
not_in_scope
where occ :: OccName
occ = RdrName -> OccName
forall name. HasOccName name => name -> OccName
occName RdrName
rdr
not_in_scope :: IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
not_in_scope = TcRnMessage
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed))))
-> TcRnMessage
-> IOEnv
(Env TcGblEnv TcLclEnv)
(GenLocated SrcSpanAnnA (HsType (GhcPass 'Renamed)))
forall a b. (a -> b) -> a -> b
$ RdrName -> NotInScopeError -> TcRnMessage
mkTcRnNotInScope RdrName
rdr NotInScopeError
NotInScope
go (L SrcSpanAnnA
l (XExpr (ExpandedThingRn (OrigExpr HsExpr (GhcPass 'Renamed)
orig) HsExpr (GhcPass 'Renamed)
_))) =
LHsExpr (GhcPass 'Renamed) -> TcM (LHsType (GhcPass 'Renamed))
go (SrcSpanAnnA
-> HsExpr (GhcPass 'Renamed)
-> GenLocated SrcSpanAnnA (HsExpr (GhcPass 'Renamed))
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l HsExpr (GhcPass 'Renamed)
orig)
go LHsExpr (GhcPass 'Renamed)
e = TcRnMessage -> TcM (LHsType (GhcPass 'Renamed))
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage -> TcM (LHsType (GhcPass 'Renamed)))
-> TcRnMessage -> TcM (LHsType (GhcPass 'Renamed))
forall a b. (a -> b) -> a -> b
$ LHsExpr (GhcPass 'Renamed) -> TcRnMessage
TcRnIllformedTypeArgument LHsExpr (GhcPass 'Renamed)
e
unwrap_wc :: HsWildCardBndrs GhcRn t -> TcM t
unwrap_wc :: forall t. HsWildCardBndrs (GhcPass 'Renamed) t -> TcM t
unwrap_wc (HsWC XHsWC (GhcPass 'Renamed) t
wcs t
t)
= do { (Name -> IOEnv (Env TcGblEnv TcLclEnv) Any) -> [Name] -> TcRn ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (RdrName -> IOEnv (Env TcGblEnv TcLclEnv) Any
forall t. RdrName -> TcM t
illegal_wc (RdrName -> IOEnv (Env TcGblEnv TcLclEnv) Any)
-> (Name -> RdrName) -> Name -> IOEnv (Env TcGblEnv TcLclEnv) Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> RdrName
nameRdrName) [Name]
XHsWC (GhcPass 'Renamed) t
wcs
; t -> IOEnv (Env TcGblEnv TcLclEnv) t
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return t
t }
illegal_wc :: RdrName -> TcM t
illegal_wc :: forall t. RdrName -> TcM t
illegal_wc RdrName
rdr = TcRnMessage -> TcRn t
forall a. TcRnMessage -> TcRn a
failWith (TcRnMessage -> TcRn t) -> TcRnMessage -> TcRn t
forall a b. (a -> b) -> a -> b
$ RdrName -> TcRnMessage
TcRnIllegalNamedWildcardInTypeArgument RdrName
rdr
illegal_implicit_tvs :: [Name] -> TcM t
illegal_implicit_tvs :: forall t. [Name] -> TcM t
illegal_implicit_tvs [Name]
tvs
= do { (Name -> TcRn ()) -> [Name] -> TcRn ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (TcRnMessage -> TcRn ()
addErr (TcRnMessage -> TcRn ())
-> (Name -> TcRnMessage) -> Name -> TcRn ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RdrName -> TcRnMessage
TcRnIllegalImplicitTyVarInTypeArgument (RdrName -> TcRnMessage)
-> (Name -> RdrName) -> Name -> TcRnMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> RdrName
nameRdrName) [Name]
tvs
; IOEnv (Env TcGblEnv TcLclEnv) t
forall env a. IOEnv env a
failM }
tc_inst_forall_arg :: ConcreteTyVars
-> (ForAllTyBinder, TcType)
-> LHsWcType GhcRn
-> TcM (TcType, TcType)
tc_inst_forall_arg :: ConcreteTyVars
-> (TyVarBinder, TcType)
-> LHsWcType (GhcPass 'Renamed)
-> TcM (TcType, TcType)
tc_inst_forall_arg ConcreteTyVars
conc_tvs (TyVarBinder
tvb, TcType
inner_ty) LHsWcType (GhcPass 'Renamed)
hs_ty
= do { let tv :: TcTyVar
tv = TyVarBinder -> TcTyVar
forall tv argf. VarBndr tv argf -> tv
binderVar TyVarBinder
tvb
kind :: TcType
kind = TcTyVar -> TcType
tyVarKind TcTyVar
tv
tv_nm :: Name
tv_nm = TcTyVar -> Name
tyVarName TcTyVar
tv
mb_conc :: Maybe ConcreteTvOrigin
mb_conc = ConcreteTyVars -> Name -> Maybe ConcreteTvOrigin
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv ConcreteTyVars
conc_tvs Name
tv_nm
; ty_arg0 <- LHsWcType (GhcPass 'Renamed) -> TcType -> TcM TcType
tcHsTypeApp LHsWcType (GhcPass 'Renamed)
hs_ty TcType
kind
; th_stage <- getStage
; ty_arg <- case mb_conc of
Maybe ConcreteTvOrigin
Nothing -> TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
ty_arg0
Just ConcreteTvOrigin
conc
| Brack ThStage
_ (TcPending {}) <- ThStage
th_stage
-> TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
ty_arg0
| Bool
otherwise
->
do { mco <- HasDebugCallStack =>
FastString -> ConcreteTvOrigin -> TcType -> TcM TcMCoercionN
FastString -> ConcreteTvOrigin -> TcType -> TcM TcMCoercionN
unifyConcrete (OccName -> FastString
occNameFS (OccName -> FastString) -> OccName -> FastString
forall a b. (a -> b) -> a -> b
$ Name -> OccName
forall a. NamedThing a => a -> OccName
getOccName (Name -> OccName) -> Name -> OccName
forall a b. (a -> b) -> a -> b
$ Name
tv_nm) ConcreteTvOrigin
conc TcType
ty_arg0
; return $ case mco of { TcMCoercionN
MRefl -> TcType
ty_arg0; MCo TcCoercionN
co -> TcCoercionN -> TcType
coercionRKind TcCoercionN
co } }
; let fun_ty = TyVarBinder -> TcType -> TcType
mkForAllTy TyVarBinder
tvb TcType
inner_ty
in_scope = Delta -> InScopeSet
mkInScopeSet (ThetaType -> Delta
tyCoVarsOfTypes [TcType
fun_ty, TcType
ty_arg])
insted_ty = HasDebugCallStack =>
InScopeSet -> [TcTyVar] -> ThetaType -> TcType -> TcType
InScopeSet -> [TcTyVar] -> ThetaType -> TcType -> TcType
substTyWithInScope InScopeSet
in_scope [TcTyVar
tv] [TcType
ty_arg] TcType
inner_ty
; traceTc "tc_inst_forall_arg (VTA/VDQ)" (
vcat [ text "fun_ty" <+> ppr fun_ty
, text "tv" <+> ppr tv <+> dcolon <+> debugPprType kind
, text "ty_arg" <+> debugPprType ty_arg <+> dcolon
<+> debugPprType (typeKind ty_arg)
, text "inner_ty" <+> debugPprType inner_ty
, text "insted_ty" <+> debugPprType insted_ty ])
; return (ty_arg, insted_ty) }
quickLookArg :: Delta
-> LHsExpr GhcRn
-> Scaled TcSigmaTypeFRR
-> TcM (Delta, EValArg 'TcpInst)
quickLookArg :: Delta
-> LHsExpr (GhcPass 'Renamed)
-> Scaled TcType
-> TcM (Delta, EValArg 'TcpInst)
quickLookArg Delta
delta LHsExpr (GhcPass 'Renamed)
larg (Scaled TcType
_ TcType
arg_ty)
| Delta -> Bool
isEmptyVarSet Delta
delta = Delta
-> LHsExpr (GhcPass 'Renamed) -> TcM (Delta, EValArg 'TcpInst)
skipQuickLook Delta
delta LHsExpr (GhcPass 'Renamed)
larg
| Bool
otherwise = TcType -> TcM (Delta, EValArg 'TcpInst)
go TcType
arg_ty
where
guarded :: Bool
guarded = TcType -> Bool
isGuardedTy TcType
arg_ty
go :: TcType -> TcM (Delta, EValArg 'TcpInst)
go TcType
arg_ty | Bool -> Bool
not (TcType -> Bool
isRhoTy TcType
arg_ty)
= Delta
-> LHsExpr (GhcPass 'Renamed) -> TcM (Delta, EValArg 'TcpInst)
skipQuickLook Delta
delta LHsExpr (GhcPass 'Renamed)
larg
| Just TcTyVar
kappa <- TcType -> Maybe TcTyVar
getTyVar_maybe TcType
arg_ty
, TcTyVar
kappa TcTyVar -> Delta -> Bool
`elemVarSet` Delta
delta
= do { info <- TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) MetaDetails
forall (m :: * -> *). MonadIO m => TcTyVar -> m MetaDetails
readMetaTyVar TcTyVar
kappa
; case info of
Indirect TcType
arg_ty' -> TcType -> TcM (Delta, EValArg 'TcpInst)
go TcType
arg_ty'
MetaDetails
Flexi -> Bool
-> Delta
-> LHsExpr (GhcPass 'Renamed)
-> TcType
-> TcM (Delta, EValArg 'TcpInst)
quickLookArg1 Bool
guarded Delta
delta LHsExpr (GhcPass 'Renamed)
larg TcType
arg_ty }
| Bool
otherwise
= Bool
-> Delta
-> LHsExpr (GhcPass 'Renamed)
-> TcType
-> TcM (Delta, EValArg 'TcpInst)
quickLookArg1 Bool
guarded Delta
delta LHsExpr (GhcPass 'Renamed)
larg TcType
arg_ty
isGuardedTy :: TcType -> Bool
isGuardedTy :: TcType -> Bool
isGuardedTy TcType
ty
| Just (TyCon
tc,ThetaType
_) <- HasCallStack => TcType -> Maybe (TyCon, ThetaType)
TcType -> Maybe (TyCon, ThetaType)
tcSplitTyConApp_maybe TcType
ty = TyCon -> Role -> Bool
isGenerativeTyCon TyCon
tc Role
Nominal
| Just {} <- TcType -> Maybe (TcType, TcType)
tcSplitAppTy_maybe TcType
ty = Bool
True
| Bool
otherwise = Bool
False
quickLookArg1 :: Bool -> Delta -> LHsExpr GhcRn -> TcSigmaTypeFRR
-> TcM (Delta, EValArg 'TcpInst)
quickLookArg1 :: Bool
-> Delta
-> LHsExpr (GhcPass 'Renamed)
-> TcType
-> TcM (Delta, EValArg 'TcpInst)
quickLookArg1 Bool
guarded Delta
delta larg :: LHsExpr (GhcPass 'Renamed)
larg@(L SrcSpanAnnA
_ HsExpr (GhcPass 'Renamed)
arg) TcType
arg_ty
= do { ((rn_fun, fun_ctxt), rn_args) <- HsExpr (GhcPass 'Renamed)
-> TcM ((HsExpr (GhcPass 'Renamed), AppCtxt), [HsExprArg 'TcpRn])
splitHsApps HsExpr (GhcPass 'Renamed)
arg
; mb_fun_ty <- tcInferAppHead_maybe rn_fun
; traceTc "quickLookArg 1" $
vcat [ text "arg:" <+> ppr arg
, text "head:" <+> ppr rn_fun <+> dcolon <+> ppr mb_fun_ty
, text "args:" <+> ppr rn_args ]
; case mb_fun_ty of {
Maybe (HsExpr GhcTc, TcType)
Nothing ->
Delta
-> LHsExpr (GhcPass 'Renamed) -> TcM (Delta, EValArg 'TcpInst)
skipQuickLook Delta
delta LHsExpr (GhcPass 'Renamed)
larg ;
Just (HsExpr GhcTc
tc_fun, TcType
fun_sigma) ->
do { let no_free_kappas :: Bool
no_free_kappas = TcType -> [HsExprArg 'TcpRn] -> Bool
findNoQuantVars TcType
fun_sigma [HsExprArg 'TcpRn]
rn_args
; String -> SDoc -> TcRn ()
traceTc String
"quickLookArg 2" (SDoc -> TcRn ()) -> SDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"no_free_kappas:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
no_free_kappas
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"guarded:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
guarded
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tc_fun:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsExpr GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
tc_fun
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fun_sigma:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
fun_sigma ]
; if Bool -> Bool
not (Bool
guarded Bool -> Bool -> Bool
|| Bool
no_free_kappas)
then Delta
-> LHsExpr (GhcPass 'Renamed) -> TcM (Delta, EValArg 'TcpInst)
skipQuickLook Delta
delta LHsExpr (GhcPass 'Renamed)
larg
else
do { do_ql <- HsExpr (GhcPass 'Renamed) -> TcM Bool
wantQuickLook HsExpr (GhcPass 'Renamed)
rn_fun
; (delta_app, inst_args, app_res_rho) <- tcInstFun do_ql True (tc_fun, fun_ctxt) fun_sigma rn_args
; traceTc "quickLookArg 3" $
vcat [ text "arg:" <+> ppr arg
, text "delta:" <+> ppr delta
, text "delta_app:" <+> ppr delta_app
, text "arg_ty:" <+> ppr arg_ty
, text "app_res_rho:" <+> ppr app_res_rho ]
; let delta' = Delta
delta Delta -> Delta -> Delta
`unionVarSet` Delta
delta_app
; qlUnify delta' arg_ty app_res_rho
; let ql_arg = ValArgQL { va_expr :: LHsExpr (GhcPass 'Renamed)
va_expr = LHsExpr (GhcPass 'Renamed)
larg
, va_fun :: (HsExpr GhcTc, AppCtxt)
va_fun = (HsExpr GhcTc
tc_fun, AppCtxt
fun_ctxt)
, va_args :: [HsExprArg 'TcpInst]
va_args = [HsExprArg 'TcpInst]
inst_args
, va_ty :: TcType
va_ty = TcType
app_res_rho }
; return (delta', ql_arg) } } } }
skipQuickLook :: Delta -> LHsExpr GhcRn -> TcM (Delta, EValArg 'TcpInst)
skipQuickLook :: Delta
-> LHsExpr (GhcPass 'Renamed) -> TcM (Delta, EValArg 'TcpInst)
skipQuickLook Delta
delta LHsExpr (GhcPass 'Renamed)
larg = (Delta, EValArg 'TcpInst) -> TcM (Delta, EValArg 'TcpInst)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Delta
delta, LHsExpr (GhcPass (XPass 'TcpInst)) -> EValArg 'TcpInst
forall (p :: TcPass). LHsExpr (GhcPass (XPass p)) -> EValArg p
ValArg LHsExpr (GhcPass 'Renamed)
LHsExpr (GhcPass (XPass 'TcpInst))
larg)
quickLookResultType :: Delta -> TcRhoType -> ExpRhoType -> TcM TcRhoType
quickLookResultType :: Delta -> TcType -> ExpRhoType -> TcM TcType
quickLookResultType Delta
delta TcType
app_res_rho (Check TcType
exp_rho)
=
do { Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Delta -> Bool
isEmptyVarSet Delta
delta) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
Delta -> TcType -> TcType -> TcRn ()
qlUnify Delta
delta TcType
app_res_rho TcType
exp_rho
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
app_res_rho }
quickLookResultType Delta
_ TcType
app_res_rho (Infer {})
= ZonkM TcType -> TcM TcType
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TcType -> TcM TcType) -> ZonkM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ TcType -> ZonkM TcType
zonkTcType TcType
app_res_rho
qlUnify :: Delta -> TcType -> TcType -> TcM ()
qlUnify :: Delta -> TcType -> TcType -> TcRn ()
qlUnify Delta
delta TcType
ty1 TcType
ty2
= do { String -> SDoc -> TcRn ()
traceTc String
"qlUnify" (Delta -> SDoc
forall a. Outputable a => a -> SDoc
ppr Delta
delta SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
ty1 SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
ty2)
; (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta
emptyVarSet,Delta
emptyVarSet) TcType
ty1 TcType
ty2 }
where
go :: (TyVarSet, TcTyVarSet)
-> TcType -> TcType
-> TcM ()
go :: (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs (TyVarTy TcTyVar
tv) TcType
ty2
| TcTyVar
tv TcTyVar -> Delta -> Bool
`elemVarSet` Delta
delta = (Delta, Delta) -> TcTyVar -> TcType -> TcRn ()
go_kappa (Delta, Delta)
bvs TcTyVar
tv TcType
ty2
go (Delta
bvs1, Delta
bvs2) TcType
ty1 (TyVarTy TcTyVar
tv)
| TcTyVar
tv TcTyVar -> Delta -> Bool
`elemVarSet` Delta
delta = (Delta, Delta) -> TcTyVar -> TcType -> TcRn ()
go_kappa (Delta
bvs2,Delta
bvs1) TcTyVar
tv TcType
ty1
go (Delta, Delta)
bvs (CastTy TcType
ty1 TcCoercionN
_) TcType
ty2 = (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
ty1 TcType
ty2
go (Delta, Delta)
bvs TcType
ty1 (CastTy TcType
ty2 TcCoercionN
_) = (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
ty1 TcType
ty2
go (Delta, Delta)
_ (TyConApp TyCon
tc1 []) (TyConApp TyCon
tc2 [])
| TyCon
tc1 TyCon -> TyCon -> Bool
forall a. Eq a => a -> a -> Bool
== TyCon
tc2
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go (Delta, Delta)
bvs TcType
rho1 TcType
rho2
| Just TcType
rho1 <- TcType -> Maybe TcType
coreView TcType
rho1 = (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
rho1 TcType
rho2
| Just TcType
rho2 <- TcType -> Maybe TcType
coreView TcType
rho2 = (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
rho1 TcType
rho2
go (Delta, Delta)
bvs (TyConApp TyCon
tc1 ThetaType
tys1) (TyConApp TyCon
tc2 ThetaType
tys2)
| TyCon
tc1 TyCon -> TyCon -> Bool
forall a. Eq a => a -> a -> Bool
== TyCon
tc2
, Bool -> Bool
not (TyCon -> Bool
isTypeFamilyTyCon TyCon
tc1)
, ThetaType
tys1 ThetaType -> ThetaType -> Bool
forall a b. [a] -> [b] -> Bool
`equalLength` ThetaType
tys2
= (TcType -> TcType -> TcRn ()) -> ThetaType -> ThetaType -> TcRn ()
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m ()
zipWithM_ ((Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs) ThetaType
tys1 ThetaType
tys2
go (Delta, Delta)
bvs (FunTy { ft_af :: TcType -> FunTyFlag
ft_af = FunTyFlag
af1, ft_arg :: TcType -> TcType
ft_arg = TcType
arg1, ft_res :: TcType -> TcType
ft_res = TcType
res1, ft_mult :: TcType -> TcType
ft_mult = TcType
mult1 })
(FunTy { ft_af :: TcType -> FunTyFlag
ft_af = FunTyFlag
af2, ft_arg :: TcType -> TcType
ft_arg = TcType
arg2, ft_res :: TcType -> TcType
ft_res = TcType
res2, ft_mult :: TcType -> TcType
ft_mult = TcType
mult2 })
| FunTyFlag
af1 FunTyFlag -> FunTyFlag -> Bool
forall a. Eq a => a -> a -> Bool
== FunTyFlag
af2
= do { Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunTyFlag -> Bool
isVisibleFunArg FunTyFlag
af1) ((Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
arg1 TcType
arg2)
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunTyFlag -> Bool
isFUNArg FunTyFlag
af1) ((Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
mult1 TcType
mult2)
; (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
res1 TcType
res2 }
go (Delta, Delta)
bvs (AppTy TcType
t1a TcType
t1b) TcType
ty2
| Just (TcType
t2a, TcType
t2b) <- TcType -> Maybe (TcType, TcType)
tcSplitAppTyNoView_maybe TcType
ty2
= do { (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
t1a TcType
t2a; (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
t1b TcType
t2b }
go (Delta, Delta)
bvs TcType
ty1 (AppTy TcType
t2a TcType
t2b)
| Just (TcType
t1a, TcType
t1b) <- TcType -> Maybe (TcType, TcType)
tcSplitAppTyNoView_maybe TcType
ty1
= do { (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
t1a TcType
t2a; (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
t1b TcType
t2b }
go (Delta
bvs1, Delta
bvs2) (ForAllTy TyVarBinder
bv1 TcType
ty1) (ForAllTy TyVarBinder
bv2 TcType
ty2)
= (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta
bvs1',Delta
bvs2') TcType
ty1 TcType
ty2
where
bvs1' :: Delta
bvs1' = Delta
bvs1 Delta -> TcTyVar -> Delta
`extendVarSet` TyVarBinder -> TcTyVar
forall tv argf. VarBndr tv argf -> tv
binderVar TyVarBinder
bv1
bvs2' :: Delta
bvs2' = Delta
bvs2 Delta -> TcTyVar -> Delta
`extendVarSet` TyVarBinder -> TcTyVar
forall tv argf. VarBndr tv argf -> tv
binderVar TyVarBinder
bv2
go (Delta, Delta)
_ TcType
_ TcType
_ = () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go_kappa :: (Delta, Delta) -> TcTyVar -> TcType -> TcRn ()
go_kappa (Delta, Delta)
bvs TcTyVar
kappa TcType
ty2
= Bool -> SDoc -> TcRn () -> TcRn ()
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TcTyVar -> Bool
isMetaTyVar TcTyVar
kappa) (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
kappa) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
do { info <- TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) MetaDetails
forall (m :: * -> *). MonadIO m => TcTyVar -> m MetaDetails
readMetaTyVar TcTyVar
kappa
; case info of
Indirect TcType
ty1 -> (Delta, Delta) -> TcType -> TcType -> TcRn ()
go (Delta, Delta)
bvs TcType
ty1 TcType
ty2
MetaDetails
Flexi -> do { ty2 <- ZonkM TcType -> TcM TcType
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TcType -> TcM TcType) -> ZonkM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ TcType -> ZonkM TcType
zonkTcType TcType
ty2
; go_flexi bvs kappa ty2 } }
go_flexi :: (a, Delta) -> TcTyVar -> TcType -> TcRn ()
go_flexi (a
_,Delta
bvs2) TcTyVar
kappa TcType
ty2
|
let ty2_tvs :: Delta
ty2_tvs = TcType -> Delta
shallowTyCoVarsOfType TcType
ty2
, Bool -> Bool
not (Delta
ty2_tvs Delta -> Delta -> Bool
`intersectsVarSet` Delta
bvs2)
, Just TcType
ty2 <- [TcTyVar] -> TcType -> Maybe TcType
occCheckExpand [TcTyVar
kappa] TcType
ty2
= do { let ty2_kind :: TcType
ty2_kind = HasDebugCallStack => TcType -> TcType
TcType -> TcType
typeKind TcType
ty2
kappa_kind :: TcType
kappa_kind = TcTyVar -> TcType
tyVarKind TcTyVar
kappa
; co <- Maybe TypedThing -> TcType -> TcType -> TcM TcCoercionN
unifyKind (TypedThing -> Maybe TypedThing
forall a. a -> Maybe a
Just (TcType -> TypedThing
TypeThing TcType
ty2)) TcType
ty2_kind TcType
kappa_kind
; traceTc "qlUnify:update" $
vcat [ hang (ppr kappa <+> dcolon <+> ppr kappa_kind)
2 (text ":=" <+> ppr ty2 <+> dcolon <+> ppr ty2_kind)
, text "co:" <+> ppr co ]
; liftZonkM $ writeMetaTyVar kappa (mkCastTy ty2 co) }
| Bool
otherwise
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
findNoQuantVars :: TcSigmaType -> [HsExprArg 'TcpRn] -> Bool
findNoQuantVars :: TcType -> [HsExprArg 'TcpRn] -> Bool
findNoQuantVars TcType
fun_ty [HsExprArg 'TcpRn]
args
= Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go Delta
emptyVarSet TcType
fun_ty [HsExprArg 'TcpRn]
args
where
need_instantiation :: [HsExprArg p] -> Bool
need_instantiation [] = Bool
True
need_instantiation (EValArg {} : [HsExprArg p]
_) = Bool
True
need_instantiation [HsExprArg p]
_ = Bool
False
go :: TyVarSet -> TcSigmaType -> [HsExprArg 'TcpRn] -> Bool
go :: Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go Delta
bvs TcType
fun_ty [HsExprArg 'TcpRn]
args
| [HsExprArg 'TcpRn] -> Bool
forall {p :: TcPass}. [HsExprArg p] -> Bool
need_instantiation [HsExprArg 'TcpRn]
args
, ([TcTyVar]
tvs, ThetaType
theta, TcType
rho) <- TcType -> ([TcTyVar], ThetaType, TcType)
tcSplitSigmaTy TcType
fun_ty
, Bool -> Bool
not ([TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
tvs Bool -> Bool -> Bool
&& ThetaType -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ThetaType
theta)
= Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go (Delta
bvs Delta -> [TcTyVar] -> Delta
`extendVarSetList` [TcTyVar]
tvs) TcType
rho [HsExprArg 'TcpRn]
args
go Delta
bvs TcType
fun_ty [] = TcType -> Delta
tyCoVarsOfType TcType
fun_ty Delta -> Delta -> Bool
`disjointVarSet` Delta
bvs
go Delta
bvs TcType
fun_ty (EWrap {} : [HsExprArg 'TcpRn]
args) = Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go Delta
bvs TcType
fun_ty [HsExprArg 'TcpRn]
args
go Delta
bvs TcType
fun_ty (EPrag {} : [HsExprArg 'TcpRn]
args) = Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go Delta
bvs TcType
fun_ty [HsExprArg 'TcpRn]
args
go Delta
bvs TcType
fun_ty args :: [HsExprArg 'TcpRn]
args@(ETypeArg {} : [HsExprArg 'TcpRn]
rest_args)
| ([TcTyVar]
tvs, TcType
body1) <- (ForAllTyFlag -> Bool) -> TcType -> ([TcTyVar], TcType)
tcSplitSomeForAllTyVars (ForAllTyFlag -> ForAllTyFlag -> Bool
forall a. Eq a => a -> a -> Bool
== ForAllTyFlag
Inferred) TcType
fun_ty
, (ThetaType
theta, TcType
body2) <- TcType -> (ThetaType, TcType)
tcSplitPhiTy TcType
body1
, Bool -> Bool
not ([TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
tvs Bool -> Bool -> Bool
&& ThetaType -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ThetaType
theta)
= Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go (Delta
bvs Delta -> [TcTyVar] -> Delta
`extendVarSetList` [TcTyVar]
tvs) TcType
body2 [HsExprArg 'TcpRn]
args
| Just (TyVarBinder
_tv, TcType
res_ty) <- TcType -> Maybe (TyVarBinder, TcType)
tcSplitForAllTyVarBinder_maybe TcType
fun_ty
= Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go Delta
bvs TcType
res_ty [HsExprArg 'TcpRn]
rest_args
| Bool
otherwise
= Bool
False
go Delta
bvs TcType
fun_ty (EValArg {} : [HsExprArg 'TcpRn]
rest_args)
| Just (Scaled TcType
_, TcType
res_ty) <- TcType -> Maybe (Scaled TcType, TcType)
tcSplitFunTy_maybe TcType
fun_ty
= Delta -> TcType -> [HsExprArg 'TcpRn] -> Bool
go Delta
bvs TcType
res_ty [HsExprArg 'TcpRn]
rest_args
| Bool
otherwise
= Bool
False
isTagToEnum :: HsExpr GhcRn -> Bool
isTagToEnum :: HsExpr (GhcPass 'Renamed) -> Bool
isTagToEnum (HsVar XVar (GhcPass 'Renamed)
_ (L SrcSpanAnnN
_ Name
fun_id)) = Name
fun_id Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
tagToEnumKey
isTagToEnum HsExpr (GhcPass 'Renamed)
_ = Bool
False
tcTagToEnum :: HsExpr GhcTc -> AppCtxt -> [HsExprArg 'TcpTc]
-> TcRhoType
-> TcM (HsExpr GhcTc)
tcTagToEnum :: HsExpr GhcTc
-> AppCtxt -> [HsExprArg 'TcpTc] -> TcType -> TcM (HsExpr GhcTc)
tcTagToEnum HsExpr GhcTc
tc_fun AppCtxt
fun_ctxt [HsExprArg 'TcpTc]
tc_args TcType
res_ty
| [HsExprArg 'TcpTc
val_arg] <- (HsExprArg 'TcpTc -> Bool)
-> [HsExprArg 'TcpTc] -> [HsExprArg 'TcpTc]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Bool -> Bool
not (Bool -> Bool)
-> (HsExprArg 'TcpTc -> Bool) -> HsExprArg 'TcpTc -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExprArg 'TcpTc -> Bool
forall (id :: TcPass). HsExprArg id -> Bool
isHsValArg) [HsExprArg 'TcpTc]
tc_args
= do { res_ty <- ZonkM TcType -> TcM TcType
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TcType -> TcM TcType) -> ZonkM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ TcType -> ZonkM TcType
zonkTcType TcType
res_ty
; case tcSplitTyConApp_maybe res_ty of {
Maybe (TyCon, ThetaType)
Nothing -> do { TcRnMessage -> TcRn ()
addErrTc (TcType -> TcRnMessage
TcRnTagToEnumUnspecifiedResTy TcType
res_ty)
; TcM (HsExpr GhcTc)
vanilla_result } ;
Just (TyCon
tc, ThetaType
tc_args) ->
do {
; fam_envs <- TcM FamInstEnvs
tcGetFamInstEnvs
; case tcLookupDataFamInst_maybe fam_envs tc tc_args of {
Maybe (TyCon, ThetaType, TcCoercionN)
Nothing -> do { TcType -> TyCon -> TcRn ()
check_enumeration TcType
res_ty TyCon
tc
; TcM (HsExpr GhcTc)
vanilla_result } ;
Just (TyCon
rep_tc, ThetaType
rep_args, TcCoercionN
coi) ->
do {
TcType -> TyCon -> TcRn ()
check_enumeration TcType
res_ty TyCon
rep_tc
; let rep_ty :: TcType
rep_ty = TyCon -> ThetaType -> TcType
mkTyConApp TyCon
rep_tc ThetaType
rep_args
tc_fun' :: HsExpr GhcTc
tc_fun' = HsWrapper -> HsExpr GhcTc -> HsExpr GhcTc
mkHsWrap (TcType -> HsWrapper
WpTyApp TcType
rep_ty) HsExpr GhcTc
tc_fun
df_wrap :: HsWrapper
df_wrap = TcCoercionN -> HsWrapper
mkWpCastR (TcCoercionN -> TcCoercionN
mkSymCo TcCoercionN
coi)
; tc_expr <- HsExpr GhcTc
-> AppCtxt -> [HsExprArg 'TcpTc] -> TcType -> TcM (HsExpr GhcTc)
rebuildHsApps HsExpr GhcTc
tc_fun' AppCtxt
fun_ctxt [HsExprArg 'TcpTc
val_arg] TcType
res_ty
; return (mkHsWrap df_wrap tc_expr) }}}}}
| Bool
otherwise
= TcRnMessage -> TcM (HsExpr GhcTc)
forall a. TcRnMessage -> TcRn a
failWithTc TcRnMessage
TcRnTagToEnumMissingValArg
where
vanilla_result :: TcM (HsExpr GhcTc)
vanilla_result = HsExpr GhcTc
-> AppCtxt -> [HsExprArg 'TcpTc] -> TcType -> TcM (HsExpr GhcTc)
rebuildHsApps HsExpr GhcTc
tc_fun AppCtxt
fun_ctxt [HsExprArg 'TcpTc]
tc_args TcType
res_ty
check_enumeration :: TcType -> TyCon -> TcRn ()
check_enumeration TcType
ty' TyCon
tc
|
TyCon -> Bool
isTypeDataTyCon TyCon
tc = TcRnMessage -> TcRn ()
addErrTc (TcType -> TcRnMessage
TcRnTagToEnumResTyTypeData TcType
ty')
| TyCon -> Bool
isEnumerationTyCon TyCon
tc = () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = TcRnMessage -> TcRn ()
addErrTc (TcType -> TcRnMessage
TcRnTagToEnumResTyNotAnEnum TcType
ty')
tcExprPrag :: HsPragE GhcRn -> HsPragE GhcTc
tcExprPrag :: HsPragE (GhcPass 'Renamed) -> HsPragE GhcTc
tcExprPrag (HsPragSCC XSCC (GhcPass 'Renamed)
x1 StringLiteral
ann) = XSCC GhcTc -> StringLiteral -> HsPragE GhcTc
forall p. XSCC p -> StringLiteral -> HsPragE p
HsPragSCC XSCC (GhcPass 'Renamed)
XSCC GhcTc
x1 StringLiteral
ann