{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonadComprehensions #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE RecursiveDo #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Tc.Gen.HsType (
kcClassSigType, tcClassSigType,
tcHsSigType, tcHsSigWcType,
tcHsPartialSigType,
tcStandaloneKindSig,
funsSigCtxt, addSigCtxt, pprSigCtxt,
tcHsClsInstType,
tcHsDefault, tcHsDeriv, tcDerivStrategy,
tcHsTypeApp,
UserTypeCtxt(..),
bindImplicitTKBndrs_Tv, bindImplicitTKBndrs_Skol,
bindImplicitTKBndrs_Q_Tv, bindImplicitTKBndrs_Q_Skol,
bindExplicitTKBndrs_Tv, bindExplicitTKBndrs_Skol,
bindExplicitTKBndrs_Q_Tv, bindExplicitTKBndrs_Q_Skol,
bindOuterFamEqnTKBndrs_Q_Tv, bindOuterFamEqnTKBndrs,
tcOuterTKBndrs, scopedSortOuter, outerTyVars, outerTyVarBndrs,
bindOuterSigTKBndrs_Tv,
tcExplicitTKBndrs,
bindNamedWildCardBinders,
bindTyClTyVars, bindTyClTyVarsAndZonk,
tcFamTyPats,
etaExpandAlgTyCon, tcbVisibilities,
zonkAndScopedSort,
InitialKindStrategy(..),
SAKS_or_CUSK(..),
ContextKind(..),
kcDeclHeader, checkForDuplicateScopedTyVars,
tcHsLiftedType, tcHsOpenType,
tcHsLiftedTypeNC, tcHsOpenTypeNC,
tcInferLHsType, tcInferLHsTypeKind, tcInferLHsTypeUnsaturated,
tcCheckLHsTypeInContext, tcCheckLHsType,
tcHsContext, tcLHsPredType,
kindGeneralizeAll,
tcLHsKindSig, checkDataKindSig, DataSort(..),
checkClassKindSig,
tcMult,
tcHsPatSigType, tcHsTyPat,
HoleMode(..),
funAppCtxt, addTyConFlavCtxt,
tyLitFromLit, tyLitFromOverloadedLit,
) where
import GHC.Prelude hiding ( head, init, last, tail )
import GHC.Hs
import GHC.Rename.Utils
import GHC.Tc.Errors.Types
import GHC.Tc.Utils.Monad
import GHC.Tc.Types.Origin
import GHC.Tc.Types.LclEnv
import GHC.Tc.Types.Constraint
import GHC.Tc.Utils.Env
import GHC.Tc.Utils.TcMType
import GHC.Tc.Validity
import GHC.Tc.Utils.Unify
import GHC.IfaceToCore
import GHC.Tc.Solver
import GHC.Tc.Zonk.Type
import GHC.Tc.Utils.TcType
import GHC.Tc.Utils.Instantiate ( tcInstInvisibleTyBinders, tcInstInvisibleTyBindersN,
tcInstInvisibleTyBinder, tcSkolemiseInvisibleBndrs,
tcInstTypeBndrs )
import GHC.Tc.Zonk.TcType
import GHC.Core.Type
import GHC.Core.TyCo.Rep
import GHC.Core.TyCo.Ppr
import GHC.Builtin.Types.Prim
import GHC.Types.Error
import GHC.Types.Name.Env
import GHC.Types.Name.Reader( lookupLocalRdrOcc )
import GHC.Types.Var
import GHC.Types.Var.Set
import GHC.Core.TyCon
import GHC.Core.ConLike
import GHC.Core.DataCon
import GHC.Core.Class
import GHC.Types.Name
import GHC.Types.Var.Env
import GHC.Builtin.Types
import GHC.Types.Basic
import GHC.Types.SrcLoc
import GHC.Types.Unique
import GHC.Types.Unique.FM
import GHC.Utils.Misc
import GHC.Types.Unique.Supply
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Builtin.Names hiding ( wildCardName )
import GHC.Driver.DynFlags
import qualified GHC.LanguageExtensions as LangExt
import GHC.Data.FastString
import GHC.Data.List.Infinite ( Infinite (..) )
import qualified GHC.Data.List.Infinite as Inf
import GHC.Data.List.SetOps
import GHC.Data.Maybe
import GHC.Data.Bag( unitBag )
import Data.Function ( on )
import Data.List.NonEmpty ( NonEmpty(..), nonEmpty )
import qualified Data.List.NonEmpty as NE
import Data.List ( mapAccumL )
import Control.Monad
import Data.Tuple( swap )
import GHC.Types.SourceText
funsSigCtxt :: [LocatedN Name] -> UserTypeCtxt
funsSigCtxt :: [GenLocated SrcSpanAnnN Name] -> UserTypeCtxt
funsSigCtxt (L SrcSpanAnnN
_ Name
name1 : [GenLocated SrcSpanAnnN Name]
_) = Name -> ReportRedundantConstraints -> UserTypeCtxt
FunSigCtxt Name
name1 ReportRedundantConstraints
NoRRC
funsSigCtxt [] = String -> UserTypeCtxt
forall a. HasCallStack => String -> a
panic String
"funSigCtxt"
addSigCtxt :: Outputable hs_ty => UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt :: forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LocatedA hs_ty
hs_ty TcM a
thing_inside
= SrcSpan -> TcM a -> TcM a
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (LocatedA hs_ty -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LocatedA hs_ty
hs_ty) (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 (UserTypeCtxt -> LocatedA hs_ty -> SDoc
forall hs_ty.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> SDoc
pprSigCtxt UserTypeCtxt
ctxt LocatedA hs_ty
hs_ty) (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
pprSigCtxt :: Outputable hs_ty => UserTypeCtxt -> LocatedA hs_ty -> SDoc
pprSigCtxt :: forall hs_ty.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> SDoc
pprSigCtxt UserTypeCtxt
ctxt LocatedA hs_ty
hs_ty
| Just Name
n <- UserTypeCtxt -> Maybe Name
isSigMaybe UserTypeCtxt
ctxt
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the type signature:")
Int
2 (Name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc Name
n SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> LocatedA hs_ty -> SDoc
forall a. Outputable a => a -> SDoc
ppr LocatedA hs_ty
hs_ty)
| Bool
otherwise
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> UserTypeCtxt -> SDoc
pprUserTypeCtxt UserTypeCtxt
ctxt SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
colon)
Int
2 (LocatedA hs_ty -> SDoc
forall a. Outputable a => a -> SDoc
ppr LocatedA hs_ty
hs_ty)
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
tcHsSigWcType UserTypeCtxt
ctxt LHsSigWcType GhcRn
sig_ty = UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcHsSigType UserTypeCtxt
ctxt (LHsSigWcType GhcRn -> LHsSigType GhcRn
forall pass. LHsSigWcType pass -> LHsSigType pass
dropWildCards LHsSigWcType GhcRn
sig_ty)
kcClassSigType :: [LocatedN Name] -> LHsSigType GhcRn -> TcM ()
kcClassSigType :: [GenLocated SrcSpanAnnN Name] -> LHsSigType GhcRn -> TcM ()
kcClassSigType [GenLocated SrcSpanAnnN Name]
names
sig_ty :: LHsSigType GhcRn
sig_ty@(L SrcSpanAnnA
_ (HsSig { sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs = HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs, sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body = LHsType GhcRn
hs_ty }))
= UserTypeCtxt
-> GenLocated SrcSpanAnnA (HsSigType GhcRn) -> TcM () -> TcM ()
forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt ([GenLocated SrcSpanAnnN Name] -> UserTypeCtxt
funsSigCtxt [GenLocated SrcSpanAnnN Name]
names) LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig_ty (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
do { _ <- HsOuterSigTyVarBndrs GhcRn
-> TcM Type -> TcM (HsOuterTyVarBndrs Specificity GhcTc, Type)
forall a.
HsOuterSigTyVarBndrs GhcRn
-> TcM a -> TcM (HsOuterTyVarBndrs Specificity GhcTc, a)
bindOuterSigTKBndrs_Tv HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs (TcM Type -> TcM (HsOuterTyVarBndrs Specificity GhcTc, Type))
-> TcM Type -> TcM (HsOuterTyVarBndrs Specificity GhcTc, Type)
forall a b. (a -> b) -> a -> b
$
LHsType GhcRn -> Type -> TcM Type
tcCheckLHsType LHsType GhcRn
hs_ty Type
liftedTypeKind
; return () }
tcClassSigType :: [LocatedN Name] -> LHsSigType GhcRn -> TcM Type
tcClassSigType :: [GenLocated SrcSpanAnnN Name] -> LHsSigType GhcRn -> TcM Type
tcClassSigType [GenLocated SrcSpanAnnN Name]
names LHsSigType GhcRn
sig_ty
= UserTypeCtxt
-> GenLocated SrcSpanAnnA (HsSigType GhcRn) -> TcM Type -> TcM Type
forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
sig_ctxt LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig_ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo SkolemInfoAnon
skol_info_anon
; (implic, ty) <- tc_lhs_sig_type skol_info sig_ty (TheKind liftedTypeKind)
; emitImplication implic
; return ty }
where
sig_ctxt :: UserTypeCtxt
sig_ctxt = [GenLocated SrcSpanAnnN Name] -> UserTypeCtxt
funsSigCtxt [GenLocated SrcSpanAnnN Name]
names
skol_info_anon :: SkolemInfoAnon
skol_info_anon = UserTypeCtxt -> SkolemInfoAnon
SigTypeSkol UserTypeCtxt
sig_ctxt
tcHsSigType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcHsSigType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcHsSigType UserTypeCtxt
ctxt LHsSigType GhcRn
sig_ty
= UserTypeCtxt
-> GenLocated SrcSpanAnnA (HsSigType GhcRn) -> TcM Type -> TcM Type
forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig_ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcM ()
traceTc String
"tcHsSigType {" (GenLocated SrcSpanAnnA (HsSigType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig_ty)
; skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo SkolemInfoAnon
skol_info
; (implic, ty) <- tc_lhs_sig_type skol_info sig_ty (expectedKindInCtxt ctxt)
; traceTc "tcHsSigType 2" (ppr implic)
; simplifyAndEmitFlatConstraints (mkImplicWC (unitBag implic))
; ty <- liftZonkM $ zonkTcType ty
; checkValidType ctxt ty
; traceTc "end tcHsSigType }" (ppr ty)
; return ty }
where
skol_info :: SkolemInfoAnon
skol_info = UserTypeCtxt -> SkolemInfoAnon
SigTypeSkol UserTypeCtxt
ctxt
tc_lhs_sig_type :: SkolemInfo -> LHsSigType GhcRn
-> ContextKind -> TcM (Implication, TcType)
tc_lhs_sig_type :: SkolemInfo
-> LHsSigType GhcRn -> ContextKind -> TcM (Implication, Type)
tc_lhs_sig_type SkolemInfo
skol_info full_hs_ty :: LHsSigType GhcRn
full_hs_ty@(L SrcSpanAnnA
loc (HsSig { sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs = HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs
, sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body = LHsType GhcRn
hs_ty })) ContextKind
ctxt_kind
= SrcSpanAnnA -> TcM (Implication, Type) -> TcM (Implication, Type)
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (TcM (Implication, Type) -> TcM (Implication, Type))
-> TcM (Implication, Type) -> TcM (Implication, Type)
forall a b. (a -> b) -> a -> b
$
do { (tc_lvl, wanted, (exp_kind, (outer_bndrs, ty)))
<- String
-> TcM (Type, (HsOuterTyVarBndrs Specificity GhcTc, Type))
-> TcM
(TcLevel, WantedConstraints,
(Type, (HsOuterTyVarBndrs Specificity GhcTc, Type)))
forall a. String -> TcM a -> TcM (TcLevel, WantedConstraints, a)
pushLevelAndSolveEqualitiesX String
"tc_lhs_sig_type" (TcM (Type, (HsOuterTyVarBndrs Specificity GhcTc, Type))
-> TcM
(TcLevel, WantedConstraints,
(Type, (HsOuterTyVarBndrs Specificity GhcTc, Type))))
-> TcM (Type, (HsOuterTyVarBndrs Specificity GhcTc, Type))
-> TcM
(TcLevel, WantedConstraints,
(Type, (HsOuterTyVarBndrs Specificity GhcTc, Type)))
forall a b. (a -> b) -> a -> b
$
do { exp_kind <- ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
; stuff <- tcOuterTKBndrs skol_info hs_outer_bndrs $
tcCheckLHsType hs_ty exp_kind
; return (exp_kind, stuff) }
; exp_kind_dvs <- candidateQTyVarsOfType exp_kind
; doNotQuantifyTyVars exp_kind_dvs (err_ctx exp_kind)
; traceTc "tc_lhs_sig_type" (ppr hs_outer_bndrs $$ ppr outer_bndrs)
; outer_bndrs <- scopedSortOuter outer_bndrs
; let outer_tv_bndrs :: [InvisTVBinder] = outerTyVarBndrs outer_bndrs
ty1 = [VarBndr TcTyVar Specificity] -> Type -> Type
mkInvisForAllTys [VarBndr TcTyVar Specificity]
outer_tv_bndrs Type
ty
; kvs <- kindGeneralizeSome skol_info wanted ty1
; implic <- buildTvImplication (getSkolemInfo skol_info) kvs tc_lvl wanted
; return (implic, mkInfForAllTys kvs ty1) }
where
err_ctx :: Type -> TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx)
err_ctx Type
exp_kind TidyEnv
tidy_env
= do { (tidy_env2, exp_kind) <- TidyEnv -> Type -> ZonkM (TidyEnv, Type)
zonkTidyTcType TidyEnv
tidy_env Type
exp_kind
; return (tidy_env2, UninfTyCtx_Sig exp_kind full_hs_ty) }
tcStandaloneKindSig :: LStandaloneKindSig GhcRn -> TcM (Name, Kind)
tcStandaloneKindSig :: LStandaloneKindSig GhcRn -> TcM (Name, Type)
tcStandaloneKindSig (L SrcSpanAnnA
_ (StandaloneKindSig XStandaloneKindSig GhcRn
_ (L SrcSpanAnnN
_ Name
name) LHsSigType GhcRn
ksig))
= UserTypeCtxt
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TcM (Name, Type)
-> TcM (Name, Type)
forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
ksig (TcM (Name, Type) -> TcM (Name, Type))
-> TcM (Name, Type) -> TcM (Name, Type)
forall a b. (a -> b) -> a -> b
$
do { kind <- TypeOrKind -> UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tc_top_lhs_type TypeOrKind
KindLevel UserTypeCtxt
ctxt LHsSigType GhcRn
ksig
; checkValidType ctxt kind
; return (name, kind) }
where
ctxt :: UserTypeCtxt
ctxt = Name -> UserTypeCtxt
StandaloneKindSigCtxt Name
name
tcTopLHsType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcTopLHsType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcTopLHsType UserTypeCtxt
ctxt LHsSigType GhcRn
lsig_ty
= TcM Type -> TcM Type
forall r. TcM r -> TcM r
checkNoErrs (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TypeOrKind -> UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tc_top_lhs_type TypeOrKind
TypeLevel UserTypeCtxt
ctxt LHsSigType GhcRn
lsig_ty
tc_top_lhs_type :: TypeOrKind -> UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tc_top_lhs_type :: TypeOrKind -> UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tc_top_lhs_type TypeOrKind
tyki UserTypeCtxt
ctxt (L SrcSpanAnnA
loc sig_ty :: HsSigType GhcRn
sig_ty@(HsSig { sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs = HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs
, sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body = LHsType GhcRn
body }))
= SrcSpanAnnA -> TcM Type -> TcM Type
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcM ()
traceTc String
"tc_top_lhs_type {" (HsSigType GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsSigType GhcRn
sig_ty)
; skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo SkolemInfoAnon
skol_info_anon
; (tclvl, wanted, (outer_bndrs, ty))
<- pushLevelAndSolveEqualitiesX "tc_top_lhs_type" $
do { kind <- newExpectedKind (expectedKindInCtxt ctxt)
; tcOuterTKBndrs skol_info hs_outer_bndrs $
tc_check_lhs_type (mkMode tyki) body kind }
; outer_bndrs <- scopedSortOuter outer_bndrs
; let outer_tv_bndrs = HsOuterTyVarBndrs Specificity GhcTc
-> [VarBndr TcTyVar Specificity]
outerTyVarBndrs HsOuterTyVarBndrs Specificity GhcTc
outer_bndrs
ty1 = [VarBndr TcTyVar Specificity] -> Type -> Type
mkInvisForAllTys [VarBndr TcTyVar Specificity]
outer_tv_bndrs Type
ty
; kvs <- kindGeneralizeAll skol_info ty1
; reportUnsolvedEqualities skol_info kvs tclvl wanted
; final_ty <- initZonkEnv DefaultFlexi
$ zonkTcTypeToTypeX (mkInfForAllTys kvs ty1)
; traceTc "tc_top_lhs_type }" (vcat [ppr sig_ty, ppr final_ty])
; return final_ty }
where
skol_info_anon :: SkolemInfoAnon
skol_info_anon = UserTypeCtxt -> SkolemInfoAnon
SigTypeSkol UserTypeCtxt
ctxt
tcClassConstraint :: Type -> TcM (Either (Maybe TyCon) ([TyVar], Class, [Type], [Kind]))
tcClassConstraint :: Type
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
tcClassConstraint Type
ty
= do { let ([TcTyVar]
tvs, Type
pred) = Type -> ([TcTyVar], Type)
splitForAllTyCoVars Type
ty
([Scaled Type]
kind_args, Type
_) = Type -> ([Scaled Type], Type)
splitFunTys (HasDebugCallStack => Type -> Type
Type -> Type
typeKind Type
pred)
; case HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
splitTyConApp_maybe Type
pred of
Just (TyCon
tyCon, [Type]
tyConArgs) ->
case TyCon -> Maybe Class
tyConClass_maybe TyCon
tyCon of
Just Class
clas ->
Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (([TcTyVar], Class, [Type], [Type])
-> Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
forall a b. b -> Either a b
Right ([TcTyVar]
tvs, Class
clas, [Type]
tyConArgs, (Scaled Type -> Type) -> [Scaled Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Scaled Type -> Type
forall a. Scaled a -> a
scaledThing [Scaled Type]
kind_args))
Maybe Class
Nothing -> Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe TyCon
-> Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
forall a b. a -> Either a b
Left (TyCon -> Maybe TyCon
forall a. a -> Maybe a
Just TyCon
tyCon))
Maybe (TyCon, [Type])
Nothing -> Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe TyCon
-> Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
forall a b. a -> Either a b
Left Maybe TyCon
forall a. Maybe a
Nothing) }
tcHsDefault :: LHsSigType GhcRn -> TcM ([TyVar], Class, [Type], [Kind])
tcHsDefault :: LHsSigType GhcRn -> TcM ([TcTyVar], Class, [Type], [Type])
tcHsDefault LHsSigType GhcRn
hs_ty
= UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcTopLHsType UserTypeCtxt
DefaultDeclCtxt LHsSigType GhcRn
hs_ty
TcM Type
-> (Type
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])))
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
forall a b.
IOEnv (Env TcGblEnv TcLclEnv) a
-> (a -> IOEnv (Env TcGblEnv TcLclEnv) b)
-> IOEnv (Env TcGblEnv TcLclEnv) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Type
-> TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
tcClassConstraint
TcM (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type]))
-> (Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
-> TcM ([TcTyVar], Class, [Type], [Type]))
-> TcM ([TcTyVar], Class, [Type], [Type])
forall a b.
IOEnv (Env TcGblEnv TcLclEnv) a
-> (a -> IOEnv (Env TcGblEnv TcLclEnv) b)
-> IOEnv (Env TcGblEnv TcLclEnv) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe TyCon -> TcM ([TcTyVar], Class, [Type], [Type]))
-> (([TcTyVar], Class, [Type], [Type])
-> TcM ([TcTyVar], Class, [Type], [Type]))
-> Either (Maybe TyCon) ([TcTyVar], Class, [Type], [Type])
-> TcM ([TcTyVar], Class, [Type], [Type])
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (TcM ([TcTyVar], Class, [Type], [Type])
-> Maybe TyCon -> TcM ([TcTyVar], Class, [Type], [Type])
forall a b. a -> b -> a
const (TcM ([TcTyVar], Class, [Type], [Type])
-> Maybe TyCon -> TcM ([TcTyVar], Class, [Type], [Type]))
-> TcM ([TcTyVar], Class, [Type], [Type])
-> Maybe TyCon
-> TcM ([TcTyVar], Class, [Type], [Type])
forall a b. (a -> b) -> a -> b
$ TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type])
forall a. TcRnMessage -> TcM a
failWithTc (TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type]))
-> TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type])
forall a b. (a -> b) -> a -> b
$ LHsSigType GhcRn -> TcRnMessage
TcRnIllegalDefaultClass LHsSigType GhcRn
hs_ty) ([TcTyVar], Class, [Type], [Type])
-> TcM ([TcTyVar], Class, [Type], [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return
tcHsDeriv :: LHsSigType GhcRn -> TcM ([TyVar], Class, [Type], [Kind])
tcHsDeriv :: LHsSigType GhcRn -> TcM ([TcTyVar], Class, [Type], [Type])
tcHsDeriv LHsSigType GhcRn
hs_ty
= do { ty <- UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcTopLHsType UserTypeCtxt
DerivClauseCtxt LHsSigType GhcRn
hs_ty
; constrained <- tcClassConstraint ty
; case constrained of
Left Maybe TyCon
Nothing -> TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type])
forall a. TcRnMessage -> TcM a
failWithTc (LHsSigType GhcRn -> TcRnMessage
TcRnIllegalDerivingItem LHsSigType GhcRn
hs_ty)
Left (Just TyCon
tyCon) ->
TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type])
forall a. TcRnMessage -> TcM a
failWithTc (TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type]))
-> TcRnMessage -> TcM ([TcTyVar], Class, [Type], [Type])
forall a b. (a -> b) -> a -> b
$ IllegalInstanceReason -> TcRnMessage
TcRnIllegalInstance
(IllegalInstanceReason -> TcRnMessage)
-> IllegalInstanceReason -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ TypedThing -> IllegalClassInstanceReason -> IllegalInstanceReason
IllegalClassInstance (Type -> TypedThing
TypeThing Type
ty)
(IllegalClassInstanceReason -> IllegalInstanceReason)
-> IllegalClassInstanceReason -> IllegalInstanceReason
forall a b. (a -> b) -> a -> b
$ IllegalInstanceHeadReason -> IllegalClassInstanceReason
IllegalInstanceHead
(IllegalInstanceHeadReason -> IllegalClassInstanceReason)
-> IllegalInstanceHeadReason -> IllegalClassInstanceReason
forall a b. (a -> b) -> a -> b
$ Maybe TyCon -> IllegalInstanceHeadReason
InstHeadNonClass
(Maybe TyCon -> IllegalInstanceHeadReason)
-> Maybe TyCon -> IllegalInstanceHeadReason
forall a b. (a -> b) -> a -> b
$ TyCon -> Maybe TyCon
forall a. a -> Maybe a
Just TyCon
tyCon
Right ([TcTyVar], Class, [Type], [Type])
result -> ([TcTyVar], Class, [Type], [Type])
-> TcM ([TcTyVar], Class, [Type], [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([TcTyVar], Class, [Type], [Type])
result }
tcDerivStrategy :: Maybe (LDerivStrategy GhcRn)
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
tcDerivStrategy :: Maybe (LDerivStrategy GhcRn)
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
tcDerivStrategy Maybe (LDerivStrategy GhcRn)
mb_lds
= case Maybe (LDerivStrategy GhcRn)
mb_lds of
Maybe (LDerivStrategy GhcRn)
Nothing -> Maybe (GenLocated EpAnnCO (DerivStrategy GhcTc))
-> TcM
(Maybe (GenLocated EpAnnCO (DerivStrategy GhcTc)), [TcTyVar])
forall ds a. ds -> TcM (ds, [a])
boring_case Maybe (GenLocated EpAnnCO (DerivStrategy GhcTc))
forall a. Maybe a
Nothing
Just (L EpAnnCO
loc DerivStrategy GhcRn
ds) ->
EpAnnCO
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA EpAnnCO
loc (TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar]))
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TcTyVar])
forall a b. (a -> b) -> a -> b
$ do
(ds', tvs) <- DerivStrategy GhcRn -> TcM (DerivStrategy GhcTc, [TcTyVar])
tc_deriv_strategy DerivStrategy GhcRn
ds
pure (Just (L loc ds'), tvs)
where
tc_deriv_strategy :: DerivStrategy GhcRn
-> TcM (DerivStrategy GhcTc, [TyVar])
tc_deriv_strategy :: DerivStrategy GhcRn -> TcM (DerivStrategy GhcTc, [TcTyVar])
tc_deriv_strategy (StockStrategy XStockStrategy GhcRn
_) = DerivStrategy GhcTc -> TcM (DerivStrategy GhcTc, [TcTyVar])
forall ds a. ds -> TcM (ds, [a])
boring_case (XStockStrategy GhcTc -> DerivStrategy GhcTc
forall pass. XStockStrategy pass -> DerivStrategy pass
StockStrategy XStockStrategy GhcTc
NoExtField
noExtField)
tc_deriv_strategy (AnyclassStrategy XAnyClassStrategy GhcRn
_) = DerivStrategy GhcTc -> TcM (DerivStrategy GhcTc, [TcTyVar])
forall ds a. ds -> TcM (ds, [a])
boring_case (XAnyClassStrategy GhcTc -> DerivStrategy GhcTc
forall pass. XAnyClassStrategy pass -> DerivStrategy pass
AnyclassStrategy XAnyClassStrategy GhcTc
NoExtField
noExtField)
tc_deriv_strategy (NewtypeStrategy XNewtypeStrategy GhcRn
_) = DerivStrategy GhcTc -> TcM (DerivStrategy GhcTc, [TcTyVar])
forall ds a. ds -> TcM (ds, [a])
boring_case (XNewtypeStrategy GhcTc -> DerivStrategy GhcTc
forall pass. XNewtypeStrategy pass -> DerivStrategy pass
NewtypeStrategy XNewtypeStrategy GhcTc
NoExtField
noExtField)
tc_deriv_strategy (ViaStrategy XViaStrategy GhcRn
hs_sig)
= do { ty <- UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcTopLHsType UserTypeCtxt
DerivClauseCtxt XViaStrategy GhcRn
LHsSigType GhcRn
hs_sig
; rec { (via_tvs, via_pred) <- tcSkolemiseInvisibleBndrs (DerivSkol via_pred) ty }
; pure (ViaStrategy via_pred, via_tvs) }
boring_case :: ds -> TcM (ds, [a])
boring_case :: forall ds a. ds -> TcM (ds, [a])
boring_case ds
ds = (ds, [a]) -> IOEnv (Env TcGblEnv TcLclEnv) (ds, [a])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ds
ds, [])
tcHsClsInstType :: UserTypeCtxt
-> LHsSigType GhcRn
-> TcM Type
tcHsClsInstType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcHsClsInstType UserTypeCtxt
user_ctxt LHsSigType GhcRn
hs_inst_ty
= SrcSpan -> TcM Type -> TcM Type
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (GenLocated SrcSpanAnnA (HsSigType GhcRn) -> SrcSpan
forall a e. HasLoc a => GenLocated a e -> SrcSpan
getLocA LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
hs_inst_ty) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { inst_ty <- UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcTopLHsType UserTypeCtxt
user_ctxt LHsSigType GhcRn
hs_inst_ty
; checkValidInstance user_ctxt hs_inst_ty inst_ty
; return inst_ty }
tcHsTypeApp :: LHsWcType GhcRn -> Kind -> TcM Type
tcHsTypeApp :: LHsWcType GhcRn -> Type -> TcM Type
tcHsTypeApp LHsWcType GhcRn
wc_ty Type
kind
| HsWC { hswc_ext :: forall pass thing. HsWildCardBndrs pass thing -> XHsWC pass thing
hswc_ext = XHsWC GhcRn (LHsType GhcRn)
sig_wcs, hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = LHsType GhcRn
hs_ty } <- LHsWcType GhcRn
wc_ty
= do { mode <- TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode TypeOrKind
TypeLevel HoleMode
HM_VTA
; ty <- addTypeCtxt hs_ty $
solveEqualities "tcHsTypeApp" $
bindNamedWildCardBinders sig_wcs $ \ [(Name, TcTyVar)]
_ ->
TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
hs_ty Type
kind
; kindGeneralizeNone ty
; ty <- liftZonkM $ zonkTcType ty
; checkValidType TypeAppCtxt ty
; return ty }
tcFamTyPats :: TyCon
-> HsFamEqnPats GhcRn
-> TcM (TcType, TcKind)
tcFamTyPats :: TyCon -> HsFamEqnPats GhcRn -> TcM (Type, Type)
tcFamTyPats TyCon
fam_tc HsFamEqnPats GhcRn
hs_pats
= do { String -> SDoc -> TcM ()
traceTc String
"tcFamTyPats {" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
fam_tc, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"arity:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
fam_arity ]
; mode <- TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode TypeOrKind
TypeLevel HoleMode
HM_FamPat
; let fun_ty = TyCon -> [Type] -> Type
mkTyConApp TyCon
fam_tc []
; (fam_app, res_kind) <- tcInferTyApps mode lhs_fun fun_ty hs_pats
; res_kind <- liftZonkM $ zonkTcType res_kind
; traceTc "End tcFamTyPats }" $
vcat [ ppr fam_tc, text "res_kind:" <+> ppr res_kind ]
; return (fam_app, res_kind) }
where
fam_name :: Name
fam_name = TyCon -> Name
tyConName TyCon
fam_tc
fam_arity :: Int
fam_arity = TyCon -> Int
tyConArity TyCon
fam_tc
lhs_fun :: GenLocated SrcSpanAnnA (HsType GhcRn)
lhs_fun = HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA (XTyVar GhcRn -> PromotionFlag -> LIdP GhcRn -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcRn
forall a. NoAnn a => a
noAnn PromotionFlag
NotPromoted (Name -> GenLocated SrcSpanAnnN Name
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA Name
fam_name))
tcHsOpenType, tcHsLiftedType,
tcHsOpenTypeNC, tcHsLiftedTypeNC :: LHsType GhcRn -> TcM TcType
tcHsOpenType :: LHsType GhcRn -> TcM Type
tcHsOpenType LHsType GhcRn
hs_ty = LHsType GhcRn -> TcM Type -> TcM Type
forall a. LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt LHsType GhcRn
hs_ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$ LHsType GhcRn -> TcM Type
tcHsOpenTypeNC LHsType GhcRn
hs_ty
tcHsLiftedType :: LHsType GhcRn -> TcM Type
tcHsLiftedType LHsType GhcRn
hs_ty = LHsType GhcRn -> TcM Type -> TcM Type
forall a. LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt LHsType GhcRn
hs_ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$ LHsType GhcRn -> TcM Type
tcHsLiftedTypeNC LHsType GhcRn
hs_ty
tcHsOpenTypeNC :: LHsType GhcRn -> TcM Type
tcHsOpenTypeNC LHsType GhcRn
hs_ty = do { ek <- TcM Type
newOpenTypeKind; tcCheckLHsType hs_ty ek }
tcHsLiftedTypeNC :: LHsType GhcRn -> TcM Type
tcHsLiftedTypeNC LHsType GhcRn
hs_ty = LHsType GhcRn -> Type -> TcM Type
tcCheckLHsType LHsType GhcRn
hs_ty Type
liftedTypeKind
tcCheckLHsTypeInContext :: LHsType GhcRn -> ContextKind -> TcM TcType
tcCheckLHsTypeInContext :: LHsType GhcRn -> ContextKind -> TcM Type
tcCheckLHsTypeInContext LHsType GhcRn
hs_ty ContextKind
exp_kind
= LHsType GhcRn -> TcM Type -> TcM Type
forall a. LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt LHsType GhcRn
hs_ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { ek <- ContextKind -> TcM Type
newExpectedKind ContextKind
exp_kind
; tcCheckLHsType hs_ty ek }
tcInferLHsType :: LHsType GhcRn -> TcM TcType
tcInferLHsType :: LHsType GhcRn -> TcM Type
tcInferLHsType LHsType GhcRn
hs_ty
= do { (ty,_kind) <- LHsType GhcRn -> TcM (Type, Type)
tcInferLHsTypeKind LHsType GhcRn
hs_ty
; return ty }
tcInferLHsTypeKind :: LHsType GhcRn -> TcM (TcType, TcKind)
tcInferLHsTypeKind :: LHsType GhcRn -> TcM (Type, Type)
tcInferLHsTypeKind lhs_ty :: LHsType GhcRn
lhs_ty@(L SrcSpanAnnA
loc HsType GhcRn
hs_ty)
= LHsType GhcRn -> TcM (Type, Type) -> TcM (Type, Type)
forall a. LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt LHsType GhcRn
lhs_ty (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
SrcSpanAnnA -> TcM (Type, Type) -> TcM (Type, Type)
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
loc (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
do { (res_ty, res_kind) <- TcTyMode -> HsType GhcRn -> TcM (Type, Type)
tc_infer_hs_type TcTyMode
typeLevelMode HsType GhcRn
hs_ty
; tcInstInvisibleTyBinders res_ty res_kind }
tcInferLHsTypeUnsaturated :: LHsType GhcRn -> TcM (TcType, TcKind)
tcInferLHsTypeUnsaturated :: LHsType GhcRn -> TcM (Type, Type)
tcInferLHsTypeUnsaturated LHsType GhcRn
hs_ty
= LHsType GhcRn -> TcM (Type, Type) -> TcM (Type, Type)
forall a. LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt LHsType GhcRn
hs_ty (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
do { mode <- TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode TypeOrKind
TypeLevel HoleMode
HM_Sig
; case splitHsAppTys_maybe (unLoc hs_ty) of
Just (LHsType GhcRn
hs_fun_ty, HsFamEqnPats GhcRn
hs_args)
-> do { (fun_ty, _ki) <- TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tcInferTyAppHead TcTyMode
mode LHsType GhcRn
hs_fun_ty
; tcInferTyApps_nosat mode hs_fun_ty fun_ty hs_args }
Maybe (LHsType GhcRn, HsFamEqnPats GhcRn)
Nothing -> TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode LHsType GhcRn
hs_ty }
tcMult :: HsArrow GhcRn -> TcM Mult
tcMult :: HsArrow GhcRn -> TcM Type
tcMult HsArrow GhcRn
hc = TcTyMode -> HsArrow GhcRn -> TcM Type
tc_mult TcTyMode
typeLevelMode HsArrow GhcRn
hc
data TcTyMode
= TcTyMode { TcTyMode -> TypeOrKind
mode_tyki :: TypeOrKind
, TcTyMode -> HoleInfo
mode_holes :: HoleInfo }
type HoleInfo = Maybe (TcLevel, HoleMode)
data HoleMode = HM_Sig
| HM_FamPat
| HM_VTA
| HM_TyAppPat
mkMode :: TypeOrKind -> TcTyMode
mkMode :: TypeOrKind -> TcTyMode
mkMode TypeOrKind
tyki = TcTyMode { mode_tyki :: TypeOrKind
mode_tyki = TypeOrKind
tyki, mode_holes :: HoleInfo
mode_holes = HoleInfo
forall a. Maybe a
Nothing }
typeLevelMode, kindLevelMode :: TcTyMode
kindLevelMode :: TcTyMode
kindLevelMode = TypeOrKind -> TcTyMode
mkMode TypeOrKind
KindLevel
typeLevelMode :: TcTyMode
typeLevelMode = TypeOrKind -> TcTyMode
mkMode TypeOrKind
TypeLevel
mkHoleMode :: TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode :: TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode TypeOrKind
tyki HoleMode
hm
= do { lvl <- TcM TcLevel
getTcLevel
; return (TcTyMode { mode_tyki = tyki
, mode_holes = Just (lvl,hm) }) }
instance Outputable HoleMode where
ppr :: HoleMode -> SDoc
ppr HoleMode
HM_Sig = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"HM_Sig"
ppr HoleMode
HM_FamPat = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"HM_FamPat"
ppr HoleMode
HM_VTA = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"HM_VTA"
ppr HoleMode
HM_TyAppPat = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"HM_TyAppPat"
instance Outputable TcTyMode where
ppr :: TcTyMode -> SDoc
ppr (TcTyMode { mode_tyki :: TcTyMode -> TypeOrKind
mode_tyki = TypeOrKind
tyki, mode_holes :: TcTyMode -> HoleInfo
mode_holes = HoleInfo
hm })
= String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"TcTyMode" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
braces ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ TypeOrKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TypeOrKind
tyki SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma
, HoleInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr HoleInfo
hm ])
tc_infer_lhs_type :: TcTyMode -> LHsType GhcRn -> TcM (TcType, TcKind)
tc_infer_lhs_type :: TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode (L SrcSpanAnnA
span HsType GhcRn
ty)
= SrcSpanAnnA -> TcM (Type, Type) -> TcM (Type, Type)
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
span (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
TcTyMode -> HsType GhcRn -> TcM (Type, Type)
tc_infer_hs_type TcTyMode
mode HsType GhcRn
ty
tc_infer_hs_type :: TcTyMode -> HsType GhcRn -> TcM (TcType, TcKind)
tc_infer_hs_type :: TcTyMode -> HsType GhcRn -> TcM (Type, Type)
tc_infer_hs_type TcTyMode
mode HsType GhcRn
rn_ty
= (ExpSigmaType -> TcM Type) -> TcM (Type, Type)
forall a. (ExpSigmaType -> TcM a) -> TcM (a, Type)
tcInfer ((ExpSigmaType -> TcM Type) -> TcM (Type, Type))
-> (ExpSigmaType -> TcM Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$ \ExpSigmaType
exp_kind -> TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tcHsType TcTyMode
mode HsType GhcRn
rn_ty ExpSigmaType
exp_kind
tcCheckLHsType :: LHsType GhcRn -> TcKind -> TcM TcType
tcCheckLHsType :: LHsType GhcRn -> Type -> TcM Type
tcCheckLHsType LHsType GhcRn
hs_ty Type
exp_kind
= TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
typeLevelMode LHsType GhcRn
hs_ty Type
exp_kind
tc_check_lhs_type :: TcTyMode -> LHsType GhcRn -> TcKind -> TcM TcType
tc_check_lhs_type :: TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode (L SrcSpanAnnA
span HsType GhcRn
ty) Type
exp_kind
= SrcSpanAnnA -> TcM Type -> TcM Type
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
span (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_check_hs_type TcTyMode
mode HsType GhcRn
ty Type
exp_kind
tc_check_hs_type :: TcTyMode -> HsType GhcRn -> TcKind -> TcM TcType
tc_check_hs_type :: TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_check_hs_type TcTyMode
mode HsType GhcRn
ty Type
ek = TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tcHsType TcTyMode
mode HsType GhcRn
ty (Type -> ExpSigmaType
Check Type
ek)
tcLHsType :: TcTyMode -> LHsType GhcRn -> ExpKind -> TcM TcType
tcLHsType :: TcTyMode -> LHsType GhcRn -> ExpSigmaType -> TcM Type
tcLHsType TcTyMode
mode (L SrcSpanAnnA
span HsType GhcRn
ty) ExpSigmaType
exp_kind
= SrcSpanAnnA -> TcM Type -> TcM Type
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
span (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tcHsType TcTyMode
mode HsType GhcRn
ty ExpSigmaType
exp_kind
tcHsType :: TcTyMode -> HsType GhcRn -> ExpKind -> TcM TcType
tcHsType :: TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tcHsType TcTyMode
mode (HsParTy XParTy GhcRn
_ LHsType GhcRn
ty) ExpSigmaType
exp_kind = TcTyMode -> LHsType GhcRn -> ExpSigmaType -> TcM Type
tcLHsType TcTyMode
mode LHsType GhcRn
ty ExpSigmaType
exp_kind
tcHsType TcTyMode
mode (HsDocTy XDocTy GhcRn
_ LHsType GhcRn
ty LHsDoc GhcRn
_) ExpSigmaType
exp_kind = TcTyMode -> LHsType GhcRn -> ExpSigmaType -> TcM Type
tcLHsType TcTyMode
mode LHsType GhcRn
ty ExpSigmaType
exp_kind
tcHsType TcTyMode
_ ty :: HsType GhcRn
ty@(HsBangTy XBangTy GhcRn
_ HsBang
bang LHsType GhcRn
_) ExpSigmaType
_
= TcRnMessage -> TcM Type
forall a. TcRnMessage -> TcM a
failWith (TcRnMessage -> TcM Type) -> TcRnMessage -> TcM Type
forall a b. (a -> b) -> a -> b
$ HsType GhcRn -> HsBang -> TcRnMessage
TcRnUnexpectedAnnotation HsType GhcRn
ty HsBang
bang
tcHsType TcTyMode
_ ty :: HsType GhcRn
ty@(HsRecTy {}) ExpSigmaType
_
= TcRnMessage -> TcM Type
forall a. TcRnMessage -> TcM a
failWithTc (TcRnMessage -> TcM Type) -> TcRnMessage -> TcM Type
forall a b. (a -> b) -> a -> b
$ Either (HsType GhcPs) (HsType GhcRn) -> TcRnMessage
TcRnIllegalRecordSyntax (HsType GhcRn -> Either (HsType GhcPs) (HsType GhcRn)
forall a b. b -> Either a b
Right HsType GhcRn
ty)
tcHsType TcTyMode
mode (HsSpliceTy (HsUntypedSpliceTop ThModFinalizers
mod_finalizers GenLocated SrcSpanAnnA (HsType GhcRn)
ty) HsUntypedSplice GhcRn
_)
ExpSigmaType
exp_kind
= do ThModFinalizers -> TcM ()
addModFinalizersWithLclEnv ThModFinalizers
mod_finalizers
TcTyMode -> LHsType GhcRn -> ExpSigmaType -> TcM Type
tcLHsType TcTyMode
mode LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty ExpSigmaType
exp_kind
tcHsType TcTyMode
_ (HsSpliceTy (HsUntypedSpliceNested Name
n) HsUntypedSplice GhcRn
s) ExpSigmaType
_ = String -> SDoc -> TcM Type
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcHsType: invalid nested splice" (Bool -> Maybe Name -> HsUntypedSplice GhcRn -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Bool -> Maybe Name -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
True (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n) HsUntypedSplice GhcRn
s)
tcHsType TcTyMode
mode (HsFunTy XFunTy GhcRn
_ HsArrow GhcRn
mult LHsType GhcRn
ty1 LHsType GhcRn
ty2) ExpSigmaType
exp_kind
= TcTyMode
-> HsArrow GhcRn
-> LHsType GhcRn
-> LHsType GhcRn
-> ExpSigmaType
-> TcM Type
tc_fun_type TcTyMode
mode HsArrow GhcRn
mult LHsType GhcRn
ty1 LHsType GhcRn
ty2 ExpSigmaType
exp_kind
tcHsType TcTyMode
mode (HsOpTy XOpTy GhcRn
_ PromotionFlag
_ LHsType GhcRn
ty1 (L SrcSpanAnnN
_ Name
op) LHsType GhcRn
ty2) ExpSigmaType
exp_kind
| Name
op Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
unrestrictedFunTyConKey
= TcTyMode
-> HsArrow GhcRn
-> LHsType GhcRn
-> LHsType GhcRn
-> ExpSigmaType
-> TcM Type
tc_fun_type TcTyMode
mode (XUnrestrictedArrow (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
-> HsArrowOf (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
forall mult pass.
XUnrestrictedArrow mult pass -> HsArrowOf mult pass
HsUnrestrictedArrow NoExtField
XUnrestrictedArrow (GenLocated SrcSpanAnnA (HsType GhcRn)) GhcRn
noExtField) LHsType GhcRn
ty1 LHsType GhcRn
ty2 ExpSigmaType
exp_kind
tcHsType TcTyMode
mode t :: HsType GhcRn
t@(HsForAllTy { hst_tele :: forall pass. HsType pass -> HsForAllTelescope pass
hst_tele = HsForAllTelescope GhcRn
tele, hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsType GhcRn
ty }) ExpSigmaType
exp_kind
| HsForAllInvis{} <- HsForAllTelescope GhcRn
tele
= HsForAllTelescope GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> ExpSigmaType
-> TcM Type
tc_hs_forall_ty HsForAllTelescope GhcRn
tele LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty ExpSigmaType
exp_kind
| HsForAllVis{} <- HsForAllTelescope GhcRn
tele
= do { ek <- TcM Type
newOpenTypeKind
; r <- tc_hs_forall_ty tele ty (Check ek)
; checkExpKind t r ek exp_kind }
where
tc_hs_forall_ty :: HsForAllTelescope GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> ExpSigmaType
-> TcM Type
tc_hs_forall_ty HsForAllTelescope GhcRn
tele GenLocated SrcSpanAnnA (HsType GhcRn)
ty ExpSigmaType
ek
= do { (tv_bndrs, ty') <- TcTyMode
-> HsForAllTelescope GhcRn
-> TcM Type
-> TcM ([TcTyVarBinder], Type)
forall a.
TcTyMode
-> HsForAllTelescope GhcRn -> TcM a -> TcM ([TcTyVarBinder], a)
tcTKTelescope TcTyMode
mode HsForAllTelescope GhcRn
tele (TcM Type -> TcM ([TcTyVarBinder], Type))
-> TcM Type -> TcM ([TcTyVarBinder], Type)
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsType GhcRn -> ExpSigmaType -> TcM Type
tcLHsType TcTyMode
mode LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty ExpSigmaType
ek
; return (mkForAllTys tv_bndrs ty') }
tcHsType TcTyMode
mode t :: HsType GhcRn
t@(HsQualTy { hst_ctxt :: forall pass. HsType pass -> LHsContext pass
hst_ctxt = LHsContext GhcRn
ctxt, hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsType GhcRn
rn_ty }) ExpSigmaType
exp_kind
| [GenLocated SrcSpanAnnA (HsType GhcRn)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall l e. GenLocated l e -> e
unLoc LHsContext GhcRn
GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
ctxt)
= TcTyMode -> LHsType GhcRn -> ExpSigmaType -> TcM Type
tcLHsType TcTyMode
mode LHsType GhcRn
rn_ty ExpSigmaType
exp_kind
| Check Type
kind <- ExpSigmaType
exp_kind
, Type -> Bool
isConstraintLikeKind Type
kind
= do { ctxt' <- TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
mode LHsContext GhcRn
ctxt
; ty' <- tc_check_lhs_type mode rn_ty constraintKind
; let res_ty = [Type] -> Type -> Type
HasDebugCallStack => [Type] -> Type -> Type
tcMkDFunPhiTy [Type]
ctxt' Type
ty'
; checkExpKind t res_ty constraintKind exp_kind }
| Bool
otherwise
= do { ctxt' <- TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
mode LHsContext GhcRn
ctxt
; ek <- newOpenTypeKind
; ty' <- tc_check_lhs_type mode rn_ty ek
; let res_ty = [Type] -> Type -> Type
HasDebugCallStack => [Type] -> Type -> Type
tcMkPhiTy [Type]
ctxt' Type
ty'
; checkExpKind t res_ty liftedTypeKind exp_kind }
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsListTy XListTy GhcRn
_ LHsType GhcRn
elt_ty) ExpSigmaType
exp_kind
= do { tau_ty <- TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
elt_ty Type
liftedTypeKind
; checkWiredInTyCon listTyCon
; checkExpKind rn_ty (mkListTy tau_ty) liftedTypeKind exp_kind }
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsTupleTy XTupleTy GhcRn
_ HsTupleSort
tup_sort [LHsType GhcRn]
tys) ExpSigmaType
exp_kind
= do k <- ExpSigmaType -> TcM Type
expTypeToType ExpSigmaType
exp_kind
tc_hs_tuple_ty rn_ty mode tup_sort tys k
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsSumTy XSumTy GhcRn
_ [LHsType GhcRn]
hs_tys) ExpSigmaType
exp_kind
= do { let arity :: Int
arity = [GenLocated SrcSpanAnnA (HsType GhcRn)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_tys
; arg_kinds <- (GenLocated SrcSpanAnnA (HsType GhcRn) -> TcM Type)
-> [GenLocated SrcSpanAnnA (HsType GhcRn)] -> TcM [Type]
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 (\GenLocated SrcSpanAnnA (HsType GhcRn)
_ -> TcM Type
newOpenTypeKind) [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_tys
; tau_tys <- zipWithM (tc_check_lhs_type mode) hs_tys arg_kinds
; let arg_reps = (Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
kindRep [Type]
arg_kinds
arg_tys = [Type]
arg_reps [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
tau_tys
sum_ty = TyCon -> [Type] -> Type
mkTyConApp (Int -> TyCon
sumTyCon Int
arity) [Type]
arg_tys
sum_kind = [Type] -> Type
unboxedSumKind [Type]
arg_reps
; checkExpKind rn_ty sum_ty sum_kind exp_kind
}
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
_ [LHsType GhcRn]
tys) ExpSigmaType
exp_kind
| [GenLocated SrcSpanAnnA (HsType GhcRn)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
= do let ty :: Type
ty = TyCon -> Type
mkTyConTy TyCon
promotedNilDataCon
let kind :: Type
kind = [TcTyVar] -> Type -> Type
mkSpecForAllTys [TcTyVar
alphaTyVar] (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type
mkListTy Type
alphaTy
HsType GhcRn -> Type -> Type -> ExpSigmaType -> TcM Type
checkExpKind HsType GhcRn
rn_ty Type
ty Type
kind ExpSigmaType
exp_kind
| Bool
otherwise
= do { tks <- (GenLocated SrcSpanAnnA (HsType GhcRn) -> TcM (Type, Type))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Type, Type)]
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 (TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode) [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
; (taus', kind) <- unifyKinds tys tks
; let ty = ((Type -> Type -> Type) -> Type -> [Type] -> Type
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Type -> Type -> Type -> Type
mk_cons Type
kind) (Type -> Type
mk_nil Type
kind) [Type]
taus')
; checkExpKind rn_ty ty (mkListTy kind) exp_kind }
where
mk_cons :: Type -> Type -> Type -> Type
mk_cons Type
k Type
a Type
b = TyCon -> [Type] -> Type
mkTyConApp (DataCon -> TyCon
promoteDataCon DataCon
consDataCon) [Type
k, Type
a, Type
b]
mk_nil :: Type -> Type
mk_nil Type
k = TyCon -> [Type] -> Type
mkTyConApp (DataCon -> TyCon
promoteDataCon DataCon
nilDataCon) [Type
k]
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsExplicitTupleTy XExplicitTupleTy GhcRn
_ PromotionFlag
_ [LHsType GhcRn]
tys) ExpSigmaType
exp_kind
= do { ks <- Int -> TcM Type -> TcM [Type]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
arity TcM Type
newMetaKindVar
; taus <- zipWithM (tc_check_lhs_type mode) tys ks
; let kind_con = Boxity -> Int -> TyCon
tupleTyCon Boxity
Boxed Int
arity
ty_con = Boxity -> Int -> TyCon
promotedTupleDataCon Boxity
Boxed Int
arity
tup_k = TyCon -> [Type] -> Type
mkTyConApp TyCon
kind_con [Type]
ks
; checkTupSize arity
; checkExpKind rn_ty (mkTyConApp ty_con (ks ++ taus)) tup_k exp_kind }
where
arity :: Int
arity = [GenLocated SrcSpanAnnA (HsType GhcRn)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsIParamTy XIParamTy GhcRn
_ (L EpAnnCO
_ HsIPName
n) LHsType GhcRn
ty) ExpSigmaType
exp_kind
= do { Bool -> TcM ()
forall (m :: * -> *). (HasCallStack, Applicative m) => Bool -> m ()
massert (TypeOrKind -> Bool
isTypeLevel (TcTyMode -> TypeOrKind
mode_tyki TcTyMode
mode))
; ty' <- TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
ty Type
liftedTypeKind
; let n' = FastString -> Type
mkStrLitTy (FastString -> Type) -> FastString -> Type
forall a b. (a -> b) -> a -> b
$ HsIPName -> FastString
hsIPNameFS HsIPName
n
; ipClass <- tcLookupClass ipClassName
; checkExpKind rn_ty (mkClassPred ipClass [n',ty'])
constraintKind exp_kind }
tcHsType TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsStarTy XStarTy GhcRn
_ Bool
_) ExpSigmaType
exp_kind
= HsType GhcRn -> Type -> Type -> ExpSigmaType -> TcM Type
checkExpKind HsType GhcRn
rn_ty Type
liftedTypeKind Type
liftedTypeKind ExpSigmaType
exp_kind
tcHsType TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsTyLit XTyLit GhcRn
_ (HsNumTy XNumTy GhcRn
_ Integer
n)) ExpSigmaType
exp_kind
= do { TyCon -> TcM ()
checkWiredInTyCon TyCon
naturalTyCon
; HsType GhcRn -> Type -> Type -> ExpSigmaType -> TcM Type
checkExpKind HsType GhcRn
rn_ty (Integer -> Type
mkNumLitTy Integer
n) Type
naturalTy ExpSigmaType
exp_kind }
tcHsType TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsTyLit XTyLit GhcRn
_ (HsStrTy XStrTy GhcRn
_ FastString
s)) ExpSigmaType
exp_kind
= do { TyCon -> TcM ()
checkWiredInTyCon TyCon
typeSymbolKindCon
; HsType GhcRn -> Type -> Type -> ExpSigmaType -> TcM Type
checkExpKind HsType GhcRn
rn_ty (FastString -> Type
mkStrLitTy FastString
s) Type
typeSymbolKind ExpSigmaType
exp_kind }
tcHsType TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsTyLit XTyLit GhcRn
_ (HsCharTy XCharTy GhcRn
_ Char
c)) ExpSigmaType
exp_kind
= do { TyCon -> TcM ()
checkWiredInTyCon TyCon
charTyCon
; HsType GhcRn -> Type -> Type -> ExpSigmaType -> TcM Type
checkExpKind HsType GhcRn
rn_ty (Char -> Type
mkCharLitTy Char
c) Type
charTy ExpSigmaType
exp_kind }
tcHsType TcTyMode
mode ty :: HsType GhcRn
ty@(HsWildCardTy XWildCardTy GhcRn
_) ExpSigmaType
ek
= do k <- ExpSigmaType -> TcM Type
expTypeToType ExpSigmaType
ek
tcAnonWildCardOcc NoExtraConstraint mode ty k
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsTyVar{}) ExpSigmaType
exp_kind = TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tc_app_ty TcTyMode
mode HsType GhcRn
rn_ty ExpSigmaType
exp_kind
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsAppTy{}) ExpSigmaType
exp_kind = TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tc_app_ty TcTyMode
mode HsType GhcRn
rn_ty ExpSigmaType
exp_kind
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsAppKindTy{}) ExpSigmaType
exp_kind = TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tc_app_ty TcTyMode
mode HsType GhcRn
rn_ty ExpSigmaType
exp_kind
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsOpTy{}) ExpSigmaType
exp_kind = TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tc_app_ty TcTyMode
mode HsType GhcRn
rn_ty ExpSigmaType
exp_kind
tcHsType TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsKindSig XKindSig GhcRn
_ LHsType GhcRn
ty LHsType GhcRn
sig) ExpSigmaType
exp_kind
= do { let mode' :: TcTyMode
mode' = TcTyMode
mode { mode_tyki = KindLevel }
; sig' <- TcTyMode -> UserTypeCtxt -> LHsType GhcRn -> TcM Type
tc_lhs_kind_sig TcTyMode
mode' UserTypeCtxt
KindSigCtxt LHsType GhcRn
sig
; traceTc "tcHsType:sig" (ppr ty $$ ppr sig')
; ty' <- tcAddKindSigPlaceholders sig $
tc_check_lhs_type mode ty sig'
; checkExpKind rn_ty ty' sig' exp_kind }
tcHsType TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(XHsType XXType GhcRn
ty) ExpSigmaType
exp_kind
= do env <- TcRnIf TcGblEnv TcLclEnv TcLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
let subst_prs :: [(Unique, TcTyVar)]
subst_prs = [ (Name -> Unique
forall a. Uniquable a => a -> Unique
getUnique Name
nm, TcTyVar
tv)
| ATyVar Name
nm TcTyVar
tv <- NameEnv TcTyThing -> [TcTyThing]
forall a. NameEnv a -> [a]
nonDetNameEnvElts (TcLclEnv -> NameEnv TcTyThing
getLclEnvTypeEnv TcLclEnv
env) ]
subst = InScopeSet -> TvSubstEnv -> Subst
mkTvSubst
([TcTyVar] -> InScopeSet
mkInScopeSetList ([TcTyVar] -> InScopeSet) -> [TcTyVar] -> InScopeSet
forall a b. (a -> b) -> a -> b
$ ((Unique, TcTyVar) -> TcTyVar) -> [(Unique, TcTyVar)] -> [TcTyVar]
forall a b. (a -> b) -> [a] -> [b]
map (Unique, TcTyVar) -> TcTyVar
forall a b. (a, b) -> b
snd [(Unique, TcTyVar)]
subst_prs)
([(Unique, Type)] -> TvSubstEnv
forall {k} elt (key :: k). [(Unique, elt)] -> UniqFM key elt
listToUFM_Directly ([(Unique, Type)] -> TvSubstEnv) -> [(Unique, Type)] -> TvSubstEnv
forall a b. (a -> b) -> a -> b
$ ((Unique, TcTyVar) -> (Unique, Type))
-> [(Unique, TcTyVar)] -> [(Unique, Type)]
forall a b. (a -> b) -> [a] -> [b]
map ((TcTyVar -> Type) -> (Unique, TcTyVar) -> (Unique, Type)
forall a b. (a -> b) -> (Unique, a) -> (Unique, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TcTyVar -> Type
mkTyVarTy) [(Unique, TcTyVar)]
subst_prs)
ty' = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst XXType GhcRn
Type
ty
checkExpKind rn_ty ty' (typeKind ty') exp_kind
tc_hs_tuple_ty :: HsType GhcRn
-> TcTyMode
-> HsTupleSort
-> [LHsType GhcRn]
-> TcKind
-> TcM TcType
tc_hs_tuple_ty :: HsType GhcRn
-> TcTyMode -> HsTupleSort -> [LHsType GhcRn] -> Type -> TcM Type
tc_hs_tuple_ty HsType GhcRn
rn_ty TcTyMode
mode HsTupleSort
HsBoxedOrConstraintTuple [LHsType GhcRn]
hs_tys Type
exp_kind
| Just TupleSort
tup_sort <- Type -> Maybe TupleSort
tupKindSort_maybe Type
exp_kind
= String -> SDoc -> TcM ()
traceTc String
"tcHsType tuple" ([GenLocated SrcSpanAnnA (HsType GhcRn)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_tys) TcM () -> TcM Type -> TcM Type
forall a b.
IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) b
-> IOEnv (Env TcGblEnv TcLclEnv) b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
HsType GhcRn
-> TcTyMode -> TupleSort -> [LHsType GhcRn] -> Type -> TcM Type
tc_tuple HsType GhcRn
rn_ty TcTyMode
mode TupleSort
tup_sort [LHsType GhcRn]
hs_tys Type
exp_kind
| Bool
otherwise
= do { String -> SDoc -> TcM ()
traceTc String
"tcHsType tuple 2" ([GenLocated SrcSpanAnnA (HsType GhcRn)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_tys)
; (tys, kinds) <- (GenLocated SrcSpanAnnA (HsType GhcRn) -> TcM (Type, Type))
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([Type], [Type])
forall (m :: * -> *) a b c.
Applicative m =>
(a -> m (b, c)) -> [a] -> m ([b], [c])
mapAndUnzipM (TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode) [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_tys
; kinds <- liftZonkM $ mapM zonkTcType kinds
; let (arg_kind, tup_sort)
= case [ (k,s) | k <- kinds
, Just s <- [tupKindSort_maybe k] ] of
((Type
k,TupleSort
s) : [(Type, TupleSort)]
_) -> (Type
k,TupleSort
s)
[] -> (Type
liftedTypeKind, TupleSort
BoxedTuple)
; tys' <- sequence [ setSrcSpanA loc $
checkExpectedKind hs_ty ty kind arg_kind
| ((L loc hs_ty),ty,kind) <- zip3 hs_tys tys kinds ]
; finish_tuple rn_ty tup_sort tys' (map (const arg_kind) tys') exp_kind }
tc_hs_tuple_ty HsType GhcRn
rn_ty TcTyMode
mode HsTupleSort
HsUnboxedTuple [LHsType GhcRn]
tys Type
exp_kind =
HsType GhcRn
-> TcTyMode -> TupleSort -> [LHsType GhcRn] -> Type -> TcM Type
tc_tuple HsType GhcRn
rn_ty TcTyMode
mode TupleSort
UnboxedTuple [LHsType GhcRn]
tys Type
exp_kind
tc_mult :: TcTyMode -> HsArrow GhcRn -> TcM Mult
tc_mult :: TcTyMode -> HsArrow GhcRn -> TcM Type
tc_mult TcTyMode
mode HsArrow GhcRn
ty = TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode (HsArrow GhcRn -> LHsType GhcRn
arrowToHsType HsArrow GhcRn
ty) Type
multiplicityTy
tc_fun_type :: TcTyMode -> HsArrow GhcRn -> LHsType GhcRn -> LHsType GhcRn -> ExpKind
-> TcM TcType
tc_fun_type :: TcTyMode
-> HsArrow GhcRn
-> LHsType GhcRn
-> LHsType GhcRn
-> ExpSigmaType
-> TcM Type
tc_fun_type TcTyMode
mode HsArrow GhcRn
mult LHsType GhcRn
ty1 LHsType GhcRn
ty2 ExpSigmaType
exp_kind = case TcTyMode -> TypeOrKind
mode_tyki TcTyMode
mode of
TypeOrKind
TypeLevel ->
do { String -> SDoc -> TcM ()
traceTc String
"tc_fun_type" (GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty1 SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
ty2)
; arg_k <- TcM Type
newOpenTypeKind
; res_k <- newOpenTypeKind
; ty1' <- tc_check_lhs_type mode ty1 arg_k
; ty2' <- tc_check_lhs_type mode ty2 res_k
; mult' <- tc_mult mode mult
; checkExpKind (HsFunTy noExtField mult ty1 ty2)
(tcMkVisFunTy mult' ty1' ty2')
liftedTypeKind exp_kind }
TypeOrKind
KindLevel ->
do { ty1' <- TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
ty1 Type
liftedTypeKind
; ty2' <- tc_check_lhs_type mode ty2 liftedTypeKind
; mult' <- tc_mult mode mult
; checkExpKind (HsFunTy noExtField mult ty1 ty2)
(tcMkVisFunTy mult' ty1' ty2')
liftedTypeKind exp_kind }
tupKindSort_maybe :: TcKind -> Maybe TupleSort
tupKindSort_maybe :: Type -> Maybe TupleSort
tupKindSort_maybe Type
k
| Just (Type
k', Coercion
_) <- Type -> Maybe (Type, Coercion)
splitCastTy_maybe Type
k = Type -> Maybe TupleSort
tupKindSort_maybe Type
k'
| Just Type
k' <- Type -> Maybe Type
coreView Type
k = Type -> Maybe TupleSort
tupKindSort_maybe Type
k'
| Type -> Bool
isConstraintKind Type
k = TupleSort -> Maybe TupleSort
forall a. a -> Maybe a
Just TupleSort
ConstraintTuple
| Type -> Bool
tcIsLiftedTypeKind Type
k = TupleSort -> Maybe TupleSort
forall a. a -> Maybe a
Just TupleSort
BoxedTuple
| Bool
otherwise = Maybe TupleSort
forall a. Maybe a
Nothing
tc_tuple :: HsType GhcRn -> TcTyMode -> TupleSort -> [LHsType GhcRn] -> TcKind -> TcM TcType
tc_tuple :: HsType GhcRn
-> TcTyMode -> TupleSort -> [LHsType GhcRn] -> Type -> TcM Type
tc_tuple HsType GhcRn
rn_ty TcTyMode
mode TupleSort
tup_sort [LHsType GhcRn]
tys Type
exp_kind
= do { arg_kinds <- case TupleSort
tup_sort of
TupleSort
BoxedTuple -> [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Type -> [Type]
forall a. Int -> a -> [a]
replicate Int
arity Type
liftedTypeKind)
TupleSort
UnboxedTuple -> Int -> TcM Type -> TcM [Type]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
arity TcM Type
newOpenTypeKind
TupleSort
ConstraintTuple -> [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Type -> [Type]
forall a. Int -> a -> [a]
replicate Int
arity Type
constraintKind)
; tau_tys <- zipWithM (tc_check_lhs_type mode) tys arg_kinds
; finish_tuple rn_ty tup_sort tau_tys arg_kinds exp_kind }
where
arity :: Int
arity = [GenLocated SrcSpanAnnA (HsType GhcRn)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcRn]
[GenLocated SrcSpanAnnA (HsType GhcRn)]
tys
finish_tuple :: HsType GhcRn
-> TupleSort
-> [TcType]
-> [TcKind]
-> TcKind
-> TcM TcType
finish_tuple :: HsType GhcRn -> TupleSort -> [Type] -> [Type] -> Type -> TcM Type
finish_tuple HsType GhcRn
rn_ty TupleSort
tup_sort [Type]
tau_tys [Type]
tau_kinds Type
exp_kind = do
String -> SDoc -> TcM ()
traceTc String
"finish_tuple" (TupleSort -> SDoc
forall a. Outputable a => a -> SDoc
ppr TupleSort
tup_sort SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
tau_kinds SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
exp_kind)
case TupleSort
tup_sort of
TupleSort
ConstraintTuple
| [Type
tau_ty] <- [Type]
tau_tys
-> Type -> Type -> TcM Type
check_expected_kind Type
tau_ty Type
constraintKind
| Bool
otherwise
-> do let tycon :: TyCon
tycon = Int -> TyCon
cTupleTyCon Int
arity
Int -> TcM ()
checkCTupSize Int
arity
Type -> Type -> TcM Type
check_expected_kind (TyCon -> [Type] -> Type
mkTyConApp TyCon
tycon [Type]
tau_tys) Type
constraintKind
TupleSort
BoxedTuple -> do
let tycon :: TyCon
tycon = Boxity -> Int -> TyCon
tupleTyCon Boxity
Boxed Int
arity
Int -> TcM ()
checkTupSize Int
arity
TyCon -> TcM ()
checkWiredInTyCon TyCon
tycon
Type -> Type -> TcM Type
check_expected_kind (TyCon -> [Type] -> Type
mkTyConApp TyCon
tycon [Type]
tau_tys) Type
liftedTypeKind
TupleSort
UnboxedTuple -> do
let tycon :: TyCon
tycon = Boxity -> Int -> TyCon
tupleTyCon Boxity
Unboxed Int
arity
tau_reps :: [Type]
tau_reps = (Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
kindRep [Type]
tau_kinds
arg_tys :: [Type]
arg_tys = [Type]
tau_reps [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
tau_tys
res_kind :: Type
res_kind = [Type] -> Type
unboxedTupleKind [Type]
tau_reps
Int -> TcM ()
checkTupSize Int
arity
Type -> Type -> TcM Type
check_expected_kind (TyCon -> [Type] -> Type
mkTyConApp TyCon
tycon [Type]
arg_tys) Type
res_kind
where
arity :: Int
arity = [Type] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Type]
tau_tys
check_expected_kind :: Type -> Type -> TcM Type
check_expected_kind Type
ty Type
act_kind =
HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
checkExpectedKind HsType GhcRn
rn_ty Type
ty Type
act_kind Type
exp_kind
splitHsAppTys_maybe :: HsType GhcRn -> Maybe (LHsType GhcRn, [LHsTypeArg GhcRn])
splitHsAppTys_maybe :: HsType GhcRn -> Maybe (LHsType GhcRn, HsFamEqnPats GhcRn)
splitHsAppTys_maybe HsType GhcRn
hs_ty
| HsType GhcRn -> Bool
is_app HsType GhcRn
hs_ty = (GenLocated SrcSpanAnnA (HsType GhcRn),
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))])
-> Maybe
(GenLocated SrcSpanAnnA (HsType GhcRn),
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))])
forall a. a -> Maybe a
Just (HsType GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
splitHsAppTys HsType GhcRn
hs_ty)
| Bool
otherwise = Maybe (LHsType GhcRn, HsFamEqnPats GhcRn)
Maybe
(GenLocated SrcSpanAnnA (HsType GhcRn),
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))])
forall a. Maybe a
Nothing
where
is_app :: HsType GhcRn -> Bool
is_app :: HsType GhcRn -> Bool
is_app (HsAppKindTy {}) = Bool
True
is_app (HsAppTy {}) = Bool
True
is_app (HsOpTy XOpTy GhcRn
_ PromotionFlag
_ LHsType GhcRn
_ (L SrcSpanAnnN
_ Name
op) LHsType GhcRn
_) = Bool -> Bool
not (Name
op Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
unrestrictedFunTyConKey)
is_app (HsTyVar {}) = Bool
True
is_app (HsParTy XParTy GhcRn
_ (L SrcSpanAnnA
_ HsType GhcRn
ty)) = HsType GhcRn -> Bool
is_app HsType GhcRn
ty
is_app HsType GhcRn
_ = Bool
False
splitHsAppTys :: HsType GhcRn -> (LHsType GhcRn, [LHsTypeArg GhcRn])
splitHsAppTys :: HsType GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
splitHsAppTys HsType GhcRn
hs_ty = LHsType GhcRn
-> HsFamEqnPats GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
go (HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall e a. HasAnnotation e => a -> GenLocated e a
noLocA HsType GhcRn
hs_ty) []
where
go :: LHsType GhcRn
-> [HsArg GhcRn (LHsType GhcRn) (LHsKind GhcRn)]
-> (LHsType GhcRn,
[HsArg GhcRn (LHsType GhcRn) (LHsKind GhcRn)])
go :: LHsType GhcRn
-> HsFamEqnPats GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
go (L SrcSpanAnnA
_ (HsAppTy XAppTy GhcRn
_ LHsType GhcRn
f LHsType GhcRn
a)) HsFamEqnPats GhcRn
as = LHsType GhcRn
-> HsFamEqnPats GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
go LHsType GhcRn
f (XValArg GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall p tm ty. XValArg p -> tm -> HsArg p tm ty
HsValArg NoExtField
XValArg GhcRn
noExtField LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
a HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
forall a. a -> [a] -> [a]
: HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
as)
go (L SrcSpanAnnA
_ (HsAppKindTy XAppKindTy GhcRn
_ LHsType GhcRn
ty LHsType GhcRn
k)) HsFamEqnPats GhcRn
as = LHsType GhcRn
-> HsFamEqnPats GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
go LHsType GhcRn
ty (XTypeArg GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall p tm ty. XTypeArg p -> ty -> HsArg p tm ty
HsTypeArg NoExtField
XTypeArg GhcRn
noExtField LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
k HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
forall a. a -> [a] -> [a]
: HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
as)
go (L SrcSpanAnnA
sp (HsParTy XParTy GhcRn
_ LHsType GhcRn
f)) HsFamEqnPats GhcRn
as = LHsType GhcRn
-> HsFamEqnPats GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
go LHsType GhcRn
f (XArgPar GhcRn
-> HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall p tm ty. XArgPar p -> HsArg p tm ty
HsArgPar (SrcSpanAnnA -> SrcSpan
forall a. HasLoc a => a -> SrcSpan
locA SrcSpanAnnA
sp) HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
forall a. a -> [a] -> [a]
: HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
as)
go (L SrcSpanAnnA
_ (HsOpTy XOpTy GhcRn
_ PromotionFlag
prom LHsType GhcRn
l op :: LIdP GhcRn
op@(L SrcSpanAnnN
sp Name
_) LHsType GhcRn
r)) HsFamEqnPats GhcRn
as
= ( SrcSpanAnnA
-> HsType GhcRn -> GenLocated SrcSpanAnnA (HsType GhcRn)
forall l e. l -> e -> GenLocated l e
L (SrcSpanAnnN -> SrcSpanAnnA
forall a b. (HasLoc a, HasAnnotation b) => a -> b
l2l SrcSpanAnnN
sp) (XTyVar GhcRn -> PromotionFlag -> LIdP GhcRn -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar XTyVar GhcRn
EpToken "'"
forall a. NoAnn a => a
noAnn PromotionFlag
prom LIdP GhcRn
op)
, XValArg GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall p tm ty. XValArg p -> tm -> HsArg p tm ty
HsValArg NoExtField
XValArg GhcRn
noExtField LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
l HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
forall a. a -> [a] -> [a]
: XValArg GhcRn
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
forall p tm ty. XValArg p -> tm -> HsArg p tm ty
HsValArg NoExtField
XValArg GhcRn
noExtField LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
r HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
forall a. a -> [a] -> [a]
: HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
as )
go LHsType GhcRn
f HsFamEqnPats GhcRn
as = (LHsType GhcRn
f, HsFamEqnPats GhcRn
as)
tcInferTyAppHead :: TcTyMode -> LHsType GhcRn -> TcM (TcType, TcKind)
tcInferTyAppHead :: TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tcInferTyAppHead TcTyMode
_ (L SrcSpanAnnA
_ (HsTyVar XTyVar GhcRn
_ PromotionFlag
_ (L SrcSpanAnnN
_ Name
tv)))
= Name -> TcM (Type, Type)
tcTyVar Name
tv
tcInferTyAppHead TcTyMode
mode LHsType GhcRn
ty
= TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode LHsType GhcRn
ty
tc_app_ty :: TcTyMode -> HsType GhcRn -> ExpKind -> TcM TcType
tc_app_ty :: TcTyMode -> HsType GhcRn -> ExpSigmaType -> TcM Type
tc_app_ty TcTyMode
mode HsType GhcRn
rn_ty ExpSigmaType
exp_kind
= do { (fun_ty, _ki) <- TcTyMode -> LHsType GhcRn -> TcM (Type, Type)
tcInferTyAppHead TcTyMode
mode LHsType GhcRn
hs_fun_ty
; (ty, infered_kind) <- tcInferTyApps mode hs_fun_ty fun_ty hs_args
; checkExpKind rn_ty ty infered_kind exp_kind }
where
(LHsType GhcRn
hs_fun_ty, HsFamEqnPats GhcRn
hs_args) = HsType GhcRn -> (LHsType GhcRn, HsFamEqnPats GhcRn)
splitHsAppTys HsType GhcRn
rn_ty
tcInferTyApps, tcInferTyApps_nosat
:: TcTyMode
-> LHsType GhcRn
-> TcType
-> [LHsTypeArg GhcRn]
-> TcM (TcType, TcKind)
tcInferTyApps :: TcTyMode
-> LHsType GhcRn -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
tcInferTyApps TcTyMode
mode LHsType GhcRn
hs_ty Type
fun HsFamEqnPats GhcRn
hs_args
= do { (f_args, res_k) <- TcTyMode
-> LHsType GhcRn -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
tcInferTyApps_nosat TcTyMode
mode LHsType GhcRn
hs_ty Type
fun HsFamEqnPats GhcRn
hs_args
; saturateFamApp f_args res_k }
tcInferTyApps_nosat :: TcTyMode
-> LHsType GhcRn -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
tcInferTyApps_nosat TcTyMode
mode LHsType GhcRn
orig_hs_ty Type
fun HsFamEqnPats GhcRn
orig_hs_args
= do { String -> SDoc -> TcM ()
traceTc String
"tcInferTyApps {" (GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
orig_hs_ty SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> SDoc
forall a. Outputable a => a -> SDoc
ppr HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
orig_hs_args)
; (f_args, res_k) <- Int
-> Type
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> TcM (Type, Type)
go_init Int
1 Type
fun HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
orig_hs_args
; traceTc "tcInferTyApps }" (ppr f_args <+> dcolon <+> ppr res_k)
; return (f_args, res_k) }
where
go_init :: Int
-> Type
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> TcM (Type, Type)
go_init Int
n Type
fun [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
all_args
= Int
-> Type -> Subst -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
go Int
n Type
fun Subst
empty_subst Type
fun_ki HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
all_args
where
fun_ki :: Type
fun_ki = HasDebugCallStack => Type -> Type
Type -> Type
typeKind Type
fun
empty_subst :: Subst
empty_subst = InScopeSet -> Subst
mkEmptySubst (InScopeSet -> Subst) -> InScopeSet -> Subst
forall a b. (a -> b) -> a -> b
$ TyVarSet -> InScopeSet
mkInScopeSet (TyVarSet -> InScopeSet) -> TyVarSet -> InScopeSet
forall a b. (a -> b) -> a -> b
$
Type -> TyVarSet
tyCoVarsOfType Type
fun_ki
go :: Int
-> TcType
-> Subst
-> TcKind
-> [LHsTypeArg GhcRn]
-> TcM (TcType, TcKind)
go :: Int
-> Type -> Subst -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
go Int
n Type
fun Subst
subst Type
fun_ki HsFamEqnPats GhcRn
all_args = case (HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
all_args, Type -> Maybe (PiTyVarBinder, Type)
tcSplitPiTy_maybe Type
fun_ki) of
([], Maybe (PiTyVarBinder, Type)
_) -> (Type, Type) -> TcM (Type, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
fun, HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
fun_ki)
(HsArgPar XArgPar GhcRn
_ : [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
args, Maybe (PiTyVarBinder, Type)
_) -> Int
-> Type -> Subst -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
go Int
n Type
fun Subst
subst Type
fun_ki HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
args
(HsTypeArg XTypeArg GhcRn
_ GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ki_arg : [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
hs_args, Just (PiTyVarBinder
ki_binder, Type
inner_ki)) ->
case PiTyVarBinder
ki_binder of
Named (Bndr TcTyVar
kv ForAllTyFlag
Inferred) -> TcTyVar -> Type -> TcM (Type, Type)
instantiate TcTyVar
kv Type
inner_ki
Named (Bndr TcTyVar
_ ForAllTyFlag
Specified) ->
do { String -> SDoc -> TcM ()
traceTc String
"tcInferTyApps (vis kind app)"
([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ PiTyVarBinder -> SDoc
forall a. Outputable a => a -> SDoc
ppr PiTyVarBinder
ki_binder, GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ki_arg
, Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PiTyVarBinder -> Type
piTyBinderType PiTyVarBinder
ki_binder)
, Subst -> SDoc
forall a. Outputable a => a -> SDoc
ppr Subst
subst ])
; let exp_kind :: Type
exp_kind = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ PiTyVarBinder -> Type
piTyBinderType PiTyVarBinder
ki_binder
; arg_mode <- TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode TypeOrKind
KindLevel HoleMode
HM_VTA
; ki_arg <- addErrCtxt (funAppCtxt orig_hs_ty hs_ki_arg n) $
tc_check_lhs_type arg_mode hs_ki_arg exp_kind
; traceTc "tcInferTyApps (vis kind app)" (ppr exp_kind)
; (subst', fun') <- mkAppTyM subst fun ki_binder ki_arg
; go (n+1) fun' subst' inner_ki hs_args }
PiTyVarBinder
_ -> GenLocated SrcSpanAnnA (HsType GhcRn) -> Type -> TcM (Type, Type)
forall {a}. GenLocated SrcSpanAnnA (HsType GhcRn) -> Type -> TcRn a
ty_app_err GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ki_arg (Type -> TcM (Type, Type)) -> Type -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
fun_ki
(HsTypeArg XTypeArg GhcRn
_ GenLocated SrcSpanAnnA (HsType GhcRn)
ki_arg : [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
_, Maybe (PiTyVarBinder, Type)
Nothing) -> TcM (Type, Type) -> TcM (Type, Type)
try_again_after_substing_or (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
GenLocated SrcSpanAnnA (HsType GhcRn) -> Type -> TcM (Type, Type)
forall {a}. GenLocated SrcSpanAnnA (HsType GhcRn) -> Type -> TcRn a
ty_app_err GenLocated SrcSpanAnnA (HsType GhcRn)
ki_arg Type
substed_fun_ki
(HsValArg XValArg GhcRn
_ GenLocated SrcSpanAnnA (HsType GhcRn)
arg : [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
args, Just (PiTyVarBinder
ki_binder, Type
inner_ki))
| Named (Bndr TcTyVar
kv ForAllTyFlag
flag) <- PiTyVarBinder
ki_binder
, ForAllTyFlag -> Bool
isInvisibleForAllTyFlag ForAllTyFlag
flag
-> TcTyVar -> Type -> TcM (Type, Type)
instantiate TcTyVar
kv Type
inner_ki
| Bool
otherwise
-> do { String -> SDoc -> TcM ()
traceTc String
"tcInferTyApps (vis normal app)"
([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ PiTyVarBinder -> SDoc
forall a. Outputable a => a -> SDoc
ppr PiTyVarBinder
ki_binder
, GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsType GhcRn)
arg
, Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PiTyVarBinder -> Type
piTyBinderType PiTyVarBinder
ki_binder)
, Subst -> SDoc
forall a. Outputable a => a -> SDoc
ppr Subst
subst ])
; let exp_kind :: Type
exp_kind = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ PiTyVarBinder -> Type
piTyBinderType PiTyVarBinder
ki_binder
; arg' <- SDoc -> TcM Type -> TcM Type
forall a. SDoc -> TcM a -> TcM a
addErrCtxt (GenLocated SrcSpanAnnA (HsType GhcRn)
-> GenLocated SrcSpanAnnA (HsType GhcRn) -> Int -> SDoc
forall fun arg.
(Outputable fun, Outputable arg) =>
fun -> arg -> Int -> SDoc
funAppCtxt LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
orig_hs_ty GenLocated SrcSpanAnnA (HsType GhcRn)
arg Int
n) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
arg Type
exp_kind
; traceTc "tcInferTyApps (vis normal app) 2" (ppr exp_kind)
; (subst', fun') <- mkAppTyM subst fun ki_binder arg'
; go (n+1) fun' subst' inner_ki args }
(HsValArg XValArg GhcRn
_ GenLocated SrcSpanAnnA (HsType GhcRn)
_ : [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
_, Maybe (PiTyVarBinder, Type)
Nothing)
-> TcM (Type, Type) -> TcM (Type, Type)
try_again_after_substing_or (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
do { let arrows_needed :: Int
arrows_needed = [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> Int
forall p tm ty. [HsArg p tm ty] -> Int
n_initial_val_args HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
all_args
; co <- TypedThing -> Int -> Type -> TcM Coercion
matchExpectedFunKind (HsType GhcRn -> TypedThing
HsTypeRnThing (HsType GhcRn -> TypedThing) -> HsType GhcRn -> TypedThing
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn
forall l e. GenLocated l e -> e
unLoc LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ty) Int
arrows_needed Type
substed_fun_ki
; fun' <- liftZonkM $ zonkTcType (fun `mkCastTy` co)
; traceTc "tcInferTyApps (no binder)" $
vcat [ ppr fun <+> dcolon <+> ppr fun_ki
, ppr arrows_needed
, ppr co
, ppr fun' <+> dcolon <+> ppr (typeKind fun')]
; go_init n fun' all_args }
where
instantiate :: TcTyVar -> Type -> TcM (Type, Type)
instantiate TcTyVar
ki_binder Type
inner_ki
= do { String -> SDoc -> TcM ()
traceTc String
"tcInferTyApps (need to instantiate)"
([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
ki_binder, Subst -> SDoc
forall a. Outputable a => a -> SDoc
ppr Subst
subst])
; (subst', arg') <- Subst -> TcTyVar -> TcM (Subst, Type)
tcInstInvisibleTyBinder Subst
subst TcTyVar
ki_binder
; go n (mkAppTy fun arg') subst' inner_ki all_args }
try_again_after_substing_or :: TcM (Type, Type) -> TcM (Type, Type)
try_again_after_substing_or TcM (Type, Type)
fallthrough
| Bool -> Bool
not (Subst -> Bool
isEmptyTCvSubst Subst
subst)
= Int
-> Type -> Subst -> Type -> HsFamEqnPats GhcRn -> TcM (Type, Type)
go Int
n Type
fun Subst
zapped_subst Type
substed_fun_ki HsFamEqnPats GhcRn
all_args
| Bool
otherwise
= TcM (Type, Type)
fallthrough
zapped_subst :: Subst
zapped_subst = Subst -> Subst
zapSubst Subst
subst
substed_fun_ki :: Type
substed_fun_ki = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
fun_ki
hs_ty :: LHsType GhcRn
hs_ty = LHsType GhcRn -> HsFamEqnPats GhcRn -> LHsType GhcRn
appTypeToArg LHsType GhcRn
orig_hs_ty (Int
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
-> [HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
forall a. Int -> [a] -> [a]
take (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) HsFamEqnPats GhcRn
[HsArg
GhcRn
(GenLocated SrcSpanAnnA (HsType GhcRn))
(GenLocated SrcSpanAnnA (HsType GhcRn))]
orig_hs_args)
n_initial_val_args :: [HsArg p tm ty] -> Arity
n_initial_val_args :: forall p tm ty. [HsArg p tm ty] -> Int
n_initial_val_args (HsValArg {} : [HsArg p tm ty]
args) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [HsArg p tm ty] -> Int
forall p tm ty. [HsArg p tm ty] -> Int
n_initial_val_args [HsArg p tm ty]
args
n_initial_val_args (HsArgPar {} : [HsArg p tm ty]
args) = [HsArg p tm ty] -> Int
forall p tm ty. [HsArg p tm ty] -> Int
n_initial_val_args [HsArg p tm ty]
args
n_initial_val_args [HsArg p tm ty]
_ = Int
0
ty_app_err :: GenLocated SrcSpanAnnA (HsType GhcRn) -> Type -> TcRn a
ty_app_err GenLocated SrcSpanAnnA (HsType GhcRn)
arg Type
ty
= TcRnMessage -> TcRn a
forall a. TcRnMessage -> TcM a
failWith (TcRnMessage -> TcRn a) -> TcRnMessage -> TcRn a
forall a b. (a -> b) -> a -> b
$ LHsType GhcRn -> Type -> TcRnMessage
TcRnInvalidVisibleKindArgument LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
arg Type
ty
mkAppTyM :: Subst
-> TcType -> PiTyBinder
-> TcType
-> TcM (Subst, TcType)
mkAppTyM :: Subst -> Type -> PiTyVarBinder -> Type -> TcM (Subst, Type)
mkAppTyM Subst
subst Type
fun PiTyVarBinder
ki_binder Type
arg
|
TyConApp TyCon
tc [Type]
args <- Type
fun
, TyCon -> Bool
isTypeSynonymTyCon TyCon
tc
, [Type]
args [Type] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthIs` (TyCon -> Int
tyConArity TyCon
tc Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
, (TcTyVar -> Bool) -> [TcTyVar] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any TcTyVar -> Bool
isTrickyTvBinder (TyCon -> [TcTyVar]
tyConTyVars TyCon
tc)
= do { (arg':args') <- ZonkM [Type] -> TcM [Type]
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM [Type] -> TcM [Type]) -> ZonkM [Type] -> TcM [Type]
forall a b. (a -> b) -> a -> b
$ [Type] -> ZonkM [Type]
zonkTcTypes (Type
argType -> [Type] -> [Type]
forall a. a -> [a] -> [a]
:[Type]
args)
; let subst' = case PiTyVarBinder
ki_binder of
Anon {} -> Subst
subst
Named (Bndr TcTyVar
tv ForAllTyFlag
_) -> Subst -> TcTyVar -> Type -> Subst
extendTvSubstAndInScope Subst
subst TcTyVar
tv Type
arg'
; return (subst', mkTyConApp tc (args' ++ [arg'])) }
mkAppTyM Subst
subst Type
fun (Anon {}) Type
arg
= (Subst, Type) -> TcM (Subst, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Subst
subst, Type -> Type -> Type
mk_app_ty Type
fun Type
arg)
mkAppTyM Subst
subst Type
fun (Named (Bndr TcTyVar
tv ForAllTyFlag
_)) Type
arg
= do { arg' <- if TcTyVar -> Bool
isTrickyTvBinder TcTyVar
tv
then
ZonkM Type -> TcM Type
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM Type -> TcM Type) -> ZonkM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$ Type -> ZonkM Type
zonkTcType Type
arg
else Type -> TcM Type
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Type
arg
; return ( extendTvSubstAndInScope subst tv arg'
, mk_app_ty fun arg' ) }
mk_app_ty :: TcType -> TcType -> TcType
mk_app_ty :: Type -> Type -> Type
mk_app_ty Type
fun Type
arg
= Bool -> SDoc -> Type -> Type
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Type -> Bool
isPiTy Type
fun_kind)
(Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
fun SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
fun_kind SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
arg) (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type -> Type -> Type
mkAppTy Type
fun Type
arg
where
fun_kind :: Type
fun_kind = HasDebugCallStack => Type -> Type
Type -> Type
typeKind Type
fun
isTrickyTvBinder :: TcTyVar -> Bool
isTrickyTvBinder :: TcTyVar -> Bool
isTrickyTvBinder TcTyVar
tv = Type -> Bool
isPiTy (TcTyVar -> Type
tyVarKind TcTyVar
tv)
saturateFamApp :: TcType -> TcKind -> TcM (TcType, TcKind)
saturateFamApp :: Type -> Type -> TcM (Type, Type)
saturateFamApp Type
ty Type
kind
| Just (TyCon
tc, [Type]
args) <- HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
tcSplitTyConApp_maybe Type
ty
, TyCon -> Bool
tyConMustBeSaturated TyCon
tc
, let n_to_inst :: Int
n_to_inst = TyCon -> Int
tyConArity TyCon
tc Int -> Int -> Int
forall a. Num a => a -> a -> a
- [Type] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Type]
args
= do { (extra_args, ki') <- Int -> Type -> TcM ([Type], Type)
tcInstInvisibleTyBindersN Int
n_to_inst Type
kind
; return (ty `mkAppTys` extra_args, ki') }
| Bool
otherwise
= (Type, Type) -> TcM (Type, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
ty, Type
kind)
appTypeToArg :: LHsType GhcRn -> [LHsTypeArg GhcRn] -> LHsType GhcRn
appTypeToArg :: LHsType GhcRn -> HsFamEqnPats GhcRn -> LHsType GhcRn
appTypeToArg LHsType GhcRn
f [] = LHsType GhcRn
f
appTypeToArg LHsType GhcRn
f (HsValArg XValArg GhcRn
_ LHsType GhcRn
arg : HsFamEqnPats GhcRn
args) = LHsType GhcRn -> HsFamEqnPats GhcRn -> LHsType GhcRn
appTypeToArg (LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
mkHsAppTy LHsType GhcRn
f LHsType GhcRn
arg) HsFamEqnPats GhcRn
args
appTypeToArg LHsType GhcRn
f (HsArgPar XArgPar GhcRn
_ : HsFamEqnPats GhcRn
args) = LHsType GhcRn -> HsFamEqnPats GhcRn -> LHsType GhcRn
appTypeToArg LHsType GhcRn
f HsFamEqnPats GhcRn
args
appTypeToArg LHsType GhcRn
f (HsTypeArg XTypeArg GhcRn
_ LHsType GhcRn
arg : HsFamEqnPats GhcRn
args)
= LHsType GhcRn -> HsFamEqnPats GhcRn -> LHsType GhcRn
appTypeToArg (XAppKindTy GhcRn -> LHsType GhcRn -> LHsType GhcRn -> LHsType GhcRn
forall (p :: Pass).
XAppKindTy (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
mkHsAppKindTy XAppKindTy GhcRn
NoExtField
noExtField LHsType GhcRn
f LHsType GhcRn
arg) HsFamEqnPats GhcRn
args
checkExpectedKind :: HasDebugCallStack
=> HsType GhcRn
-> TcType
-> TcKind
-> TcKind
-> TcM TcType
checkExpectedKind :: HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
checkExpectedKind HsType GhcRn
hs_ty Type
ty Type
act_kind Type
exp_kind
= do { String -> SDoc -> TcM ()
traceTc String
"checkExpectedKind" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
act_kind)
; (new_args, act_kind') <- Int -> Type -> TcM ([Type], Type)
tcInstInvisibleTyBindersN Int
n_to_inst Type
act_kind
; let origin = TypeEqOrigin { uo_actual :: Type
uo_actual = Type
act_kind'
, uo_expected :: Type
uo_expected = Type
exp_kind
, uo_thing :: Maybe TypedThing
uo_thing = TypedThing -> Maybe TypedThing
forall a. a -> Maybe a
Just (HsType GhcRn -> TypedThing
HsTypeRnThing HsType GhcRn
hs_ty)
, uo_visible :: Bool
uo_visible = Bool
True }
; traceTc "checkExpectedKindX" $
vcat [ ppr hs_ty
, text "act_kind':" <+> ppr act_kind'
, text "exp_kind:" <+> ppr exp_kind ]
; let res_ty = Type
ty Type -> [Type] -> Type
`mkAppTys` [Type]
new_args
; if act_kind' `tcEqType` exp_kind
then return res_ty
else do { co_k <- unifyTypeAndEmit KindLevel origin act_kind' exp_kind
; traceTc "checkExpectedKind" (vcat [ ppr act_kind
, ppr exp_kind
, ppr co_k ])
; return (res_ty `mkCastTy` co_k) } }
where
n_exp_invis_bndrs :: Int
n_exp_invis_bndrs = Type -> Int
invisibleTyBndrCount Type
exp_kind
n_act_invis_bndrs :: Int
n_act_invis_bndrs = Type -> Int
invisibleTyBndrCount Type
act_kind
n_to_inst :: Int
n_to_inst = Int
n_act_invis_bndrs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n_exp_invis_bndrs
checkExpKind :: HsType GhcRn -> TcType -> TcKind -> ExpKind -> TcM TcType
checkExpKind :: HsType GhcRn -> Type -> Type -> ExpSigmaType -> TcM Type
checkExpKind HsType GhcRn
rn_ty Type
ty Type
ki (Check Type
ki') =
HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
checkExpectedKind HsType GhcRn
rn_ty Type
ty Type
ki Type
ki'
checkExpKind HsType GhcRn
_rn_ty Type
ty Type
ki (Infer InferResult
cell) = do
co <- Type -> InferResult -> TcM Coercion
fillInferResult Type
ki InferResult
cell
pure (ty `mkCastTy` co)
tcHsContext :: Maybe (LHsContext GhcRn) -> TcM [PredType]
tcHsContext :: Maybe (LHsContext GhcRn) -> TcM [Type]
tcHsContext Maybe (LHsContext GhcRn)
Nothing = [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return []
tcHsContext (Just LHsContext GhcRn
cxt) = TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
typeLevelMode LHsContext GhcRn
cxt
tcLHsPredType :: LHsType GhcRn -> TcM PredType
tcLHsPredType :: LHsType GhcRn -> TcM Type
tcLHsPredType LHsType GhcRn
pred = TcTyMode -> LHsType GhcRn -> TcM Type
tc_lhs_pred TcTyMode
typeLevelMode LHsType GhcRn
pred
tc_hs_context :: TcTyMode -> LHsContext GhcRn -> TcM [PredType]
tc_hs_context :: TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
mode LHsContext GhcRn
ctxt = (GenLocated SrcSpanAnnA (HsType GhcRn) -> TcM Type)
-> [GenLocated SrcSpanAnnA (HsType GhcRn)] -> TcM [Type]
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 (TcTyMode -> LHsType GhcRn -> TcM Type
tc_lhs_pred TcTyMode
mode) (GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> [GenLocated SrcSpanAnnA (HsType GhcRn)]
forall l e. GenLocated l e -> e
unLoc LHsContext GhcRn
GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcRn)]
ctxt)
tc_lhs_pred :: TcTyMode -> LHsType GhcRn -> TcM PredType
tc_lhs_pred :: TcTyMode -> LHsType GhcRn -> TcM Type
tc_lhs_pred TcTyMode
mode LHsType GhcRn
pred = TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
pred Type
constraintKind
tcTyVar :: Name -> TcM (TcType, TcKind)
tcTyVar :: Name -> TcM (Type, Type)
tcTyVar Name
name
= do { String -> SDoc -> TcM ()
traceTc String
"lk1" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
; thing <- Name -> TcM TcTyThing
tcLookup Name
name
; case thing of
ATyVar Name
_ TcTyVar
tv -> (Type, Type) -> TcM (Type, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> Type
mkTyVarTy TcTyVar
tv, TcTyVar -> Type
tyVarKind TcTyVar
tv)
(TcTyThing -> Maybe TyCon
tcTyThingTyCon_maybe -> Just TyCon
tc)
-> (Type, Type) -> TcM (Type, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> Type
mkTyConTy TyCon
tc, TyCon -> Type
tyConKind TyCon
tc)
AGlobal (AConLike (RealDataCon DataCon
dc))
-> do { Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TyCon -> Bool
isFamInstTyCon (DataCon -> TyCon
dataConTyCon DataCon
dc)) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
Name -> PromotionErr -> TcM ()
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
FamDataConPE
; let ([TcTyVar]
_, [TcTyVar]
_, [EqSpec]
_, [Type]
theta, [Scaled Type]
_, Type
_) = DataCon
-> ([TcTyVar], [TcTyVar], [EqSpec], [Type], [Scaled Type], Type)
dataConFullSig DataCon
dc
; String -> SDoc -> TcM ()
traceTc String
"tcTyVar" (DataCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr DataCon
dc SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
theta)
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Type]
theta) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
Name -> PromotionErr -> TcM ()
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name ([Type] -> PromotionErr
ConstrainedDataConPE [Type]
theta)
; let tc :: TyCon
tc = DataCon -> TyCon
promoteDataCon DataCon
dc
; (Type, Type) -> TcM (Type, Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> [Type] -> Type
mkTyConApp TyCon
tc [], TyCon -> Type
tyConKind TyCon
tc) }
AGlobal AnId{} -> Name -> PromotionErr -> TcM (Type, Type)
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
TermVariablePE
ATcId{} -> Name -> PromotionErr -> TcM (Type, Type)
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
TermVariablePE
APromotionErr PromotionErr
err -> Name -> PromotionErr -> TcM (Type, Type)
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
err
TcTyThing
_ -> WrongThingSort -> TcTyThing -> Name -> TcM (Type, Type)
forall a. WrongThingSort -> TcTyThing -> Name -> TcM a
wrongThingErr WrongThingSort
WrongThingType TcTyThing
thing Name
name }
addTypeCtxt :: LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt :: forall a. LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt (L SrcSpanAnnA
_ (HsWildCardTy XWildCardTy GhcRn
_)) TcM a
thing = TcM a
thing
addTypeCtxt (L SrcSpanAnnA
_ HsType GhcRn
ty) TcM a
thing
= SDoc -> TcM a -> TcM a
forall a. SDoc -> TcM a -> TcM a
addErrCtxt SDoc
doc TcM a
thing
where
doc :: SDoc
doc = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (HsType GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsType GhcRn
ty)
bindNamedWildCardBinders :: [Name]
-> ([(Name, TcTyVar)] -> TcM a)
-> TcM a
bindNamedWildCardBinders :: forall a. HsQTvsRn -> ([(Name, TcTyVar)] -> TcM a) -> TcM a
bindNamedWildCardBinders HsQTvsRn
wc_names [(Name, TcTyVar)] -> TcM a
thing_inside
= do { wcs <- (Name -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> HsQTvsRn -> TcM [TcTyVar]
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 Name -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedWildTyVar HsQTvsRn
wc_names
; let wc_prs = HsQTvsRn
wc_names HsQTvsRn -> [TcTyVar] -> [(Name, TcTyVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TcTyVar]
wcs
; tcExtendNameTyVarEnv wc_prs $
thing_inside wc_prs }
newNamedWildTyVar :: Name -> TcM TcTyVar
newNamedWildTyVar :: Name -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedWildTyVar Name
_name
= do { kind <- TcM Type
newMetaKindVar
; details <- newMetaDetails TauTv
; wc_name <- newMetaTyVarName (fsLit "w")
; let tyvar = Name -> Type -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
wc_name Type
kind TcTyVarDetails
details
; traceTc "newWildTyVar" (ppr tyvar)
; return tyvar }
tcAnonWildCardOcc :: IsExtraConstraint
-> TcTyMode -> HsType GhcRn -> Kind -> TcM TcType
tcAnonWildCardOcc :: IsExtraConstraint -> TcTyMode -> HsType GhcRn -> Type -> TcM Type
tcAnonWildCardOcc IsExtraConstraint
is_extra (TcTyMode { mode_holes :: TcTyMode -> HoleInfo
mode_holes = Just (TcLevel
hole_lvl, HoleMode
hole_mode) })
HsType GhcRn
ty Type
exp_kind
= do { kv_details <- TcLevel -> TcM TcTyVarDetails
newTauTvDetailsAtLevel TcLevel
hole_lvl
; kv_name <- newMetaTyVarName (fsLit "k")
; wc_details <- newTauTvDetailsAtLevel hole_lvl
; wc_name <- newMetaTyVarName wc_nm
; let kv = Name -> Type -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
kv_name Type
liftedTypeKind TcTyVarDetails
kv_details
wc_kind = TcTyVar -> Type
mkTyVarTy TcTyVar
kv
wc_tv = Name -> Type -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
wc_name Type
wc_kind TcTyVarDetails
wc_details
; traceTc "tcAnonWildCardOcc" (ppr hole_lvl <+> ppr emit_holes)
; when emit_holes $
emitAnonTypeHole is_extra wc_tv
; checkExpectedKind ty (mkTyVarTy wc_tv) wc_kind exp_kind }
where
wc_nm :: FastString
wc_nm = case HoleMode
hole_mode of
HoleMode
HM_Sig -> String -> FastString
fsLit String
"w"
HoleMode
HM_FamPat -> String -> FastString
fsLit String
"_"
HoleMode
HM_VTA -> String -> FastString
fsLit String
"w"
HoleMode
HM_TyAppPat -> String -> FastString
fsLit String
"_"
emit_holes :: Bool
emit_holes = case HoleMode
hole_mode of
HoleMode
HM_Sig -> Bool
True
HoleMode
HM_FamPat -> Bool
False
HoleMode
HM_VTA -> Bool
False
HoleMode
HM_TyAppPat -> Bool
False
tcAnonWildCardOcc IsExtraConstraint
is_extra TcTyMode
_ HsType GhcRn
_ Type
_
= TcRnMessage -> TcM Type
forall a. TcRnMessage -> TcM a
failWith (TcRnMessage -> TcM Type) -> TcRnMessage -> TcM Type
forall a b. (a -> b) -> a -> b
$ Maybe Name -> BadAnonWildcardContext -> TcRnMessage
TcRnIllegalWildcardInType Maybe Name
forall a. Maybe a
Nothing BadAnonWildcardContext
reason
where
reason :: BadAnonWildcardContext
reason =
case IsExtraConstraint
is_extra of
IsExtraConstraint
YesExtraConstraint ->
SoleExtraConstraintWildcardAllowed -> BadAnonWildcardContext
ExtraConstraintWildcardNotAllowed
SoleExtraConstraintWildcardAllowed
SoleExtraConstraintWildcardNotAllowed
IsExtraConstraint
NoExtraConstraint ->
BadAnonWildcardContext
WildcardsNotAllowedAtAll
data InitialKindStrategy
= InitialKindCheck SAKS_or_CUSK
| InitialKindInfer
data SAKS_or_CUSK
= SAKS Kind
| CUSK
instance Outputable SAKS_or_CUSK where
ppr :: SAKS_or_CUSK -> SDoc
ppr (SAKS Type
k) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"SAKS" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
k
ppr SAKS_or_CUSK
CUSK = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"CUSK"
kcDeclHeader
:: InitialKindStrategy
-> Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TcTyCon
(InitialKindCheck SAKS_or_CUSK
msig) = SAKS_or_CUSK
-> Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TyCon
kcCheckDeclHeader SAKS_or_CUSK
msig
kcDeclHeader InitialKindStrategy
InitialKindInfer = Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TyCon
kcInferDeclHeader
kcCheckDeclHeader
:: SAKS_or_CUSK
-> Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM PolyTcTyCon
(SAKS Type
sig) = Type
-> Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TyCon
kcCheckDeclHeader_sig Type
sig
kcCheckDeclHeader SAKS_or_CUSK
CUSK = Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TyCon
kcCheckDeclHeader_cusk
kcCheckDeclHeader_cusk
:: Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM PolyTcTyCon
Name
name TyConFlavour TyCon
flav
(HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = XHsQTvs GhcRn
kv_ns
, hsq_explicit :: forall pass.
LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
hsq_explicit = [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_tvs }) TcM ContextKind
kc_res_ki
= Name -> TyConFlavour TyCon -> TcM TyCon -> TcM TyCon
forall tc a. Name -> TyConFlavour tc -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour TyCon
flav (TcM TyCon -> TcM TyCon) -> TcM TyCon -> TcM TyCon
forall a b. (a -> b) -> a -> b
$
do { skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo SkolemInfoAnon
skol_info_anon
; (tclvl, wanted, (scoped_kvs, (tc_bndrs, res_kind)))
<- pushLevelAndSolveEqualitiesX "kcCheckDeclHeader_cusk" $
bindImplicitTKBndrs_Q_Skol skol_info kv_ns $
bindExplicitTKBndrs_Q_Skol skol_info ctxt_kind hs_tvs $
newExpectedKind =<< kc_res_ki
; let spec_req_tkvs = [TcTyVar]
scoped_kvs [TcTyVar] -> [TcTyVar] -> [TcTyVar]
forall a. [a] -> [a] -> [a]
++ [VarBndr TcTyVar (HsBndrVis GhcRn)] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [VarBndr TcTyVar (HsBndrVis GhcRn)]
tc_bndrs
all_kinds = Type
res_kind Type -> [Type] -> [Type]
forall a. a -> [a] -> [a]
: (TcTyVar -> Type) -> [TcTyVar] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map TcTyVar -> Type
tyVarKind [TcTyVar]
spec_req_tkvs
; candidates <- candidateQTyVarsOfKinds all_kinds
; inferred <- quantifyTyVars skol_info DefaultNonStandardTyVars $
candidates `delCandidates` spec_req_tkvs
; (scoped_kvs, tc_bndrs, res_kind) <- liftZonkM $
do { scoped_kvs <- mapM zonkTyCoVarKind scoped_kvs
; tc_bndrs <- mapM zonkTyCoVarBndrKind tc_bndrs
; res_kind <- zonkTcType res_kind
; return (scoped_kvs, tc_bndrs, res_kind) }
; let mentioned_kv_set = CandidatesQTvs -> TyVarSet
candidateKindVars CandidatesQTvs
candidates
specified = [TcTyVar] -> [TcTyVar]
scopedSort [TcTyVar]
scoped_kvs
all_tcbs = ForAllTyFlag -> [TcTyVar] -> [TyConBinder]
mkNamedTyConBinders ForAllTyFlag
Inferred [TcTyVar]
inferred
[TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
++ ForAllTyFlag -> [TcTyVar] -> [TyConBinder]
mkNamedTyConBinders ForAllTyFlag
Specified [TcTyVar]
specified
[TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
++ (VarBndr TcTyVar (HsBndrVis GhcRn) -> TyConBinder)
-> [VarBndr TcTyVar (HsBndrVis GhcRn)] -> [TyConBinder]
forall a b. (a -> b) -> [a] -> [b]
map (TyVarSet -> VarBndr TcTyVar (HsBndrVis GhcRn) -> TyConBinder
mkExplicitTyConBinder TyVarSet
mentioned_kv_set) [VarBndr TcTyVar (HsBndrVis GhcRn)]
tc_bndrs
; (eta_tcbs, res_kind) <- etaExpandAlgTyCon flav skol_info all_tcbs res_kind
; let all_tv_prs = [TcTyVar] -> [(Name, TcTyVar)]
mkTyVarNamePairs ([TcTyVar]
scoped_kvs [TcTyVar] -> [TcTyVar] -> [TcTyVar]
forall a. [a] -> [a] -> [a]
++ [VarBndr TcTyVar (HsBndrVis GhcRn)] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [VarBndr TcTyVar (HsBndrVis GhcRn)]
tc_bndrs)
final_tcbs = [TyConBinder]
all_tcbs [TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
`chkAppend` [TyConBinder]
eta_tcbs
tycon = Name
-> [TyConBinder]
-> Type
-> [(Name, TcTyVar)]
-> Bool
-> TyConFlavour TyCon
-> TyCon
mkTcTyCon Name
name [TyConBinder]
final_tcbs Type
res_kind [(Name, TcTyVar)]
all_tv_prs
Bool
True
TyConFlavour TyCon
flav
; reportUnsolvedEqualities skol_info (binderVars final_tcbs)
tclvl wanted
; checkTyConTelescope tycon
; traceTc "kcCheckDeclHeader_cusk " $
vcat [ text "name" <+> ppr name
, text "candidates" <+> ppr candidates
, text "mentioned_kv_set" <+> ppr mentioned_kv_set
, text "kv_ns" <+> ppr kv_ns
, text "hs_tvs" <+> ppr hs_tvs
, text "scoped_kvs" <+> ppr scoped_kvs
, text "spec_req_tvs" <+> pprTyVars spec_req_tkvs
, text "all_kinds" <+> ppr all_kinds
, text "tc_tvs" <+> pprTyVars (binderVars tc_bndrs)
, text "res_kind" <+> ppr res_kind
, text "inferred" <+> ppr inferred
, text "specified" <+> ppr specified
, text "final_tcbs" <+> ppr final_tcbs
, text "mkTyConKind final_tc_bndrs res_kind"
<+> ppr (mkTyConKind final_tcbs res_kind)
, text "all_tv_prs" <+> ppr all_tv_prs ]
; return tycon }
where
skol_info_anon :: SkolemInfoAnon
skol_info_anon = TyConFlavour TyCon -> Name -> SkolemInfoAnon
TyConSkol TyConFlavour TyCon
flav Name
name
ctxt_kind :: ContextKind
ctxt_kind | TyConFlavour TyCon -> Bool
forall tc. TyConFlavour tc -> Bool
tcFlavourIsOpen TyConFlavour TyCon
flav = Type -> ContextKind
TheKind Type
liftedTypeKind
| Bool
otherwise = ContextKind
AnyKind
mkExplicitTyConBinder :: TyCoVarSet
-> VarBndr TyVar (HsBndrVis GhcRn)
-> TyConBinder
mkExplicitTyConBinder :: TyVarSet -> VarBndr TcTyVar (HsBndrVis GhcRn) -> TyConBinder
mkExplicitTyConBinder TyVarSet
dep_set (Bndr TcTyVar
tv HsBndrVis GhcRn
flag) =
case HsBndrVis GhcRn
flag of
HsBndrRequired{} -> TyVarSet -> TcTyVar -> TyConBinder
mkRequiredTyConBinder TyVarSet
dep_set TcTyVar
tv
HsBndrInvisible{} -> ForAllTyFlag -> TcTyVar -> TyConBinder
mkNamedTyConBinder ForAllTyFlag
Specified TcTyVar
tv
kcInferDeclHeader
:: Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM MonoTcTyCon
Name
name TyConFlavour TyCon
flav
(HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = XHsQTvs GhcRn
kv_ns
, hsq_explicit :: forall pass.
LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
hsq_explicit = [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_bndrs }) TcM ContextKind
kc_res_ki
= Name -> TyConFlavour TyCon -> TcM TyCon -> TcM TyCon
forall tc a. Name -> TyConFlavour tc -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour TyCon
flav (TcM TyCon -> TcM TyCon) -> TcM TyCon -> TcM TyCon
forall a b. (a -> b) -> a -> b
$
do { Name -> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn] -> TcM ()
rejectInvisibleBinders Name
name [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_bndrs
; (scoped_kvs, (tc_bndrs, res_kind))
<- HsQTvsRn
-> TcM ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type)
-> TcM ([TcTyVar], ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type))
forall a. HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Q_Tv HsQTvsRn
XHsQTvs GhcRn
kv_ns (TcM ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type)
-> TcM ([TcTyVar], ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type)))
-> TcM ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type)
-> TcM ([TcTyVar], ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type))
forall a b. (a -> b) -> a -> b
$
ContextKind
-> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
-> TcM Type
-> TcM ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
ContextKind
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrs_Q_Tv ContextKind
ctxt_kind [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_bndrs (TcM Type -> TcM ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type))
-> TcM Type -> TcM ([VarBndr TcTyVar (HsBndrVis GhcRn)], Type)
forall a b. (a -> b) -> a -> b
$
ContextKind -> TcM Type
newExpectedKind (ContextKind -> TcM Type) -> TcM ContextKind -> TcM Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TcM ContextKind
kc_res_ki
; let
tc_tvs = [VarBndr TcTyVar (HsBndrVis GhcRn)] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [VarBndr TcTyVar (HsBndrVis GhcRn)]
tc_bndrs
tc_binders = [TcTyVar] -> [TyConBinder]
mkAnonTyConBinders [TcTyVar]
tc_tvs
all_tv_prs = [TcTyVar] -> [(Name, TcTyVar)]
mkTyVarNamePairs ([TcTyVar]
scoped_kvs [TcTyVar] -> [TcTyVar] -> [TcTyVar]
forall a. [a] -> [a] -> [a]
++ [TcTyVar]
tc_tvs)
tycon = Name
-> [TyConBinder]
-> Type
-> [(Name, TcTyVar)]
-> Bool
-> TyConFlavour TyCon
-> TyCon
mkTcTyCon Name
name [TyConBinder]
tc_binders Type
res_kind [(Name, TcTyVar)]
all_tv_prs
Bool
False
TyConFlavour TyCon
flav
; traceTc "kcInferDeclHeader: not-cusk" $
vcat [ ppr name, ppr kv_ns, ppr hs_bndrs
, ppr scoped_kvs
, ppr tc_tvs, ppr (mkTyConKind tc_binders res_kind) ]
; return tycon }
where
ctxt_kind :: ContextKind
ctxt_kind | TyConFlavour TyCon -> Bool
forall tc. TyConFlavour tc -> Bool
tcFlavourIsOpen TyConFlavour TyCon
flav = Type -> ContextKind
TheKind Type
liftedTypeKind
| Bool
otherwise = ContextKind
AnyKind
rejectInvisibleBinders :: Name -> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn] -> TcM ()
rejectInvisibleBinders :: Name -> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn] -> TcM ()
rejectInvisibleBinders Name
name = (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> TcM ())
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ LHsTyVarBndr (HsBndrVis GhcRn) GhcRn -> TcM ()
GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> TcM ()
check_bndr_vis
where
check_bndr_vis :: LHsTyVarBndr (HsBndrVis GhcRn) GhcRn -> TcM ()
check_bndr_vis :: LHsTyVarBndr (HsBndrVis GhcRn) GhcRn -> TcM ()
check_bndr_vis LHsTyVarBndr (HsBndrVis GhcRn) GhcRn
bndr =
Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HsBndrVis GhcRn -> Bool
forall pass. HsBndrVis pass -> Bool
isHsBndrInvisible (HsTyVarBndr (HsBndrVis GhcRn) GhcRn -> HsBndrVis GhcRn
forall flag (pass :: Pass). HsTyVarBndr flag (GhcPass pass) -> flag
hsTyVarBndrFlag (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> HsTyVarBndr (HsBndrVis GhcRn) GhcRn
forall l e. GenLocated l e -> e
unLoc LHsTyVarBndr (HsBndrVis GhcRn) GhcRn
GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
bndr))) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> TcM ()
addErr (Name -> LHsTyVarBndr (HsBndrVis GhcRn) GhcRn -> TcRnMessage
TcRnInvisBndrWithoutSig Name
name LHsTyVarBndr (HsBndrVis GhcRn) GhcRn
bndr)
kcCheckDeclHeader_sig
:: Kind
-> Name
-> TyConFlavour TyCon
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM PolyTcTyCon
Type
sig_kind Name
name TyConFlavour TyCon
flav
(HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = XHsQTvs GhcRn
implicit_nms
, hsq_explicit :: forall pass.
LHsQTyVars pass -> [LHsTyVarBndr (HsBndrVis pass) pass]
hsq_explicit = [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_tv_bndrs }) TcM ContextKind
kc_res_ki
= Name -> TyConFlavour TyCon -> TcM TyCon -> TcM TyCon
forall tc a. Name -> TyConFlavour tc -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour TyCon
flav (TcM TyCon -> TcM TyCon) -> TcM TyCon -> TcM TyCon
forall a b. (a -> b) -> a -> b
$
do { skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (TyConFlavour TyCon -> Name -> SkolemInfoAnon
TyConSkol TyConFlavour TyCon
flav Name
name)
; let avoid_occs = (Name -> OccName) -> HsQTvsRn -> [OccName]
forall a b. (a -> b) -> [a] -> [b]
map Name -> OccName
nameOccName ([LHsTyVarBndr (HsBndrVis GhcRn) GhcRn] -> [IdP GhcRn]
forall flag (p :: Pass).
[LHsTyVarBndr flag (GhcPass p)] -> [IdP (GhcPass p)]
hsLTyVarNames [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_tv_bndrs)
; (sig_tcbs :: [TcTyConBinder], sig_res_kind :: Kind)
<- splitTyConKind skol_info emptyInScopeSet
avoid_occs sig_kind
; traceTc "kcCheckDeclHeader_sig {" $
vcat [ text "sig_kind:" <+> ppr sig_kind
, text "sig_tcbs:" <+> ppr sig_tcbs
, text "sig_res_kind:" <+> ppr sig_res_kind
, text "implict_nms:" <+> ppr implicit_nms
, text "hs_tv_bndrs:" <+> ppr hs_tv_bndrs ]
; (tclvl, wanted, (implicit_tvs, (skol_tcbs, skol_scoped_tvs, (extra_tcbs, tycon_res_kind))))
<- pushLevelAndSolveEqualitiesX "kcCheckDeclHeader_sig" $
bindImplicitTKBndrs_Q_Tv implicit_nms $
matchUpSigWithDecl name sig_tcbs sig_res_kind hs_tv_bndrs $ \ [TyConBinder]
excess_sig_tcbs Type
sig_res_kind ->
do {
; res_kind :: ContextKind <- TcM ContextKind
kc_res_ki
; let sig_res_kind' = [TyConBinder] -> Type -> Type
mkTyConKind [TyConBinder]
excess_sig_tcbs Type
sig_res_kind
; traceTc "kcCheckDeclHeader_sig 2" $
vcat [ text "excess_sig_tcbs" <+> ppr excess_sig_tcbs
, text "res_kind" <+> ppr res_kind
, text "sig_res_kind'" <+> ppr sig_res_kind'
]
; checkExpectedResKind sig_res_kind' res_kind
; if null excess_sig_tcbs || not (needsEtaExpansion flav)
then return ([], sig_res_kind')
else return (excess_sig_tcbs, sig_res_kind)
}
; let all_tcbs = [TyConBinder]
skol_tcbs [TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
++ [TyConBinder]
extra_tcbs
; reportUnsolvedEqualities skol_info (binderVars all_tcbs) tclvl wanted
; implicit_tvs <- liftZonkM $ zonkTcTyVarsToTcTyVars implicit_tvs
; let implicit_prs = HsQTvsRn
XHsQTvs GhcRn
implicit_nms HsQTvsRn -> [TcTyVar] -> [(Name, TcTyVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TcTyVar]
implicit_tvs
dup_chk_prs = [(Name, TcTyVar)]
implicit_prs [(Name, TcTyVar)] -> [(Name, TcTyVar)] -> [(Name, TcTyVar)]
forall a. [a] -> [a] -> [a]
++ [TcTyVar] -> [(Name, TcTyVar)]
mkTyVarNamePairs [TcTyVar]
skol_scoped_tvs
; unless (null implicit_nms) $
checkForDuplicateScopedTyVars dup_chk_prs
; checkForDisconnectedScopedTyVars name flav all_tcbs implicit_prs
; let swizzle_env = [(TcTyVar, Name)] -> VarEnv Name
forall a. [(TcTyVar, a)] -> VarEnv a
mkVarEnv (((Name, TcTyVar) -> (TcTyVar, Name))
-> [(Name, TcTyVar)] -> [(TcTyVar, Name)]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TcTyVar) -> (TcTyVar, Name)
forall a b. (a, b) -> (b, a)
swap [(Name, TcTyVar)]
implicit_prs)
(subst, swizzled_tcbs) = mapAccumL (swizzleTcb swizzle_env) emptySubst all_tcbs
swizzled_kind = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
tycon_res_kind
all_tv_prs = [TcTyVar] -> [(Name, TcTyVar)]
mkTyVarNamePairs ([TyConBinder] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
swizzled_tcbs)
; traceTc "kcCheckDeclHeader swizzle" $ vcat
[ text "sig_tcbs =" <+> ppr sig_tcbs
, text "implicit_prs =" <+> ppr implicit_prs
, text "hs_tv_bndrs =" <+> ppr hs_tv_bndrs
, text "all_tcbs =" <+> pprTyVars (binderVars all_tcbs)
, text "swizzled_tcbs =" <+> pprTyVars (binderVars swizzled_tcbs)
, text "tycon_res_kind =" <+> ppr tycon_res_kind
, text "swizzled_kind =" <+> ppr swizzled_kind ]
; let tc = Name
-> [TyConBinder]
-> Type
-> [(Name, TcTyVar)]
-> Bool
-> TyConFlavour TyCon
-> TyCon
mkTcTyCon Name
name [TyConBinder]
swizzled_tcbs Type
swizzled_kind [(Name, TcTyVar)]
all_tv_prs
Bool
True
TyConFlavour TyCon
flav
; traceTc "kcCheckDeclHeader_sig }" $ vcat
[ text "tyConName = " <+> ppr (tyConName tc)
, text "sig_kind =" <+> debugPprType sig_kind
, text "tyConKind =" <+> debugPprType (tyConKind tc)
, text "tyConBinders = " <+> ppr (tyConBinders tc)
, text "tyConResKind" <+> debugPprType (tyConResKind tc)
]
; return tc }
checkExpectedResKind :: TcKind
-> ContextKind
-> TcM ()
checkExpectedResKind :: Type -> ContextKind -> TcM ()
checkExpectedResKind Type
_ ContextKind
AnyKind
= () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkExpectedResKind Type
sig_kind ContextKind
res_ki
= do { actual_res_ki <- ContextKind -> TcM Type
newExpectedKind ContextKind
res_ki
; let
n_res_invis_bndrs = Type -> Int
invisibleTyBndrCount Type
actual_res_ki
n_sig_invis_bndrs = Type -> Int
invisibleTyBndrCount Type
sig_kind
n_to_inst = Int
n_sig_invis_bndrs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n_res_invis_bndrs
(_, sig_kind') = splitInvisPiTysN n_to_inst sig_kind
; discardResult $ unifyKind Nothing sig_kind' actual_res_ki }
matchUpSigWithDecl
:: Name
-> [TcTyConBinder]
-> TcKind
-> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
-> ([TcTyConBinder] -> TcKind -> TcM a)
-> TcM ( [TcTyConBinder]
, [TcTyVar]
, a )
matchUpSigWithDecl :: forall a.
Name
-> [TyConBinder]
-> Type
-> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
-> ([TyConBinder] -> Type -> TcM a)
-> TcM ([TyConBinder], [TcTyVar], a)
matchUpSigWithDecl Name
name [TyConBinder]
sig_tcbs Type
sig_res_kind [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
hs_bndrs [TyConBinder] -> Type -> TcM a
thing_inside
= Subst
-> [TyConBinder]
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
go Subst
emptySubst [TyConBinder]
sig_tcbs [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs
where
go :: Subst
-> [TyConBinder]
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
go Subst
subst [TyConBinder]
tcbs []
= do { let (Subst
subst', [TyConBinder]
tcbs') = Subst -> [TyConBinder] -> (Subst, [TyConBinder])
substTyConBindersX Subst
subst [TyConBinder]
tcbs
; res <- [TyConBinder] -> Type -> TcM a
thing_inside [TyConBinder]
tcbs' (HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst' Type
sig_res_kind)
; return ([], [], res) }
go Subst
_ [] [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs
= TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
forall a. TcRnMessage -> TcM a
failWithTc (Type -> [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn] -> TcRnMessage
TcRnTooManyBinders Type
sig_res_kind [LHsTyVarBndr (HsBndrVis GhcRn) GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs)
go Subst
subst (TyConBinder
tcb : [TyConBinder]
tcbs') hs_bndrs :: [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs@(GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr : [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs')
| TyConBndrVis -> HsBndrVis GhcRn -> Bool
zippable (TyConBinder -> TyConBndrVis
forall tv argf. VarBndr tv argf -> argf
binderFlag TyConBinder
tcb) (HsTyVarBndr (HsBndrVis GhcRn) GhcRn -> HsBndrVis GhcRn
forall flag (pass :: Pass). HsTyVarBndr flag (GhcPass pass) -> flag
hsTyVarBndrFlag (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> HsTyVarBndr (HsBndrVis GhcRn) GhcRn
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr))
=
do { let Bndr TcTyVar
tv TyConBndrVis
vis = TyConBinder
tcb
tv' :: TcTyVar
tv' = (Type -> Type) -> TcTyVar -> TcTyVar
updateTyVarKind (HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst) (TcTyVar -> TcTyVar) -> TcTyVar -> TcTyVar
forall a b. (a -> b) -> a -> b
$
TcTyVar -> (Name -> TcTyVar) -> Maybe Name -> TcTyVar
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TcTyVar
tv (TcTyVar -> Name -> TcTyVar
setTyVarName TcTyVar
tv) (LHsTyVarBndr (HsBndrVis GhcRn) GhcRn -> Maybe (IdP GhcRn)
forall flag (p :: Pass).
LHsTyVarBndr flag (GhcPass p) -> Maybe (IdP (GhcPass p))
hsLTyVarName LHsTyVarBndr (HsBndrVis GhcRn) GhcRn
GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr)
subst' :: Subst
subst' = Subst -> TcTyVar -> TcTyVar -> Subst
extendTCvSubstWithClone Subst
subst TcTyVar
tv TcTyVar
tv'
; HsTyVarBndr (HsBndrVis GhcRn) GhcRn -> Type -> TcM ()
tc_hs_bndr (GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> HsTyVarBndr (HsBndrVis GhcRn) GhcRn
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr) (TcTyVar -> Type
tyVarKind TcTyVar
tv')
; String -> SDoc -> TcM ()
traceTc String
"musd1" (TyConBinder -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyConBinder
tcb SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv')
; (tcbs', tvs, res) <- [TcTyVar]
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
forall r. [TcTyVar] -> TcM r -> TcM r
tcExtendTyVarEnv [TcTyVar
tv'] (IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a))
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
forall a b. (a -> b) -> a -> b
$
Subst
-> [TyConBinder]
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
go Subst
subst' [TyConBinder]
tcbs' [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs'
; return (Bndr tv' vis : tcbs', tv':tvs, res) }
| TyConBndrVis -> Bool
skippable (TyConBinder -> TyConBndrVis
forall tv argf. VarBndr tv argf -> argf
binderFlag TyConBinder
tcb)
=
do { let (Subst
subst', TyConBinder
tcb') = Subst -> TyConBinder -> (Subst, TyConBinder)
substTyConBinderX Subst
subst TyConBinder
tcb
; String -> SDoc -> TcM ()
traceTc String
"musd2" (TyConBinder -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyConBinder
tcb SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
-> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ TyConBinder -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyConBinder
tcb')
; (tcbs', tvs, res) <- Subst
-> [TyConBinder]
-> [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
go Subst
subst' [TyConBinder]
tcbs' [GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)]
hs_bndrs
; return (tcb' : tcbs', tvs, res) }
| Bool
otherwise =
TcRnMessage
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [TcTyVar], a)
forall a. TcRnMessage -> TcM a
failWithTc (Name -> LHsTyVarBndr (HsBndrVis GhcRn) GhcRn -> TcRnMessage
TcRnInvalidInvisTyVarBndr Name
name LHsTyVarBndr (HsBndrVis GhcRn) GhcRn
GenLocated SrcSpanAnnA (HsTyVarBndr (HsBndrVis GhcRn) GhcRn)
hs_bndr)
tc_hs_bndr :: HsTyVarBndr (HsBndrVis GhcRn) GhcRn -> TcKind -> TcM ()
tc_hs_bndr :: HsTyVarBndr (HsBndrVis GhcRn) GhcRn -> Type -> TcM ()
tc_hs_bndr (HsTvb { tvb_kind :: forall flag pass. HsTyVarBndr flag pass -> HsBndrKind pass
tvb_kind = HsBndrNoKind XBndrNoKind GhcRn
_ }) Type
_ = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
tc_hs_bndr (HsTvb { tvb_kind :: forall flag pass. HsTyVarBndr flag pass -> HsBndrKind pass
tvb_kind = HsBndrKind XBndrKind GhcRn
_ LHsType GhcRn
kind, tvb_var :: forall flag pass. HsTyVarBndr flag pass -> HsBndrVar pass
tvb_var = HsBndrVar GhcRn
bvar })
Type
expected_kind
= do { String -> SDoc -> TcM ()
traceTc String
"musd3:unifying" (GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
kind SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
expected_kind)
; HsBndrVar GhcRn -> LHsType GhcRn -> Type -> TcM ()
tcHsTvbKind HsBndrVar GhcRn
bvar LHsType GhcRn
kind Type
expected_kind }
zippable :: TyConBndrVis -> HsBndrVis GhcRn -> Bool
zippable :: TyConBndrVis -> HsBndrVis GhcRn -> Bool
zippable TyConBndrVis
vis (HsBndrInvisible XBndrInvisible GhcRn
_) = TyConBndrVis -> Bool
isInvisSpecTcbVis TyConBndrVis
vis
zippable TyConBndrVis
vis (HsBndrRequired XBndrRequired GhcRn
_) = TyConBndrVis -> Bool
isVisibleTcbVis TyConBndrVis
vis
skippable :: TyConBndrVis -> Bool
skippable :: TyConBndrVis -> Bool
skippable TyConBndrVis
vis = Bool -> Bool
not (TyConBndrVis -> Bool
isVisibleTcbVis TyConBndrVis
vis)
tcHsTvbKind :: HsBndrVar GhcRn -> LHsKind GhcRn -> TcKind -> TcM ()
tcHsTvbKind :: HsBndrVar GhcRn -> LHsType GhcRn -> Type -> TcM ()
tcHsTvbKind HsBndrVar GhcRn
bvar LHsType GhcRn
kind Type
expected_kind =
do { sig_kind <- UserTypeCtxt -> LHsType GhcRn -> TcM Type
tcLHsKindSig UserTypeCtxt
ctxt LHsType GhcRn
kind
; traceTc "tcHsTvbKind:unifying" (ppr sig_kind $$ ppr expected_kind)
; discardResult $
unifyKind mb_thing sig_kind expected_kind }
where
(UserTypeCtxt
ctxt, Maybe TypedThing
mb_thing) = case HsBndrVar GhcRn
bvar of
HsBndrVar XBndrVar GhcRn
_ (L SrcSpanAnnN
_ Name
hs_nm) -> (Name -> UserTypeCtxt
TyVarBndrKindCtxt Name
hs_nm, TypedThing -> Maybe TypedThing
forall a. a -> Maybe a
Just (Name -> TypedThing
NameThing Name
hs_nm))
HsBndrWildCard XBndrWildCard GhcRn
_ -> (UserTypeCtxt
KindSigCtxt, Maybe TypedThing
forall a. Maybe a
Nothing)
substTyConBinderX :: Subst -> TyConBinder -> (Subst, TyConBinder)
substTyConBinderX :: Subst -> TyConBinder -> (Subst, TyConBinder)
substTyConBinderX Subst
subst (Bndr TcTyVar
tv TyConBndrVis
vis)
= (Subst
subst', TcTyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TcTyVar
tv' TyConBndrVis
vis)
where
(Subst
subst', TcTyVar
tv') = HasDebugCallStack => Subst -> TcTyVar -> (Subst, TcTyVar)
Subst -> TcTyVar -> (Subst, TcTyVar)
substTyVarBndr Subst
subst TcTyVar
tv
substTyConBindersX :: Subst -> [TyConBinder] -> (Subst, [TyConBinder])
substTyConBindersX :: Subst -> [TyConBinder] -> (Subst, [TyConBinder])
substTyConBindersX = (Subst -> TyConBinder -> (Subst, TyConBinder))
-> Subst -> [TyConBinder] -> (Subst, [TyConBinder])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL Subst -> TyConBinder -> (Subst, TyConBinder)
substTyConBinderX
swizzleTcb :: VarEnv Name -> Subst -> TyConBinder -> (Subst, TyConBinder)
swizzleTcb :: VarEnv Name -> Subst -> TyConBinder -> (Subst, TyConBinder)
swizzleTcb VarEnv Name
swizzle_env Subst
subst (Bndr TcTyVar
tv TyConBndrVis
vis)
= (Subst
subst', TcTyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TcTyVar
tv2 TyConBndrVis
vis)
where
subst' :: Subst
subst' = Subst -> TcTyVar -> TcTyVar -> Subst
extendTCvSubstWithClone Subst
subst TcTyVar
tv TcTyVar
tv2
tv1 :: TcTyVar
tv1 = (Type -> Type) -> TcTyVar -> TcTyVar
updateTyVarKind (HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst) TcTyVar
tv
tv2 :: TcTyVar
tv2 = case VarEnv Name -> TcTyVar -> Maybe Name
forall a. VarEnv a -> TcTyVar -> Maybe a
lookupVarEnv VarEnv Name
swizzle_env TcTyVar
tv of
Just Name
user_name -> TcTyVar -> Name -> TcTyVar
setTyVarName TcTyVar
tv1 Name
user_name
Maybe Name
Nothing -> TcTyVar
tv1
data ContextKind = TheKind TcKind
| AnyKind
| OpenKind
instance Outputable ContextKind where
ppr :: ContextKind -> SDoc
ppr ContextKind
AnyKind = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"AnyKind"
ppr ContextKind
OpenKind = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"OpenKind"
ppr (TheKind Type
k) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"TheKind" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
k
newExpectedKind :: ContextKind -> TcM TcKind
newExpectedKind :: ContextKind -> TcM Type
newExpectedKind (TheKind Type
k) = Type -> TcM Type
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Type
k
newExpectedKind ContextKind
AnyKind = TcM Type
newMetaKindVar
newExpectedKind ContextKind
OpenKind = TcM Type
newOpenTypeKind
expectedKindInCtxt :: UserTypeCtxt -> ContextKind
expectedKindInCtxt :: UserTypeCtxt -> ContextKind
expectedKindInCtxt (TySynCtxt Name
_) = ContextKind
AnyKind
expectedKindInCtxt (GhciCtxt {}) = ContextKind
AnyKind
expectedKindInCtxt UserTypeCtxt
DefaultDeclCtxt = ContextKind
AnyKind
expectedKindInCtxt UserTypeCtxt
DerivClauseCtxt = ContextKind
AnyKind
expectedKindInCtxt UserTypeCtxt
TypeAppCtxt = ContextKind
AnyKind
expectedKindInCtxt (ForSigCtxt Name
_) = Type -> ContextKind
TheKind Type
liftedTypeKind
expectedKindInCtxt (InstDeclCtxt {}) = Type -> ContextKind
TheKind Type
constraintKind
expectedKindInCtxt UserTypeCtxt
SpecInstCtxt = Type -> ContextKind
TheKind Type
constraintKind
expectedKindInCtxt UserTypeCtxt
_ = ContextKind
OpenKind
checkForDisconnectedScopedTyVars :: Name -> TyConFlavour TyCon -> [TcTyConBinder]
-> [(Name,TcTyVar)] -> TcM ()
checkForDisconnectedScopedTyVars :: Name
-> TyConFlavour TyCon
-> [TyConBinder]
-> [(Name, TcTyVar)]
-> TcM ()
checkForDisconnectedScopedTyVars Name
name TyConFlavour TyCon
flav [TyConBinder]
all_tcbs [(Name, TcTyVar)]
scoped_prs
| TyConFlavour TyCon -> Bool
forall tc. TyConFlavour tc -> Bool
needsEtaExpansion TyConFlavour TyCon
flav = ((Name, TcTyVar) -> TcM ()) -> [(Name, TcTyVar)] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Name, TcTyVar) -> TcM ()
report_disconnected (((Name, TcTyVar) -> Bool) -> [(Name, TcTyVar)] -> [(Name, TcTyVar)]
forall a. (a -> Bool) -> [a] -> [a]
filterOut (Name, TcTyVar) -> Bool
ok [(Name, TcTyVar)]
scoped_prs)
| TyConFlavour TyCon
flav TyConFlavour TyCon -> TyConFlavour TyCon -> Bool
forall a. Eq a => a -> a -> Bool
== TyConFlavour TyCon
forall tc. TyConFlavour tc
TypeSynonymFlavour = ((Name, TcTyVar) -> TcM ()) -> [(Name, TcTyVar)] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Name, TcTyVar) -> TcM ()
report_out_of_arity (((Name, TcTyVar) -> Bool) -> [(Name, TcTyVar)] -> [(Name, TcTyVar)]
forall a. (a -> Bool) -> [a] -> [a]
filterOut (Name, TcTyVar) -> Bool
ok [(Name, TcTyVar)]
scoped_prs)
| Bool
otherwise = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
where
all_tvs :: TyVarSet
all_tvs = [TcTyVar] -> TyVarSet
mkVarSet ([TyConBinder] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
all_tcbs)
ok :: (Name, TcTyVar) -> Bool
ok (Name
_, TcTyVar
tc_tv) = TcTyVar
tc_tv TcTyVar -> TyVarSet -> Bool
`elemVarSet` TyVarSet
all_tvs
report_disconnected :: (Name,TcTyVar) -> TcM ()
report_disconnected :: (Name, TcTyVar) -> TcM ()
report_disconnected (Name
nm, TcTyVar
_)
= SrcSpan -> TcM () -> TcM ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (Name -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
nm) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> TcM ()
addErrTc (TcRnMessage -> TcM ()) -> TcRnMessage -> TcM ()
forall a b. (a -> b) -> a -> b
$ Name -> TcRnMessage
TcRnDisconnectedTyVar Name
nm
report_out_of_arity :: (Name,TcTyVar) -> TcM ()
report_out_of_arity :: (Name, TcTyVar) -> TcM ()
report_out_of_arity (Name
tv_nm, TcTyVar
_)
= SrcSpan -> TcM () -> TcM ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (Name -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
tv_nm) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> TcM ()
addErrTc (TcRnMessage -> TcM ()) -> TcRnMessage -> TcM ()
forall a b. (a -> b) -> a -> b
$ Name -> Name -> TcRnMessage
TcRnOutOfArityTyVar Name
name Name
tv_nm
checkForDuplicateScopedTyVars :: [(Name,TcTyVar)] -> TcM ()
checkForDuplicateScopedTyVars :: [(Name, TcTyVar)] -> TcM ()
checkForDuplicateScopedTyVars [(Name, TcTyVar)]
scoped_prs
= Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([(Name, Name)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, Name)]
err_prs) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
do { ((Name, Name) -> TcM ()) -> [(Name, Name)] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Name, Name) -> TcM ()
report_dup [(Name, Name)]
err_prs; TcM ()
forall env a. IOEnv env a
failM }
where
err_prs :: [(Name,Name)]
err_prs :: [(Name, Name)]
err_prs = [ (Name
n1,Name
n2)
| NonEmpty (Name, TcTyVar)
prs :: NonEmpty (Name,TyVar) <- ((Name, TcTyVar) -> (Name, TcTyVar) -> Bool)
-> [(Name, TcTyVar)] -> [NonEmpty (Name, TcTyVar)]
forall a. (a -> a -> Bool) -> [a] -> [NonEmpty a]
findDupsEq (TcTyVar -> TcTyVar -> Bool
forall a. Eq a => a -> a -> Bool
(==) (TcTyVar -> TcTyVar -> Bool)
-> ((Name, TcTyVar) -> TcTyVar)
-> (Name, TcTyVar)
-> (Name, TcTyVar)
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Name, TcTyVar) -> TcTyVar
forall a b. (a, b) -> b
snd) [(Name, TcTyVar)]
scoped_prs
, (Name
n1,TcTyVar
_) :| ((Name
n2,TcTyVar
_) : [(Name, TcTyVar)]
_) <- [((Name, TcTyVar) -> (Name, TcTyVar) -> Bool)
-> NonEmpty (Name, TcTyVar) -> NonEmpty (Name, TcTyVar)
forall a. (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
NE.nubBy (Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Name -> Name -> Bool)
-> ((Name, TcTyVar) -> Name)
-> (Name, TcTyVar)
-> (Name, TcTyVar)
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Name, TcTyVar) -> Name
forall a b. (a, b) -> a
fst) NonEmpty (Name, TcTyVar)
prs] ]
report_dup :: (Name,Name) -> TcM ()
report_dup :: (Name, Name) -> TcM ()
report_dup (Name
n1,Name
n2)
= SrcSpan -> TcM () -> TcM ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (Name -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
n2) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
TcRnMessage -> TcM ()
addErrTc (TcRnMessage -> TcM ()) -> TcRnMessage -> TcM ()
forall a b. (a -> b) -> a -> b
$ Name -> Name -> TcRnMessage
TcRnDifferentNamesForTyVar Name
n1 Name
n2
tcTKTelescope :: TcTyMode
-> HsForAllTelescope GhcRn
-> TcM a
-> TcM ([TcTyVarBinder], a)
tcTKTelescope :: forall a.
TcTyMode
-> HsForAllTelescope GhcRn -> TcM a -> TcM ([TcTyVarBinder], a)
tcTKTelescope TcTyMode
mode HsForAllTelescope GhcRn
tele TcM a
thing_inside = case HsForAllTelescope GhcRn
tele of
HsForAllVis { hsf_vis_bndrs :: forall pass. HsForAllTelescope pass -> [LHsTyVarBndr () pass]
hsf_vis_bndrs = [LHsTyVarBndr () GhcRn]
bndrs }
-> do { skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (TyVarBndrs -> SkolemInfoAnon
ForAllSkol ([HsTyVarBndr () GhcRn] -> TyVarBndrs
forall flag.
OutputableBndrFlag flag 'Renamed =>
[HsTyVarBndr flag GhcRn] -> TyVarBndrs
HsTyVarBndrsRn (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
-> HsTyVarBndr () GhcRn
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)
-> HsTyVarBndr () GhcRn)
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
-> [HsTyVarBndr () GhcRn]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsTyVarBndr () GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr () GhcRn)]
bndrs)))
; let skol_mode = SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_holes = mode_holes mode
, sm_tvtv = SMDSkolemTv skol_info }
; (req_tv_bndrs, thing) <- tcExplicitTKBndrsX skol_mode bndrs thing_inside
; return (tyVarReqToBinders req_tv_bndrs, thing) }
HsForAllInvis { hsf_invis_bndrs :: forall pass.
HsForAllTelescope pass -> [LHsTyVarBndr Specificity pass]
hsf_invis_bndrs = [LHsTyVarBndr Specificity GhcRn]
bndrs }
-> do { skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (TyVarBndrs -> SkolemInfoAnon
ForAllSkol ([HsTyVarBndr Specificity GhcRn] -> TyVarBndrs
forall flag.
OutputableBndrFlag flag 'Renamed =>
[HsTyVarBndr flag GhcRn] -> TyVarBndrs
HsTyVarBndrsRn (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)
-> HsTyVarBndr Specificity GhcRn
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)
-> HsTyVarBndr Specificity GhcRn)
-> [GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
-> [HsTyVarBndr Specificity GhcRn]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsTyVarBndr Specificity GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcRn)]
bndrs)))
; let skol_mode = SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_holes = mode_holes mode
, sm_tvtv = SMDSkolemTv skol_info }
; (inv_tv_bndrs, thing) <- tcExplicitTKBndrsX skol_mode bndrs thing_inside
; return (tyVarSpecToBinders inv_tv_bndrs, thing) }
bindOuterTKBndrsX :: OutputableBndrFlag flag 'Renamed
=> SkolemMode
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
bindOuterTKBndrsX :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
bindOuterTKBndrsX SkolemMode
skol_mode HsOuterTyVarBndrs flag GhcRn
outer_bndrs TcM a
thing_inside
= case HsOuterTyVarBndrs flag GhcRn
outer_bndrs of
HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit GhcRn
imp_tvs} ->
do { (imp_tvs', thing) <- SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX SkolemMode
skol_mode HsQTvsRn
XHsOuterImplicit GhcRn
imp_tvs TcM a
thing_inside
; return ( HsOuterImplicit{hso_ximplicit = imp_tvs'}
, thing) }
HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr flag (NoGhcTc GhcRn)]
exp_bndrs} ->
do { (exp_tvs', thing) <- SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX SkolemMode
skol_mode [LHsTyVarBndr flag (NoGhcTc GhcRn)]
[LHsTyVarBndr flag GhcRn]
exp_bndrs TcM a
thing_inside
; return ( HsOuterExplicit { hso_xexplicit = exp_tvs'
, hso_bndrs = exp_bndrs }
, thing) }
outerTyVars :: HsOuterTyVarBndrs flag GhcTc -> [TcTyVar]
outerTyVars :: forall flag. HsOuterTyVarBndrs flag GhcTc -> [TcTyVar]
outerTyVars (HsOuterImplicit { hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit GhcTc
tvs }) = [TcTyVar]
XHsOuterImplicit GhcTc
tvs
outerTyVars (HsOuterExplicit { hso_xexplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterExplicit pass flag
hso_xexplicit = XHsOuterExplicit GhcTc flag
tvbs }) = [VarBndr TcTyVar flag] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [VarBndr TcTyVar flag]
XHsOuterExplicit GhcTc flag
tvbs
outerTyVarBndrs :: HsOuterTyVarBndrs Specificity GhcTc -> [InvisTVBinder]
outerTyVarBndrs :: HsOuterTyVarBndrs Specificity GhcTc
-> [VarBndr TcTyVar Specificity]
outerTyVarBndrs (HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit GhcTc
imp_tvs}) = [TcTyVar -> Specificity -> VarBndr TcTyVar Specificity
forall var argf. var -> argf -> VarBndr var argf
Bndr TcTyVar
tv Specificity
SpecifiedSpec | TcTyVar
tv <- [TcTyVar]
XHsOuterImplicit GhcTc
imp_tvs]
outerTyVarBndrs (HsOuterExplicit{hso_xexplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterExplicit pass flag
hso_xexplicit = XHsOuterExplicit GhcTc Specificity
exp_tvs}) = [VarBndr TcTyVar Specificity]
XHsOuterExplicit GhcTc Specificity
exp_tvs
scopedSortOuter :: HsOuterTyVarBndrs flag GhcTc -> TcM (HsOuterTyVarBndrs flag GhcTc)
scopedSortOuter :: forall flag.
HsOuterTyVarBndrs flag GhcTc -> TcM (HsOuterTyVarBndrs flag GhcTc)
scopedSortOuter (HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit GhcTc
imp_tvs})
= do { imp_tvs <- [TcTyVar] -> TcM [TcTyVar]
zonkAndScopedSort [TcTyVar]
XHsOuterImplicit GhcTc
imp_tvs
; return (HsOuterImplicit { hso_ximplicit = imp_tvs }) }
scopedSortOuter bndrs :: HsOuterTyVarBndrs flag GhcTc
bndrs@(HsOuterExplicit{})
=
HsOuterTyVarBndrs flag GhcTc
-> IOEnv (Env TcGblEnv TcLclEnv) (HsOuterTyVarBndrs flag GhcTc)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return HsOuterTyVarBndrs flag GhcTc
bndrs
bindOuterSigTKBndrs_Tv :: HsOuterSigTyVarBndrs GhcRn
-> TcM a -> TcM (HsOuterSigTyVarBndrs GhcTc, a)
bindOuterSigTKBndrs_Tv :: forall a.
HsOuterSigTyVarBndrs GhcRn
-> TcM a -> TcM (HsOuterTyVarBndrs Specificity GhcTc, a)
bindOuterSigTKBndrs_Tv
= SkolemMode
-> HsOuterSigTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs Specificity GhcTc, a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
bindOuterTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv })
bindOuterSigTKBndrs_Tv_M :: TcTyMode
-> HsOuterSigTyVarBndrs GhcRn
-> TcM a -> TcM (HsOuterSigTyVarBndrs GhcTc, a)
bindOuterSigTKBndrs_Tv_M :: forall a.
TcTyMode
-> HsOuterSigTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs Specificity GhcTc, a)
bindOuterSigTKBndrs_Tv_M TcTyMode
mode
= SkolemMode
-> HsOuterSigTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs Specificity GhcTc, a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
bindOuterTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv
, sm_holes = mode_holes mode })
bindOuterFamEqnTKBndrs_Q_Tv :: HsOuterFamEqnTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterFamEqnTyVarBndrs GhcTc, a)
bindOuterFamEqnTKBndrs_Q_Tv :: forall a.
HsOuterFamEqnTyVarBndrs GhcRn
-> TcM a -> TcM (HsOuterFamEqnTyVarBndrs GhcTc, a)
bindOuterFamEqnTKBndrs_Q_Tv HsOuterFamEqnTyVarBndrs GhcRn
hs_bndrs TcM a
thing_inside
= SkolemMode
-> HsOuterFamEqnTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterFamEqnTyVarBndrs GhcTc, a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
bindOuterTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_parent = True
, sm_tvtv = SMDTyVarTv })
HsOuterFamEqnTyVarBndrs GhcRn
hs_bndrs TcM a
thing_inside
bindOuterFamEqnTKBndrs :: SkolemInfo
-> HsOuterFamEqnTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterFamEqnTyVarBndrs GhcTc, a)
bindOuterFamEqnTKBndrs :: forall a.
SkolemInfo
-> HsOuterFamEqnTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterFamEqnTyVarBndrs GhcTc, a)
bindOuterFamEqnTKBndrs SkolemInfo
skol_info
= SkolemMode
-> HsOuterFamEqnTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterFamEqnTyVarBndrs GhcTc, a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
bindOuterTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_parent = True
, sm_tvtv = SMDSkolemTv skol_info })
tcOuterTKBndrs :: OutputableBndrFlag flag 'Renamed
=> SkolemInfo
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a -> TcM (HsOuterTyVarBndrs flag GhcTc, a)
tcOuterTKBndrs :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemInfo
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
tcOuterTKBndrs SkolemInfo
skol_info
= SkolemMode
-> SkolemInfo
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> SkolemInfo
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
tcOuterTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False
, sm_tvtv = SMDSkolemTv skol_info })
SkolemInfo
skol_info
tcOuterTKBndrsX :: OutputableBndrFlag flag 'Renamed
=> SkolemMode -> SkolemInfo
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a -> TcM (HsOuterTyVarBndrs flag GhcTc, a)
tcOuterTKBndrsX :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> SkolemInfo
-> HsOuterTyVarBndrs flag GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs flag GhcTc, a)
tcOuterTKBndrsX SkolemMode
skol_mode SkolemInfo
skol_info HsOuterTyVarBndrs flag GhcRn
outer_bndrs TcM a
thing_inside
= case HsOuterTyVarBndrs flag GhcRn
outer_bndrs of
HsOuterImplicit{hso_ximplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterImplicit pass
hso_ximplicit = XHsOuterImplicit GhcRn
imp_tvs} ->
do { (imp_tvs', thing) <- SkolemMode -> SkolemInfo -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
forall a.
SkolemMode -> SkolemInfo -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
tcImplicitTKBndrsX SkolemMode
skol_mode SkolemInfo
skol_info HsQTvsRn
XHsOuterImplicit GhcRn
imp_tvs TcM a
thing_inside
; return ( HsOuterImplicit{hso_ximplicit = imp_tvs'}
, thing) }
HsOuterExplicit{hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs = [LHsTyVarBndr flag (NoGhcTc GhcRn)]
exp_bndrs} ->
do { (exp_tvs', thing) <- SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
tcExplicitTKBndrsX SkolemMode
skol_mode [LHsTyVarBndr flag (NoGhcTc GhcRn)]
[LHsTyVarBndr flag GhcRn]
exp_bndrs TcM a
thing_inside
; return ( HsOuterExplicit { hso_xexplicit = exp_tvs'
, hso_bndrs = exp_bndrs }
, thing) }
tcExplicitTKBndrs :: OutputableBndrFlag flag 'Renamed
=> SkolemInfo
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
tcExplicitTKBndrs :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemInfo
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
tcExplicitTKBndrs SkolemInfo
skol_info
= SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
tcExplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = True, sm_tvtv = SMDSkolemTv skol_info })
tcExplicitTKBndrsX :: OutputableBndrFlag flag 'Renamed
=> SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
tcExplicitTKBndrsX :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
tcExplicitTKBndrsX SkolemMode
skol_mode [LHsTyVarBndr flag GhcRn]
bndrs TcM a
thing_inside = case [GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
-> Maybe
(NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)))
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [LHsTyVarBndr flag GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
bndrs of
Maybe (NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)))
Nothing -> do
{ res <- TcM a
thing_inside
; return ([], res) }
Just NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))
bndrs1 -> do
{ (tclvl, wanted, (skol_tvs, res))
<- TcM ([VarBndr TcTyVar flag], a)
-> TcM (TcLevel, WantedConstraints, ([VarBndr TcTyVar flag], a))
forall a. TcM a -> TcM (TcLevel, WantedConstraints, a)
pushLevelAndCaptureConstraints (TcM ([VarBndr TcTyVar flag], a)
-> TcM (TcLevel, WantedConstraints, ([VarBndr TcTyVar flag], a)))
-> TcM ([VarBndr TcTyVar flag], a)
-> TcM (TcLevel, WantedConstraints, ([VarBndr TcTyVar flag], a))
forall a b. (a -> b) -> a -> b
$
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX SkolemMode
skol_mode [LHsTyVarBndr flag GhcRn]
bndrs (TcM a -> TcM ([VarBndr TcTyVar flag], a))
-> TcM a -> TcM ([VarBndr TcTyVar flag], a)
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
; let bndr_1 = NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))
-> GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)
forall a. NonEmpty a -> a
NE.head NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))
bndrs1; bndr_n = NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))
-> GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)
forall a. NonEmpty a -> a
NE.last NonEmpty (GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn))
bndrs1
; skol_info <- mkSkolemInfo (ForAllSkol (HsTyVarBndrsRn (unLoc <$> bndrs)))
; setSrcSpan (combineSrcSpans (getLocA bndr_1) (getLocA bndr_n))
$ emitResidualTvConstraint skol_info (binderVars skol_tvs) tclvl wanted
; return (skol_tvs, res) }
bindExplicitTKBndrs_Skol
:: (OutputableBndrFlag flag 'Renamed)
=> SkolemInfo
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Tv
:: (OutputableBndrFlag flag 'Renamed)
=> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Skol :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemInfo
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrs_Skol SkolemInfo
skol_info = SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_tvtv = SMDSkolemTv skol_info })
bindExplicitTKBndrs_Tv :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
[LHsTyVarBndr flag GhcRn]
-> TcM a -> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrs_Tv = SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv })
bindExplicitTKBndrs_Q_Skol
:: (OutputableBndrFlag flag 'Renamed)
=> SkolemInfo
-> ContextKind
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Q_Tv
:: (OutputableBndrFlag flag 'Renamed)
=> ContextKind
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Q_Skol :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemInfo
-> ContextKind
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrs_Q_Skol SkolemInfo
skol_info ContextKind
ctxt_kind [LHsTyVarBndr flag GhcRn]
hs_bndrs TcM a
thing_inside
= SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_parent = True
, sm_kind = ctxt_kind, sm_tvtv = SMDSkolemTv skol_info })
[LHsTyVarBndr flag GhcRn]
hs_bndrs TcM a
thing_inside
bindExplicitTKBndrs_Q_Tv :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
ContextKind
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrs_Q_Tv ContextKind
ctxt_kind [LHsTyVarBndr flag GhcRn]
hs_bndrs TcM a
thing_inside
= SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_parent = True
, sm_tvtv = SMDTyVarTv, sm_kind = ctxt_kind })
[LHsTyVarBndr flag GhcRn]
hs_bndrs TcM a
thing_inside
bindExplicitTKBndrsX
:: (OutputableBndrFlag flag 'Renamed)
=> SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrsX :: forall flag a.
OutputableBndrFlag flag 'Renamed =>
SkolemMode
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TcTyVar flag], a)
bindExplicitTKBndrsX skol_mode :: SkolemMode
skol_mode@(SM { sm_parent :: SkolemMode -> Bool
sm_parent = Bool
check_parent, sm_kind :: SkolemMode -> ContextKind
sm_kind = ContextKind
ctxt_kind
, sm_holes :: SkolemMode -> HoleInfo
sm_holes = HoleInfo
hole_info })
[LHsTyVarBndr flag GhcRn]
hs_tvs TcM a
thing_inside
= do { String -> SDoc -> TcM ()
traceTc String
"bindExplicitTKBndrs" ([GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LHsTyVarBndr flag GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
hs_tvs)
; [GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([VarBndr TcTyVar flag], a)
go [LHsTyVarBndr flag GhcRn]
[GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
hs_tvs }
where
tc_ki_mode :: TcTyMode
tc_ki_mode = TcTyMode { mode_tyki :: TypeOrKind
mode_tyki = TypeOrKind
KindLevel, mode_holes :: HoleInfo
mode_holes = HoleInfo
hole_info }
go :: [GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
-> IOEnv (Env TcGblEnv TcLclEnv) ([VarBndr TcTyVar flag], a)
go [] = do { res <- TcM a
thing_inside
; return ([], res) }
go (L SrcSpanAnnA
_ HsTyVarBndr flag GhcRn
hs_tv : [GenLocated SrcSpanAnnA (HsTyVarBndr flag GhcRn)]
hs_tvs)
= do { lcl_env <- TcM (NameEnv TcTyThing)
getLclTypeEnv
; tv <- tc_hs_bndr lcl_env hs_tv
; (tvs,res) <- tcExtendNameTyVarEnv (mk_tvb_pairs hs_tv tv) $
go hs_tvs
; return (Bndr tv (hsTyVarBndrFlag hs_tv):tvs, res) }
tc_hs_bndr :: TcTypeEnv -> HsTyVarBndr flag GhcRn -> TcM TcTyVar
tc_hs_bndr :: forall flag.
NameEnv TcTyThing
-> HsTyVarBndr flag GhcRn -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
tc_hs_bndr NameEnv TcTyThing
lcl_env (HsTvb { tvb_var :: forall flag pass. HsTyVarBndr flag pass -> HsBndrVar pass
tvb_var = HsBndrVar GhcRn
bvar, tvb_kind :: forall flag pass. HsTyVarBndr flag pass -> HsBndrKind pass
tvb_kind = HsBndrKind GhcRn
kind })
| Bool
check_parent
, HsBndrVar XBndrVar GhcRn
_ (L SrcSpanAnnN
_ Name
name) <- HsBndrVar GhcRn
bvar
, Just (ATyVar Name
_ TcTyVar
tv) <- NameEnv TcTyThing -> Name -> Maybe TcTyThing
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv TcTyThing
lcl_env Name
name
= do { Name -> Type -> HsBndrKind GhcRn -> TcM ()
check_hs_bndr_kind Name
name (TcTyVar -> Type
tyVarKind TcTyVar
tv) HsBndrKind GhcRn
kind
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tv }
| Bool
otherwise
= do { name <- HsBndrVar GhcRn -> TcM Name
tcHsBndrVarName HsBndrVar GhcRn
bvar
; kind' <- tc_hs_bndr_kind name kind
; newTyVarBndr skol_mode name kind' }
tc_hs_bndr_kind :: Name -> HsBndrKind GhcRn -> TcM Kind
tc_hs_bndr_kind :: Name -> HsBndrKind GhcRn -> TcM Type
tc_hs_bndr_kind Name
_ (HsBndrNoKind XBndrNoKind GhcRn
_) = ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
tc_hs_bndr_kind Name
name (HsBndrKind XBndrKind GhcRn
_ LHsType GhcRn
kind) = TcTyMode -> UserTypeCtxt -> LHsType GhcRn -> TcM Type
tc_lhs_kind_sig TcTyMode
tc_ki_mode (Name -> UserTypeCtxt
TyVarBndrKindCtxt Name
name) LHsType GhcRn
kind
check_hs_bndr_kind :: Name -> Kind -> HsBndrKind GhcRn -> TcM ()
check_hs_bndr_kind :: Name -> Type -> HsBndrKind GhcRn -> TcM ()
check_hs_bndr_kind Name
_ Type
_ (HsBndrNoKind XBndrNoKind GhcRn
_) = () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
check_hs_bndr_kind Name
name Type
parent_kind (HsBndrKind XBndrKind GhcRn
_ LHsType GhcRn
kind) =
do { kind' <- TcTyMode -> UserTypeCtxt -> LHsType GhcRn -> TcM Type
tc_lhs_kind_sig TcTyMode
tc_ki_mode (Name -> UserTypeCtxt
TyVarBndrKindCtxt Name
name) LHsType GhcRn
kind
; discardResult $
unifyKind (Just $ NameThing name) kind' parent_kind }
tcHsBndrVarName :: HsBndrVar GhcRn -> TcM Name
tcHsBndrVarName :: HsBndrVar GhcRn -> TcM Name
tcHsBndrVarName (HsBndrVar XBndrVar GhcRn
_ (L SrcSpanAnnN
_ Name
name)) = Name -> TcM Name
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Name
name
tcHsBndrVarName (HsBndrWildCard XBndrWildCard GhcRn
_) = OccName -> TcM Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (String -> OccName
mkTyVarOcc String
"_")
mk_tvb_pairs :: HsTyVarBndr flag GhcRn -> TcTyVar -> [(Name, TcTyVar)]
mk_tvb_pairs :: forall flag. HsTyVarBndr flag GhcRn -> TcTyVar -> [(Name, TcTyVar)]
mk_tvb_pairs HsTyVarBndr flag GhcRn
tvb TcTyVar
tv =
case HsTyVarBndr flag GhcRn -> Maybe (IdP GhcRn)
forall flag (p :: Pass).
HsTyVarBndr flag (GhcPass p) -> Maybe (IdP (GhcPass p))
hsTyVarName HsTyVarBndr flag GhcRn
tvb of
Maybe (IdP GhcRn)
Nothing -> []
Just IdP GhcRn
nm -> [(IdP GhcRn
Name
nm, TcTyVar
tv)]
newTyVarBndr :: SkolemMode -> Name -> Kind -> TcM TcTyVar
newTyVarBndr :: SkolemMode -> Name -> Type -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newTyVarBndr (SM { sm_clone :: SkolemMode -> Bool
sm_clone = Bool
clone, sm_tvtv :: SkolemMode -> SkolemModeDetails
sm_tvtv = SkolemModeDetails
tvtv }) Name
name Type
kind
= do { name <- case Bool
clone of
Bool
True -> do { uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; return (setNameUnique name uniq) }
Bool
False -> Name -> TcM Name
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Name
name
; details <- case tvtv of
SkolemModeDetails
SMDTyVarTv -> MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TyVarTv
SMDSkolemTv SkolemInfo
skol_info ->
do { lvl <- TcM TcLevel
getTcLevel
; return (SkolemTv skol_info lvl False) }
; return (mkTcTyVar name kind details) }
tcImplicitTKBndrsX :: SkolemMode -> SkolemInfo
-> [Name]
-> TcM a
-> TcM ([TcTyVar], a)
tcImplicitTKBndrsX :: forall a.
SkolemMode -> SkolemInfo -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
tcImplicitTKBndrsX SkolemMode
skol_mode SkolemInfo
skol_info HsQTvsRn
bndrs TcM a
thing_inside
| HsQTvsRn -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HsQTvsRn
bndrs
= do { res <- TcM a
thing_inside; return ([], res) }
| Bool
otherwise
= do { (tclvl, wanted, (skol_tvs, res))
<- IOEnv (Env TcGblEnv TcLclEnv) ([TcTyVar], a)
-> TcM (TcLevel, WantedConstraints, ([TcTyVar], a))
forall a. TcM a -> TcM (TcLevel, WantedConstraints, a)
pushLevelAndCaptureConstraints (IOEnv (Env TcGblEnv TcLclEnv) ([TcTyVar], a)
-> TcM (TcLevel, WantedConstraints, ([TcTyVar], a)))
-> IOEnv (Env TcGblEnv TcLclEnv) ([TcTyVar], a)
-> TcM (TcLevel, WantedConstraints, ([TcTyVar], a))
forall a b. (a -> b) -> a -> b
$
SkolemMode
-> HsQTvsRn
-> TcM a
-> IOEnv (Env TcGblEnv TcLclEnv) ([TcTyVar], a)
forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX SkolemMode
skol_mode HsQTvsRn
bndrs (TcM a -> IOEnv (Env TcGblEnv TcLclEnv) ([TcTyVar], a))
-> TcM a -> IOEnv (Env TcGblEnv TcLclEnv) ([TcTyVar], a)
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
; emitResidualTvConstraint skol_info skol_tvs tclvl wanted
; return (skol_tvs, res) }
bindImplicitTKBndrs_Skol,
bindImplicitTKBndrs_Q_Skol :: SkolemInfo -> [Name] -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Tv, bindImplicitTKBndrs_Q_Tv :: [Name] -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Skol :: forall a. SkolemInfo -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Skol SkolemInfo
skol_info = SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = True, sm_tvtv = SMDSkolemTv skol_info })
bindImplicitTKBndrs_Tv :: forall a. HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Tv = SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = True, sm_tvtv = SMDTyVarTv })
bindImplicitTKBndrs_Q_Skol :: forall a. SkolemInfo -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Q_Skol SkolemInfo
skol_info = SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_parent = True, sm_tvtv = SMDSkolemTv skol_info })
bindImplicitTKBndrs_Q_Tv :: forall a. HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Q_Tv = SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX (SkolemMode
HasDebugCallStack => SkolemMode
smVanilla { sm_clone = False, sm_parent = True, sm_tvtv = SMDTyVarTv })
bindImplicitTKBndrsX
:: SkolemMode
-> [Name]
-> TcM a
-> TcM ([TcTyVar], a)
bindImplicitTKBndrsX :: forall a. SkolemMode -> HsQTvsRn -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrsX skol_mode :: SkolemMode
skol_mode@(SM { sm_parent :: SkolemMode -> Bool
sm_parent = Bool
check_parent, sm_kind :: SkolemMode -> ContextKind
sm_kind = ContextKind
ctxt_kind })
HsQTvsRn
tv_names TcM a
thing_inside
= do { lcl_env <- TcM (NameEnv TcTyThing)
getLclTypeEnv
; tkvs <- mapM (new_tv lcl_env) tv_names
; traceTc "bindImplicitTKBndrsX" (ppr tv_names $$ ppr tkvs)
; res <- tcExtendNameTyVarEnv (tv_names `zip` tkvs)
thing_inside
; return (tkvs, res) }
where
new_tv :: NameEnv TcTyThing -> Name -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
new_tv NameEnv TcTyThing
lcl_env Name
name
| Bool
check_parent
, Just (ATyVar Name
_ TcTyVar
tv) <- NameEnv TcTyThing -> Name -> Maybe TcTyThing
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv TcTyThing
lcl_env Name
name
= TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tv
| Bool
otherwise
= do { kind <- ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
; newTyVarBndr skol_mode name kind }
data SkolemMode
= SM { SkolemMode -> Bool
sm_parent :: Bool
, SkolemMode -> Bool
sm_clone :: Bool
, SkolemMode -> SkolemModeDetails
sm_tvtv :: SkolemModeDetails
, SkolemMode -> ContextKind
sm_kind :: ContextKind
, SkolemMode -> HoleInfo
sm_holes :: HoleInfo
}
data SkolemModeDetails
= SMDTyVarTv
| SMDSkolemTv SkolemInfo
smVanilla :: HasDebugCallStack => SkolemMode
smVanilla :: HasDebugCallStack => SkolemMode
smVanilla = SM { sm_clone :: Bool
sm_clone = String -> Bool
forall a. HasCallStack => String -> a
panic String
"sm_clone"
, sm_parent :: Bool
sm_parent = Bool
False
, sm_tvtv :: SkolemModeDetails
sm_tvtv = String -> SDoc -> SkolemModeDetails
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"sm_tvtv" SDoc
HasCallStack => SDoc
callStackDoc
, sm_kind :: ContextKind
sm_kind = ContextKind
AnyKind
, sm_holes :: HoleInfo
sm_holes = HoleInfo
forall a. Maybe a
Nothing }
bindTyClTyVars :: Name -> ([TcTyConBinder] -> TcKind -> TcM a) -> TcM a
bindTyClTyVars :: forall a. Name -> ([TyConBinder] -> Type -> TcM a) -> TcM a
bindTyClTyVars Name
tycon_name [TyConBinder] -> Type -> TcM a
thing_inside
= do { tycon <- HasDebugCallStack => Name -> TcM TyCon
Name -> TcM TyCon
tcLookupTcTyCon Name
tycon_name
; let res_kind = TyCon -> Type
tyConResKind TyCon
tycon
binders = TyCon -> [TyConBinder]
tyConBinders TyCon
tycon
; traceTc "bindTyClTyVars" (ppr tycon_name $$ ppr binders)
; tcExtendTyVarEnv (binderVars binders) $
thing_inside binders res_kind }
bindTyClTyVarsAndZonk :: Name -> ([TyConBinder] -> Kind -> TcM a) -> TcM a
bindTyClTyVarsAndZonk :: forall a. Name -> ([TyConBinder] -> Type -> TcM a) -> TcM a
bindTyClTyVarsAndZonk Name
tycon_name [TyConBinder] -> Type -> TcM a
thing_inside
= Name -> ([TyConBinder] -> Type -> TcM a) -> TcM a
forall a. Name -> ([TyConBinder] -> Type -> TcM a) -> TcM a
bindTyClTyVars Name
tycon_name (([TyConBinder] -> Type -> TcM a) -> TcM a)
-> ([TyConBinder] -> Type -> TcM a) -> TcM a
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
tc_bndrs Type
tc_kind ->
do { (bndrs, kind) <- ZonkFlexi
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type)
-> TcM ([TyConBinder], Type)
forall (m :: * -> *) b. MonadIO m => ZonkFlexi -> ZonkT m b -> m b
initZonkEnv ZonkFlexi
NoFlexi (ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type)
-> TcM ([TyConBinder], Type))
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type)
-> TcM ([TyConBinder], Type)
forall a b. (a -> b) -> a -> b
$
ZonkBndrT (IOEnv (Env TcGblEnv TcLclEnv)) [TyConBinder]
-> forall r.
([TyConBinder] -> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) r)
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) r
forall (m :: * -> *) a.
ZonkBndrT m a -> forall r. (a -> ZonkT m r) -> ZonkT m r
runZonkBndrT ([TyConBinder]
-> ZonkBndrT (IOEnv (Env TcGblEnv TcLclEnv)) [TyConBinder]
forall vis.
[VarBndr TcTyVar vis] -> ZonkBndrTcM [VarBndr TcTyVar vis]
zonkTyVarBindersX [TyConBinder]
tc_bndrs) (([TyConBinder]
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type))
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type))
-> ([TyConBinder]
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type))
-> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) ([TyConBinder], Type)
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
bndrs ->
do { kind <- Type -> ZonkT (IOEnv (Env TcGblEnv TcLclEnv)) Type
zonkTcTypeToTypeX Type
tc_kind
; return (bndrs, kind) }
; thing_inside bndrs kind }
zonkAndScopedSort :: [TcTyVar] -> TcM [TcTyVar]
zonkAndScopedSort :: [TcTyVar] -> TcM [TcTyVar]
zonkAndScopedSort [TcTyVar]
spec_tkvs
= do { spec_tkvs <- ZonkM [TcTyVar] -> TcM [TcTyVar]
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM [TcTyVar] -> TcM [TcTyVar])
-> ZonkM [TcTyVar] -> TcM [TcTyVar]
forall a b. (a -> b) -> a -> b
$ [TcTyVar] -> ZonkM [TcTyVar]
HasDebugCallStack => [TcTyVar] -> ZonkM [TcTyVar]
zonkTcTyVarsToTcTyVars [TcTyVar]
spec_tkvs
; return (scopedSort spec_tkvs) }
kindGeneralizeSome :: SkolemInfo
-> WantedConstraints
-> TcType
-> TcM [KindVar]
kindGeneralizeSome :: SkolemInfo -> WantedConstraints -> Type -> TcM [TcTyVar]
kindGeneralizeSome SkolemInfo
skol_info WantedConstraints
wanted Type
kind_or_type
= do {
; dvs <- Type -> TcM CandidatesQTvs
candidateQTyVarsOfKind Type
kind_or_type
; filtered_dvs <- filterConstrainedCandidates wanted dvs
; traceTc "kindGeneralizeSome" $
vcat [ text "type:" <+> ppr kind_or_type
, text "dvs:" <+> ppr dvs
, text "filtered_dvs:" <+> ppr filtered_dvs ]
; quantifyTyVars skol_info DefaultNonStandardTyVars filtered_dvs }
filterConstrainedCandidates
:: WantedConstraints
-> CandidatesQTvs
-> TcM CandidatesQTvs
filterConstrainedCandidates :: WantedConstraints -> CandidatesQTvs -> TcM CandidatesQTvs
filterConstrainedCandidates WantedConstraints
wanted CandidatesQTvs
dvs
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wanted
= CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dvs
| Bool
otherwise
= do { wc_tvs <- ZonkM TyVarSet -> TcM TyVarSet
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TyVarSet -> TcM TyVarSet) -> ZonkM TyVarSet -> TcM TyVarSet
forall a b. (a -> b) -> a -> b
$ TyVarSet -> ZonkM TyVarSet
zonkTyCoVarsAndFV (WantedConstraints -> TyVarSet
tyCoVarsOfWC WantedConstraints
wanted)
; let (to_promote, dvs') = partitionCandidates dvs (`elemVarSet` wc_tvs)
; _ <- promoteTyVarSet to_promote
; return dvs' }
kindGeneralizeAll :: SkolemInfo -> TcType -> TcM [KindVar]
kindGeneralizeAll :: SkolemInfo -> Type -> TcM [TcTyVar]
kindGeneralizeAll SkolemInfo
skol_info Type
kind_or_type
= do { String -> SDoc -> TcM ()
traceTc String
"kindGeneralizeAll" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
kind_or_type)
; dvs <- Type -> TcM CandidatesQTvs
candidateQTyVarsOfKind Type
kind_or_type
; quantifyTyVars skol_info DefaultNonStandardTyVars dvs }
kindGeneralizeNone :: TcType
-> TcM ()
kindGeneralizeNone :: Type -> TcM ()
kindGeneralizeNone Type
kind_or_type
= do { String -> SDoc -> TcM ()
traceTc String
"kindGeneralizeNone" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
kind_or_type)
; dvs <- Type -> TcM CandidatesQTvs
candidateQTyVarsOfKind Type
kind_or_type
; _ <- promoteTyVarSet (candidateKindVars dvs)
; return () }
etaExpandAlgTyCon :: TyConFlavour tc -> SkolemInfo
-> [TcTyConBinder] -> Kind
-> TcM ([TcTyConBinder], Kind)
etaExpandAlgTyCon :: forall tc.
TyConFlavour tc
-> SkolemInfo -> [TyConBinder] -> Type -> TcM ([TyConBinder], Type)
etaExpandAlgTyCon TyConFlavour tc
flav SkolemInfo
skol_info [TyConBinder]
tcbs Type
res_kind
| TyConFlavour tc -> Bool
forall tc. TyConFlavour tc -> Bool
needsEtaExpansion TyConFlavour tc
flav
= SkolemInfo
-> InScopeSet -> [OccName] -> Type -> TcM ([TyConBinder], Type)
splitTyConKind SkolemInfo
skol_info InScopeSet
in_scope [OccName]
avoid_occs Type
res_kind
| Bool
otherwise
= ([TyConBinder], Type) -> TcM ([TyConBinder], Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], Type
res_kind)
where
tyvars :: [TcTyVar]
tyvars = [TyConBinder] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
tcbs
in_scope :: InScopeSet
in_scope = [TcTyVar] -> InScopeSet
mkInScopeSetList [TcTyVar]
tyvars
avoid_occs :: [OccName]
avoid_occs = (TcTyVar -> OccName) -> [TcTyVar] -> [OccName]
forall a b. (a -> b) -> [a] -> [b]
map TcTyVar -> OccName
forall a. NamedThing a => a -> OccName
getOccName [TcTyVar]
tyvars
needsEtaExpansion :: TyConFlavour tc -> Bool
needsEtaExpansion :: forall tc. TyConFlavour tc -> Bool
needsEtaExpansion TyConFlavour tc
NewtypeFlavour = Bool
True
needsEtaExpansion TyConFlavour tc
DataTypeFlavour = Bool
True
needsEtaExpansion TyConFlavour tc
ClassFlavour = Bool
True
needsEtaExpansion TyConFlavour tc
_ = Bool
False
splitTyConKind :: SkolemInfo
-> InScopeSet
-> [OccName]
-> Kind
-> TcM ([TcTyConBinder], TcKind)
splitTyConKind :: SkolemInfo
-> InScopeSet -> [OccName] -> Type -> TcM ([TyConBinder], Type)
splitTyConKind SkolemInfo
skol_info InScopeSet
in_scope [OccName]
avoid_occs Type
kind
= do { loc <- TcRn SrcSpan
getSrcSpanM
; new_uniqs <- getUniquesM
; rdr_env <- getLocalRdrEnv
; lvl <- getTcLevel
; let new_occs = (OccName -> Bool) -> Infinite OccName -> Infinite OccName
forall a. (a -> Bool) -> Infinite a -> Infinite a
Inf.filter (\ OccName
occ ->
Maybe Name -> Bool
forall a. Maybe a -> Bool
isNothing (LocalRdrEnv -> OccName -> Maybe Name
lookupLocalRdrOcc LocalRdrEnv
rdr_env OccName
occ) Bool -> Bool -> Bool
&&
Bool -> Bool
not (OccName
occ OccName -> [OccName] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [OccName]
avoid_occs)) (Infinite OccName -> Infinite OccName)
-> Infinite OccName -> Infinite OccName
forall a b. (a -> b) -> a -> b
$ NameSpace -> String -> OccName
mkOccName NameSpace
tvName (String -> OccName) -> Infinite String -> Infinite OccName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Infinite String
allNameStrings
subst = InScopeSet -> Subst
mkEmptySubst InScopeSet
in_scope
details = SkolemInfo -> TcLevel -> Bool -> TcTyVarDetails
SkolemTv SkolemInfo
skol_info (TcLevel -> TcLevel
pushTcLevel TcLevel
lvl) Bool
False
go Infinite OccName
occs [Unique]
uniqs Subst
subst [TyConBinder]
acc Type
kind
= case Type -> Maybe (PiTyVarBinder, Type)
splitPiTy_maybe Type
kind of
Maybe (PiTyVarBinder, Type)
Nothing -> ([TyConBinder] -> [TyConBinder]
forall a. [a] -> [a]
reverse [TyConBinder]
acc, HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
kind)
Just (Anon Scaled Type
arg FunTyFlag
af, Type
kind')
-> Bool -> ([TyConBinder], Type) -> ([TyConBinder], Type)
forall a. HasCallStack => Bool -> a -> a
assert (FunTyFlag
af FunTyFlag -> FunTyFlag -> Bool
forall a. Eq a => a -> a -> Bool
== FunTyFlag
FTF_T_T) (([TyConBinder], Type) -> ([TyConBinder], Type))
-> ([TyConBinder], Type) -> ([TyConBinder], Type)
forall a b. (a -> b) -> a -> b
$
Infinite OccName
-> [Unique]
-> Subst
-> [TyConBinder]
-> Type
-> ([TyConBinder], Type)
go Infinite OccName
occs' [Unique]
uniqs' Subst
subst' (TyConBinder
tcb TyConBinder -> [TyConBinder] -> [TyConBinder]
forall a. a -> [a] -> [a]
: [TyConBinder]
acc) Type
kind'
where
tcb :: TyConBinder
tcb = TcTyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TcTyVar
tv TyConBndrVis
AnonTCB
arg' :: Type
arg' = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst (Scaled Type -> Type
forall a. Scaled a -> a
scaledThing Scaled Type
arg)
name :: Name
name = Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
uniq OccName
occ SrcSpan
loc
tv :: TcTyVar
tv = Name -> Type -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name Type
arg' TcTyVarDetails
details
subst' :: Subst
subst' = Subst -> TcTyVar -> Subst
extendSubstInScope Subst
subst TcTyVar
tv
Unique
uniq:[Unique]
uniqs' = [Unique]
uniqs
Inf OccName
occ Infinite OccName
occs' = Infinite OccName
occs
Just (Named (Bndr TcTyVar
tv ForAllTyFlag
vis), Type
kind')
-> Infinite OccName
-> [Unique]
-> Subst
-> [TyConBinder]
-> Type
-> ([TyConBinder], Type)
go Infinite OccName
occs [Unique]
uniqs Subst
subst' (TyConBinder
tcb TyConBinder -> [TyConBinder] -> [TyConBinder]
forall a. a -> [a] -> [a]
: [TyConBinder]
acc) Type
kind'
where
tcb :: TyConBinder
tcb = TcTyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TcTyVar
tv' (ForAllTyFlag -> TyConBndrVis
NamedTCB ForAllTyFlag
vis)
tc_tyvar :: TcTyVar
tc_tyvar = Name -> Type -> TcTyVarDetails -> TcTyVar
mkTcTyVar (TcTyVar -> Name
tyVarName TcTyVar
tv) (TcTyVar -> Type
tyVarKind TcTyVar
tv) TcTyVarDetails
details
(Subst
subst', TcTyVar
tv') = HasDebugCallStack => Subst -> TcTyVar -> (Subst, TcTyVar)
Subst -> TcTyVar -> (Subst, TcTyVar)
substTyVarBndr Subst
subst TcTyVar
tc_tyvar
; return (go new_occs new_uniqs subst [] kind) }
isAllowedDataResKind :: AllowedDataResKind -> Kind -> Bool
isAllowedDataResKind :: AllowedDataResKind -> Type -> Bool
isAllowedDataResKind AllowedDataResKind
AnyTYPEKind Type
kind = Type -> Bool
isTypeLikeKind Type
kind
isAllowedDataResKind AllowedDataResKind
AnyBoxedKind Type
kind = Type -> Bool
tcIsBoxedTypeKind Type
kind
isAllowedDataResKind AllowedDataResKind
LiftedKind Type
kind = Type -> Bool
tcIsLiftedTypeKind Type
kind
checkDataKindSig :: DataSort -> Kind
-> TcM ()
checkDataKindSig :: DataSort -> Type -> TcM ()
checkDataKindSig DataSort
data_sort Type
kind
= do { dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; traceTc "checkDataKindSig" (ppr kind)
; checkTc (tYPE_ok dflags || is_kind_var)
(err_msg dflags) }
where
res_kind :: Type
res_kind = ([PiTyVarBinder], Type) -> Type
forall a b. (a, b) -> b
snd (Type -> ([PiTyVarBinder], Type)
tcSplitPiTys Type
kind)
is_newtype :: Bool
is_newtype :: Bool
is_newtype =
case DataSort
data_sort of
DataDeclSort NewOrData
new_or_data -> NewOrData
new_or_data NewOrData -> NewOrData -> Bool
forall a. Eq a => a -> a -> Bool
== NewOrData
NewType
DataInstanceSort NewOrData
new_or_data -> NewOrData
new_or_data NewOrData -> NewOrData -> Bool
forall a. Eq a => a -> a -> Bool
== NewOrData
NewType
DataSort
DataFamilySort -> Bool
False
is_datatype :: Bool
is_datatype :: Bool
is_datatype =
case DataSort
data_sort of
DataDeclSort NewOrData
DataType -> Bool
True
DataInstanceSort NewOrData
DataType -> Bool
True
DataSort
_ -> Bool
False
is_data_family :: Bool
is_data_family :: Bool
is_data_family =
case DataSort
data_sort of
DataDeclSort{} -> Bool
False
DataInstanceSort{} -> Bool
False
DataSort
DataFamilySort -> Bool
True
allowed_kind :: DynFlags -> AllowedDataResKind
allowed_kind :: DynFlags -> AllowedDataResKind
allowed_kind DynFlags
dflags
| Bool
is_newtype Bool -> Bool -> Bool
&& Extension -> DynFlags -> Bool
xopt Extension
LangExt.UnliftedNewtypes DynFlags
dflags
= AllowedDataResKind
AnyTYPEKind
| Bool
is_data_family
= AllowedDataResKind
AnyTYPEKind
| Bool
is_datatype Bool -> Bool -> Bool
&& Extension -> DynFlags -> Bool
xopt Extension
LangExt.UnliftedDatatypes DynFlags
dflags
= AllowedDataResKind
AnyBoxedKind
| Bool
otherwise
= AllowedDataResKind
LiftedKind
tYPE_ok :: DynFlags -> Bool
tYPE_ok :: DynFlags -> Bool
tYPE_ok DynFlags
dflags = AllowedDataResKind -> Type -> Bool
isAllowedDataResKind (DynFlags -> AllowedDataResKind
allowed_kind DynFlags
dflags) Type
res_kind
is_kind_var :: Bool
is_kind_var :: Bool
is_kind_var | Bool
is_data_family = Maybe (TcTyVar, Coercion) -> Bool
forall a. Maybe a -> Bool
isJust (Type -> Maybe (TcTyVar, Coercion)
getCastedTyVar_maybe Type
res_kind)
| Bool
otherwise = Bool
False
err_msg :: DynFlags -> TcRnMessage
err_msg :: DynFlags -> TcRnMessage
err_msg DynFlags
dflags =
DataSort
-> AllowedDataResKind
-> Type
-> Maybe SuggestUnliftedTypes
-> TcRnMessage
TcRnInvalidReturnKind DataSort
data_sort (DynFlags -> AllowedDataResKind
allowed_kind DynFlags
dflags) Type
kind (DynFlags -> Maybe SuggestUnliftedTypes
ext_hint DynFlags
dflags)
ext_hint :: DynFlags -> Maybe SuggestUnliftedTypes
ext_hint DynFlags
dflags
| Type -> Bool
isTypeLikeKind Type
kind
, Bool
is_newtype
, Bool -> Bool
not (Extension -> DynFlags -> Bool
xopt Extension
LangExt.UnliftedNewtypes DynFlags
dflags)
= SuggestUnliftedTypes -> Maybe SuggestUnliftedTypes
forall a. a -> Maybe a
Just SuggestUnliftedTypes
SuggestUnliftedNewtypes
| Type -> Bool
tcIsBoxedTypeKind Type
kind
, Bool
is_datatype
, Bool -> Bool
not (Extension -> DynFlags -> Bool
xopt Extension
LangExt.UnliftedDatatypes DynFlags
dflags)
= SuggestUnliftedTypes -> Maybe SuggestUnliftedTypes
forall a. a -> Maybe a
Just SuggestUnliftedTypes
SuggestUnliftedDatatypes
| Bool
otherwise
= Maybe SuggestUnliftedTypes
forall a. Maybe a
Nothing
checkClassKindSig :: Kind -> TcM ()
checkClassKindSig :: Type -> TcM ()
checkClassKindSig Type
kind = Bool -> TcRnMessage -> TcM ()
checkTc (Type -> Bool
isConstraintKind Type
kind) TcRnMessage
err_msg
where
err_msg :: TcRnMessage
err_msg :: TcRnMessage
err_msg = Type -> TcRnMessage
TcRnClassKindNotConstraint Type
kind
tcbVisibilities :: TyCon -> [Type] -> [TyConBndrVis]
tcbVisibilities :: TyCon -> [Type] -> [TyConBndrVis]
tcbVisibilities TyCon
tc [Type]
orig_args
= Type -> Subst -> [Type] -> [TyConBndrVis]
go (TyCon -> Type
tyConKind TyCon
tc) Subst
init_subst [Type]
orig_args
where
init_subst :: Subst
init_subst = InScopeSet -> Subst
mkEmptySubst (TyVarSet -> InScopeSet
mkInScopeSet ([Type] -> TyVarSet
tyCoVarsOfTypes [Type]
orig_args))
go :: Type -> Subst -> [Type] -> [TyConBndrVis]
go Type
_ Subst
_ []
= []
go Type
fun_kind Subst
subst all_args :: [Type]
all_args@(Type
arg : [Type]
args)
| Just (PiTyVarBinder
tcb, Type
inner_kind) <- Type -> Maybe (PiTyVarBinder, Type)
splitPiTy_maybe Type
fun_kind
= case PiTyVarBinder
tcb of
Anon Scaled Type
_ FunTyFlag
af -> Bool -> [TyConBndrVis] -> [TyConBndrVis]
forall a. HasCallStack => Bool -> a -> a
assert (FunTyFlag
af FunTyFlag -> FunTyFlag -> Bool
forall a. Eq a => a -> a -> Bool
== FunTyFlag
FTF_T_T) ([TyConBndrVis] -> [TyConBndrVis])
-> [TyConBndrVis] -> [TyConBndrVis]
forall a b. (a -> b) -> a -> b
$
TyConBndrVis
AnonTCB TyConBndrVis -> [TyConBndrVis] -> [TyConBndrVis]
forall a. a -> [a] -> [a]
: Type -> Subst -> [Type] -> [TyConBndrVis]
go Type
inner_kind Subst
subst [Type]
args
Named (Bndr TcTyVar
tv ForAllTyFlag
vis) -> ForAllTyFlag -> TyConBndrVis
NamedTCB ForAllTyFlag
vis TyConBndrVis -> [TyConBndrVis] -> [TyConBndrVis]
forall a. a -> [a] -> [a]
: Type -> Subst -> [Type] -> [TyConBndrVis]
go Type
inner_kind Subst
subst' [Type]
args
where
subst' :: Subst
subst' = Subst -> TcTyVar -> Type -> Subst
extendTCvSubst Subst
subst TcTyVar
tv Type
arg
| Bool -> Bool
not (Subst -> Bool
isEmptyTCvSubst Subst
subst)
= Type -> Subst -> [Type] -> [TyConBndrVis]
go (HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
fun_kind) Subst
init_subst [Type]
all_args
| Bool
otherwise
= String -> SDoc -> [TyConBndrVis]
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"addTcbVisibilities" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
orig_args)
tcHsPartialSigType
:: UserTypeCtxt
-> LHsSigWcType GhcRn
-> TcM ( [(Name, TcTyVar)]
, Maybe TcType
, [(Name,InvisTVBinder)]
, TcThetaType
, TcType )
tcHsPartialSigType :: UserTypeCtxt
-> LHsSigWcType GhcRn
-> TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type)
tcHsPartialSigType UserTypeCtxt
ctxt LHsSigWcType GhcRn
sig_ty
| HsWC { hswc_ext :: forall pass thing. HsWildCardBndrs pass thing -> XHsWC pass thing
hswc_ext = XHsWC GhcRn (LHsSigType GhcRn)
sig_wcs, hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = LHsSigType GhcRn
sig_ty } <- LHsSigWcType GhcRn
sig_ty
, L SrcSpanAnnA
_ (HsSig{sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
sig_bndrs = HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs, sig_body :: forall pass. HsSigType pass -> LHsType pass
sig_body = LHsType GhcRn
body_ty}) <- LHsSigType GhcRn
sig_ty
, (Maybe (LHsContext GhcRn)
hs_ctxt, LHsType GhcRn
hs_tau) <- LHsType GhcRn -> (Maybe (LHsContext GhcRn), LHsType GhcRn)
forall (pass :: Pass).
LHsType (GhcPass pass)
-> (Maybe (LHsContext (GhcPass pass)), LHsType (GhcPass pass))
splitLHsQualTy LHsType GhcRn
body_ty
= UserTypeCtxt
-> GenLocated SrcSpanAnnA (HsSigType GhcRn)
-> TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type)
-> TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type)
forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsSigType GhcRn
GenLocated SrcSpanAnnA (HsSigType GhcRn)
sig_ty (TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type)
-> TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type))
-> TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type)
-> TcM
([(Name, TcTyVar)], Maybe Type,
[(Name, VarBndr TcTyVar Specificity)], [Type], Type)
forall a b. (a -> b) -> a -> b
$
do { mode <- TypeOrKind -> HoleMode -> TcM TcTyMode
mkHoleMode TypeOrKind
TypeLevel HoleMode
HM_Sig
; (outer_bndrs, (wcs, wcx, theta, tau))
<- solveEqualities "tcHsPartialSigType" $
bindNamedWildCardBinders sig_wcs $ \ [(Name, TcTyVar)]
wcs ->
TcTyMode
-> HsOuterSigTyVarBndrs GhcRn
-> TcM ([(Name, TcTyVar)], Maybe Type, [Type], Type)
-> TcM
(HsOuterTyVarBndrs Specificity GhcTc,
([(Name, TcTyVar)], Maybe Type, [Type], Type))
forall a.
TcTyMode
-> HsOuterSigTyVarBndrs GhcRn
-> TcM a
-> TcM (HsOuterTyVarBndrs Specificity GhcTc, a)
bindOuterSigTKBndrs_Tv_M TcTyMode
mode HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs (TcM ([(Name, TcTyVar)], Maybe Type, [Type], Type)
-> TcM
(HsOuterTyVarBndrs Specificity GhcTc,
([(Name, TcTyVar)], Maybe Type, [Type], Type)))
-> TcM ([(Name, TcTyVar)], Maybe Type, [Type], Type)
-> TcM
(HsOuterTyVarBndrs Specificity GhcTc,
([(Name, TcTyVar)], Maybe Type, [Type], Type))
forall a b. (a -> b) -> a -> b
$
do {
(theta, wcx) <- TcTyMode -> Maybe (LHsContext GhcRn) -> TcM ([Type], Maybe Type)
tcPartialContext TcTyMode
mode Maybe (LHsContext GhcRn)
hs_ctxt
; ek <- newOpenTypeKind
; tau <-
tc_check_lhs_type mode hs_tau ek
; return (wcs, wcx, theta, tau) }
; traceTc "tcHsPartialSigType 2" empty
; outer_bndrs <- scopedSortOuter outer_bndrs
; let outer_tv_bndrs = HsOuterTyVarBndrs Specificity GhcTc
-> [VarBndr TcTyVar Specificity]
outerTyVarBndrs HsOuterTyVarBndrs Specificity GhcTc
outer_bndrs
; traceTc "tcHsPartialSigType 3" empty
; kindGeneralizeNone (mkInvisForAllTys outer_tv_bndrs $
tcMkPhiTy theta $
tau)
; mapM_ emitNamedTypeHole wcs
; (tv_prs', theta', tau) <- tcInstTypeBndrs tau
; let outer_bndr_names :: [Name]
outer_bndr_names = HsOuterSigTyVarBndrs GhcRn -> HsQTvsRn
forall flag. HsOuterTyVarBndrs flag GhcRn -> HsQTvsRn
hsOuterTyVarNames HsOuterSigTyVarBndrs GhcRn
hs_outer_bndrs
tv_prs :: [(Name,InvisTVBinder)]
tv_prs = HsQTvsRn
outer_bndr_names HsQTvsRn
-> [VarBndr TcTyVar Specificity]
-> [(Name, VarBndr TcTyVar Specificity)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [VarBndr TcTyVar Specificity]
outer_tv_bndrs
; (tv_prs, theta, tau) <- liftZonkM $
do { tv_prs <- mapSndM zonkInvisTVBinder (tv_prs ++ tv_prs')
; theta <- mapM zonkTcType (theta ++ theta')
; tau <- zonkTcType tau
; return (tv_prs, theta, tau) }
; traceTc "tcHsPartialSigType" (ppr tv_prs)
; return (wcs, wcx, tv_prs, theta, tau) }
tcPartialContext :: TcTyMode -> Maybe (LHsContext GhcRn) -> TcM (TcThetaType, Maybe TcType)
tcPartialContext :: TcTyMode -> Maybe (LHsContext GhcRn) -> TcM ([Type], Maybe Type)
tcPartialContext TcTyMode
_ Maybe (LHsContext GhcRn)
Nothing = ([Type], Maybe Type) -> TcM ([Type], Maybe Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], Maybe Type
forall a. Maybe a
Nothing)
tcPartialContext TcTyMode
mode (Just (L SrcSpanAnnC
_ [GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_theta))
| Just ([GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_theta1, GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ctxt_last) <- [GenLocated SrcSpanAnnA (HsType GhcRn)]
-> Maybe
([GenLocated SrcSpanAnnA (HsType GhcRn)],
GenLocated SrcSpanAnnA (HsType GhcRn))
forall a. [a] -> Maybe ([a], a)
snocView [GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_theta
, L SrcSpanAnnA
wc_loc ty :: HsType GhcRn
ty@(HsWildCardTy XWildCardTy GhcRn
_) <- LHsType GhcRn -> LHsType GhcRn
forall (p :: Pass). LHsType (GhcPass p) -> LHsType (GhcPass p)
ignoreParens LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ctxt_last
= do { wc_tv_ty <- SrcSpanAnnA -> TcM Type -> TcM Type
forall ann a. EpAnn ann -> TcRn a -> TcRn a
setSrcSpanA SrcSpanAnnA
wc_loc (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
IsExtraConstraint -> TcTyMode -> HsType GhcRn -> Type -> TcM Type
tcAnonWildCardOcc IsExtraConstraint
YesExtraConstraint TcTyMode
mode HsType GhcRn
ty Type
constraintKind
; theta <- mapM (tc_lhs_pred mode) hs_theta1
; return (theta, Just wc_tv_ty) }
| Bool
otherwise
= do { theta <- (GenLocated SrcSpanAnnA (HsType GhcRn) -> TcM Type)
-> [GenLocated SrcSpanAnnA (HsType GhcRn)] -> TcM [Type]
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 (TcTyMode -> LHsType GhcRn -> TcM Type
tc_lhs_pred TcTyMode
mode) [GenLocated SrcSpanAnnA (HsType GhcRn)]
hs_theta
; return (theta, Nothing) }
tcHsPatSigType :: UserTypeCtxt
-> HoleMode
-> HsPatSigType GhcRn
-> ContextKind
-> TcM ( [(Name, TcTyVar)]
, [(Name, TcTyVar)]
, TcType)
tcHsPatSigType :: UserTypeCtxt
-> HoleMode
-> HsPatSigType GhcRn
-> ContextKind
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tcHsPatSigType UserTypeCtxt
ctxt HoleMode
hole_mode
(HsPS { hsps_ext :: forall pass. HsPatSigType pass -> XHsPS pass
hsps_ext = HsPSRn { hsps_nwcs :: HsPSRn -> HsQTvsRn
hsps_nwcs = HsQTvsRn
sig_wcs, hsps_imp_tvs :: HsPSRn -> HsQTvsRn
hsps_imp_tvs = HsQTvsRn
sig_ns }
, hsps_body :: forall pass. HsPatSigType pass -> LHsType pass
hsps_body = LHsType GhcRn
hs_ty })
ContextKind
ctxt_kind
= UserTypeCtxt
-> HoleMode
-> LHsType GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> ContextKind
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_type_in_pat UserTypeCtxt
ctxt HoleMode
hole_mode LHsType GhcRn
hs_ty HsQTvsRn
sig_wcs HsQTvsRn
sig_ns ContextKind
ctxt_kind
tcHsTyPat :: HsTyPat GhcRn
-> Kind
-> TcM ( [(Name, TcTyVar)]
, [(Name, TcTyVar)]
, TcType)
tcHsTyPat :: HsTyPat GhcRn
-> Type -> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tcHsTyPat hs_pat :: HsTyPat GhcRn
hs_pat@(HsTP{hstp_ext :: forall pass. HsTyPat pass -> XHsTP pass
hstp_ext = XHsTP GhcRn
hstp_rn, hstp_body :: forall pass. HsTyPat pass -> LHsType pass
hstp_body = LHsType GhcRn
hs_ty}) Type
expected_kind
= case HsTyPat GhcRn -> Maybe (HsTyVarBndr () GhcRn)
tyPatToBndr HsTyPat GhcRn
hs_pat of
Maybe (HsTyVarBndr () GhcRn)
Nothing -> GenLocated SrcSpanAnnA (HsType GhcRn)
-> HsQTvsRn
-> HsQTvsRn
-> ContextKind
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_unif_in_pat LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ty HsQTvsRn
wcs HsQTvsRn
all_ns (Type -> ContextKind
TheKind Type
expected_kind)
Just HsTyVarBndr () GhcRn
bndr -> HsTyVarBndr () GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> Type
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
forall flag.
HsTyVarBndr flag GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> Type
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_bndr_in_pat HsTyVarBndr () GhcRn
bndr HsQTvsRn
wcs HsQTvsRn
imp_ns Type
expected_kind
where
all_ns :: HsQTvsRn
all_ns = HsQTvsRn
imp_ns HsQTvsRn -> HsQTvsRn -> HsQTvsRn
forall a. [a] -> [a] -> [a]
++ HsQTvsRn
exp_ns
HsTPRn{hstp_nwcs :: HsTyPatRn -> HsQTvsRn
hstp_nwcs = HsQTvsRn
wcs, hstp_imp_tvs :: HsTyPatRn -> HsQTvsRn
hstp_imp_tvs = HsQTvsRn
imp_ns, hstp_exp_tvs :: HsTyPatRn -> HsQTvsRn
hstp_exp_tvs = HsQTvsRn
exp_ns} = XHsTP GhcRn
hstp_rn
tc_unif_in_pat :: LHsType GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> ContextKind
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_unif_in_pat = UserTypeCtxt
-> HoleMode
-> LHsType GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> ContextKind
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_type_in_pat UserTypeCtxt
TypeAppCtxt HoleMode
HM_TyAppPat
tc_bndr_in_pat :: HsTyVarBndr flag GhcRn
-> [Name]
-> [Name]
-> Kind
-> TcM ( [(Name, TcTyVar)]
, [(Name, TcTyVar)]
, TcType)
tc_bndr_in_pat :: forall flag.
HsTyVarBndr flag GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> Type
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_bndr_in_pat HsTyVarBndr flag GhcRn
bndr HsQTvsRn
wcs HsQTvsRn
imp_ns Type
expected_kind = do
let HsTvb { tvb_var :: forall flag pass. HsTyVarBndr flag pass -> HsBndrVar pass
tvb_var = HsBndrVar GhcRn
bvar, tvb_kind :: forall flag pass. HsTyVarBndr flag pass -> HsBndrKind pass
tvb_kind = HsBndrKind GhcRn
bkind } = HsTyVarBndr flag GhcRn
bndr
String -> SDoc -> TcM ()
traceTc String
"tc_bndr_in_pat 1" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
expected_kind)
name <- HsBndrVar GhcRn -> TcM Name
tcHsBndrVarName HsBndrVar GhcRn
bvar
tv <- newPatTyVar name expected_kind
case bkind of
HsBndrNoKind XBndrNoKind GhcRn
_ ->
([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([], HsTyVarBndr flag GhcRn -> TcTyVar -> [(Name, TcTyVar)]
forall flag. HsTyVarBndr flag GhcRn -> TcTyVar -> [(Name, TcTyVar)]
mk_tvb_pairs HsTyVarBndr flag GhcRn
bndr TcTyVar
tv, TcTyVar -> Type
mkTyVarTy TcTyVar
tv)
HsBndrKind XBndrKind GhcRn
_ LHsType GhcRn
ki -> do
tkv_prs <- (Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcTyVar))
-> HsQTvsRn -> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
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 Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcTyVar)
new_implicit_tv HsQTvsRn
imp_ns
wcs <- addTypeCtxt ki $
solveEqualities "tc_bndr_in_pat" $
bindNamedWildCardBinders wcs $ \ [(Name, TcTyVar)]
wcs ->
[(Name, TcTyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
forall r. [(Name, TcTyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcTyVar)]
tkv_prs (IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
forall a b. (a -> b) -> a -> b
$
do { HsBndrVar GhcRn -> LHsType GhcRn -> Type -> TcM ()
tcHsTvbKind HsBndrVar GhcRn
bvar LHsType GhcRn
ki Type
expected_kind
; [(Name, TcTyVar)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(Name, TcTyVar)]
wcs }
mapM_ emitNamedTypeHole wcs
traceTc "tc_bndr_in_pat 2" $ vcat
[ text "expected_kind" <+> ppr expected_kind
, text "wcs" <+> ppr wcs
, text "(name,tv)" <+> ppr (name,tv)
, text "tkv_prs" <+> ppr tkv_prs]
let tvb_prs = HsTyVarBndr flag GhcRn -> TcTyVar -> [(Name, TcTyVar)]
forall flag. HsTyVarBndr flag GhcRn -> TcTyVar -> [(Name, TcTyVar)]
mk_tvb_pairs HsTyVarBndr flag GhcRn
bndr TcTyVar
tv
pure (wcs, tvb_prs ++ tkv_prs, mkTyVarTy tv)
where
new_implicit_tv :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcTyVar)
new_implicit_tv Name
name
= do { kind <- TcM Type
newMetaKindVar
; tv <- newPatTyVar name kind
; return (name, tv) }
tc_type_in_pat :: UserTypeCtxt
-> HoleMode
-> LHsType GhcRn
-> [Name]
-> [Name]
-> ContextKind
-> TcM ( [(Name, TcTyVar)]
, [(Name, TcTyVar)]
, TcType)
tc_type_in_pat :: UserTypeCtxt
-> HoleMode
-> LHsType GhcRn
-> HsQTvsRn
-> HsQTvsRn
-> ContextKind
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
tc_type_in_pat UserTypeCtxt
ctxt HoleMode
hole_mode LHsType GhcRn
hs_ty HsQTvsRn
wcs HsQTvsRn
ns ContextKind
ctxt_kind
= UserTypeCtxt
-> GenLocated SrcSpanAnnA (HsType GhcRn)
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
forall hs_ty a.
Outputable hs_ty =>
UserTypeCtxt -> LocatedA hs_ty -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
hs_ty (TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type))
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
-> TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], Type)
forall a b. (a -> b) -> a -> b
$
do { tkv_prs <- (Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcTyVar))
-> HsQTvsRn -> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcTyVar)]
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 Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcTyVar)
new_implicit_tv HsQTvsRn
ns
; mode <- mkHoleMode TypeLevel hole_mode
; (wcs, ty)
<- addTypeCtxt hs_ty $
solveEqualities "tc_type_in_pat" $
bindNamedWildCardBinders wcs $ \ [(Name, TcTyVar)]
wcs ->
[(Name, TcTyVar)]
-> TcM ([(Name, TcTyVar)], Type) -> TcM ([(Name, TcTyVar)], Type)
forall r. [(Name, TcTyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TcTyVar)]
tkv_prs (TcM ([(Name, TcTyVar)], Type) -> TcM ([(Name, TcTyVar)], Type))
-> TcM ([(Name, TcTyVar)], Type) -> TcM ([(Name, TcTyVar)], Type)
forall a b. (a -> b) -> a -> b
$
do { ek <- ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
; ty <- tc_check_lhs_type mode hs_ty ek
; return (wcs, ty) }
; mapM_ emitNamedTypeHole wcs
; kindGeneralizeNone ty
; ty <- liftZonkM $ zonkTcType ty
; checkValidType ctxt ty
; traceTc "tc_type_in_pat" (ppr tkv_prs)
; return (wcs, tkv_prs, ty) }
where
new_implicit_tv :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcTyVar)
new_implicit_tv Name
name
= do { kind <- TcM Type
newMetaKindVar
; tv <- case ctxt of
RuleSigCtxt FastString
rname Name
_ -> do
skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo (FastString -> SkolemInfoAnon
RuleSkol FastString
rname)
newSkolemTyVar skol_info name kind
UserTypeCtxt
_ -> Name -> Type -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newPatTyVar Name
name Type
kind
; return (name, tv) }
tyPatToBndr :: HsTyPat GhcRn -> Maybe (HsTyVarBndr () GhcRn)
tyPatToBndr :: HsTyPat GhcRn -> Maybe (HsTyVarBndr () GhcRn)
tyPatToBndr HsTP{hstp_body :: forall pass. HsTyPat pass -> LHsType pass
hstp_body = (L SrcSpanAnnA
_ HsType GhcRn
hs_ty)} = HsType GhcRn -> Maybe (HsTyVarBndr () GhcRn)
go HsType GhcRn
hs_ty where
go :: HsType GhcRn -> Maybe (HsTyVarBndr () GhcRn)
go :: HsType GhcRn -> Maybe (HsTyVarBndr () GhcRn)
go (HsParTy XParTy GhcRn
_ (L SrcSpanAnnA
_ HsType GhcRn
ty)) = HsType GhcRn -> Maybe (HsTyVarBndr () GhcRn)
go HsType GhcRn
ty
go (HsKindSig XKindSig GhcRn
_ (L SrcSpanAnnA
_ HsType GhcRn
ty) LHsType GhcRn
ki) = do
bvar <- HsType GhcRn -> Maybe (HsBndrVar GhcRn)
go_bvar HsType GhcRn
ty
let bkind = XBndrKind GhcRn -> LHsType GhcRn -> HsBndrKind GhcRn
forall pass. XBndrKind pass -> LHsKind pass -> HsBndrKind pass
HsBndrKind NoExtField
XBndrKind GhcRn
noExtField LHsType GhcRn
ki
Just (HsTvb noAnn () bvar bkind)
go HsType GhcRn
ty = do
bvar <- HsType GhcRn -> Maybe (HsBndrVar GhcRn)
go_bvar HsType GhcRn
ty
let bkind = XBndrNoKind GhcRn -> HsBndrKind GhcRn
forall pass. XBndrNoKind pass -> HsBndrKind pass
HsBndrNoKind NoExtField
XBndrNoKind GhcRn
noExtField
Just (HsTvb noAnn () bvar bkind)
go_bvar :: HsType GhcRn -> Maybe (HsBndrVar GhcRn)
go_bvar :: HsType GhcRn -> Maybe (HsBndrVar GhcRn)
go_bvar (HsTyVar XTyVar GhcRn
_ PromotionFlag
_ LIdP GhcRn
name)
| Name -> Bool
isTyVarName (GenLocated SrcSpanAnnN Name -> Name
forall l e. GenLocated l e -> e
unLoc LIdP GhcRn
GenLocated SrcSpanAnnN Name
name)
= HsBndrVar GhcRn -> Maybe (HsBndrVar GhcRn)
forall a. a -> Maybe a
Just (XBndrVar GhcRn -> LIdP GhcRn -> HsBndrVar GhcRn
forall pass. XBndrVar pass -> LIdP pass -> HsBndrVar pass
HsBndrVar NoExtField
XBndrVar GhcRn
noExtField LIdP GhcRn
name)
go_bvar (HsWildCardTy XWildCardTy GhcRn
_)
= HsBndrVar GhcRn -> Maybe (HsBndrVar GhcRn)
forall a. a -> Maybe a
Just (XBndrWildCard GhcRn -> HsBndrVar GhcRn
forall pass. XBndrWildCard pass -> HsBndrVar pass
HsBndrWildCard NoExtField
XBndrWildCard GhcRn
noExtField)
go_bvar HsType GhcRn
_ = Maybe (HsBndrVar GhcRn)
forall a. Maybe a
Nothing
unifyKinds :: [LHsType GhcRn] -> [(TcType, TcKind)] -> TcM ([TcType], TcKind)
unifyKinds :: [LHsType GhcRn] -> [(Type, Type)] -> TcM ([Type], Type)
unifyKinds [LHsType GhcRn]
rn_tys [(Type, Type)]
act_kinds
= do { kind <- TcM Type
newMetaKindVar
; let check GenLocated SrcSpanAnnA (HsType GhcRn)
rn_ty (Type
ty, Type
act_kind)
= HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
checkExpectedKind (GenLocated SrcSpanAnnA (HsType GhcRn) -> HsType GhcRn
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsType GhcRn)
rn_ty) Type
ty Type
act_kind Type
kind
; tys' <- zipWithM check rn_tys act_kinds
; return (tys', kind) }
tcLHsKindSig :: UserTypeCtxt -> LHsKind GhcRn -> TcM Kind
tcLHsKindSig :: UserTypeCtxt -> LHsType GhcRn -> TcM Type
tcLHsKindSig UserTypeCtxt
ctxt LHsType GhcRn
hs_kind
= TcTyMode -> UserTypeCtxt -> LHsType GhcRn -> TcM Type
tc_lhs_kind_sig TcTyMode
kindLevelMode UserTypeCtxt
ctxt LHsType GhcRn
hs_kind
tc_lhs_kind_sig :: TcTyMode -> UserTypeCtxt -> LHsKind GhcRn -> TcM Kind
tc_lhs_kind_sig :: TcTyMode -> UserTypeCtxt -> LHsType GhcRn -> TcM Type
tc_lhs_kind_sig TcTyMode
mode UserTypeCtxt
ctxt LHsType GhcRn
hs_kind
= do { kind <- SDoc -> TcM Type -> TcM Type
forall a. SDoc -> TcM a -> TcM a
addErrCtxt (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the kind" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (GenLocated SrcSpanAnnA (HsType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType GhcRn
GenLocated SrcSpanAnnA (HsType GhcRn)
hs_kind)) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
String -> TcM Type -> TcM Type
forall a. String -> TcM a -> TcM a
solveEqualities String
"tcLHsKindSig" (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsType GhcRn -> Type -> TcM Type
tc_check_lhs_type TcTyMode
mode LHsType GhcRn
hs_kind Type
liftedTypeKind
; traceTc "tcLHsKindSig" (ppr hs_kind $$ ppr kind)
; kindGeneralizeNone kind
; kind <- liftZonkM $ zonkTcType kind
; checkValidType ctxt kind
; traceTc "tcLHsKindSig2" (ppr kind)
; return kind }
promotionErr :: Name -> PromotionErr -> TcM a
promotionErr :: forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
err
= TcRnMessage -> TcM a
forall a. TcRnMessage -> TcM a
failWithTc (TcRnMessage -> TcM a) -> TcRnMessage -> TcM a
forall a b. (a -> b) -> a -> b
$ Name -> PromotionErr -> TcRnMessage
TcRnUnpromotableThing Name
name PromotionErr
err
funAppCtxt :: (Outputable fun, Outputable arg) => fun -> arg -> Int -> SDoc
funAppCtxt :: forall fun arg.
(Outputable fun, Outputable arg) =>
fun -> arg -> Int -> SDoc
funAppCtxt fun
fun arg
arg Int
arg_no
= SDoc -> Int -> SDoc -> SDoc
hang ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the", Int -> SDoc
speakNth Int
arg_no, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"argument of",
SDoc -> SDoc
quotes (fun -> SDoc
forall a. Outputable a => a -> SDoc
ppr fun
fun) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
", namely"])
Int
2 (SDoc -> SDoc
quotes (arg -> SDoc
forall a. Outputable a => a -> SDoc
ppr arg
arg))
addTyConFlavCtxt :: Name -> TyConFlavour tc -> TcM a -> TcM a
addTyConFlavCtxt :: forall tc a. Name -> TyConFlavour tc -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour tc
flav
= SDoc -> TcM a -> TcM a
forall a. SDoc -> TcM a -> TcM a
addErrCtxt (SDoc -> TcM a -> TcM a) -> SDoc -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"In the", TyConFlavour tc -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyConFlavour tc
flav
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"declaration for", SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) ]
tyLitFromLit :: HsLit GhcRn -> Maybe (HsTyLit GhcRn)
tyLitFromLit :: HsLit GhcRn -> Maybe (HsTyLit GhcRn)
tyLitFromLit (HsString XHsString GhcRn
x FastString
str) = HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a. a -> Maybe a
Just (XStrTy GhcRn -> FastString -> HsTyLit GhcRn
forall pass. XStrTy pass -> FastString -> HsTyLit pass
HsStrTy XStrTy GhcRn
XHsString GhcRn
x FastString
str)
tyLitFromLit (HsMultilineString XHsMultilineString GhcRn
x FastString
str) = HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a. a -> Maybe a
Just (XStrTy GhcRn -> FastString -> HsTyLit GhcRn
forall pass. XStrTy pass -> FastString -> HsTyLit pass
HsStrTy XStrTy GhcRn
XHsMultilineString GhcRn
x FastString
str)
tyLitFromLit (HsChar XHsChar GhcRn
x Char
char) = HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a. a -> Maybe a
Just (XCharTy GhcRn -> Char -> HsTyLit GhcRn
forall pass. XCharTy pass -> Char -> HsTyLit pass
HsCharTy XCharTy GhcRn
XHsChar GhcRn
x Char
char)
tyLitFromLit HsLit GhcRn
_ = Maybe (HsTyLit GhcRn)
forall a. Maybe a
Nothing
tyLitFromOverloadedLit :: OverLitVal -> Maybe (HsTyLit GhcRn)
tyLitFromOverloadedLit :: OverLitVal -> Maybe (HsTyLit GhcRn)
tyLitFromOverloadedLit (HsIntegral IntegralLit
n) = HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a. a -> Maybe a
Just (HsTyLit GhcRn -> Maybe (HsTyLit GhcRn))
-> HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a b. (a -> b) -> a -> b
$ XNumTy GhcRn -> Integer -> HsTyLit GhcRn
forall pass. XNumTy pass -> Integer -> HsTyLit pass
HsNumTy XNumTy GhcRn
SourceText
NoSourceText (IntegralLit -> Integer
il_value IntegralLit
n)
tyLitFromOverloadedLit (HsIsString SourceText
_ FastString
s) = HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a. a -> Maybe a
Just (HsTyLit GhcRn -> Maybe (HsTyLit GhcRn))
-> HsTyLit GhcRn -> Maybe (HsTyLit GhcRn)
forall a b. (a -> b) -> a -> b
$ XStrTy GhcRn -> FastString -> HsTyLit GhcRn
forall pass. XStrTy pass -> FastString -> HsTyLit pass
HsStrTy XStrTy GhcRn
SourceText
NoSourceText FastString
s
tyLitFromOverloadedLit HsFractional{} = Maybe (HsTyLit GhcRn)
forall a. Maybe a
Nothing