{-# LANGUAGE CPP, TupleSections, MultiWayIf, RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Tc.Gen.HsType (
kcClassSigType, tcClassSigType,
tcHsSigType, tcHsSigWcType,
tcHsPartialSigType,
tcStandaloneKindSig,
funsSigCtxt, addSigCtxt, pprSigCtxt,
tcHsClsInstType,
tcHsDeriv, tcDerivStrategy,
tcHsTypeApp,
UserTypeCtxt(..),
bindImplicitTKBndrs_Tv, bindImplicitTKBndrs_Skol,
bindImplicitTKBndrs_Q_Tv, bindImplicitTKBndrs_Q_Skol,
bindExplicitTKBndrs_Tv, bindExplicitTKBndrs_Skol,
bindExplicitTKBndrs_Q_Tv, bindExplicitTKBndrs_Q_Skol,
ContextKind(..),
bindTyClTyVars,
etaExpandAlgTyCon, tcbVisibilities,
zonkAndScopedSort,
InitialKindStrategy(..),
SAKS_or_CUSK(..),
kcDeclHeader,
tcNamedWildCardBinders,
tcHsLiftedType, tcHsOpenType,
tcHsLiftedTypeNC, tcHsOpenTypeNC,
tcLHsType, tcLHsTypeUnsaturated, tcCheckLHsType,
tcHsMbContext, tcHsContext, tcLHsPredType, tcInferApps,
failIfEmitsConstraints,
solveEqualities,
typeLevelMode, kindLevelMode,
kindGeneralizeAll, kindGeneralizeSome, kindGeneralizeNone,
tcLHsKindSig, checkDataKindSig, DataSort(..),
checkClassKindSig,
tcHsPatSigType,
funAppCtxt, addTyConFlavCtxt
) where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Hs
import GHC.Tc.Utils.Monad
import GHC.Tc.Types.Origin
import GHC.Core.Predicate
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.Utils.Zonk
import GHC.Core.TyCo.Rep
import GHC.Core.TyCo.Ppr
import GHC.Tc.Errors ( reportAllUnsolved )
import GHC.Tc.Utils.TcType
import GHC.Tc.Utils.Instantiate ( tcInstInvisibleTyBinders, tcInstInvisibleTyBinder )
import GHC.Core.Type
import GHC.Builtin.Types.Prim
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.Settings.Constants ( mAX_CTUPLE_SIZE )
import GHC.Utils.Error( MsgDoc )
import GHC.Types.Unique
import GHC.Types.Unique.Set
import GHC.Utils.Misc
import GHC.Types.Unique.Supply
import GHC.Utils.Outputable
import GHC.Data.FastString
import GHC.Builtin.Names hiding ( wildCardName )
import GHC.Driver.Session
import qualified GHC.LanguageExtensions as LangExt
import GHC.Data.Maybe
import Data.List ( find )
import Control.Monad
funsSigCtxt :: [Located Name] -> UserTypeCtxt
funsSigCtxt :: [Located Name] -> UserTypeCtxt
funsSigCtxt (L SrcSpan
_ Name
name1 : [Located Name]
_) = Name -> Bool -> UserTypeCtxt
FunSigCtxt Name
name1 Bool
False
funsSigCtxt [] = String -> UserTypeCtxt
forall a. String -> a
panic String
"funSigCtxt"
addSigCtxt :: UserTypeCtxt -> LHsType GhcRn -> TcM a -> TcM a
addSigCtxt :: UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsKind GhcRn
hs_ty TcM a
thing_inside
= SrcSpan -> TcM a -> TcM a
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (LHsKind GhcRn -> SrcSpan
forall l e. GenLocated l e -> l
getLoc LHsKind GhcRn
hs_ty) (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
MsgDoc -> TcM a -> TcM a
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (UserTypeCtxt -> LHsKind GhcRn -> MsgDoc
pprSigCtxt UserTypeCtxt
ctxt LHsKind GhcRn
hs_ty) (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TcM a
thing_inside
pprSigCtxt :: UserTypeCtxt -> LHsType GhcRn -> SDoc
pprSigCtxt :: UserTypeCtxt -> LHsKind GhcRn -> MsgDoc
pprSigCtxt UserTypeCtxt
ctxt LHsKind GhcRn
hs_ty
| Just Name
n <- UserTypeCtxt -> Maybe Name
isSigMaybe UserTypeCtxt
ctxt
= MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"In the type signature:")
Arity
2 (Name -> MsgDoc
forall a. OutputableBndr a => a -> MsgDoc
External instance of the constraint type OutputableBndr Name
pprPrefixOcc Name
n MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
dcolon MsgDoc -> MsgDoc -> MsgDoc
<+> LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
hs_ty)
| Bool
otherwise
= MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"In" MsgDoc -> MsgDoc -> MsgDoc
<+> UserTypeCtxt -> MsgDoc
pprUserTypeCtxt UserTypeCtxt
ctxt MsgDoc -> MsgDoc -> MsgDoc
<> MsgDoc
colon)
Arity
2 (LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
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 :: SkolemInfo -> [Located Name] -> LHsSigType GhcRn -> TcM ()
kcClassSigType :: SkolemInfo -> [Located Name] -> LHsSigType GhcRn -> TcM ()
kcClassSigType SkolemInfo
skol_info [Located Name]
names (HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (LHsKind GhcRn)
sig_vars
, hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsKind GhcRn
hs_ty })
= UserTypeCtxt -> LHsKind GhcRn -> TcM () -> TcM ()
forall a. UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt ([Located Name] -> UserTypeCtxt
funsSigCtxt [Located Name]
names) LHsKind GhcRn
hs_ty (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
do { (TcLevel
tc_lvl, (WantedConstraints
wanted, ([TyVar]
spec_tkvs, Type
_)))
<- TcM (WantedConstraints, ([TyVar], Type))
-> TcM (TcLevel, (WantedConstraints, ([TyVar], Type)))
forall a. TcM a -> TcM (TcLevel, a)
pushTcLevelM (TcM (WantedConstraints, ([TyVar], Type))
-> TcM (TcLevel, (WantedConstraints, ([TyVar], Type))))
-> TcM (WantedConstraints, ([TyVar], Type))
-> TcM (TcLevel, (WantedConstraints, ([TyVar], Type)))
forall a b. (a -> b) -> a -> b
$
String
-> TcM ([TyVar], Type) -> TcM (WantedConstraints, ([TyVar], Type))
forall a. String -> TcM a -> TcM (WantedConstraints, a)
solveLocalEqualitiesX String
"kcClassSigType" (TcM ([TyVar], Type) -> TcM (WantedConstraints, ([TyVar], Type)))
-> TcM ([TyVar], Type) -> TcM (WantedConstraints, ([TyVar], Type))
forall a b. (a -> b) -> a -> b
$
HsQTvsRn -> TcM Type -> TcM ([TyVar], Type)
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Skol HsQTvsRn
XHsIB GhcRn (LHsKind GhcRn)
sig_vars (TcM Type -> TcM ([TyVar], Type))
-> TcM Type -> TcM ([TyVar], Type)
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
typeLevelMode LHsKind GhcRn
hs_ty Type
liftedTypeKind
; SkolemInfo
-> Maybe MsgDoc
-> [TyVar]
-> TcLevel
-> WantedConstraints
-> TcM ()
emitResidualTvConstraint SkolemInfo
skol_info Maybe MsgDoc
forall a. Maybe a
Nothing [TyVar]
spec_tkvs
TcLevel
tc_lvl WantedConstraints
wanted }
tcClassSigType :: SkolemInfo -> [Located Name] -> LHsSigType GhcRn -> TcM Type
tcClassSigType :: SkolemInfo -> [Located Name] -> LHsSigType GhcRn -> TcM Type
tcClassSigType SkolemInfo
skol_info [Located Name]
names LHsSigType GhcRn
sig_ty
= UserTypeCtxt -> LHsKind GhcRn -> TcM Type -> TcM Type
forall a. UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt ([Located Name] -> UserTypeCtxt
funsSigCtxt [Located Name]
names) (LHsSigType GhcRn -> LHsKind GhcRn
forall (p :: Pass). LHsSigType (GhcPass p) -> LHsType (GhcPass p)
hsSigType LHsSigType GhcRn
sig_ty) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
(Bool, Type) -> Type
forall a b. (a, b) -> b
snd ((Bool, Type) -> Type)
-> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Type) -> TcM Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
External instance of the constraint type forall env. Functor (IOEnv env)
<$> SkolemInfo
-> LHsSigType GhcRn
-> ContextKind
-> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Type)
tc_hs_sig_type SkolemInfo
skol_info LHsSigType GhcRn
sig_ty (Type -> ContextKind
TheKind Type
liftedTypeKind)
tcHsSigType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcHsSigType :: UserTypeCtxt -> LHsSigType GhcRn -> TcM Type
tcHsSigType UserTypeCtxt
ctxt LHsSigType GhcRn
sig_ty
= UserTypeCtxt -> LHsKind GhcRn -> TcM Type -> TcM Type
forall a. UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt (LHsSigType GhcRn -> LHsKind GhcRn
forall (p :: Pass). LHsSigType (GhcPass p) -> LHsType (GhcPass p)
hsSigType LHsSigType GhcRn
sig_ty) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { String -> MsgDoc -> TcM ()
traceTc String
"tcHsSigType {" (LHsSigType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall thing (p :: Pass).
Outputable thing =>
Outputable (HsImplicitBndrs (GhcPass p) thing)
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsSigType GhcRn
sig_ty)
; (Bool
insol, Type
ty) <- SkolemInfo
-> LHsSigType GhcRn
-> ContextKind
-> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Type)
tc_hs_sig_type SkolemInfo
skol_info LHsSigType GhcRn
sig_ty
(UserTypeCtxt -> ContextKind
expectedKindInCtxt UserTypeCtxt
ctxt)
; Type
ty <- Type -> TcM Type
zonkTcType Type
ty
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
when Bool
insol TcM ()
forall env a. IOEnv env a
failM
; UserTypeCtxt -> Type -> TcM ()
checkValidType UserTypeCtxt
ctxt Type
ty
; String -> MsgDoc -> TcM ()
traceTc String
"end tcHsSigType }" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
ty)
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
ty }
where
skol_info :: SkolemInfo
skol_info = UserTypeCtxt -> SkolemInfo
SigTypeSkol UserTypeCtxt
ctxt
tcStandaloneKindSig :: LStandaloneKindSig GhcRn -> TcM (Name, Kind)
tcStandaloneKindSig :: LStandaloneKindSig GhcRn -> TcM (Name, Type)
tcStandaloneKindSig (L SrcSpan
_ StandaloneKindSig GhcRn
kisig) = case StandaloneKindSig GhcRn
kisig of
StandaloneKindSig XStandaloneKindSig GhcRn
_ (L SrcSpan
_ IdP GhcRn
name) LHsSigType GhcRn
ksig ->
let ctxt :: UserTypeCtxt
ctxt = Name -> UserTypeCtxt
StandaloneKindSigCtxt Name
IdP GhcRn
name in
UserTypeCtxt
-> LHsKind GhcRn -> TcM (Name, Type) -> TcM (Name, Type)
forall a. UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt (LHsSigType GhcRn -> LHsKind GhcRn
forall (p :: Pass). LHsSigType (GhcPass p) -> LHsType (GhcPass p)
hsSigType LHsSigType GhcRn
ksig) (TcM (Name, Type) -> TcM (Name, Type))
-> TcM (Name, Type) -> TcM (Name, Type)
forall a b. (a -> b) -> a -> b
$
do { Type
kind <- TcTyMode -> LHsSigType GhcRn -> ContextKind -> TcM Type
tcTopLHsType TcTyMode
kindLevelMode LHsSigType GhcRn
ksig (UserTypeCtxt -> ContextKind
expectedKindInCtxt UserTypeCtxt
ctxt)
; UserTypeCtxt -> Type -> TcM ()
checkValidType UserTypeCtxt
ctxt Type
kind
; (Name, Type) -> TcM (Name, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Name
IdP GhcRn
name, Type
kind) }
tc_hs_sig_type :: SkolemInfo -> LHsSigType GhcRn
-> ContextKind -> TcM (Bool, TcType)
tc_hs_sig_type :: SkolemInfo
-> LHsSigType GhcRn
-> ContextKind
-> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Type)
tc_hs_sig_type SkolemInfo
skol_info LHsSigType GhcRn
hs_sig_type ContextKind
ctxt_kind
| HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (LHsKind GhcRn)
sig_vars, hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsKind GhcRn
hs_ty } <- LHsSigType GhcRn
hs_sig_type
= do { (TcLevel
tc_lvl, (WantedConstraints
wanted, ([TyVar]
spec_tkvs, Type
ty)))
<- TcM (WantedConstraints, ([TyVar], Type))
-> TcM (TcLevel, (WantedConstraints, ([TyVar], Type)))
forall a. TcM a -> TcM (TcLevel, a)
pushTcLevelM (TcM (WantedConstraints, ([TyVar], Type))
-> TcM (TcLevel, (WantedConstraints, ([TyVar], Type))))
-> TcM (WantedConstraints, ([TyVar], Type))
-> TcM (TcLevel, (WantedConstraints, ([TyVar], Type)))
forall a b. (a -> b) -> a -> b
$
String
-> TcM ([TyVar], Type) -> TcM (WantedConstraints, ([TyVar], Type))
forall a. String -> TcM a -> TcM (WantedConstraints, a)
solveLocalEqualitiesX String
"tc_hs_sig_type" (TcM ([TyVar], Type) -> TcM (WantedConstraints, ([TyVar], Type)))
-> TcM ([TyVar], Type) -> TcM (WantedConstraints, ([TyVar], Type))
forall a b. (a -> b) -> a -> b
$
HsQTvsRn -> TcM Type -> TcM ([TyVar], Type)
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Skol HsQTvsRn
XHsIB GhcRn (LHsKind GhcRn)
sig_vars (TcM Type -> TcM ([TyVar], Type))
-> TcM Type -> TcM ([TyVar], Type)
forall a b. (a -> b) -> a -> b
$
do { Type
kind <- ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
; TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
typeLevelMode LHsKind GhcRn
hs_ty Type
kind }
; [TyVar]
spec_tkvs <- [TyVar] -> TcM [TyVar]
zonkAndScopedSort [TyVar]
spec_tkvs
; let ty1 :: Type
ty1 = [TyVar] -> Type -> Type
mkSpecForAllTys [TyVar]
spec_tkvs Type
ty
; TyCoVarSet
constrained <- TyCoVarSet -> TcM TyCoVarSet
zonkTyCoVarsAndFV (WantedConstraints -> TyCoVarSet
tyCoVarsOfWC WantedConstraints
wanted)
; let should_gen :: TyVar -> Bool
should_gen = Bool -> Bool
not (Bool -> Bool) -> (TyVar -> Bool) -> TyVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TyVar -> TyCoVarSet -> Bool
`elemVarSet` TyCoVarSet
constrained)
; [TyVar]
kvs <- (TyVar -> Bool) -> Type -> TcM [TyVar]
kindGeneralizeSome TyVar -> Bool
should_gen Type
ty1
; SkolemInfo
-> Maybe MsgDoc
-> [TyVar]
-> TcLevel
-> WantedConstraints
-> TcM ()
emitResidualTvConstraint SkolemInfo
skol_info Maybe MsgDoc
forall a. Maybe a
Nothing ([TyVar]
kvs [TyVar] -> [TyVar] -> [TyVar]
forall a. [a] -> [a] -> [a]
++ [TyVar]
spec_tkvs)
TcLevel
tc_lvl WantedConstraints
wanted
; (Bool, Type) -> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (WantedConstraints -> Bool
insolubleWC WantedConstraints
wanted, [TyVar] -> Type -> Type
mkInfForAllTys [TyVar]
kvs Type
ty1) }
tcTopLHsType :: TcTyMode -> LHsSigType GhcRn -> ContextKind -> TcM Type
tcTopLHsType :: TcTyMode -> LHsSigType GhcRn -> ContextKind -> TcM Type
tcTopLHsType TcTyMode
mode LHsSigType GhcRn
hs_sig_type ContextKind
ctxt_kind
| HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (LHsKind GhcRn)
sig_vars, hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsKind GhcRn
hs_ty } <- LHsSigType GhcRn
hs_sig_type
= do { String -> MsgDoc -> TcM ()
traceTc String
"tcTopLHsType {" (LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
hs_ty)
; ([TyVar]
spec_tkvs, Type
ty)
<- TcM ([TyVar], Type) -> TcM ([TyVar], Type)
forall a. TcM a -> TcM a
pushTcLevelM_ (TcM ([TyVar], Type) -> TcM ([TyVar], Type))
-> TcM ([TyVar], Type) -> TcM ([TyVar], Type)
forall a b. (a -> b) -> a -> b
$
TcM ([TyVar], Type) -> TcM ([TyVar], Type)
forall a. TcM a -> TcM a
solveEqualities (TcM ([TyVar], Type) -> TcM ([TyVar], Type))
-> TcM ([TyVar], Type) -> TcM ([TyVar], Type)
forall a b. (a -> b) -> a -> b
$
HsQTvsRn -> TcM Type -> TcM ([TyVar], Type)
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Skol HsQTvsRn
XHsIB GhcRn (LHsKind GhcRn)
sig_vars (TcM Type -> TcM ([TyVar], Type))
-> TcM Type -> TcM ([TyVar], Type)
forall a b. (a -> b) -> a -> b
$
do { Type
kind <- ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
; TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
hs_ty Type
kind }
; [TyVar]
spec_tkvs <- [TyVar] -> TcM [TyVar]
zonkAndScopedSort [TyVar]
spec_tkvs
; let ty1 :: Type
ty1 = [TyVar] -> Type -> Type
mkSpecForAllTys [TyVar]
spec_tkvs Type
ty
; [TyVar]
kvs <- Type -> TcM [TyVar]
kindGeneralizeAll Type
ty1
; Type
final_ty <- Type -> TcM Type
zonkTcTypeToType ([TyVar] -> Type -> Type
mkInfForAllTys [TyVar]
kvs Type
ty1)
; String -> MsgDoc -> TcM ()
traceTc String
"End tcTopLHsType }" ([MsgDoc] -> MsgDoc
vcat [LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
hs_ty, Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
final_ty])
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
final_ty}
tcHsDeriv :: LHsSigType GhcRn -> TcM ([TyVar], Class, [Type], [Kind])
tcHsDeriv :: LHsSigType GhcRn -> TcM ([TyVar], Class, [Type], [Type])
tcHsDeriv LHsSigType GhcRn
hs_ty
= do { Type
ty <- TcM Type -> TcM Type
forall a. TcM a -> TcM a
checkNoErrs (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsSigType GhcRn -> ContextKind -> TcM Type
tcTopLHsType TcTyMode
typeLevelMode LHsSigType GhcRn
hs_ty ContextKind
AnyKind
; let ([TyVar]
tvs, Type
pred) = Type -> ([TyVar], Type)
splitForAllTys Type
ty
([Type]
kind_args, Type
_) = Type -> ([Type], Type)
splitFunTys (HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
tcTypeKind Type
pred)
; case Type -> Maybe (Class, [Type])
getClassPredTys_maybe Type
pred of
Just (Class
cls, [Type]
tys) -> ([TyVar], Class, [Type], [Type])
-> TcM ([TyVar], Class, [Type], [Type])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([TyVar]
tvs, Class
cls, [Type]
tys, [Type]
kind_args)
Maybe (Class, [Type])
Nothing -> MsgDoc -> TcM ([TyVar], Class, [Type], [Type])
forall a. MsgDoc -> TcM a
failWithTc (String -> MsgDoc
text String
"Illegal deriving item" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (LHsSigType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall thing (p :: Pass).
Outputable thing =>
Outputable (HsImplicitBndrs (GhcPass p) thing)
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsSigType GhcRn
hs_ty)) }
tcDerivStrategy ::
Maybe (LDerivStrategy GhcRn)
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
tcDerivStrategy :: Maybe (LDerivStrategy GhcRn)
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
tcDerivStrategy Maybe (LDerivStrategy GhcRn)
mb_lds
= case Maybe (LDerivStrategy GhcRn)
mb_lds of
Maybe (LDerivStrategy GhcRn)
Nothing -> Maybe (LDerivStrategy GhcTc)
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
forall ds. ds -> TcM (ds, [TyVar])
boring_case Maybe (LDerivStrategy GhcTc)
forall a. Maybe a
Nothing
Just (L SrcSpan
loc DerivStrategy GhcRn
ds) ->
SrcSpan
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar]))
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
forall a b. (a -> b) -> a -> b
$ do
(DerivStrategy GhcTc
ds', [TyVar]
tvs) <- DerivStrategy GhcRn -> TcM (DerivStrategy GhcTc, [TyVar])
tc_deriv_strategy DerivStrategy GhcRn
ds
(Maybe (LDerivStrategy GhcTc), [TyVar])
-> TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
forall (f :: * -> *) a. Applicative f => a -> f a
External instance of the constraint type forall m. Applicative (IOEnv m)
pure (LDerivStrategy GhcTc -> Maybe (LDerivStrategy GhcTc)
forall a. a -> Maybe a
Just (SrcSpan -> DerivStrategy GhcTc -> LDerivStrategy GhcTc
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc DerivStrategy GhcTc
ds'), [TyVar]
tvs)
where
tc_deriv_strategy :: DerivStrategy GhcRn
-> TcM (DerivStrategy GhcTc, [TyVar])
tc_deriv_strategy :: DerivStrategy GhcRn -> TcM (DerivStrategy GhcTc, [TyVar])
tc_deriv_strategy DerivStrategy GhcRn
StockStrategy = DerivStrategy GhcTc -> TcM (DerivStrategy GhcTc, [TyVar])
forall ds. ds -> TcM (ds, [TyVar])
boring_case DerivStrategy GhcTc
forall pass. DerivStrategy pass
StockStrategy
tc_deriv_strategy DerivStrategy GhcRn
AnyclassStrategy = DerivStrategy GhcTc -> TcM (DerivStrategy GhcTc, [TyVar])
forall ds. ds -> TcM (ds, [TyVar])
boring_case DerivStrategy GhcTc
forall pass. DerivStrategy pass
AnyclassStrategy
tc_deriv_strategy DerivStrategy GhcRn
NewtypeStrategy = DerivStrategy GhcTc -> TcM (DerivStrategy GhcTc, [TyVar])
forall ds. ds -> TcM (ds, [TyVar])
boring_case DerivStrategy GhcTc
forall pass. DerivStrategy pass
NewtypeStrategy
tc_deriv_strategy (ViaStrategy XViaStrategy GhcRn
ty) = do
Type
ty' <- TcM Type -> TcM Type
forall a. TcM a -> TcM a
checkNoErrs (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$ TcTyMode -> LHsSigType GhcRn -> ContextKind -> TcM Type
tcTopLHsType TcTyMode
typeLevelMode XViaStrategy GhcRn
LHsSigType GhcRn
ty ContextKind
AnyKind
let ([TyVar]
via_tvs, Type
via_pred) = Type -> ([TyVar], Type)
splitForAllTys Type
ty'
(DerivStrategy GhcTc, [TyVar])
-> TcM (DerivStrategy GhcTc, [TyVar])
forall (f :: * -> *) a. Applicative f => a -> f a
External instance of the constraint type forall m. Applicative (IOEnv m)
pure (XViaStrategy GhcTc -> DerivStrategy GhcTc
forall pass. XViaStrategy pass -> DerivStrategy pass
ViaStrategy Type
XViaStrategy GhcTc
via_pred, [TyVar]
via_tvs)
boring_case :: ds -> TcM (ds, [TyVar])
boring_case :: ds -> TcM (ds, [TyVar])
boring_case ds
ds = (ds, [TyVar]) -> TcM (ds, [TyVar])
forall (f :: * -> *) a. Applicative f => a -> f a
External instance of the constraint type forall m. Applicative (IOEnv m)
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 (LHsKind GhcRn -> SrcSpan
forall l e. GenLocated l e -> l
getLoc (LHsSigType GhcRn -> LHsKind GhcRn
forall (p :: Pass). LHsSigType (GhcPass p) -> LHsType (GhcPass p)
hsSigType LHsSigType GhcRn
hs_inst_ty)) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do {
Type
inst_ty <- TcM Type -> TcM Type
forall a. TcM a -> TcM a
checkNoErrs (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsSigType GhcRn -> ContextKind -> TcM Type
tcTopLHsType TcTyMode
typeLevelMode LHsSigType GhcRn
hs_inst_ty (Type -> ContextKind
TheKind Type
constraintKind)
; UserTypeCtxt -> LHsSigType GhcRn -> Type -> TcM ()
checkValidInstance UserTypeCtxt
user_ctxt LHsSigType GhcRn
hs_inst_ty Type
inst_ty
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
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 (LHsKind GhcRn)
sig_wcs, hswc_body :: forall pass thing. HsWildCardBndrs pass thing -> thing
hswc_body = LHsKind GhcRn
hs_ty } <- LHsWcType GhcRn
wc_ty
= do { Type
ty <- String -> TcM Type -> TcM Type
forall a. String -> TcM a -> TcM a
solveLocalEqualities String
"tcHsTypeApp" (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
WarningFlag -> TcM Type -> TcM Type
forall gbl lcl a.
WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetWOptM WarningFlag
Opt_WarnPartialTypeSignatures (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
Extension -> TcM Type -> TcM Type
forall gbl lcl a. Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setXOptM Extension
LangExt.PartialTypeSignatures (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
HsQTvsRn -> ([(Name, TyVar)] -> TcM Type) -> TcM Type
forall a. HsQTvsRn -> ([(Name, TyVar)] -> TcM a) -> TcM a
tcNamedWildCardBinders HsQTvsRn
XHsWC GhcRn (LHsKind GhcRn)
sig_wcs (([(Name, TyVar)] -> TcM Type) -> TcM Type)
-> ([(Name, TyVar)] -> TcM Type) -> TcM Type
forall a b. (a -> b) -> a -> b
$ \ [(Name, TyVar)]
_ ->
LHsKind GhcRn -> ContextKind -> TcM Type
tcCheckLHsType LHsKind GhcRn
hs_ty (Type -> ContextKind
TheKind Type
kind)
; Type -> TcM ()
kindGeneralizeNone Type
ty
; Type
ty <- Type -> TcM Type
zonkTcType Type
ty
; UserTypeCtxt -> Type -> TcM ()
checkValidType UserTypeCtxt
TypeAppCtxt Type
ty
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
ty }
tcHsOpenType, tcHsLiftedType,
tcHsOpenTypeNC, tcHsLiftedTypeNC :: LHsType GhcRn -> TcM TcType
tcHsOpenType :: LHsKind GhcRn -> TcM Type
tcHsOpenType LHsKind GhcRn
ty = LHsKind GhcRn -> TcM Type -> TcM Type
forall a. LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt LHsKind GhcRn
ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$ LHsKind GhcRn -> TcM Type
tcHsOpenTypeNC LHsKind GhcRn
ty
tcHsLiftedType :: LHsKind GhcRn -> TcM Type
tcHsLiftedType LHsKind GhcRn
ty = LHsKind GhcRn -> TcM Type -> TcM Type
forall a. LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt LHsKind GhcRn
ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$ LHsKind GhcRn -> TcM Type
tcHsLiftedTypeNC LHsKind GhcRn
ty
tcHsOpenTypeNC :: LHsKind GhcRn -> TcM Type
tcHsOpenTypeNC LHsKind GhcRn
ty = do { Type
ek <- TcM Type
newOpenTypeKind
; TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
typeLevelMode LHsKind GhcRn
ty Type
ek }
tcHsLiftedTypeNC :: LHsKind GhcRn -> TcM Type
tcHsLiftedTypeNC LHsKind GhcRn
ty = TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
typeLevelMode LHsKind GhcRn
ty Type
liftedTypeKind
tcCheckLHsType :: LHsType GhcRn -> ContextKind -> TcM TcType
tcCheckLHsType :: LHsKind GhcRn -> ContextKind -> TcM Type
tcCheckLHsType LHsKind GhcRn
hs_ty ContextKind
exp_kind
= LHsKind GhcRn -> TcM Type -> TcM Type
forall a. LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt LHsKind GhcRn
hs_ty (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
do { Type
ek <- ContextKind -> TcM Type
newExpectedKind ContextKind
exp_kind
; TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
typeLevelMode LHsKind GhcRn
hs_ty Type
ek }
tcLHsType :: LHsType GhcRn -> TcM (TcType, TcKind)
tcLHsType :: LHsKind GhcRn -> TcM (Type, Type)
tcLHsType LHsKind GhcRn
ty = LHsKind GhcRn -> TcM (Type, Type) -> TcM (Type, Type)
forall a. LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt LHsKind GhcRn
ty (TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
typeLevelMode LHsKind GhcRn
ty)
tcLHsTypeUnsaturated :: LHsType GhcRn -> TcM (TcType, TcKind)
tcLHsTypeUnsaturated :: LHsKind GhcRn -> TcM (Type, Type)
tcLHsTypeUnsaturated LHsKind GhcRn
hs_ty
| Just (LHsKind GhcRn
hs_fun_ty, [LHsTypeArg GhcRn]
hs_args) <- HsType GhcRn -> Maybe (LHsKind GhcRn, [LHsTypeArg GhcRn])
splitHsAppTys (LHsKind GhcRn -> HsType GhcRn
forall l e. GenLocated l e -> e
unLoc LHsKind GhcRn
hs_ty)
= LHsKind GhcRn -> TcM (Type, Type) -> TcM (Type, Type)
forall a. LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt LHsKind GhcRn
hs_ty (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
do { (Type
fun_ty, Type
_ki) <- TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tcInferAppHead TcTyMode
mode LHsKind GhcRn
hs_fun_ty
; TcTyMode
-> LHsKind GhcRn -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
tcInferApps_nosat TcTyMode
mode LHsKind GhcRn
hs_fun_ty Type
fun_ty [LHsTypeArg GhcRn]
hs_args }
| Bool
otherwise
= LHsKind GhcRn -> TcM (Type, Type) -> TcM (Type, Type)
forall a. LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt LHsKind GhcRn
hs_ty (TcM (Type, Type) -> TcM (Type, Type))
-> TcM (Type, Type) -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode LHsKind GhcRn
hs_ty
where
mode :: TcTyMode
mode = TcTyMode
typeLevelMode
data TcTyMode = TcTyMode { TcTyMode -> TypeOrKind
mode_level :: TypeOrKind }
typeLevelMode :: TcTyMode
typeLevelMode :: TcTyMode
typeLevelMode = TcTyMode :: TypeOrKind -> TcTyMode
TcTyMode { mode_level :: TypeOrKind
mode_level = TypeOrKind
TypeLevel }
kindLevelMode :: TcTyMode
kindLevelMode :: TcTyMode
kindLevelMode = TcTyMode :: TypeOrKind -> TcTyMode
TcTyMode { mode_level :: TypeOrKind
mode_level = TypeOrKind
KindLevel }
kindLevel :: TcTyMode -> TcTyMode
kindLevel :: TcTyMode -> TcTyMode
kindLevel TcTyMode
mode = TcTyMode
mode { mode_level :: TypeOrKind
mode_level = TypeOrKind
KindLevel }
instance Outputable TcTyMode where
ppr :: TcTyMode -> MsgDoc
ppr = TypeOrKind -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TypeOrKind
ppr (TypeOrKind -> MsgDoc)
-> (TcTyMode -> TypeOrKind) -> TcTyMode -> MsgDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcTyMode -> TypeOrKind
mode_level
tc_infer_lhs_type :: TcTyMode -> LHsType GhcRn -> TcM (TcType, TcKind)
tc_infer_lhs_type :: TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode (L SrcSpan
span HsType GhcRn
ty)
= SrcSpan -> TcM (Type, Type) -> TcM (Type, Type)
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
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_ek :: HasDebugCallStack => TcTyMode -> HsType GhcRn -> TcKind -> TcM TcType
tc_infer_hs_type_ek :: TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
hs_ty Type
ek
= do { (Type
ty, Type
k) <- TcTyMode -> HsType GhcRn -> TcM (Type, Type)
tc_infer_hs_type TcTyMode
mode HsType GhcRn
hs_ty
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
Evidence bound by a type signature of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
hs_ty Type
ty Type
k Type
ek }
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 (HsParTy XParTy GhcRn
_ LHsKind GhcRn
t)
= TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode LHsKind GhcRn
t
tc_infer_hs_type TcTyMode
mode HsType GhcRn
ty
| Just (LHsKind GhcRn
hs_fun_ty, [LHsTypeArg GhcRn]
hs_args) <- HsType GhcRn -> Maybe (LHsKind GhcRn, [LHsTypeArg GhcRn])
splitHsAppTys HsType GhcRn
ty
= do { (Type
fun_ty, Type
_ki) <- TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tcInferAppHead TcTyMode
mode LHsKind GhcRn
hs_fun_ty
; TcTyMode
-> LHsKind GhcRn -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
tcInferApps TcTyMode
mode LHsKind GhcRn
hs_fun_ty Type
fun_ty [LHsTypeArg GhcRn]
hs_args }
tc_infer_hs_type TcTyMode
mode (HsKindSig XKindSig GhcRn
_ LHsKind GhcRn
ty LHsKind GhcRn
sig)
= do { Type
sig' <- UserTypeCtxt -> LHsKind GhcRn -> TcM Type
tcLHsKindSig UserTypeCtxt
KindSigCtxt LHsKind GhcRn
sig
; String -> MsgDoc -> TcM ()
traceTc String
"tc_infer_hs_type:sig" (LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
ty MsgDoc -> MsgDoc -> MsgDoc
$$ Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
sig')
; Type
ty' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty Type
sig'
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
ty', Type
sig') }
tc_infer_hs_type TcTyMode
mode (HsSpliceTy XSpliceTy GhcRn
_ (HsSpliced XSpliced GhcRn
_ ThModFinalizers
_ (HsSplicedTy HsType GhcRn
ty)))
= TcTyMode -> HsType GhcRn -> TcM (Type, Type)
tc_infer_hs_type TcTyMode
mode HsType GhcRn
ty
tc_infer_hs_type TcTyMode
mode (HsDocTy XDocTy GhcRn
_ LHsKind GhcRn
ty LHsDocString
_) = TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode LHsKind GhcRn
ty
tc_infer_hs_type TcTyMode
_ (XHsType (NHsCoreTy Type
ty))
= (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
ty, HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
tcTypeKind Type
ty)
tc_infer_hs_type TcTyMode
_ (HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
_ [LHsKind GhcRn]
tys)
| [LHsKind GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [LHsKind GhcRn]
tys
= (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TyCon -> Type
mkTyConTy TyCon
promotedNilDataCon,
[TyVar] -> Type -> Type
mkSpecForAllTys [TyVar
alphaTyVar] (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type
mkListTy Type
alphaTy)
tc_infer_hs_type TcTyMode
mode HsType GhcRn
other_ty
= do { Type
kv <- TcM Type
newMetaKindVar
; Type
ty' <- TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_hs_type TcTyMode
mode HsType GhcRn
other_ty Type
kv
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
ty', Type
kv) }
tc_lhs_type :: TcTyMode -> LHsType GhcRn -> TcKind -> TcM TcType
tc_lhs_type :: TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode (L SrcSpan
span HsType GhcRn
ty) Type
exp_kind
= SrcSpan -> TcM Type -> TcM Type
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
span (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_hs_type TcTyMode
mode HsType GhcRn
ty Type
exp_kind
tc_hs_type :: TcTyMode -> HsType GhcRn -> TcKind -> TcM TcType
tc_hs_type :: TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_hs_type TcTyMode
mode (HsParTy XParTy GhcRn
_ LHsKind GhcRn
ty) Type
exp_kind = TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty Type
exp_kind
tc_hs_type TcTyMode
mode (HsDocTy XDocTy GhcRn
_ LHsKind GhcRn
ty LHsDocString
_) Type
exp_kind = TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty Type
exp_kind
tc_hs_type TcTyMode
_ ty :: HsType GhcRn
ty@(HsBangTy XBangTy GhcRn
_ HsSrcBang
bang LHsKind GhcRn
_) Type
_
= do { let bangError :: String -> TcM Type
bangError String
err = MsgDoc -> TcM Type
forall a. MsgDoc -> TcM a
failWith (MsgDoc -> TcM Type) -> MsgDoc -> TcM Type
forall a b. (a -> b) -> a -> b
$
String -> MsgDoc
text String
"Unexpected" MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
err MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
"annotation:" MsgDoc -> MsgDoc -> MsgDoc
<+> HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
ty MsgDoc -> MsgDoc -> MsgDoc
$$
String -> MsgDoc
text String
err MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
"annotation cannot appear nested inside a type"
; case HsSrcBang
bang of
HsSrcBang SourceText
_ SrcUnpackedness
SrcUnpack SrcStrictness
_ -> String -> TcM Type
bangError String
"UNPACK"
HsSrcBang SourceText
_ SrcUnpackedness
SrcNoUnpack SrcStrictness
_ -> String -> TcM Type
bangError String
"NOUNPACK"
HsSrcBang SourceText
_ SrcUnpackedness
NoSrcUnpack SrcStrictness
SrcLazy -> String -> TcM Type
bangError String
"laziness"
HsSrcBang SourceText
_ SrcUnpackedness
_ SrcStrictness
_ -> String -> TcM Type
bangError String
"strictness" }
tc_hs_type TcTyMode
_ ty :: HsType GhcRn
ty@(HsRecTy {}) Type
_
= MsgDoc -> TcM Type
forall a. MsgDoc -> TcM a
failWithTc (String -> MsgDoc
text String
"Record syntax is illegal here:" MsgDoc -> MsgDoc -> MsgDoc
<+> HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
ty)
tc_hs_type TcTyMode
mode (HsSpliceTy XSpliceTy GhcRn
_ (HsSpliced XSpliced GhcRn
_ ThModFinalizers
mod_finalizers (HsSplicedTy HsType GhcRn
ty)))
Type
exp_kind
= do ThModFinalizers -> TcM ()
addModFinalizersWithLclEnv ThModFinalizers
mod_finalizers
TcTyMode -> HsType GhcRn -> Type -> TcM Type
tc_hs_type TcTyMode
mode HsType GhcRn
ty Type
exp_kind
tc_hs_type TcTyMode
_ ty :: HsType GhcRn
ty@(HsSpliceTy {}) Type
_exp_kind
= MsgDoc -> TcM Type
forall a. MsgDoc -> TcM a
failWithTc (String -> MsgDoc
text String
"Unexpected type splice:" MsgDoc -> MsgDoc -> MsgDoc
<+> HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
ty)
tc_hs_type TcTyMode
mode (HsFunTy XFunTy GhcRn
_ LHsKind GhcRn
ty1 LHsKind GhcRn
ty2) Type
exp_kind
= TcTyMode -> LHsKind GhcRn -> LHsKind GhcRn -> Type -> TcM Type
tc_fun_type TcTyMode
mode LHsKind GhcRn
ty1 LHsKind GhcRn
ty2 Type
exp_kind
tc_hs_type TcTyMode
mode (HsOpTy XOpTy GhcRn
_ LHsKind GhcRn
ty1 (L SrcSpan
_ IdP GhcRn
op) LHsKind GhcRn
ty2) Type
exp_kind
| Name
IdP GhcRn
op Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
External instance of the constraint type Uniquable Name
`hasKey` Unique
funTyConKey
= TcTyMode -> LHsKind GhcRn -> LHsKind GhcRn -> Type -> TcM Type
tc_fun_type TcTyMode
mode LHsKind GhcRn
ty1 LHsKind GhcRn
ty2 Type
exp_kind
tc_hs_type TcTyMode
mode forall :: HsType GhcRn
forall@(HsForAllTy { hst_fvf :: forall pass. HsType pass -> ForallVisFlag
hst_fvf = ForallVisFlag
fvf, hst_bndrs :: forall pass. HsType pass -> [LHsTyVarBndr Specificity pass]
hst_bndrs = [LHsTyVarBndr Specificity GhcRn]
hs_tvs
, hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsKind GhcRn
ty }) Type
exp_kind
= do { (TcLevel
tclvl, WantedConstraints
wanted, ([VarBndr TyVar Specificity]
inv_tv_bndrs, Type
ty'))
<- TcM ([VarBndr TyVar Specificity], Type)
-> TcM
(TcLevel, WantedConstraints, ([VarBndr TyVar Specificity], Type))
forall a. TcM a -> TcM (TcLevel, WantedConstraints, a)
pushLevelAndCaptureConstraints (TcM ([VarBndr TyVar Specificity], Type)
-> TcM
(TcLevel, WantedConstraints, ([VarBndr TyVar Specificity], Type)))
-> TcM ([VarBndr TyVar Specificity], Type)
-> TcM
(TcLevel, WantedConstraints, ([VarBndr TyVar Specificity], Type))
forall a b. (a -> b) -> a -> b
$
[LHsTyVarBndr Specificity GhcRn]
-> TcM Type -> TcM ([VarBndr TyVar Specificity], Type)
forall flag a.
OutputableBndrFlag flag =>
[LHsTyVarBndr flag GhcRn] -> TcM a -> TcM ([VarBndr TyVar flag], a)
External instance of the constraint type OutputableBndrFlag Specificity
bindExplicitTKBndrs_Skol [LHsTyVarBndr Specificity GhcRn]
hs_tvs (TcM Type -> TcM ([VarBndr TyVar Specificity], Type))
-> TcM Type -> TcM ([VarBndr TyVar Specificity], Type)
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty Type
exp_kind
; let skol_info :: SkolemInfo
skol_info = MsgDoc -> SkolemInfo
ForAllSkol (HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
forall)
m_telescope :: Maybe MsgDoc
m_telescope = MsgDoc -> Maybe MsgDoc
forall a. a -> Maybe a
Just ([MsgDoc] -> MsgDoc
sep ((LHsTyVarBndr Specificity GhcRn -> MsgDoc)
-> [LHsTyVarBndr Specificity GhcRn] -> [MsgDoc]
forall a b. (a -> b) -> [a] -> [b]
map LHsTyVarBndr Specificity GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass) flag.
(OutputableBndrId p, OutputableBndrFlag flag) =>
Outputable (HsTyVarBndr flag (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type OutputableBndrFlag Specificity
ppr [LHsTyVarBndr Specificity GhcRn]
hs_tvs))
; [TcTyVarBinder]
tv_bndrs <- (VarBndr TyVar Specificity
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVarBinder)
-> [VarBndr TyVar Specificity]
-> IOEnv (Env TcGblEnv TcLclEnv) [TcTyVarBinder]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM VarBndr TyVar Specificity
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVarBinder
construct_bndr [VarBndr TyVar Specificity]
inv_tv_bndrs
; SkolemInfo
-> Maybe MsgDoc
-> [TyVar]
-> TcLevel
-> WantedConstraints
-> TcM ()
emitResidualTvConstraint SkolemInfo
skol_info Maybe MsgDoc
m_telescope ([TcTyVarBinder] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TcTyVarBinder]
tv_bndrs) TcLevel
tclvl WantedConstraints
wanted
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([TcTyVarBinder] -> Type -> Type
mkForAllTys [TcTyVarBinder]
tv_bndrs Type
ty') }
where
construct_bndr :: TcInvisTVBinder -> TcM TcTyVarBinder
construct_bndr :: VarBndr TyVar Specificity
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVarBinder
construct_bndr (Bndr TyVar
tv Specificity
spec) = do { ArgFlag
argf <- Specificity -> TcM ArgFlag
spec_to_argf Specificity
spec
; TcTyVarBinder -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVarBinder
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TcTyVarBinder -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVarBinder)
-> TcTyVarBinder -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVarBinder
forall a b. (a -> b) -> a -> b
$ ArgFlag -> TyVar -> TcTyVarBinder
forall vis. vis -> TyVar -> VarBndr TyVar vis
mkTyVarBinder ArgFlag
argf TyVar
tv }
spec_to_argf :: Specificity -> TcM ArgFlag
spec_to_argf :: Specificity -> TcM ArgFlag
spec_to_argf Specificity
SpecifiedSpec = case ForallVisFlag
fvf of
ForallVisFlag
ForallVis -> ArgFlag -> TcM ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ArgFlag
Required
ForallVisFlag
ForallInvis -> ArgFlag -> TcM ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ArgFlag
Specified
spec_to_argf Specificity
InferredSpec = case ForallVisFlag
fvf of
ForallVisFlag
ForallVis -> do { MsgDoc -> TcM ()
addErrTc (MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"Unexpected inferred variable in visible forall binder:")
Arity
2 (HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
forall))
; ArgFlag -> TcM ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ArgFlag
Required }
ForallVisFlag
ForallInvis -> ArgFlag -> TcM ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ArgFlag
Inferred
tc_hs_type TcTyMode
mode (HsQualTy { hst_ctxt :: forall pass. HsType pass -> LHsContext pass
hst_ctxt = LHsContext GhcRn
ctxt, hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsKind GhcRn
rn_ty }) Type
exp_kind
| [LHsKind GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null (LHsContext GhcRn -> [LHsKind GhcRn]
forall l e. GenLocated l e -> e
unLoc LHsContext GhcRn
ctxt)
= TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
rn_ty Type
exp_kind
| Type -> Bool
tcIsConstraintKind Type
exp_kind
= do { [Type]
ctxt' <- TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
mode LHsContext GhcRn
ctxt
; Type
ty' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
rn_ty Type
constraintKind
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([Type] -> Type -> Type
mkPhiTy [Type]
ctxt' Type
ty') }
| Bool
otherwise
= do { [Type]
ctxt' <- TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
mode LHsContext GhcRn
ctxt
; Type
ek <- TcM Type
newOpenTypeKind
; Type
ty' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
rn_ty Type
ek
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind (LHsKind GhcRn -> HsType GhcRn
forall l e. GenLocated l e -> e
unLoc LHsKind GhcRn
rn_ty) ([Type] -> Type -> Type
mkPhiTy [Type]
ctxt' Type
ty')
Type
liftedTypeKind Type
exp_kind }
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsListTy XListTy GhcRn
_ LHsKind GhcRn
elt_ty) Type
exp_kind
= do { Type
tau_ty <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
elt_ty Type
liftedTypeKind
; TyCon -> TcM ()
checkWiredInTyCon TyCon
listTyCon
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty (Type -> Type
mkListTy Type
tau_ty) Type
liftedTypeKind Type
exp_kind }
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsTupleTy XTupleTy GhcRn
_ HsTupleSort
HsBoxedOrConstraintTuple [LHsKind GhcRn]
hs_tys) Type
exp_kind
| Just TupleSort
tup_sort <- Type -> Maybe TupleSort
tupKindSort_maybe Type
exp_kind
= String -> MsgDoc -> TcM ()
traceTc String
"tc_hs_type tuple" ([LHsKind GhcRn] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr [LHsKind GhcRn]
hs_tys) TcM () -> TcM Type -> TcM Type
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
External instance of the constraint type forall m. Monad (IOEnv m)
>>
HsType GhcRn
-> TcTyMode -> TupleSort -> [LHsKind GhcRn] -> Type -> TcM Type
tc_tuple HsType GhcRn
rn_ty TcTyMode
mode TupleSort
tup_sort [LHsKind GhcRn]
hs_tys Type
exp_kind
| Bool
otherwise
= do { String -> MsgDoc -> TcM ()
traceTc String
"tc_hs_type tuple 2" ([LHsKind GhcRn] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr [LHsKind GhcRn]
hs_tys)
; ([Type]
tys, [Type]
kinds) <- (LHsKind GhcRn -> TcM (Type, Type))
-> [LHsKind GhcRn]
-> IOEnv (Env TcGblEnv TcLclEnv) ([Type], [Type])
forall (m :: * -> *) a b c.
Applicative m =>
(a -> m (b, c)) -> [a] -> m ([b], [c])
External instance of the constraint type forall m. Applicative (IOEnv m)
mapAndUnzipM (TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode) [LHsKind GhcRn]
hs_tys
; [Type]
kinds <- (Type -> TcM Type) -> [Type] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM Type -> TcM Type
zonkTcType [Type]
kinds
; let (Type
arg_kind, TupleSort
tup_sort)
= case [ (Type
k,TupleSort
s) | Type
k <- [Type]
kinds
, Just TupleSort
s <- [Type -> Maybe TupleSort
tupKindSort_maybe Type
k] ] of
((Type
k,TupleSort
s) : [(Type, TupleSort)]
_) -> (Type
k,TupleSort
s)
[] -> (Type
liftedTypeKind, TupleSort
BoxedTuple)
; [Type]
tys' <- [TcM Type] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
sequence [ SrcSpan -> TcM Type -> TcM Type
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
hs_ty Type
ty Type
kind Type
arg_kind
| ((L SrcSpan
loc HsType GhcRn
hs_ty),Type
ty,Type
kind) <- [LHsKind GhcRn]
-> [Type] -> [Type] -> [(LHsKind GhcRn, Type, Type)]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [LHsKind GhcRn]
hs_tys [Type]
tys [Type]
kinds ]
; HsType GhcRn -> TupleSort -> [Type] -> [Type] -> Type -> TcM Type
finish_tuple HsType GhcRn
rn_ty TupleSort
tup_sort [Type]
tys' ((Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Type -> Type
forall a b. a -> b -> a
const Type
arg_kind) [Type]
tys') Type
exp_kind }
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsTupleTy XTupleTy GhcRn
_ HsTupleSort
hs_tup_sort [LHsKind GhcRn]
tys) Type
exp_kind
= HsType GhcRn
-> TcTyMode -> TupleSort -> [LHsKind GhcRn] -> Type -> TcM Type
tc_tuple HsType GhcRn
rn_ty TcTyMode
mode TupleSort
tup_sort [LHsKind GhcRn]
tys Type
exp_kind
where
tup_sort :: TupleSort
tup_sort = case HsTupleSort
hs_tup_sort of
HsTupleSort
HsUnboxedTuple -> TupleSort
UnboxedTuple
HsTupleSort
HsBoxedTuple -> TupleSort
BoxedTuple
HsTupleSort
HsConstraintTuple -> TupleSort
ConstraintTuple
HsTupleSort
_ -> String -> TupleSort
forall a. String -> a
panic String
"tc_hs_type HsTupleTy"
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsSumTy XSumTy GhcRn
_ [LHsKind GhcRn]
hs_tys) Type
exp_kind
= do { let arity :: Arity
arity = [LHsKind GhcRn] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
External instance of the constraint type Foldable []
length [LHsKind GhcRn]
hs_tys
; [Type]
arg_kinds <- (LHsKind GhcRn -> TcM Type) -> [LHsKind GhcRn] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM (\LHsKind GhcRn
_ -> TcM Type
newOpenTypeKind) [LHsKind GhcRn]
hs_tys
; [Type]
tau_tys <- (LHsKind GhcRn -> Type -> TcM Type)
-> [LHsKind GhcRn] -> [Type] -> TcM [Type]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
External instance of the constraint type forall m. Applicative (IOEnv m)
zipWithM (TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode) [LHsKind GhcRn]
hs_tys [Type]
arg_kinds
; let arg_reps :: [Type]
arg_reps = (Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
kindRep [Type]
arg_kinds
arg_tys :: [Type]
arg_tys = [Type]
arg_reps [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
tau_tys
sum_ty :: Type
sum_ty = TyCon -> [Type] -> Type
mkTyConApp (Arity -> TyCon
sumTyCon Arity
arity) [Type]
arg_tys
sum_kind :: Type
sum_kind = [Type] -> Type
unboxedSumKind [Type]
arg_reps
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty Type
sum_ty Type
sum_kind Type
exp_kind
}
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsExplicitListTy XExplicitListTy GhcRn
_ PromotionFlag
_ [LHsKind GhcRn]
tys) Type
exp_kind
= do { [(Type, Type)]
tks <- (LHsKind GhcRn -> TcM (Type, Type))
-> [LHsKind GhcRn] -> IOEnv (Env TcGblEnv TcLclEnv) [(Type, Type)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM (TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode) [LHsKind GhcRn]
tys
; ([Type]
taus', Type
kind) <- [LHsKind GhcRn] -> [(Type, Type)] -> TcM ([Type], Type)
unifyKinds [LHsKind GhcRn]
tys [(Type, Type)]
tks
; let ty :: Type
ty = ((Type -> Type -> Type) -> Type -> [Type] -> Type
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
External instance of the constraint type Foldable []
foldr (Type -> Type -> Type -> Type
mk_cons Type
kind) (Type -> Type
mk_nil Type
kind) [Type]
taus')
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty Type
ty (Type -> Type
mkListTy Type
kind) Type
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]
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsExplicitTupleTy XExplicitTupleTy GhcRn
_ [LHsKind GhcRn]
tys) Type
exp_kind
= do { [Type]
ks <- Arity -> TcM Type -> TcM [Type]
forall (m :: * -> *) a. Applicative m => Arity -> m a -> m [a]
External instance of the constraint type forall m. Applicative (IOEnv m)
replicateM Arity
arity TcM Type
newMetaKindVar
; [Type]
taus <- (LHsKind GhcRn -> Type -> TcM Type)
-> [LHsKind GhcRn] -> [Type] -> TcM [Type]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
External instance of the constraint type forall m. Applicative (IOEnv m)
zipWithM (TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode) [LHsKind GhcRn]
tys [Type]
ks
; let kind_con :: TyCon
kind_con = Boxity -> Arity -> TyCon
tupleTyCon Boxity
Boxed Arity
arity
ty_con :: TyCon
ty_con = Boxity -> Arity -> TyCon
promotedTupleDataCon Boxity
Boxed Arity
arity
tup_k :: Type
tup_k = TyCon -> [Type] -> Type
mkTyConApp TyCon
kind_con [Type]
ks
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty (TyCon -> [Type] -> Type
mkTyConApp TyCon
ty_con ([Type]
ks [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
taus)) Type
tup_k Type
exp_kind }
where
arity :: Arity
arity = [LHsKind GhcRn] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
External instance of the constraint type Foldable []
length [LHsKind GhcRn]
tys
tc_hs_type TcTyMode
mode rn_ty :: HsType GhcRn
rn_ty@(HsIParamTy XIParamTy GhcRn
_ (L SrcSpan
_ HsIPName
n) LHsKind GhcRn
ty) Type
exp_kind
= do { MASSERT( isTypeLevel (mode_level mode) )
; Type
ty' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty Type
liftedTypeKind
; let n' :: Type
n' = FastString -> Type
mkStrLitTy (FastString -> Type) -> FastString -> Type
forall a b. (a -> b) -> a -> b
$ HsIPName -> FastString
hsIPNameFS HsIPName
n
; Class
ipClass <- Name -> TcM Class
tcLookupClass Name
ipClassName
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty (Class -> [Type] -> Type
mkClassPred Class
ipClass [Type
n',Type
ty'])
Type
constraintKind Type
exp_kind }
tc_hs_type TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsStarTy XStarTy GhcRn
_ Bool
_) Type
exp_kind
= HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty Type
liftedTypeKind Type
liftedTypeKind Type
exp_kind
tc_hs_type TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsTyLit XTyLit GhcRn
_ (HsNumTy SourceText
_ Integer
n)) Type
exp_kind
= do { TyCon -> TcM ()
checkWiredInTyCon TyCon
typeNatKindCon
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty (Integer -> Type
mkNumLitTy Integer
n) Type
typeNatKind Type
exp_kind }
tc_hs_type TcTyMode
_ rn_ty :: HsType GhcRn
rn_ty@(HsTyLit XTyLit GhcRn
_ (HsStrTy SourceText
_ FastString
s)) Type
exp_kind
= do { TyCon -> TcM ()
checkWiredInTyCon TyCon
typeSymbolKindCon
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty (FastString -> Type
mkStrLitTy FastString
s) Type
typeSymbolKind Type
exp_kind }
tc_hs_type TcTyMode
mode ty :: HsType GhcRn
ty@(HsTyVar {}) Type
ek = HasDebugCallStack => TcTyMode -> HsType GhcRn -> Type -> TcM Type
TcTyMode -> HsType GhcRn -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
ty Type
ek
tc_hs_type TcTyMode
mode ty :: HsType GhcRn
ty@(HsAppTy {}) Type
ek = HasDebugCallStack => TcTyMode -> HsType GhcRn -> Type -> TcM Type
TcTyMode -> HsType GhcRn -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
ty Type
ek
tc_hs_type TcTyMode
mode ty :: HsType GhcRn
ty@(HsAppKindTy{}) Type
ek = HasDebugCallStack => TcTyMode -> HsType GhcRn -> Type -> TcM Type
TcTyMode -> HsType GhcRn -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
ty Type
ek
tc_hs_type TcTyMode
mode ty :: HsType GhcRn
ty@(HsOpTy {}) Type
ek = HasDebugCallStack => TcTyMode -> HsType GhcRn -> Type -> TcM Type
TcTyMode -> HsType GhcRn -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
ty Type
ek
tc_hs_type TcTyMode
mode ty :: HsType GhcRn
ty@(HsKindSig {}) Type
ek = HasDebugCallStack => TcTyMode -> HsType GhcRn -> Type -> TcM Type
TcTyMode -> HsType GhcRn -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
ty Type
ek
tc_hs_type TcTyMode
mode ty :: HsType GhcRn
ty@(XHsType (NHsCoreTy{})) Type
ek = HasDebugCallStack => TcTyMode -> HsType GhcRn -> Type -> TcM Type
TcTyMode -> HsType GhcRn -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
tc_infer_hs_type_ek TcTyMode
mode HsType GhcRn
ty Type
ek
tc_hs_type TcTyMode
_ wc :: HsType GhcRn
wc@(HsWildCardTy XWildCardTy GhcRn
_) Type
ek = HsType GhcRn -> Type -> TcM Type
tcAnonWildCardOcc HsType GhcRn
wc Type
ek
tc_fun_type :: TcTyMode -> LHsType GhcRn -> LHsType GhcRn -> TcKind
-> TcM TcType
tc_fun_type :: TcTyMode -> LHsKind GhcRn -> LHsKind GhcRn -> Type -> TcM Type
tc_fun_type TcTyMode
mode LHsKind GhcRn
ty1 LHsKind GhcRn
ty2 Type
exp_kind = case TcTyMode -> TypeOrKind
mode_level TcTyMode
mode of
TypeOrKind
TypeLevel ->
do { Type
arg_k <- TcM Type
newOpenTypeKind
; Type
res_k <- TcM Type
newOpenTypeKind
; Type
ty1' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty1 Type
arg_k
; Type
ty2' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty2 Type
res_k
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind (XFunTy GhcRn -> LHsKind GhcRn -> LHsKind GhcRn -> HsType GhcRn
forall pass.
XFunTy pass -> LHsType pass -> LHsType pass -> HsType pass
HsFunTy XFunTy GhcRn
NoExtField
noExtField LHsKind GhcRn
ty1 LHsKind GhcRn
ty2) (Type -> Type -> Type
mkVisFunTy Type
ty1' Type
ty2')
Type
liftedTypeKind Type
exp_kind }
TypeOrKind
KindLevel ->
do { Type
ty1' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty1 Type
liftedTypeKind
; Type
ty2' <- TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
ty2 Type
liftedTypeKind
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind (XFunTy GhcRn -> LHsKind GhcRn -> LHsKind GhcRn -> HsType GhcRn
forall pass.
XFunTy pass -> LHsType pass -> LHsType pass -> HsType pass
HsFunTy XFunTy GhcRn
NoExtField
noExtField LHsKind GhcRn
ty1 LHsKind GhcRn
ty2) (Type -> Type -> Type
mkVisFunTy Type
ty1' Type
ty2')
Type
liftedTypeKind Type
exp_kind }
tcAnonWildCardOcc :: HsType GhcRn -> Kind -> TcM TcType
tcAnonWildCardOcc :: HsType GhcRn -> Type -> TcM Type
tcAnonWildCardOcc HsType GhcRn
wc Type
exp_kind
= do { TyVar
wc_tv <- TcM TyVar
newWildTyVar
; Bool
part_tysig <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PartialTypeSignatures
; Bool
warning <- WarningFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. WarningFlag -> TcRnIf gbl lcl Bool
woptM WarningFlag
Opt_WarnPartialTypeSignatures
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
unless (Bool
part_tysig Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
warning) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
TyVar -> TcM ()
emitAnonTypeHole TyVar
wc_tv
; HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
wc (TyVar -> Type
mkTyVarTy TyVar
wc_tv)
(TyVar -> Type
tyVarKind TyVar
wc_tv) Type
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
tcView Type
k = Type -> Maybe TupleSort
tupKindSort_maybe Type
k'
| Type -> Bool
tcIsConstraintKind 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 -> [LHsKind GhcRn] -> Type -> TcM Type
tc_tuple HsType GhcRn
rn_ty TcTyMode
mode TupleSort
tup_sort [LHsKind GhcRn]
tys Type
exp_kind
= do { [Type]
arg_kinds <- case TupleSort
tup_sort of
TupleSort
BoxedTuple -> [Type] -> TcM [Type]
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Arity -> Type -> [Type]
forall a. Arity -> a -> [a]
replicate Arity
arity Type
liftedTypeKind)
TupleSort
UnboxedTuple -> Arity -> TcM Type -> TcM [Type]
forall (m :: * -> *) a. Applicative m => Arity -> m a -> m [a]
External instance of the constraint type forall m. Applicative (IOEnv m)
replicateM Arity
arity TcM Type
newOpenTypeKind
TupleSort
ConstraintTuple -> [Type] -> TcM [Type]
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Arity -> Type -> [Type]
forall a. Arity -> a -> [a]
replicate Arity
arity Type
constraintKind)
; [Type]
tau_tys <- (LHsKind GhcRn -> Type -> TcM Type)
-> [LHsKind GhcRn] -> [Type] -> TcM [Type]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
External instance of the constraint type forall m. Applicative (IOEnv m)
zipWithM (TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode) [LHsKind GhcRn]
tys [Type]
arg_kinds
; HsType GhcRn -> TupleSort -> [Type] -> [Type] -> Type -> TcM Type
finish_tuple HsType GhcRn
rn_ty TupleSort
tup_sort [Type]
tau_tys [Type]
arg_kinds Type
exp_kind }
where
arity :: Arity
arity = [LHsKind GhcRn] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
External instance of the constraint type Foldable []
length [LHsKind 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 -> MsgDoc -> TcM ()
traceTc String
"finish_tuple" (TupleSort -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TupleSort
ppr TupleSort
tup_sort MsgDoc -> MsgDoc -> MsgDoc
$$ [Type] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable Type
ppr [Type]
tau_kinds MsgDoc -> MsgDoc -> MsgDoc
$$ Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
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
| Arity
arity Arity -> Arity -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type Ord Arity
> Arity
mAX_CTUPLE_SIZE
-> MsgDoc -> TcM Type
forall a. MsgDoc -> TcM a
failWith (Arity -> MsgDoc
bigConstraintTuple Arity
arity)
| Bool
otherwise
-> do TyCon
tycon <- Name -> TcM TyCon
tcLookupTyCon (Arity -> Name
cTupleTyConName Arity
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 -> Arity -> TyCon
tupleTyCon Boxity
Boxed Arity
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 ->
let tycon :: TyCon
tycon = Boxity -> Arity -> TyCon
tupleTyCon Boxity
Unboxed Arity
arity
tau_reps :: [Type]
tau_reps = (Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
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 in
Type -> Type -> TcM Type
check_expected_kind (TyCon -> [Type] -> Type
mkTyConApp TyCon
tycon [Type]
arg_tys) Type
res_kind
where
arity :: Arity
arity = [Type] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
External instance of the constraint type Foldable []
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
External instance of the constraint type HasDebugCallStack
checkExpectedKind HsType GhcRn
rn_ty Type
ty Type
act_kind Type
exp_kind
bigConstraintTuple :: Arity -> MsgDoc
bigConstraintTuple :: Arity -> MsgDoc
bigConstraintTuple Arity
arity
= MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"Constraint tuple arity too large:" MsgDoc -> MsgDoc -> MsgDoc
<+> Arity -> MsgDoc
int Arity
arity
MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
parens (String -> MsgDoc
text String
"max arity =" MsgDoc -> MsgDoc -> MsgDoc
<+> Arity -> MsgDoc
int Arity
mAX_CTUPLE_SIZE))
Arity
2 (String -> MsgDoc
text String
"Instead, use a nested tuple")
splitHsAppTys :: HsType GhcRn -> Maybe (LHsType GhcRn, [LHsTypeArg GhcRn])
splitHsAppTys :: HsType GhcRn -> Maybe (LHsKind GhcRn, [LHsTypeArg GhcRn])
splitHsAppTys HsType GhcRn
hs_ty
| HsType GhcRn -> Bool
is_app HsType GhcRn
hs_ty = (LHsKind GhcRn, [LHsTypeArg GhcRn])
-> Maybe (LHsKind GhcRn, [LHsTypeArg GhcRn])
forall a. a -> Maybe a
Just (LHsKind GhcRn
-> [LHsTypeArg GhcRn] -> (LHsKind GhcRn, [LHsTypeArg GhcRn])
forall {pass}.
(XTyVar pass ~ NoExtField, XAppKindTy pass ~ SrcSpan) =>
LHsType pass
-> [HsArg (LHsType pass) (LHsType pass)]
-> (LHsType pass, [HsArg (LHsType pass) (LHsType pass)])
go (HsType GhcRn -> LHsKind GhcRn
forall e. e -> Located e
noLoc HsType GhcRn
hs_ty) [])
| Bool
otherwise = Maybe (LHsKind GhcRn, [LHsTypeArg 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
_ LHsKind GhcRn
_ (L SrcSpan
_ IdP GhcRn
op) LHsKind GhcRn
_) = Bool -> Bool
not (Name
IdP GhcRn
op Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
External instance of the constraint type Uniquable Name
`hasKey` Unique
funTyConKey)
is_app (HsTyVar {}) = Bool
True
is_app (HsParTy XParTy GhcRn
_ (L SrcSpan
_ HsType GhcRn
ty)) = HsType GhcRn -> Bool
is_app HsType GhcRn
ty
is_app HsType GhcRn
_ = Bool
False
go :: LHsType pass
-> [HsArg (LHsType pass) (LHsType pass)]
-> (LHsType pass, [HsArg (LHsType pass) (LHsType pass)])
go (L SrcSpan
_ (HsAppTy XAppTy pass
_ LHsType pass
f LHsType pass
a)) [HsArg (LHsType pass) (LHsType pass)]
as = LHsType pass
-> [HsArg (LHsType pass) (LHsType pass)]
-> (LHsType pass, [HsArg (LHsType pass) (LHsType pass)])
go LHsType pass
f (LHsType pass -> HsArg (LHsType pass) (LHsType pass)
forall tm ty. tm -> HsArg tm ty
HsValArg LHsType pass
a HsArg (LHsType pass) (LHsType pass)
-> [HsArg (LHsType pass) (LHsType pass)]
-> [HsArg (LHsType pass) (LHsType pass)]
forall a. a -> [a] -> [a]
: [HsArg (LHsType pass) (LHsType pass)]
as)
go (L SrcSpan
_ (HsAppKindTy XAppKindTy pass
l LHsType pass
ty LHsType pass
k)) [HsArg (LHsType pass) (LHsType pass)]
as = LHsType pass
-> [HsArg (LHsType pass) (LHsType pass)]
-> (LHsType pass, [HsArg (LHsType pass) (LHsType pass)])
go LHsType pass
ty (SrcSpan -> LHsType pass -> HsArg (LHsType pass) (LHsType pass)
forall tm ty. SrcSpan -> ty -> HsArg tm ty
HsTypeArg SrcSpan
XAppKindTy pass
l LHsType pass
k HsArg (LHsType pass) (LHsType pass)
-> [HsArg (LHsType pass) (LHsType pass)]
-> [HsArg (LHsType pass) (LHsType pass)]
forall a. a -> [a] -> [a]
: [HsArg (LHsType pass) (LHsType pass)]
as)
go (L SrcSpan
sp (HsParTy XParTy pass
_ LHsType pass
f)) [HsArg (LHsType pass) (LHsType pass)]
as = LHsType pass
-> [HsArg (LHsType pass) (LHsType pass)]
-> (LHsType pass, [HsArg (LHsType pass) (LHsType pass)])
go LHsType pass
f (SrcSpan -> HsArg (LHsType pass) (LHsType pass)
forall tm ty. SrcSpan -> HsArg tm ty
HsArgPar SrcSpan
sp HsArg (LHsType pass) (LHsType pass)
-> [HsArg (LHsType pass) (LHsType pass)]
-> [HsArg (LHsType pass) (LHsType pass)]
forall a. a -> [a] -> [a]
: [HsArg (LHsType pass) (LHsType pass)]
as)
go (L SrcSpan
_ (HsOpTy XOpTy pass
_ LHsType pass
l op :: Located (IdP pass)
op@(L SrcSpan
sp IdP pass
_) LHsType pass
r)) [HsArg (LHsType pass) (LHsType pass)]
as
= ( SrcSpan -> HsType pass -> LHsType pass
forall l e. l -> e -> GenLocated l e
L SrcSpan
sp (XTyVar pass -> PromotionFlag -> Located (IdP pass) -> HsType pass
forall pass.
XTyVar pass -> PromotionFlag -> Located (IdP pass) -> HsType pass
HsTyVar XTyVar pass
NoExtField
noExtField PromotionFlag
NotPromoted Located (IdP pass)
op)
, LHsType pass -> HsArg (LHsType pass) (LHsType pass)
forall tm ty. tm -> HsArg tm ty
HsValArg LHsType pass
l HsArg (LHsType pass) (LHsType pass)
-> [HsArg (LHsType pass) (LHsType pass)]
-> [HsArg (LHsType pass) (LHsType pass)]
forall a. a -> [a] -> [a]
: LHsType pass -> HsArg (LHsType pass) (LHsType pass)
forall tm ty. tm -> HsArg tm ty
HsValArg LHsType pass
r HsArg (LHsType pass) (LHsType pass)
-> [HsArg (LHsType pass) (LHsType pass)]
-> [HsArg (LHsType pass) (LHsType pass)]
forall a. a -> [a] -> [a]
: [HsArg (LHsType pass) (LHsType pass)]
as )
go LHsType pass
f [HsArg (LHsType pass) (LHsType pass)]
as = (LHsType pass
f, [HsArg (LHsType pass) (LHsType pass)]
as)
tcInferAppHead :: TcTyMode -> LHsType GhcRn -> TcM (TcType, TcKind)
tcInferAppHead :: TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tcInferAppHead TcTyMode
mode (L SrcSpan
_ (HsTyVar XTyVar GhcRn
_ PromotionFlag
_ (L SrcSpan
_ IdP GhcRn
tv)))
= TcTyMode -> Name -> TcM (Type, Type)
tcTyVar TcTyMode
mode Name
IdP GhcRn
tv
tcInferAppHead TcTyMode
mode LHsKind GhcRn
ty
= TcTyMode -> LHsKind GhcRn -> TcM (Type, Type)
tc_infer_lhs_type TcTyMode
mode LHsKind GhcRn
ty
tcInferApps, tcInferApps_nosat
:: TcTyMode
-> LHsType GhcRn
-> TcType
-> [LHsTypeArg GhcRn]
-> TcM (TcType, TcKind)
tcInferApps :: TcTyMode
-> LHsKind GhcRn -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
tcInferApps TcTyMode
mode LHsKind GhcRn
hs_ty Type
fun [LHsTypeArg GhcRn]
hs_args
= do { (Type
f_args, Type
res_k) <- TcTyMode
-> LHsKind GhcRn -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
tcInferApps_nosat TcTyMode
mode LHsKind GhcRn
hs_ty Type
fun [LHsTypeArg GhcRn]
hs_args
; Type -> Type -> TcM (Type, Type)
saturateFamApp Type
f_args Type
res_k }
tcInferApps_nosat :: TcTyMode
-> LHsKind GhcRn -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
tcInferApps_nosat TcTyMode
mode LHsKind GhcRn
orig_hs_ty Type
fun [LHsTypeArg GhcRn]
orig_hs_args
= do { String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps {" (LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
orig_hs_ty MsgDoc -> MsgDoc -> MsgDoc
$$ [LHsTypeArg GhcRn] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall tm ty.
(Outputable tm, Outputable ty) =>
Outputable (HsArg tm ty)
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr [LHsTypeArg GhcRn]
orig_hs_args)
; (Type
f_args, Type
res_k) <- Arity -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
go_init Arity
1 Type
fun [LHsTypeArg GhcRn]
orig_hs_args
; String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps }" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
f_args MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
dcolon MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
res_k)
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
f_args, Type
res_k) }
where
go_init :: Arity -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
go_init Arity
n Type
fun [LHsTypeArg GhcRn]
all_args
= Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go Arity
n Type
fun TCvSubst
empty_subst Type
fun_ki [LHsTypeArg GhcRn]
all_args
where
fun_ki :: Type
fun_ki = HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
tcTypeKind Type
fun
empty_subst :: TCvSubst
empty_subst = InScopeSet -> TCvSubst
mkEmptyTCvSubst (InScopeSet -> TCvSubst) -> InScopeSet -> TCvSubst
forall a b. (a -> b) -> a -> b
$ TyCoVarSet -> InScopeSet
mkInScopeSet (TyCoVarSet -> InScopeSet) -> TyCoVarSet -> InScopeSet
forall a b. (a -> b) -> a -> b
$
Type -> TyCoVarSet
tyCoVarsOfType Type
fun_ki
go :: Int
-> TcType
-> TCvSubst
-> TcKind
-> [LHsTypeArg GhcRn]
-> TcM (TcType, TcKind)
go :: Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go Arity
n Type
fun TCvSubst
subst Type
fun_ki [LHsTypeArg GhcRn]
all_args = case ([LHsTypeArg GhcRn]
all_args, Type -> Maybe (TyCoBinder, Type)
tcSplitPiTy_maybe Type
fun_ki) of
([], Maybe (TyCoBinder, Type)
_) -> (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
fun, HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst Type
fun_ki)
(HsArgPar SrcSpan
_ : [LHsTypeArg GhcRn]
args, Maybe (TyCoBinder, Type)
_) -> Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go Arity
n Type
fun TCvSubst
subst Type
fun_ki [LHsTypeArg GhcRn]
args
(HsTypeArg SrcSpan
_ LHsKind GhcRn
hs_ki_arg : [LHsTypeArg GhcRn]
hs_args, Just (TyCoBinder
ki_binder, Type
inner_ki)) ->
case TyCoBinder
ki_binder of
Named (Bndr TyVar
_ ArgFlag
Inferred) -> TyCoBinder -> Type -> TcM (Type, Type)
instantiate TyCoBinder
ki_binder Type
inner_ki
Anon AnonArgFlag
InvisArg Type
_ -> TyCoBinder -> Type -> TcM (Type, Type)
instantiate TyCoBinder
ki_binder Type
inner_ki
Named (Bndr TyVar
_ ArgFlag
Specified) ->
do { String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps (vis kind app)"
([MsgDoc] -> MsgDoc
vcat [ TyCoBinder -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TyCoBinder
ppr TyCoBinder
ki_binder, LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
hs_ki_arg
, Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr (TyCoBinder -> Type
tyBinderType TyCoBinder
ki_binder)
, TCvSubst -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TCvSubst
ppr TCvSubst
subst ])
; let exp_kind :: Type
exp_kind = HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ TyCoBinder -> Type
tyBinderType TyCoBinder
ki_binder
; Type
ki_arg <- MsgDoc -> TcM Type -> TcM Type
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (LHsKind GhcRn -> LHsKind GhcRn -> Arity -> MsgDoc
forall fun arg.
(Outputable fun, Outputable arg) =>
fun -> arg -> Arity -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
funAppCtxt LHsKind GhcRn
orig_hs_ty LHsKind GhcRn
hs_ki_arg Arity
n) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
WarningFlag -> TcM Type -> TcM Type
forall gbl lcl a.
WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
unsetWOptM WarningFlag
Opt_WarnPartialTypeSignatures (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
Extension -> TcM Type -> TcM Type
forall gbl lcl a. Extension -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
setXOptM Extension
LangExt.PartialTypeSignatures (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type (TcTyMode -> TcTyMode
kindLevel TcTyMode
mode) LHsKind GhcRn
hs_ki_arg Type
exp_kind
; String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps (vis kind app)" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
exp_kind)
; (TCvSubst
subst', Type
fun') <- TCvSubst -> Type -> TyCoBinder -> Type -> TcM (TCvSubst, Type)
mkAppTyM TCvSubst
subst Type
fun TyCoBinder
ki_binder Type
ki_arg
; Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go (Arity
nArity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
+Arity
1) Type
fun' TCvSubst
subst' Type
inner_ki [LHsTypeArg GhcRn]
hs_args }
TyCoBinder
_ -> LHsKind GhcRn -> Type -> TcM (Type, Type)
forall {a} {a} {a}.
(Outputable a, Outputable a) =>
a -> a -> TcRn a
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type Outputable Type
ty_app_err LHsKind GhcRn
hs_ki_arg (Type -> TcM (Type, Type)) -> Type -> TcM (Type, Type)
forall a b. (a -> b) -> a -> b
$ HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst Type
fun_ki
(HsTypeArg SrcSpan
_ LHsKind GhcRn
ki_arg : [LHsTypeArg GhcRn]
_, Maybe (TyCoBinder, 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
$
LHsKind GhcRn -> Type -> TcM (Type, Type)
forall {a} {a} {a}.
(Outputable a, Outputable a) =>
a -> a -> TcRn a
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type Outputable Type
ty_app_err LHsKind GhcRn
ki_arg Type
substed_fun_ki
(HsValArg LHsKind GhcRn
arg : [LHsTypeArg GhcRn]
args, Just (TyCoBinder
ki_binder, Type
inner_ki))
| TyCoBinder -> Bool
isInvisibleBinder TyCoBinder
ki_binder
-> TyCoBinder -> Type -> TcM (Type, Type)
instantiate TyCoBinder
ki_binder Type
inner_ki
| Bool
otherwise
-> do { String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps (vis normal app)"
([MsgDoc] -> MsgDoc
vcat [ TyCoBinder -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TyCoBinder
ppr TyCoBinder
ki_binder
, LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
arg
, Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr (TyCoBinder -> Type
tyBinderType TyCoBinder
ki_binder)
, TCvSubst -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TCvSubst
ppr TCvSubst
subst ])
; let exp_kind :: Type
exp_kind = HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ TyCoBinder -> Type
tyBinderType TyCoBinder
ki_binder
; Type
arg' <- MsgDoc -> TcM Type -> TcM Type
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (LHsKind GhcRn -> LHsKind GhcRn -> Arity -> MsgDoc
forall fun arg.
(Outputable fun, Outputable arg) =>
fun -> arg -> Arity -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
funAppCtxt LHsKind GhcRn
orig_hs_ty LHsKind GhcRn
arg Arity
n) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
arg Type
exp_kind
; String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps (vis normal app) 2" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
exp_kind)
; (TCvSubst
subst', Type
fun') <- TCvSubst -> Type -> TyCoBinder -> Type -> TcM (TCvSubst, Type)
mkAppTyM TCvSubst
subst Type
fun TyCoBinder
ki_binder Type
arg'
; Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go (Arity
nArity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
+Arity
1) Type
fun' TCvSubst
subst' Type
inner_ki [LHsTypeArg GhcRn]
args }
(HsValArg LHsKind GhcRn
_ : [LHsTypeArg GhcRn]
_, Maybe (TyCoBinder, 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 :: Arity
arrows_needed = [LHsTypeArg GhcRn] -> Arity
forall tm ty. [HsArg tm ty] -> Arity
n_initial_val_args [LHsTypeArg GhcRn]
all_args
; Coercion
co <- LHsKind GhcRn -> Arity -> Type -> TcM Coercion
forall fun. Outputable fun => fun -> Arity -> Type -> TcM Coercion
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
matchExpectedFunKind LHsKind GhcRn
hs_ty Arity
arrows_needed Type
substed_fun_ki
; Type
fun' <- Type -> TcM Type
zonkTcType (Type
fun Type -> Coercion -> Type
`mkTcCastTy` Coercion
co)
; String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps (no binder)" (MsgDoc -> TcM ()) -> MsgDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
fun MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
dcolon MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
fun_ki
, Arity -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Arity
ppr Arity
arrows_needed
, Coercion -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Coercion
ppr Coercion
co
, Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
fun' MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc
dcolon MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr (HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
tcTypeKind Type
fun')]
; Arity -> Type -> [LHsTypeArg GhcRn] -> TcM (Type, Type)
go_init Arity
n Type
fun' [LHsTypeArg GhcRn]
all_args }
where
instantiate :: TyCoBinder -> Type -> TcM (Type, Type)
instantiate TyCoBinder
ki_binder Type
inner_ki
= do { String -> MsgDoc -> TcM ()
traceTc String
"tcInferApps (need to instantiate)"
([MsgDoc] -> MsgDoc
vcat [ TyCoBinder -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TyCoBinder
ppr TyCoBinder
ki_binder, TCvSubst -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TCvSubst
ppr TCvSubst
subst])
; (TCvSubst
subst', Type
arg') <- TCvSubst -> TyCoBinder -> TcM (TCvSubst, Type)
tcInstInvisibleTyBinder TCvSubst
subst TyCoBinder
ki_binder
; Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go Arity
n (Type -> Type -> Type
mkAppTy Type
fun Type
arg') TCvSubst
subst' Type
inner_ki [LHsTypeArg GhcRn]
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 (TCvSubst -> Bool
isEmptyTCvSubst TCvSubst
subst)
= Arity
-> Type
-> TCvSubst
-> Type
-> [LHsTypeArg GhcRn]
-> TcM (Type, Type)
go Arity
n Type
fun TCvSubst
zapped_subst Type
substed_fun_ki [LHsTypeArg GhcRn]
all_args
| Bool
otherwise
= TcM (Type, Type)
fallthrough
zapped_subst :: TCvSubst
zapped_subst = TCvSubst -> TCvSubst
zapTCvSubst TCvSubst
subst
substed_fun_ki :: Type
substed_fun_ki = HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst Type
fun_ki
hs_ty :: LHsKind GhcRn
hs_ty = LHsKind GhcRn -> [LHsTypeArg GhcRn] -> LHsKind GhcRn
appTypeToArg LHsKind GhcRn
orig_hs_ty (Arity -> [LHsTypeArg GhcRn] -> [LHsTypeArg GhcRn]
forall a. Arity -> [a] -> [a]
take (Arity
nArity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
-Arity
1) [LHsTypeArg GhcRn]
orig_hs_args)
n_initial_val_args :: [HsArg tm ty] -> Arity
n_initial_val_args :: [HsArg tm ty] -> Arity
n_initial_val_args (HsValArg {} : [HsArg tm ty]
args) = Arity
1 Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
+ [HsArg tm ty] -> Arity
forall tm ty. [HsArg tm ty] -> Arity
n_initial_val_args [HsArg tm ty]
args
n_initial_val_args (HsArgPar {} : [HsArg tm ty]
args) = [HsArg tm ty] -> Arity
forall tm ty. [HsArg tm ty] -> Arity
n_initial_val_args [HsArg tm ty]
args
n_initial_val_args [HsArg tm ty]
_ = Arity
0
ty_app_err :: a -> a -> TcRn a
ty_app_err a
arg a
ty
= MsgDoc -> TcRn a
forall a. MsgDoc -> TcM a
failWith (MsgDoc -> TcRn a) -> MsgDoc -> TcRn a
forall a b. (a -> b) -> a -> b
$ String -> MsgDoc
text String
"Cannot apply function of kind" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (a -> MsgDoc
forall a. Outputable a => a -> MsgDoc
Evidence bound by a type signature of the constraint type Outputable a
ppr a
ty)
MsgDoc -> MsgDoc -> MsgDoc
$$ String -> MsgDoc
text String
"to visible kind argument" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (a -> MsgDoc
forall a. Outputable a => a -> MsgDoc
Evidence bound by a type signature of the constraint type Outputable a
ppr a
arg)
mkAppTyM :: TCvSubst
-> TcType -> TyCoBinder
-> TcType
-> TcM (TCvSubst, TcType)
mkAppTyM :: TCvSubst -> Type -> TyCoBinder -> Type -> TcM (TCvSubst, Type)
mkAppTyM TCvSubst
subst Type
fun TyCoBinder
ki_binder Type
arg
|
TyConApp TyCon
tc [Type]
args <- Type
fun
, TyCon -> Bool
isTypeSynonymTyCon TyCon
tc
, [Type]
args [Type] -> Arity -> Bool
forall a. [a] -> Arity -> Bool
`lengthIs` (TyCon -> Arity
tyConArity TyCon
tc Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
- Arity
1)
, (TyVar -> Bool) -> [TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
External instance of the constraint type Foldable []
any TyVar -> Bool
isTrickyTvBinder (TyCon -> [TyVar]
tyConTyVars TyCon
tc)
= do { Type
arg' <- Type -> TcM Type
zonkTcType Type
arg
; [Type]
args' <- [Type] -> TcM [Type]
zonkTcTypes [Type]
args
; let subst' :: TCvSubst
subst' = case TyCoBinder
ki_binder of
Anon {} -> TCvSubst
subst
Named (Bndr TyVar
tv ArgFlag
_) -> TCvSubst -> TyVar -> Type -> TCvSubst
extendTvSubstAndInScope TCvSubst
subst TyVar
tv Type
arg'
; (TCvSubst, Type) -> TcM (TCvSubst, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TCvSubst
subst', TyCon -> [Type] -> Type
mkTyConApp TyCon
tc ([Type]
args' [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type
arg'])) }
mkAppTyM TCvSubst
subst Type
fun (Anon {}) Type
arg
= (TCvSubst, Type) -> TcM (TCvSubst, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TCvSubst
subst, Type -> Type -> Type
mk_app_ty Type
fun Type
arg)
mkAppTyM TCvSubst
subst Type
fun (Named (Bndr TyVar
tv ArgFlag
_)) Type
arg
= do { Type
arg' <- if TyVar -> Bool
isTrickyTvBinder TyVar
tv
then
Type -> TcM Type
zonkTcType Type
arg
else Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
arg
; (TCvSubst, Type) -> TcM (TCvSubst, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ( TCvSubst -> TyVar -> Type -> TCvSubst
extendTvSubstAndInScope TCvSubst
subst TyVar
tv Type
arg'
, Type -> Type -> Type
mk_app_ty Type
fun Type
arg' ) }
mk_app_ty :: TcType -> TcType -> TcType
mk_app_ty :: Type -> Type -> Type
mk_app_ty Type
fun Type
arg
= ASSERT2( isPiTy fun_kind
, ppr fun <+> dcolon <+> ppr fun_kind $$ ppr arg )
Type -> Type -> Type
mkAppTy Type
fun Type
arg
where
fun_kind :: Type
fun_kind = HasDebugCallStack => Type -> Type
Type -> Type
External instance of the constraint type HasDebugCallStack
tcTypeKind Type
fun
isTrickyTvBinder :: TcTyVar -> Bool
isTrickyTvBinder :: TyVar -> Bool
isTrickyTvBinder TyVar
tv = Type -> Bool
isPiTy (TyVar -> Type
tyVarKind TyVar
tv)
saturateFamApp :: TcType -> TcKind -> TcM (TcType, TcKind)
saturateFamApp :: Type -> Type -> TcM (Type, Type)
saturateFamApp Type
ty Type
kind
| Just (TyCon
tc, [Type]
args) <- HasCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
tcSplitTyConApp_maybe Type
ty
, TyCon -> Bool
mustBeSaturated TyCon
tc
, let n_to_inst :: Arity
n_to_inst = TyCon -> Arity
tyConArity TyCon
tc Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
- [Type] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
External instance of the constraint type Foldable []
length [Type]
args
= do { ([Type]
extra_args, Type
ki') <- Arity -> Type -> TcM ([Type], Type)
tcInstInvisibleTyBinders Arity
n_to_inst Type
kind
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
ty Type -> [Type] -> Type
`mkTcAppTys` [Type]
extra_args, Type
ki') }
| Bool
otherwise
= (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
ty, Type
kind)
appTypeToArg :: LHsType GhcRn -> [LHsTypeArg GhcRn] -> LHsType GhcRn
appTypeToArg :: LHsKind GhcRn -> [LHsTypeArg GhcRn] -> LHsKind GhcRn
appTypeToArg LHsKind GhcRn
f [] = LHsKind GhcRn
f
appTypeToArg LHsKind GhcRn
f (HsValArg LHsKind GhcRn
arg : [LHsTypeArg GhcRn]
args) = LHsKind GhcRn -> [LHsTypeArg GhcRn] -> LHsKind GhcRn
appTypeToArg (LHsKind GhcRn -> LHsKind GhcRn -> LHsKind GhcRn
forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
mkHsAppTy LHsKind GhcRn
f LHsKind GhcRn
arg) [LHsTypeArg GhcRn]
args
appTypeToArg LHsKind GhcRn
f (HsArgPar SrcSpan
_ : [LHsTypeArg GhcRn]
args) = LHsKind GhcRn -> [LHsTypeArg GhcRn] -> LHsKind GhcRn
appTypeToArg LHsKind GhcRn
f [LHsTypeArg GhcRn]
args
appTypeToArg LHsKind GhcRn
f (HsTypeArg SrcSpan
l LHsKind GhcRn
arg : [LHsTypeArg GhcRn]
args)
= LHsKind GhcRn -> [LHsTypeArg GhcRn] -> LHsKind GhcRn
appTypeToArg (XAppKindTy GhcRn -> LHsKind GhcRn -> LHsKind GhcRn -> LHsKind GhcRn
forall (p :: Pass).
XAppKindTy (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
mkHsAppKindTy SrcSpan
XAppKindTy GhcRn
l LHsKind GhcRn
f LHsKind GhcRn
arg) [LHsTypeArg GhcRn]
args
checkExpectedKind :: HasDebugCallStack
=> HsType GhcRn
-> TcType
-> TcKind
-> TcKind
-> TcM TcType
checkExpectedKind :: HsType GhcRn -> Type -> Type -> Type -> TcM Type
checkExpectedKind HsType GhcRn
hs_ty Type
ty Type
act_kind Type
exp_kind
= do { String -> MsgDoc -> TcM ()
traceTc String
"checkExpectedKind" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
ty MsgDoc -> MsgDoc -> MsgDoc
$$ Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
act_kind)
; ([Type]
new_args, Type
act_kind') <- Arity -> Type -> TcM ([Type], Type)
tcInstInvisibleTyBinders Arity
n_to_inst Type
act_kind
; let origin :: CtOrigin
origin = TypeEqOrigin :: Type -> Type -> Maybe MsgDoc -> Bool -> CtOrigin
TypeEqOrigin { uo_actual :: Type
uo_actual = Type
act_kind'
, uo_expected :: Type
uo_expected = Type
exp_kind
, uo_thing :: Maybe MsgDoc
uo_thing = MsgDoc -> Maybe MsgDoc
forall a. a -> Maybe a
Just (HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
hs_ty)
, uo_visible :: Bool
uo_visible = Bool
True }
; String -> MsgDoc -> TcM ()
traceTc String
"checkExpectedKindX" (MsgDoc -> TcM ()) -> MsgDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
hs_ty
, String -> MsgDoc
text String
"act_kind':" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
act_kind'
, String -> MsgDoc
text String
"exp_kind:" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
exp_kind ]
; let res_ty :: Type
res_ty = Type
ty Type -> [Type] -> Type
`mkTcAppTys` [Type]
new_args
; if Type
act_kind' HasDebugCallStack => Type -> Type -> Bool
Type -> Type -> Bool
Evidence bound by a type signature of the constraint type HasDebugCallStack
`tcEqType` Type
exp_kind
then Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
res_ty
else do { Coercion
co_k <- TypeOrKind -> CtOrigin -> Type -> Type -> TcM Coercion
uType TypeOrKind
KindLevel CtOrigin
origin Type
act_kind' Type
exp_kind
; String -> MsgDoc -> TcM ()
traceTc String
"checkExpectedKind" ([MsgDoc] -> MsgDoc
vcat [ Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
act_kind
, Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
exp_kind
, Coercion -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Coercion
ppr Coercion
co_k ])
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Type
res_ty Type -> Coercion -> Type
`mkTcCastTy` Coercion
co_k) } }
where
n_exp_invis_bndrs :: Arity
n_exp_invis_bndrs = Type -> Arity
invisibleTyBndrCount Type
exp_kind
n_act_invis_bndrs :: Arity
n_act_invis_bndrs = Type -> Arity
invisibleTyBndrCount Type
act_kind
n_to_inst :: Arity
n_to_inst = Arity
n_act_invis_bndrs Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
- Arity
n_exp_invis_bndrs
tcHsMbContext :: Maybe (LHsContext GhcRn) -> TcM [PredType]
tcHsMbContext :: Maybe (LHsContext GhcRn) -> TcM [Type]
tcHsMbContext Maybe (LHsContext GhcRn)
Nothing = [Type] -> TcM [Type]
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return []
tcHsMbContext (Just LHsContext GhcRn
cxt) = LHsContext GhcRn -> TcM [Type]
tcHsContext LHsContext GhcRn
cxt
tcHsContext :: LHsContext GhcRn -> TcM [PredType]
tcHsContext :: LHsContext GhcRn -> TcM [Type]
tcHsContext = TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
typeLevelMode
tcLHsPredType :: LHsType GhcRn -> TcM PredType
tcLHsPredType :: LHsKind GhcRn -> TcM Type
tcLHsPredType = TcTyMode -> LHsKind GhcRn -> TcM Type
tc_lhs_pred TcTyMode
typeLevelMode
tc_hs_context :: TcTyMode -> LHsContext GhcRn -> TcM [PredType]
tc_hs_context :: TcTyMode -> LHsContext GhcRn -> TcM [Type]
tc_hs_context TcTyMode
mode LHsContext GhcRn
ctxt = (LHsKind GhcRn -> TcM Type) -> [LHsKind GhcRn] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM (TcTyMode -> LHsKind GhcRn -> TcM Type
tc_lhs_pred TcTyMode
mode) (LHsContext GhcRn -> [LHsKind GhcRn]
forall l e. GenLocated l e -> e
unLoc LHsContext GhcRn
ctxt)
tc_lhs_pred :: TcTyMode -> LHsType GhcRn -> TcM PredType
tc_lhs_pred :: TcTyMode -> LHsKind GhcRn -> TcM Type
tc_lhs_pred TcTyMode
mode LHsKind GhcRn
pred = TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type TcTyMode
mode LHsKind GhcRn
pred Type
constraintKind
tcTyVar :: TcTyMode -> Name -> TcM (TcType, TcKind)
tcTyVar :: TcTyMode -> Name -> TcM (Type, Type)
tcTyVar TcTyMode
mode Name
name
= do { String -> MsgDoc -> TcM ()
traceTc String
"lk1" (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr Name
name)
; TcTyThing
thing <- Name -> TcM TcTyThing
tcLookup Name
name
; case TcTyThing
thing of
ATyVar Name
_ TyVar
tv -> (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TyVar -> Type
mkTyVarTy TyVar
tv, TyVar -> Type
tyVarKind TyVar
tv)
ATcTyCon TyCon
tc_tc
-> do {
Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
unless (TypeOrKind -> Bool
isTypeLevel (TcTyMode -> TypeOrKind
mode_level TcTyMode
mode))
(Name -> PromotionErr -> TcM ()
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
TyConPE)
; TyCon -> TcM ()
check_tc TyCon
tc_tc
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TyCon -> Type
mkTyConTy TyCon
tc_tc, TyCon -> Type
tyConKind TyCon
tc_tc) }
AGlobal (ATyCon TyCon
tc)
-> do { TyCon -> TcM ()
check_tc TyCon
tc
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TyCon -> Type
mkTyConTy TyCon
tc, TyCon -> Type
tyConKind TyCon
tc) }
AGlobal (AConLike (RealDataCon DataCon
dc))
-> do { Bool
data_kinds <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.DataKinds
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
unless (Bool
data_kinds Bool -> Bool -> Bool
|| DataCon -> Bool
specialPromotedDc 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
NoDataKindsDC
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
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 ([TyVar]
_, [TyVar]
_, [EqSpec]
_, [Type]
theta, [Type]
_, Type
_) = DataCon -> ([TyVar], [TyVar], [EqSpec], [Type], [Type], Type)
dataConFullSig DataCon
dc
; String -> MsgDoc -> TcM ()
traceTc String
"tcTyVar" (DataCon -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable DataCon
ppr DataCon
dc MsgDoc -> MsgDoc -> MsgDoc
<+> [Type] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable Type
ppr [Type]
theta MsgDoc -> MsgDoc -> MsgDoc
$$ Maybe Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable (Maybe a)
External instance of the constraint type Outputable Type
ppr ([Type] -> Maybe Type
dc_theta_illegal_constraint [Type]
theta))
; case [Type] -> Maybe Type
dc_theta_illegal_constraint [Type]
theta of
Just Type
pred -> Name -> PromotionErr -> TcM ()
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name (PromotionErr -> TcM ()) -> PromotionErr -> TcM ()
forall a b. (a -> b) -> a -> b
$
Type -> PromotionErr
ConstrainedDataConPE Type
pred
Maybe Type
Nothing -> () -> TcM ()
forall (f :: * -> *) a. Applicative f => a -> f a
External instance of the constraint type forall m. Applicative (IOEnv m)
pure ()
; let tc :: TyCon
tc = DataCon -> TyCon
promoteDataCon DataCon
dc
; (Type, Type) -> TcM (Type, Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (TyCon -> [Type] -> Type
mkTyConApp TyCon
tc [], TyCon -> Type
tyConKind TyCon
tc) }
APromotionErr PromotionErr
err -> Name -> PromotionErr -> TcM (Type, Type)
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
err
TcTyThing
_ -> String -> TcTyThing -> Name -> TcM (Type, Type)
forall a. String -> TcTyThing -> Name -> TcM a
wrongThingErr String
"type" TcTyThing
thing Name
name }
where
check_tc :: TyCon -> TcM ()
check_tc :: TyCon -> TcM ()
check_tc TyCon
tc = do { Bool
data_kinds <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.DataKinds
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
unless (TypeOrKind -> Bool
isTypeLevel (TcTyMode -> TypeOrKind
mode_level TcTyMode
mode) Bool -> Bool -> Bool
||
Bool
data_kinds Bool -> Bool -> Bool
||
TyCon -> Bool
isKindTyCon TyCon
tc) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
Name -> PromotionErr -> TcM ()
forall a. Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
NoDataKindsTC }
dc_theta_illegal_constraint :: ThetaType -> Maybe PredType
dc_theta_illegal_constraint :: [Type] -> Maybe Type
dc_theta_illegal_constraint = (Type -> Bool) -> [Type] -> Maybe Type
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
External instance of the constraint type Foldable []
find (Bool -> Bool
not (Bool -> Bool) -> (Type -> Bool) -> Type -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Bool
isEqPred)
addTypeCtxt :: LHsType GhcRn -> TcM a -> TcM a
addTypeCtxt :: LHsKind GhcRn -> TcM a -> TcM a
addTypeCtxt (L SrcSpan
_ (HsWildCardTy XWildCardTy GhcRn
_)) TcM a
thing = TcM a
thing
addTypeCtxt (L SrcSpan
_ HsType GhcRn
ty) TcM a
thing
= MsgDoc -> TcM a -> TcM a
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt MsgDoc
doc TcM a
thing
where
doc :: MsgDoc
doc = String -> MsgDoc
text String
"In the type" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (HsType GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr HsType GhcRn
ty)
tcNamedWildCardBinders :: [Name]
-> ([(Name, TcTyVar)] -> TcM a)
-> TcM a
tcNamedWildCardBinders :: HsQTvsRn -> ([(Name, TyVar)] -> TcM a) -> TcM a
tcNamedWildCardBinders HsQTvsRn
wc_names [(Name, TyVar)] -> TcM a
thing_inside
= do { [TyVar]
wcs <- (Name -> TcM TyVar) -> HsQTvsRn -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM (TcM TyVar -> Name -> TcM TyVar
forall a b. a -> b -> a
const TcM TyVar
newWildTyVar) HsQTvsRn
wc_names
; let wc_prs :: [(Name, TyVar)]
wc_prs = HsQTvsRn
wc_names HsQTvsRn -> [TyVar] -> [(Name, TyVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TyVar]
wcs
; [(Name, TyVar)] -> TcM a -> TcM a
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyVar)]
wc_prs (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
[(Name, TyVar)] -> TcM a
thing_inside [(Name, TyVar)]
wc_prs }
newWildTyVar :: TcM TcTyVar
newWildTyVar :: TcM TyVar
newWildTyVar
= do { Type
kind <- TcM Type
newMetaKindVar
; Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TauTv
; let name :: Name
name = Unique -> FastString -> Name
mkSysTvName Unique
uniq (String -> FastString
fsLit String
"_")
tyvar :: TyVar
tyvar = Name -> Type -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name Type
kind TcTyVarDetails
details
; String -> MsgDoc -> TcM ()
traceTc String
"newWildTyVar" (TyVar -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TyVar
ppr TyVar
tyvar)
; TyVar -> TcM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyVar
tyvar }
data InitialKindStrategy
= InitialKindCheck SAKS_or_CUSK
| InitialKindInfer
data SAKS_or_CUSK
= SAKS Kind
| CUSK
instance Outputable SAKS_or_CUSK where
ppr :: SAKS_or_CUSK -> MsgDoc
ppr (SAKS Type
k) = String -> MsgDoc
text String
"SAKS" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
k
ppr SAKS_or_CUSK
CUSK = String -> MsgDoc
text String
"CUSK"
kcDeclHeader
:: InitialKindStrategy
-> Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TcTyCon
(InitialKindCheck SAKS_or_CUSK
msig) = SAKS_or_CUSK
-> Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TyCon
kcCheckDeclHeader SAKS_or_CUSK
msig
kcDeclHeader InitialKindStrategy
InitialKindInfer = Name
-> TyConFlavour -> LHsQTyVars GhcRn -> TcM ContextKind -> TcM TyCon
kcInferDeclHeader
kcCheckDeclHeader
:: SAKS_or_CUSK
-> Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TcTyCon
(SAKS Type
sig) = Type
-> Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TyCon
kcCheckDeclHeader_sig Type
sig
kcCheckDeclHeader SAKS_or_CUSK
CUSK = Name
-> TyConFlavour -> LHsQTyVars GhcRn -> TcM ContextKind -> TcM TyCon
kcCheckDeclHeader_cusk
kcCheckDeclHeader_cusk
:: Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TcTyCon
Name
name TyConFlavour
flav
(HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = XHsQTvs GhcRn
kv_ns
, hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
hsq_explicit = [LHsTyVarBndr () GhcRn]
hs_tvs }) TcM ContextKind
kc_res_ki
= Name -> TyConFlavour -> TcM TyCon -> TcM TyCon
forall a. Name -> TyConFlavour -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour
flav (TcM TyCon -> TcM TyCon) -> TcM TyCon -> TcM TyCon
forall a b. (a -> b) -> a -> b
$
do { ([TyVar]
scoped_kvs, ([TyVar]
tc_tvs, Type
res_kind))
<- TcM ([TyVar], ([TyVar], Type)) -> TcM ([TyVar], ([TyVar], Type))
forall a. TcM a -> TcM a
pushTcLevelM_ (TcM ([TyVar], ([TyVar], Type)) -> TcM ([TyVar], ([TyVar], Type)))
-> TcM ([TyVar], ([TyVar], Type)) -> TcM ([TyVar], ([TyVar], Type))
forall a b. (a -> b) -> a -> b
$
TcM ([TyVar], ([TyVar], Type)) -> TcM ([TyVar], ([TyVar], Type))
forall a. TcM a -> TcM a
solveEqualities (TcM ([TyVar], ([TyVar], Type)) -> TcM ([TyVar], ([TyVar], Type)))
-> TcM ([TyVar], ([TyVar], Type)) -> TcM ([TyVar], ([TyVar], Type))
forall a b. (a -> b) -> a -> b
$
HsQTvsRn -> TcM ([TyVar], Type) -> TcM ([TyVar], ([TyVar], Type))
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Q_Skol HsQTvsRn
XHsQTvs GhcRn
kv_ns (TcM ([TyVar], Type) -> TcM ([TyVar], ([TyVar], Type)))
-> TcM ([TyVar], Type) -> TcM ([TyVar], ([TyVar], Type))
forall a b. (a -> b) -> a -> b
$
ContextKind
-> [LHsTyVarBndr () GhcRn] -> TcM Type -> TcM ([TyVar], Type)
forall a.
ContextKind -> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrs_Q_Skol ContextKind
ctxt_kind [LHsTyVarBndr () GhcRn]
hs_tvs (TcM Type -> TcM ([TyVar], Type))
-> TcM Type -> TcM ([TyVar], 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
External instance of the constraint type forall m. Monad (IOEnv m)
=<< TcM ContextKind
kc_res_ki
; let spec_req_tkvs :: [TyVar]
spec_req_tkvs = [TyVar]
scoped_kvs [TyVar] -> [TyVar] -> [TyVar]
forall a. [a] -> [a] -> [a]
++ [TyVar]
tc_tvs
all_kinds :: [Type]
all_kinds = Type
res_kind Type -> [Type] -> [Type]
forall a. a -> [a] -> [a]
: (TyVar -> Type) -> [TyVar] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> Type
tyVarKind [TyVar]
spec_req_tkvs
; CandidatesQTvs
candidates' <- [Type] -> TcM CandidatesQTvs
candidateQTyVarsOfKinds [Type]
all_kinds
; let non_tc_candidates :: [TyVar]
non_tc_candidates = (TyVar -> Bool) -> [TyVar] -> [TyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (TyVar -> Bool) -> TyVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyVar -> Bool
isTcTyVar) (TyCoVarSet -> [TyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet ([Type] -> TyCoVarSet
tyCoVarsOfTypes [Type]
all_kinds))
candidates :: CandidatesQTvs
candidates = CandidatesQTvs
candidates' { dv_kvs :: DTyVarSet
dv_kvs = CandidatesQTvs -> DTyVarSet
dv_kvs CandidatesQTvs
candidates' DTyVarSet -> [TyVar] -> DTyVarSet
`extendDVarSetList` [TyVar]
non_tc_candidates }
inf_candidates :: CandidatesQTvs
inf_candidates = CandidatesQTvs
candidates CandidatesQTvs -> [TyVar] -> CandidatesQTvs
`delCandidates` [TyVar]
spec_req_tkvs
; [TyVar]
inferred <- CandidatesQTvs -> TcM [TyVar]
quantifyTyVars CandidatesQTvs
inf_candidates
; [TyVar]
scoped_kvs <- (TyVar -> TcM TyVar) -> [TyVar] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM TyVar -> TcM TyVar
zonkTyCoVarKind [TyVar]
scoped_kvs
; [TyVar]
tc_tvs <- (TyVar -> TcM TyVar) -> [TyVar] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM TyVar -> TcM TyVar
zonkTyCoVarKind [TyVar]
tc_tvs
; Type
res_kind <- Type -> TcM Type
zonkTcType Type
res_kind
; let mentioned_kv_set :: TyCoVarSet
mentioned_kv_set = CandidatesQTvs -> TyCoVarSet
candidateKindVars CandidatesQTvs
candidates
specified :: [TyVar]
specified = [TyVar] -> [TyVar]
scopedSort [TyVar]
scoped_kvs
final_tc_binders :: [TyConBinder]
final_tc_binders = ArgFlag -> [TyVar] -> [TyConBinder]
mkNamedTyConBinders ArgFlag
Inferred [TyVar]
inferred
[TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
++ ArgFlag -> [TyVar] -> [TyConBinder]
mkNamedTyConBinders ArgFlag
Specified [TyVar]
specified
[TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
++ (TyVar -> TyConBinder) -> [TyVar] -> [TyConBinder]
forall a b. (a -> b) -> [a] -> [b]
map (TyCoVarSet -> TyVar -> TyConBinder
mkRequiredTyConBinder TyCoVarSet
mentioned_kv_set) [TyVar]
tc_tvs
all_tv_prs :: [(Name, TyVar)]
all_tv_prs = [TyVar] -> [(Name, TyVar)]
mkTyVarNamePairs ([TyVar]
scoped_kvs [TyVar] -> [TyVar] -> [TyVar]
forall a. [a] -> [a] -> [a]
++ [TyVar]
tc_tvs)
tycon :: TyCon
tycon = Name
-> [TyConBinder]
-> Type
-> [(Name, TyVar)]
-> Bool
-> TyConFlavour
-> TyCon
mkTcTyCon Name
name [TyConBinder]
final_tc_binders Type
res_kind [(Name, TyVar)]
all_tv_prs
Bool
True
TyConFlavour
flav
; TyCon -> TcM ()
checkTyConTelescope TyCon
tycon
; String -> MsgDoc -> TcM ()
traceTc String
"kcCheckDeclHeader_cusk " (MsgDoc -> TcM ()) -> MsgDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ String -> MsgDoc
text String
"name" MsgDoc -> MsgDoc -> MsgDoc
<+> Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr Name
name
, String -> MsgDoc
text String
"kv_ns" MsgDoc -> MsgDoc -> MsgDoc
<+> HsQTvsRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable Name
ppr HsQTvsRn
XHsQTvs GhcRn
kv_ns
, String -> MsgDoc
text String
"hs_tvs" MsgDoc -> MsgDoc -> MsgDoc
<+> [LHsTyVarBndr () GhcRn] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass) flag.
(OutputableBndrId p, OutputableBndrFlag flag) =>
Outputable (HsTyVarBndr flag (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type OutputableBndrFlag ()
ppr [LHsTyVarBndr () GhcRn]
hs_tvs
, String -> MsgDoc
text String
"scoped_kvs" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
scoped_kvs
, String -> MsgDoc
text String
"tc_tvs" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
tc_tvs
, String -> MsgDoc
text String
"res_kind" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
res_kind
, String -> MsgDoc
text String
"candidates" MsgDoc -> MsgDoc -> MsgDoc
<+> CandidatesQTvs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable CandidatesQTvs
ppr CandidatesQTvs
candidates
, String -> MsgDoc
text String
"inferred" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
inferred
, String -> MsgDoc
text String
"specified" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
specified
, String -> MsgDoc
text String
"final_tc_binders" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyConBinder] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall tv.
OutputableBndr tv =>
Outputable (VarBndr tv TyConBndrVis)
External instance of the constraint type OutputableBndr TyVar
ppr [TyConBinder]
final_tc_binders
, String -> MsgDoc
text String
"mkTyConKind final_tc_bndrs res_kind"
MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr ([TyConBinder] -> Type -> Type
mkTyConKind [TyConBinder]
final_tc_binders Type
res_kind)
, String -> MsgDoc
text String
"all_tv_prs" MsgDoc -> MsgDoc -> MsgDoc
<+> [(Name, TyVar)] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall a b. (Outputable a, Outputable b) => Outputable (a, b)
External instance of the constraint type Outputable Name
External instance of the constraint type Outputable TyVar
ppr [(Name, TyVar)]
all_tv_prs ]
; TyCon -> TcM TyCon
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyCon
tycon }
where
ctxt_kind :: ContextKind
ctxt_kind | TyConFlavour -> Bool
tcFlavourIsOpen TyConFlavour
flav = Type -> ContextKind
TheKind Type
liftedTypeKind
| Bool
otherwise = ContextKind
AnyKind
kcInferDeclHeader
:: Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TcTyCon
Name
name TyConFlavour
flav
(HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = XHsQTvs GhcRn
kv_ns
, hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
hsq_explicit = [LHsTyVarBndr () GhcRn]
hs_tvs }) TcM ContextKind
kc_res_ki
= Name -> TyConFlavour -> TcM TyCon -> TcM TyCon
forall a. Name -> TyConFlavour -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour
flav (TcM TyCon -> TcM TyCon) -> TcM TyCon -> TcM TyCon
forall a b. (a -> b) -> a -> b
$
do { ([TyVar]
scoped_kvs, ([TyVar]
tc_tvs, Type
res_kind))
<- HsQTvsRn -> TcM ([TyVar], Type) -> TcM ([TyVar], ([TyVar], Type))
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Q_Tv HsQTvsRn
XHsQTvs GhcRn
kv_ns (TcM ([TyVar], Type) -> TcM ([TyVar], ([TyVar], Type)))
-> TcM ([TyVar], Type) -> TcM ([TyVar], ([TyVar], Type))
forall a b. (a -> b) -> a -> b
$
ContextKind
-> [LHsTyVarBndr () GhcRn] -> TcM Type -> TcM ([TyVar], Type)
forall a.
ContextKind -> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrs_Q_Tv ContextKind
ctxt_kind [LHsTyVarBndr () GhcRn]
hs_tvs (TcM Type -> TcM ([TyVar], Type))
-> TcM Type -> TcM ([TyVar], 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
External instance of the constraint type forall m. Monad (IOEnv m)
=<< TcM ContextKind
kc_res_ki
; let
tc_binders :: [TyConBinder]
tc_binders = AnonArgFlag -> [TyVar] -> [TyConBinder]
mkAnonTyConBinders AnonArgFlag
VisArg [TyVar]
tc_tvs
all_tv_prs :: [(Name, TyVar)]
all_tv_prs = [TyVar] -> [(Name, TyVar)]
mkTyVarNamePairs ([TyVar]
scoped_kvs [TyVar] -> [TyVar] -> [TyVar]
forall a. [a] -> [a] -> [a]
++ [TyVar]
tc_tvs)
tycon :: TyCon
tycon = Name
-> [TyConBinder]
-> Type
-> [(Name, TyVar)]
-> Bool
-> TyConFlavour
-> TyCon
mkTcTyCon Name
name [TyConBinder]
tc_binders Type
res_kind [(Name, TyVar)]
all_tv_prs
Bool
False
TyConFlavour
flav
; String -> MsgDoc -> TcM ()
traceTc String
"kcInferDeclHeader: not-cusk" (MsgDoc -> TcM ()) -> MsgDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr Name
name, HsQTvsRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable Name
ppr HsQTvsRn
XHsQTvs GhcRn
kv_ns, [LHsTyVarBndr () GhcRn] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass) flag.
(OutputableBndrId p, OutputableBndrFlag flag) =>
Outputable (HsTyVarBndr flag (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type OutputableBndrFlag ()
ppr [LHsTyVarBndr () GhcRn]
hs_tvs
, [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
scoped_kvs
, [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
tc_tvs, Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr ([TyConBinder] -> Type -> Type
mkTyConKind [TyConBinder]
tc_binders Type
res_kind) ]
; TyCon -> TcM TyCon
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyCon
tycon }
where
ctxt_kind :: ContextKind
ctxt_kind | TyConFlavour -> Bool
tcFlavourIsOpen TyConFlavour
flav = Type -> ContextKind
TheKind Type
liftedTypeKind
| Bool
otherwise = ContextKind
AnyKind
kcCheckDeclHeader_sig
:: Kind
-> Name
-> TyConFlavour
-> LHsQTyVars GhcRn
-> TcM ContextKind
-> TcM TcTyCon
Type
kisig Name
name TyConFlavour
flav
(HsQTvs { hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_ext = XHsQTvs GhcRn
implicit_nms
, hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
hsq_explicit = [LHsTyVarBndr () GhcRn]
explicit_nms }) TcM ContextKind
kc_res_ki
= Name -> TyConFlavour -> TcM TyCon -> TcM TyCon
forall a. Name -> TyConFlavour -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour
flav (TcM TyCon -> TcM TyCon) -> TcM TyCon -> TcM TyCon
forall a b. (a -> b) -> a -> b
$
do {
let ([ZippedBinder]
zipped_binders, [LHsTyVarBndr () GhcRn]
excess_bndrs, Type
kisig') = Type
-> [LHsTyVarBndr () GhcRn]
-> ([ZippedBinder], [LHsTyVarBndr () GhcRn], Type)
zipBinders Type
kisig [LHsTyVarBndr () GhcRn]
explicit_nms
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
External instance of the constraint type forall m. Applicative (IOEnv m)
unless ([LHsTyVarBndr () GhcRn] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
External instance of the constraint type Foldable []
null [LHsTyVarBndr () GhcRn]
excess_bndrs) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ MsgDoc -> TcM ()
forall a. MsgDoc -> TcM a
failWithTc (Type -> [LHsTyVarBndr () GhcRn] -> MsgDoc
tooManyBindersErr Type
kisig' [LHsTyVarBndr () GhcRn]
excess_bndrs)
; ([TyConBinder]
vis_tcbs, [[(Name, TyVar)]] -> [(Name, TyVar)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
External instance of the constraint type Foldable []
concat -> [(Name, TyVar)]
explicit_tv_prs) <- (ZippedBinder
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)]))
-> [ZippedBinder]
-> IOEnv (Env TcGblEnv TcLclEnv) ([TyConBinder], [[(Name, TyVar)]])
forall (m :: * -> *) a b c.
Applicative m =>
(a -> m (b, c)) -> [a] -> m ([b], [c])
External instance of the constraint type forall m. Applicative (IOEnv m)
mapAndUnzipM ZippedBinder
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
zipped_to_tcb [ZippedBinder]
zipped_binders
; ([TyVar]
implicit_tvs, ([TyCoBinder]
invis_binders, Type
r_ki))
<- TcM ([TyVar], ([TyCoBinder], Type))
-> TcM ([TyVar], ([TyCoBinder], Type))
forall a. TcM a -> TcM a
pushTcLevelM_ (TcM ([TyVar], ([TyCoBinder], Type))
-> TcM ([TyVar], ([TyCoBinder], Type)))
-> TcM ([TyVar], ([TyCoBinder], Type))
-> TcM ([TyVar], ([TyCoBinder], Type))
forall a b. (a -> b) -> a -> b
$
TcM ([TyVar], ([TyCoBinder], Type))
-> TcM ([TyVar], ([TyCoBinder], Type))
forall a. TcM a -> TcM a
solveEqualities (TcM ([TyVar], ([TyCoBinder], Type))
-> TcM ([TyVar], ([TyCoBinder], Type)))
-> TcM ([TyVar], ([TyCoBinder], Type))
-> TcM ([TyVar], ([TyCoBinder], Type))
forall a b. (a -> b) -> a -> b
$
HsQTvsRn
-> TcM ([TyCoBinder], Type) -> TcM ([TyVar], ([TyCoBinder], Type))
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Tv HsQTvsRn
XHsQTvs GhcRn
implicit_nms (TcM ([TyCoBinder], Type) -> TcM ([TyVar], ([TyCoBinder], Type)))
-> TcM ([TyCoBinder], Type) -> TcM ([TyVar], ([TyCoBinder], Type))
forall a b. (a -> b) -> a -> b
$
[(Name, TyVar)]
-> TcM ([TyCoBinder], Type) -> TcM ([TyCoBinder], Type)
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyVar)]
explicit_tv_prs (TcM ([TyCoBinder], Type) -> TcM ([TyCoBinder], Type))
-> TcM ([TyCoBinder], Type) -> TcM ([TyCoBinder], Type)
forall a b. (a -> b) -> a -> b
$
do {
(ZippedBinder -> TcM ()) -> [ZippedBinder] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Foldable []
mapM_ ZippedBinder -> TcM ()
check_zipped_binder [ZippedBinder]
zipped_binders
; ContextKind
ctx_k <- TcM ContextKind
kc_res_ki
; Maybe Type
m_res_ki <- case ContextKind
ctx_k of
ContextKind
AnyKind -> Maybe Type -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Maybe Type
forall a. Maybe a
Nothing
ContextKind
_ -> Type -> Maybe Type
forall a. a -> Maybe a
Just (Type -> Maybe Type)
-> TcM Type -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
External instance of the constraint type forall env. Functor (IOEnv env)
<$> ContextKind -> TcM Type
newExpectedKind ContextKind
ctx_k
; let ([TyCoBinder]
invis_binders, Type
r_ki) = Type -> Maybe Type -> ([TyCoBinder], Type)
split_invis Type
kisig' Maybe Type
m_res_ki
; Maybe Type -> (Type -> TcM ()) -> TcM ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
External instance of the constraint type forall m. Monad (IOEnv m)
whenIsJust Maybe Type
m_res_ki ((Type -> TcM ()) -> TcM ()) -> (Type -> TcM ()) -> TcM ()
forall a b. (a -> b) -> a -> b
$ \Type
res_ki ->
TcM Coercion -> TcM ()
forall a. TcM a -> TcM ()
discardResult (TcM Coercion -> TcM ()) -> TcM Coercion -> TcM ()
forall a b. (a -> b) -> a -> b
$
Maybe (HsType GhcRn) -> Type -> Type -> TcM Coercion
unifyKind Maybe (HsType GhcRn)
forall a. Maybe a
Nothing Type
r_ki Type
res_ki
; ([TyCoBinder], Type) -> TcM ([TyCoBinder], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([TyCoBinder]
invis_binders, Type
r_ki) }
; [TyVar]
implicit_tvs <- (TyVar -> TcM TyVar) -> [TyVar] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM HasDebugCallStack => TyVar -> TcM TyVar
TyVar -> TcM TyVar
External instance of the constraint type HasDebugCallStack
zonkTcTyVarToTyVar [TyVar]
implicit_tvs
; [TyConBinder]
invis_tcbs <- (TyCoBinder -> IOEnv (Env TcGblEnv TcLclEnv) TyConBinder)
-> [TyCoBinder] -> IOEnv (Env TcGblEnv TcLclEnv) [TyConBinder]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM TyCoBinder -> IOEnv (Env TcGblEnv TcLclEnv) TyConBinder
invis_to_tcb [TyCoBinder]
invis_binders
; let tcbs :: [TyConBinder]
tcbs = [TyConBinder]
vis_tcbs [TyConBinder] -> [TyConBinder] -> [TyConBinder]
forall a. [a] -> [a] -> [a]
++ [TyConBinder]
invis_tcbs
implicit_tv_prs :: [(Name, TyVar)]
implicit_tv_prs = HsQTvsRn
XHsQTvs GhcRn
implicit_nms HsQTvsRn -> [TyVar] -> [(Name, TyVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TyVar]
implicit_tvs
all_tv_prs :: [(Name, TyVar)]
all_tv_prs = [(Name, TyVar)]
implicit_tv_prs [(Name, TyVar)] -> [(Name, TyVar)] -> [(Name, TyVar)]
forall a. [a] -> [a] -> [a]
++ [(Name, TyVar)]
explicit_tv_prs
tc :: TyCon
tc = Name
-> [TyConBinder]
-> Type
-> [(Name, TyVar)]
-> Bool
-> TyConFlavour
-> TyCon
mkTcTyCon Name
name [TyConBinder]
tcbs Type
r_ki [(Name, TyVar)]
all_tv_prs Bool
True TyConFlavour
flav
; String -> MsgDoc -> TcM ()
traceTc String
"kcCheckDeclHeader_sig done:" (MsgDoc -> TcM ()) -> MsgDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ [MsgDoc] -> MsgDoc
vcat
[ String -> MsgDoc
text String
"tyConName = " MsgDoc -> MsgDoc -> MsgDoc
<+> Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr (TyCon -> Name
tyConName TyCon
tc)
, String -> MsgDoc
text String
"kisig =" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
debugPprType Type
kisig
, String -> MsgDoc
text String
"tyConKind =" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
debugPprType (TyCon -> Type
tyConKind TyCon
tc)
, String -> MsgDoc
text String
"tyConBinders = " MsgDoc -> MsgDoc -> MsgDoc
<+> [TyConBinder] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall tv.
OutputableBndr tv =>
Outputable (VarBndr tv TyConBndrVis)
External instance of the constraint type OutputableBndr TyVar
ppr (TyCon -> [TyConBinder]
tyConBinders TyCon
tc)
, String -> MsgDoc
text String
"tcTyConScopedTyVars" MsgDoc -> MsgDoc -> MsgDoc
<+> [(Name, TyVar)] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall a b. (Outputable a, Outputable b) => Outputable (a, b)
External instance of the constraint type Outputable Name
External instance of the constraint type Outputable TyVar
ppr (TyCon -> [(Name, TyVar)]
tcTyConScopedTyVars TyCon
tc)
, String -> MsgDoc
text String
"tyConResKind" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
debugPprType (TyCon -> Type
tyConResKind TyCon
tc)
]
; TyCon -> TcM TyCon
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyCon
tc }
where
zipped_to_tcb :: ZippedBinder -> TcM (TyConBinder, [(Name, TcTyVar)])
zipped_to_tcb :: ZippedBinder
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
zipped_to_tcb ZippedBinder
zb = case ZippedBinder
zb of
ZippedBinder (Named (Bndr TyVar
v ArgFlag
Specified)) Maybe (LHsTyVarBndr () GhcRn)
Nothing ->
(TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder ArgFlag
Specified TyVar
v, [])
ZippedBinder (Named (Bndr TyVar
v ArgFlag
Inferred)) Maybe (LHsTyVarBndr () GhcRn)
Nothing ->
(TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder ArgFlag
Inferred TyVar
v, [])
ZippedBinder (Anon AnonArgFlag
InvisArg Type
bndr_ki) Maybe (LHsTyVarBndr () GhcRn)
Nothing -> do
Name
name <- OccName -> TcRnIf TcGblEnv TcLclEnv Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (FastString -> OccName
mkTyVarOccFS (String -> FastString
fsLit String
"ev"))
let tv :: TyVar
tv = Name -> Type -> TyVar
mkTyVar Name
name Type
bndr_ki
(TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (AnonArgFlag -> TyVar -> TyConBinder
mkAnonTyConBinder AnonArgFlag
InvisArg TyVar
tv, [])
ZippedBinder (Anon AnonArgFlag
VisArg Type
bndr_ki) (Just LHsTyVarBndr () GhcRn
b) ->
(TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ((TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)]))
-> (TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall a b. (a -> b) -> a -> b
$
let v_name :: Name
v_name = LHsTyVarBndr () GhcRn -> Name
forall a. NamedThing a => a -> Name
External instance of the constraint type forall e. NamedThing e => NamedThing (Located e)
External instance of the constraint type forall flag. NamedThing (HsTyVarBndr flag GhcRn)
getName LHsTyVarBndr () GhcRn
b
tv :: TyVar
tv = Name -> Type -> TyVar
mkTyVar Name
v_name Type
bndr_ki
tcb :: TyConBinder
tcb = AnonArgFlag -> TyVar -> TyConBinder
mkAnonTyConBinder AnonArgFlag
VisArg TyVar
tv
in (TyConBinder
tcb, [(Name
v_name, TyVar
tv)])
ZippedBinder (Named (Bndr TyVar
v ArgFlag
Required)) (Just LHsTyVarBndr () GhcRn
b) ->
(TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ((TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)]))
-> (TyConBinder, [(Name, TyVar)])
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall a b. (a -> b) -> a -> b
$
let v_name :: Name
v_name = LHsTyVarBndr () GhcRn -> Name
forall a. NamedThing a => a -> Name
External instance of the constraint type forall e. NamedThing e => NamedThing (Located e)
External instance of the constraint type forall flag. NamedThing (HsTyVarBndr flag GhcRn)
getName LHsTyVarBndr () GhcRn
b
tcb :: TyConBinder
tcb = ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder ArgFlag
Required TyVar
v
in (TyConBinder
tcb, [(Name
v_name, TyVar
v)])
ZippedBinder
_ -> String
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
forall a. String -> a
panic String
"goVis: invalid ZippedBinder"
invis_to_tcb :: TyCoBinder -> TcM TyConBinder
invis_to_tcb :: TyCoBinder -> IOEnv (Env TcGblEnv TcLclEnv) TyConBinder
invis_to_tcb TyCoBinder
tb = do
(TyConBinder
tcb, [(Name, TyVar)]
stv) <- ZippedBinder
-> IOEnv (Env TcGblEnv TcLclEnv) (TyConBinder, [(Name, TyVar)])
zipped_to_tcb (TyCoBinder -> Maybe (LHsTyVarBndr () GhcRn) -> ZippedBinder
ZippedBinder TyCoBinder
tb Maybe (LHsTyVarBndr () GhcRn)
forall a. Maybe a
Nothing)
MASSERT(null stv)
TyConBinder -> IOEnv (Env TcGblEnv TcLclEnv) TyConBinder
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyConBinder
tcb
check_zipped_binder :: ZippedBinder -> TcM ()
check_zipped_binder :: ZippedBinder -> TcM ()
check_zipped_binder (ZippedBinder TyCoBinder
_ Maybe (LHsTyVarBndr () GhcRn)
Nothing) = () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ()
check_zipped_binder (ZippedBinder TyCoBinder
tb (Just LHsTyVarBndr () GhcRn
b)) =
case LHsTyVarBndr () GhcRn -> HsTyVarBndr () GhcRn
forall l e. GenLocated l e -> e
unLoc LHsTyVarBndr () GhcRn
b of
UserTyVar XUserTyVar GhcRn
_ ()
_ GenLocated SrcSpan (IdP GhcRn)
_ -> () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ()
KindedTyVar XKindedTyVar GhcRn
_ ()
_ GenLocated SrcSpan (IdP GhcRn)
v LHsKind GhcRn
v_hs_ki -> do
Type
v_ki <- UserTypeCtxt -> LHsKind GhcRn -> TcM Type
tcLHsKindSig (Name -> UserTypeCtxt
TyVarBndrKindCtxt (Located Name -> Name
forall l e. GenLocated l e -> e
unLoc Located Name
GenLocated SrcSpan (IdP GhcRn)
v)) LHsKind GhcRn
v_hs_ki
TcM Coercion -> TcM ()
forall a. TcM a -> TcM ()
discardResult (TcM Coercion -> TcM ()) -> TcM Coercion -> TcM ()
forall a b. (a -> b) -> a -> b
$
Maybe (HsType GhcRn) -> Type -> Type -> TcM Coercion
unifyKind (HsType GhcRn -> Maybe (HsType GhcRn)
forall a. a -> Maybe a
Just (XTyVar GhcRn
-> PromotionFlag -> GenLocated SrcSpan (IdP GhcRn) -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> Located (IdP pass) -> HsType pass
HsTyVar XTyVar GhcRn
NoExtField
noExtField PromotionFlag
NotPromoted GenLocated SrcSpan (IdP GhcRn)
v))
(TyCoBinder -> Type
tyBinderType TyCoBinder
tb)
Type
v_ki
split_invis :: Kind -> Maybe Kind -> ([TyCoBinder], Kind)
split_invis :: Type -> Maybe Type -> ([TyCoBinder], Type)
split_invis Type
sig_ki Maybe Type
Nothing =
Type -> ([TyCoBinder], Type)
splitPiTysInvisible Type
sig_ki
split_invis Type
sig_ki (Just Type
res_ki) =
let n_res_invis_bndrs :: Arity
n_res_invis_bndrs = Type -> Arity
invisibleTyBndrCount Type
res_ki
n_sig_invis_bndrs :: Arity
n_sig_invis_bndrs = Type -> Arity
invisibleTyBndrCount Type
sig_ki
n_inst :: Arity
n_inst = Arity
n_sig_invis_bndrs Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
External instance of the constraint type Num Arity
- Arity
n_res_invis_bndrs
in Arity -> Type -> ([TyCoBinder], Type)
splitPiTysInvisibleN Arity
n_inst Type
sig_ki
data ZippedBinder =
ZippedBinder TyBinder (Maybe (LHsTyVarBndr () GhcRn))
zipBinders
:: Kind
-> [LHsTyVarBndr () GhcRn]
-> ([ZippedBinder],
[LHsTyVarBndr () GhcRn],
Kind)
zipBinders :: Type
-> [LHsTyVarBndr () GhcRn]
-> ([ZippedBinder], [LHsTyVarBndr () GhcRn], Type)
zipBinders = [ZippedBinder]
-> Type
-> [LHsTyVarBndr () GhcRn]
-> ([ZippedBinder], [LHsTyVarBndr () GhcRn], Type)
zip_binders []
where
zip_binders :: [ZippedBinder]
-> Type
-> [LHsTyVarBndr () GhcRn]
-> ([ZippedBinder], [LHsTyVarBndr () GhcRn], Type)
zip_binders [ZippedBinder]
acc Type
ki [] = ([ZippedBinder] -> [ZippedBinder]
forall a. [a] -> [a]
reverse [ZippedBinder]
acc, [], Type
ki)
zip_binders [ZippedBinder]
acc Type
ki (LHsTyVarBndr () GhcRn
b:[LHsTyVarBndr () GhcRn]
bs) =
case Type -> Maybe (TyCoBinder, Type)
tcSplitPiTy_maybe Type
ki of
Maybe (TyCoBinder, Type)
Nothing -> ([ZippedBinder] -> [ZippedBinder]
forall a. [a] -> [a]
reverse [ZippedBinder]
acc, LHsTyVarBndr () GhcRn
bLHsTyVarBndr () GhcRn
-> [LHsTyVarBndr () GhcRn] -> [LHsTyVarBndr () GhcRn]
forall a. a -> [a] -> [a]
:[LHsTyVarBndr () GhcRn]
bs, Type
ki)
Just (TyCoBinder
tb, Type
ki') ->
let
(ZippedBinder
zb, [LHsTyVarBndr () GhcRn]
bs') | Bool
zippable = (TyCoBinder -> Maybe (LHsTyVarBndr () GhcRn) -> ZippedBinder
ZippedBinder TyCoBinder
tb (LHsTyVarBndr () GhcRn -> Maybe (LHsTyVarBndr () GhcRn)
forall a. a -> Maybe a
Just LHsTyVarBndr () GhcRn
b), [LHsTyVarBndr () GhcRn]
bs)
| Bool
otherwise = (TyCoBinder -> Maybe (LHsTyVarBndr () GhcRn) -> ZippedBinder
ZippedBinder TyCoBinder
tb Maybe (LHsTyVarBndr () GhcRn)
forall a. Maybe a
Nothing, LHsTyVarBndr () GhcRn
bLHsTyVarBndr () GhcRn
-> [LHsTyVarBndr () GhcRn] -> [LHsTyVarBndr () GhcRn]
forall a. a -> [a] -> [a]
:[LHsTyVarBndr () GhcRn]
bs)
zippable :: Bool
zippable =
case TyCoBinder
tb of
Named (Bndr TyVar
_ (Invisible Specificity
_)) -> Bool
False
Named (Bndr TyVar
_ ArgFlag
Required) -> Bool
True
Anon AnonArgFlag
InvisArg Type
_ -> Bool
False
Anon AnonArgFlag
VisArg Type
_ -> Bool
True
in
[ZippedBinder]
-> Type
-> [LHsTyVarBndr () GhcRn]
-> ([ZippedBinder], [LHsTyVarBndr () GhcRn], Type)
zip_binders (ZippedBinder
zbZippedBinder -> [ZippedBinder] -> [ZippedBinder]
forall a. a -> [a] -> [a]
:[ZippedBinder]
acc) Type
ki' [LHsTyVarBndr () GhcRn]
bs'
tooManyBindersErr :: Kind -> [LHsTyVarBndr () GhcRn] -> SDoc
tooManyBindersErr :: Type -> [LHsTyVarBndr () GhcRn] -> MsgDoc
tooManyBindersErr Type
ki [LHsTyVarBndr () GhcRn]
bndrs =
MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"Not a function kind:")
Arity
4 (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
ki) MsgDoc -> MsgDoc -> MsgDoc
$$
MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (String -> MsgDoc
text String
"but extra binders found:")
Arity
4 ([MsgDoc] -> MsgDoc
fsep ((LHsTyVarBndr () GhcRn -> MsgDoc)
-> [LHsTyVarBndr () GhcRn] -> [MsgDoc]
forall a b. (a -> b) -> [a] -> [b]
map LHsTyVarBndr () GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass) flag.
(OutputableBndrId p, OutputableBndrFlag flag) =>
Outputable (HsTyVarBndr flag (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
External instance of the constraint type OutputableBndrFlag ()
ppr [LHsTyVarBndr () GhcRn]
bndrs))
data ContextKind = TheKind Kind
| AnyKind
| OpenKind
newExpectedKind :: ContextKind -> TcM Kind
newExpectedKind :: ContextKind -> TcM Type
newExpectedKind (TheKind Type
k) = Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
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 UserTypeCtxt
ThBrackCtxt = ContextKind
AnyKind
expectedKindInCtxt (GhciCtxt {}) = ContextKind
AnyKind
expectedKindInCtxt UserTypeCtxt
DefaultDeclCtxt = 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
bindImplicitTKBndrs_Skol, bindImplicitTKBndrs_Tv,
bindImplicitTKBndrs_Q_Skol, bindImplicitTKBndrs_Q_Tv
:: [Name] -> TcM a -> TcM ([TcTyVar], a)
bindImplicitTKBndrs_Q_Skol :: HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Q_Skol = (Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
forall a.
(Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrsX ((Name -> TcM TyVar) -> Name -> TcM TyVar
newImplicitTyVarQ Name -> TcM TyVar
newFlexiKindedSkolemTyVar)
bindImplicitTKBndrs_Q_Tv :: HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Q_Tv = (Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
forall a.
(Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrsX ((Name -> TcM TyVar) -> Name -> TcM TyVar
newImplicitTyVarQ Name -> TcM TyVar
newFlexiKindedTyVarTyVar)
bindImplicitTKBndrs_Skol :: HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Skol = (Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
forall a.
(Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrsX Name -> TcM TyVar
newFlexiKindedSkolemTyVar
bindImplicitTKBndrs_Tv :: HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Tv = (Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
forall a.
(Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrsX Name -> TcM TyVar
cloneFlexiKindedTyVarTyVar
bindImplicitTKBndrsX
:: (Name -> TcM TcTyVar)
-> [Name]
-> TcM a
-> TcM ([TcTyVar], a)
bindImplicitTKBndrsX :: (Name -> TcM TyVar) -> HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrsX Name -> TcM TyVar
new_tv HsQTvsRn
tv_names TcM a
thing_inside
= do { [TyVar]
tkvs <- (Name -> TcM TyVar) -> HsQTvsRn -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM Name -> TcM TyVar
new_tv HsQTvsRn
tv_names
; String -> MsgDoc -> TcM ()
traceTc String
"bindImplicitTKBndrs" (HsQTvsRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable Name
ppr HsQTvsRn
tv_names MsgDoc -> MsgDoc -> MsgDoc
$$ [TyVar] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable TyVar
ppr [TyVar]
tkvs)
; a
res <- [(Name, TyVar)] -> TcM a -> TcM a
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv (HsQTvsRn
tv_names HsQTvsRn -> [TyVar] -> [(Name, TyVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TyVar]
tkvs)
TcM a
thing_inside
; ([TyVar], a) -> TcM ([TyVar], a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([TyVar]
tkvs, a
res) }
newImplicitTyVarQ :: (Name -> TcM TcTyVar) -> Name -> TcM TcTyVar
newImplicitTyVarQ :: (Name -> TcM TyVar) -> Name -> TcM TyVar
newImplicitTyVarQ Name -> TcM TyVar
new_tv Name
name
= do { Maybe TcTyThing
mb_tv <- Name -> TcM (Maybe TcTyThing)
tcLookupLcl_maybe Name
name
; case Maybe TcTyThing
mb_tv of
Just (ATyVar Name
_ TyVar
tv) -> TyVar -> TcM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyVar
tv
Maybe TcTyThing
_ -> Name -> TcM TyVar
new_tv Name
name }
newFlexiKindedTyVar :: (Name -> Kind -> TcM TyVar) -> Name -> TcM TyVar
newFlexiKindedTyVar :: (Name -> Type -> TcM TyVar) -> Name -> TcM TyVar
newFlexiKindedTyVar Name -> Type -> TcM TyVar
new_tv Name
name
= do { Type
kind <- TcM Type
newMetaKindVar
; Name -> Type -> TcM TyVar
new_tv Name
name Type
kind }
newFlexiKindedSkolemTyVar :: Name -> TcM TyVar
newFlexiKindedSkolemTyVar :: Name -> TcM TyVar
newFlexiKindedSkolemTyVar = (Name -> Type -> TcM TyVar) -> Name -> TcM TyVar
newFlexiKindedTyVar Name -> Type -> TcM TyVar
newSkolemTyVar
newFlexiKindedTyVarTyVar :: Name -> TcM TyVar
newFlexiKindedTyVarTyVar :: Name -> TcM TyVar
newFlexiKindedTyVarTyVar = (Name -> Type -> TcM TyVar) -> Name -> TcM TyVar
newFlexiKindedTyVar Name -> Type -> TcM TyVar
newTyVarTyVar
cloneFlexiKindedTyVarTyVar :: Name -> TcM TyVar
cloneFlexiKindedTyVarTyVar :: Name -> TcM TyVar
cloneFlexiKindedTyVarTyVar = (Name -> Type -> TcM TyVar) -> Name -> TcM TyVar
newFlexiKindedTyVar Name -> Type -> TcM TyVar
cloneTyVarTyVar
bindExplicitTKBndrs_Skol, bindExplicitTKBndrs_Tv
:: (OutputableBndrFlag flag)
=> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Skol :: [LHsTyVarBndr flag GhcRn] -> TcM a -> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Skol = (HsTyVarBndr flag GhcRn -> TcM TyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
forall flag a.
OutputableBndrFlag flag =>
(HsTyVarBndr flag GhcRn -> TcM TyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
Evidence bound by a type signature of the constraint type OutputableBndrFlag flag
bindExplicitTKBndrsX ((Name -> Type -> TcM TyVar) -> HsTyVarBndr flag GhcRn -> TcM TyVar
forall flag.
(Name -> Type -> TcM TyVar) -> HsTyVarBndr flag GhcRn -> TcM TyVar
tcHsTyVarBndr Name -> Type -> TcM TyVar
newSkolemTyVar)
bindExplicitTKBndrs_Tv :: [LHsTyVarBndr flag GhcRn] -> TcM a -> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrs_Tv = (HsTyVarBndr flag GhcRn -> TcM TyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
forall flag a.
OutputableBndrFlag flag =>
(HsTyVarBndr flag GhcRn -> TcM TyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
Evidence bound by a type signature of the constraint type OutputableBndrFlag flag
bindExplicitTKBndrsX ((Name -> Type -> TcM TyVar) -> HsTyVarBndr flag GhcRn -> TcM TyVar
forall flag.
(Name -> Type -> TcM TyVar) -> HsTyVarBndr flag GhcRn -> TcM TyVar
tcHsTyVarBndr Name -> Type -> TcM TyVar
cloneTyVarTyVar)
bindExplicitTKBndrs_Q_Skol, bindExplicitTKBndrs_Q_Tv
:: ContextKind
-> [LHsTyVarBndr () GhcRn]
-> TcM a
-> TcM ([TcTyVar], a)
bindExplicitTKBndrs_Q_Skol :: ContextKind -> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrs_Q_Skol ContextKind
ctxt_kind = (HsTyVarBndr () GhcRn -> TcM TyVar)
-> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
forall a.
(HsTyVarBndr () GhcRn -> TcM TyVar)
-> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrsX_Q (ContextKind
-> (Name -> Type -> TcM TyVar) -> HsTyVarBndr () GhcRn -> TcM TyVar
tcHsQTyVarBndr ContextKind
ctxt_kind Name -> Type -> TcM TyVar
newSkolemTyVar)
bindExplicitTKBndrs_Q_Tv :: ContextKind -> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrs_Q_Tv ContextKind
ctxt_kind = (HsTyVarBndr () GhcRn -> TcM TyVar)
-> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
forall a.
(HsTyVarBndr () GhcRn -> TcM TyVar)
-> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrsX_Q (ContextKind
-> (Name -> Type -> TcM TyVar) -> HsTyVarBndr () GhcRn -> TcM TyVar
tcHsQTyVarBndr ContextKind
ctxt_kind Name -> Type -> TcM TyVar
newTyVarTyVar)
bindExplicitTKBndrsX_Q
:: (HsTyVarBndr () GhcRn -> TcM TcTyVar)
-> [LHsTyVarBndr () GhcRn]
-> TcM a
-> TcM ([TcTyVar], a)
bindExplicitTKBndrsX_Q :: (HsTyVarBndr () GhcRn -> TcM TyVar)
-> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([TyVar], a)
bindExplicitTKBndrsX_Q HsTyVarBndr () GhcRn -> TcM TyVar
tc_tv [LHsTyVarBndr () GhcRn]
hs_tvs TcM a
thing_inside
= do { ([VarBndr TyVar ()]
tv_bndrs,a
res) <- (HsTyVarBndr () GhcRn -> TcM TyVar)
-> [LHsTyVarBndr () GhcRn] -> TcM a -> TcM ([VarBndr TyVar ()], a)
forall flag a.
OutputableBndrFlag flag =>
(HsTyVarBndr flag GhcRn -> TcM TyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
External instance of the constraint type OutputableBndrFlag ()
bindExplicitTKBndrsX HsTyVarBndr () GhcRn -> TcM TyVar
tc_tv [LHsTyVarBndr () GhcRn]
hs_tvs TcM a
thing_inside
; ([TyVar], a) -> TcM ([TyVar], a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (([VarBndr TyVar ()] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [VarBndr TyVar ()]
tv_bndrs),a
res) }
bindExplicitTKBndrsX :: (OutputableBndrFlag flag)
=> (HsTyVarBndr flag GhcRn -> TcM TcTyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrsX :: (HsTyVarBndr flag GhcRn -> TcM TyVar)
-> [LHsTyVarBndr flag GhcRn]
-> TcM a
-> TcM ([VarBndr TyVar flag], a)
bindExplicitTKBndrsX HsTyVarBndr flag GhcRn -> TcM TyVar
tc_tv [LHsTyVarBndr flag GhcRn]
hs_tvs TcM a
thing_inside
= do { String -> MsgDoc -> TcM ()
traceTc String
"bindExplicTKBndrs" ([LHsTyVarBndr flag GhcRn] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass) flag.
(OutputableBndrId p, OutputableBndrFlag flag) =>
Outputable (HsTyVarBndr flag (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
Evidence bound by a type signature of the constraint type OutputableBndrFlag flag
ppr [LHsTyVarBndr flag GhcRn]
hs_tvs)
; [LHsTyVarBndr flag GhcRn] -> TcM ([VarBndr TyVar flag], a)
go [LHsTyVarBndr flag GhcRn]
hs_tvs }
where
go :: [LHsTyVarBndr flag GhcRn] -> TcM ([VarBndr TyVar flag], a)
go [] = do { a
res <- TcM a
thing_inside
; ([VarBndr TyVar flag], a) -> TcM ([VarBndr TyVar flag], a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([], a
res) }
go (L SrcSpan
_ HsTyVarBndr flag GhcRn
hs_tv : [LHsTyVarBndr flag GhcRn]
hs_tvs)
= do { TyVar
tv <- HsTyVarBndr flag GhcRn -> TcM TyVar
tc_tv HsTyVarBndr flag GhcRn
hs_tv
; ([VarBndr TyVar flag]
tvs,a
res) <- [(Name, TyVar)]
-> TcM ([VarBndr TyVar flag], a) -> TcM ([VarBndr TyVar flag], a)
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(HsTyVarBndr flag GhcRn -> IdP GhcRn
forall flag (p :: Pass).
HsTyVarBndr flag (GhcPass p) -> IdP (GhcPass p)
hsTyVarName HsTyVarBndr flag GhcRn
hs_tv, TyVar
tv)] (TcM ([VarBndr TyVar flag], a) -> TcM ([VarBndr TyVar flag], a))
-> TcM ([VarBndr TyVar flag], a) -> TcM ([VarBndr TyVar flag], a)
forall a b. (a -> b) -> a -> b
$
[LHsTyVarBndr flag GhcRn] -> TcM ([VarBndr TyVar flag], a)
go [LHsTyVarBndr flag GhcRn]
hs_tvs
; ([VarBndr TyVar flag], a) -> TcM ([VarBndr TyVar flag], a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ((TyVar -> flag -> VarBndr TyVar flag
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv (HsTyVarBndr flag GhcRn -> flag
forall flag (pass :: Pass). HsTyVarBndr flag (GhcPass pass) -> flag
hsTyVarBndrFlag HsTyVarBndr flag GhcRn
hs_tv))VarBndr TyVar flag -> [VarBndr TyVar flag] -> [VarBndr TyVar flag]
forall a. a -> [a] -> [a]
:[VarBndr TyVar flag]
tvs, a
res) }
tcHsTyVarBndr :: (Name -> Kind -> TcM TyVar)
-> HsTyVarBndr flag GhcRn -> TcM TcTyVar
tcHsTyVarBndr :: (Name -> Type -> TcM TyVar) -> HsTyVarBndr flag GhcRn -> TcM TyVar
tcHsTyVarBndr Name -> Type -> TcM TyVar
new_tv (UserTyVar XUserTyVar GhcRn
_ flag
_ (L SrcSpan
_ IdP GhcRn
tv_nm))
= do { Type
kind <- TcM Type
newMetaKindVar
; Name -> Type -> TcM TyVar
new_tv Name
IdP GhcRn
tv_nm Type
kind }
tcHsTyVarBndr Name -> Type -> TcM TyVar
new_tv (KindedTyVar XKindedTyVar GhcRn
_ flag
_ (L SrcSpan
_ IdP GhcRn
tv_nm) LHsKind GhcRn
lhs_kind)
= do { Type
kind <- UserTypeCtxt -> LHsKind GhcRn -> TcM Type
tcLHsKindSig (Name -> UserTypeCtxt
TyVarBndrKindCtxt Name
IdP GhcRn
tv_nm) LHsKind GhcRn
lhs_kind
; Name -> Type -> TcM TyVar
new_tv Name
IdP GhcRn
tv_nm Type
kind }
tcHsQTyVarBndr :: ContextKind
-> (Name -> Kind -> TcM TyVar)
-> HsTyVarBndr () GhcRn -> TcM TcTyVar
tcHsQTyVarBndr :: ContextKind
-> (Name -> Type -> TcM TyVar) -> HsTyVarBndr () GhcRn -> TcM TyVar
tcHsQTyVarBndr ContextKind
ctxt_kind Name -> Type -> TcM TyVar
new_tv (UserTyVar XUserTyVar GhcRn
_ ()
_ (L SrcSpan
_ IdP GhcRn
tv_nm))
= do { Maybe TcTyThing
mb_tv <- Name -> TcM (Maybe TcTyThing)
tcLookupLcl_maybe Name
IdP GhcRn
tv_nm
; case Maybe TcTyThing
mb_tv of
Just (ATyVar Name
_ TyVar
tv) -> TyVar -> TcM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyVar
tv
Maybe TcTyThing
_ -> do { Type
kind <- ContextKind -> TcM Type
newExpectedKind ContextKind
ctxt_kind
; Name -> Type -> TcM TyVar
new_tv Name
IdP GhcRn
tv_nm Type
kind } }
tcHsQTyVarBndr ContextKind
_ Name -> Type -> TcM TyVar
new_tv (KindedTyVar XKindedTyVar GhcRn
_ ()
_ (L SrcSpan
_ IdP GhcRn
tv_nm) LHsKind GhcRn
lhs_kind)
= do { Type
kind <- UserTypeCtxt -> LHsKind GhcRn -> TcM Type
tcLHsKindSig (Name -> UserTypeCtxt
TyVarBndrKindCtxt Name
IdP GhcRn
tv_nm) LHsKind GhcRn
lhs_kind
; Maybe TcTyThing
mb_tv <- Name -> TcM (Maybe TcTyThing)
tcLookupLcl_maybe Name
IdP GhcRn
tv_nm
; case Maybe TcTyThing
mb_tv of
Just (ATyVar Name
_ TyVar
tv)
-> do { TcM Coercion -> TcM ()
forall a. TcM a -> TcM ()
discardResult (TcM Coercion -> TcM ()) -> TcM Coercion -> TcM ()
forall a b. (a -> b) -> a -> b
$ Maybe (HsType GhcRn) -> Type -> Type -> TcM Coercion
unifyKind (HsType GhcRn -> Maybe (HsType GhcRn)
forall a. a -> Maybe a
Just HsType GhcRn
hs_tv)
Type
kind (TyVar -> Type
tyVarKind TyVar
tv)
; TyVar -> TcM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return TyVar
tv }
Maybe TcTyThing
_ -> Name -> Type -> TcM TyVar
new_tv Name
IdP GhcRn
tv_nm Type
kind }
where
hs_tv :: HsType GhcRn
hs_tv = XTyVar GhcRn
-> PromotionFlag -> GenLocated SrcSpan (IdP GhcRn) -> HsType GhcRn
forall pass.
XTyVar pass -> PromotionFlag -> Located (IdP pass) -> HsType pass
HsTyVar XTyVar GhcRn
NoExtField
noExtField PromotionFlag
NotPromoted (Name -> Located Name
forall e. e -> Located e
noLoc Name
IdP GhcRn
tv_nm)
bindTyClTyVars :: Name
-> (TcTyCon -> [TyConBinder] -> Kind -> TcM a) -> TcM a
bindTyClTyVars :: Name -> (TyCon -> [TyConBinder] -> Type -> TcM a) -> TcM a
bindTyClTyVars Name
tycon_name TyCon -> [TyConBinder] -> Type -> TcM a
thing_inside
= do { TyCon
tycon <- HasDebugCallStack => Name -> TcM TyCon
Name -> TcM TyCon
External instance of the constraint type HasDebugCallStack
tcLookupTcTyCon Name
tycon_name
; let scoped_prs :: [(Name, TyVar)]
scoped_prs = TyCon -> [(Name, TyVar)]
tcTyConScopedTyVars TyCon
tycon
res_kind :: Type
res_kind = TyCon -> Type
tyConResKind TyCon
tycon
binders :: [TyConBinder]
binders = TyCon -> [TyConBinder]
tyConBinders TyCon
tycon
; String -> MsgDoc -> TcM ()
traceTc String
"bindTyClTyVars" (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr Name
tycon_name MsgDoc -> MsgDoc -> MsgDoc
<+> [TyConBinder] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall tv.
OutputableBndr tv =>
Outputable (VarBndr tv TyConBndrVis)
External instance of the constraint type OutputableBndr TyVar
ppr [TyConBinder]
binders MsgDoc -> MsgDoc -> MsgDoc
$$ [(Name, TyVar)] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall a b. (Outputable a, Outputable b) => Outputable (a, b)
External instance of the constraint type Outputable Name
External instance of the constraint type Outputable TyVar
ppr [(Name, TyVar)]
scoped_prs)
; [(Name, TyVar)] -> TcM a -> TcM a
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyVar)]
scoped_prs (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
TyCon -> [TyConBinder] -> Type -> TcM a
thing_inside TyCon
tycon [TyConBinder]
binders Type
res_kind }
zonkAndScopedSort :: [TcTyVar] -> TcM [TcTyVar]
zonkAndScopedSort :: [TyVar] -> TcM [TyVar]
zonkAndScopedSort [TyVar]
spec_tkvs
= do { [TyVar]
spec_tkvs <- (TyVar -> TcM TyVar) -> [TyVar] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM TyVar -> TcM TyVar
zonkAndSkolemise [TyVar]
spec_tkvs
; [TyVar] -> TcM [TyVar]
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([TyVar] -> [TyVar]
scopedSort [TyVar]
spec_tkvs) }
kindGeneralizeSome :: (TcTyVar -> Bool)
-> TcType
-> TcM [KindVar]
kindGeneralizeSome :: (TyVar -> Bool) -> Type -> TcM [TyVar]
kindGeneralizeSome TyVar -> Bool
should_gen Type
kind_or_type
= do { String -> MsgDoc -> TcM ()
traceTc String
"kindGeneralizeSome {" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
kind_or_type)
; CandidatesQTvs
dvs <- Type -> TcM CandidatesQTvs
candidateQTyVarsOfKind Type
kind_or_type
; let (DTyVarSet
to_promote, CandidatesQTvs
dvs') = CandidatesQTvs -> (TyVar -> Bool) -> (DTyVarSet, CandidatesQTvs)
partitionCandidates CandidatesQTvs
dvs (Bool -> Bool
not (Bool -> Bool) -> (TyVar -> Bool) -> TyVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyVar -> Bool
should_gen)
; (Bool
_, TyCoVarSet
promoted) <- TyCoVarSet -> TcM (Bool, TyCoVarSet)
promoteTyVarSet (DTyVarSet -> TyCoVarSet
dVarSetToVarSet DTyVarSet
to_promote)
; [TyVar]
qkvs <- CandidatesQTvs -> TcM [TyVar]
quantifyTyVars CandidatesQTvs
dvs'
; String -> MsgDoc -> TcM ()
traceTc String
"kindGeneralizeSome }" (MsgDoc -> TcM ()) -> MsgDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[MsgDoc] -> MsgDoc
vcat [ String -> MsgDoc
text String
"Kind or type:" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
kind_or_type
, String -> MsgDoc
text String
"dvs:" MsgDoc -> MsgDoc -> MsgDoc
<+> CandidatesQTvs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable CandidatesQTvs
ppr CandidatesQTvs
dvs
, String -> MsgDoc
text String
"dvs':" MsgDoc -> MsgDoc -> MsgDoc
<+> CandidatesQTvs -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable CandidatesQTvs
ppr CandidatesQTvs
dvs'
, String -> MsgDoc
text String
"to_promote:" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
pprTyVars (DTyVarSet -> [TyVar]
dVarSetElems DTyVarSet
to_promote)
, String -> MsgDoc
text String
"promoted:" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
pprTyVars (TyCoVarSet -> [TyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet TyCoVarSet
promoted)
, String -> MsgDoc
text String
"qkvs:" MsgDoc -> MsgDoc -> MsgDoc
<+> [TyVar] -> MsgDoc
pprTyVars [TyVar]
qkvs ]
; [TyVar] -> TcM [TyVar]
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return [TyVar]
qkvs }
kindGeneralizeAll :: TcType
-> TcM [KindVar]
kindGeneralizeAll :: Type -> TcM [TyVar]
kindGeneralizeAll Type
ty = do { String -> MsgDoc -> TcM ()
traceTc String
"kindGeneralizeAll" MsgDoc
empty
; (TyVar -> Bool) -> Type -> TcM [TyVar]
kindGeneralizeSome (Bool -> TyVar -> Bool
forall a b. a -> b -> a
const Bool
True) Type
ty }
kindGeneralizeNone :: TcType
-> TcM ()
kindGeneralizeNone :: Type -> TcM ()
kindGeneralizeNone Type
ty
= do { String -> MsgDoc -> TcM ()
traceTc String
"kindGeneralizeNone" MsgDoc
empty
; [TyVar]
kvs <- (TyVar -> Bool) -> Type -> TcM [TyVar]
kindGeneralizeSome (Bool -> TyVar -> Bool
forall a b. a -> b -> a
const Bool
False) Type
ty
; MASSERT( null kvs )
}
etaExpandAlgTyCon :: [TyConBinder]
-> Kind
-> TcM ([TyConBinder], Kind)
etaExpandAlgTyCon :: [TyConBinder] -> Type -> TcM ([TyConBinder], Type)
etaExpandAlgTyCon [TyConBinder]
tc_bndrs Type
kind
= do { SrcSpan
loc <- TcRn SrcSpan
getSrcSpanM
; UniqSupply
uniqs <- TcRnIf TcGblEnv TcLclEnv UniqSupply
forall gbl lcl. TcRnIf gbl lcl UniqSupply
newUniqueSupply
; LocalRdrEnv
rdr_env <- RnM LocalRdrEnv
getLocalRdrEnv
; let new_occs :: [OccName]
new_occs = [ OccName
occ
| String
str <- [String]
allNameStrings
, let occ :: OccName
occ = NameSpace -> String -> OccName
mkOccName NameSpace
tvName String
str
, Maybe Name -> Bool
forall a. Maybe a -> Bool
isNothing (LocalRdrEnv -> OccName -> Maybe Name
lookupLocalRdrOcc LocalRdrEnv
rdr_env OccName
occ)
, Bool -> Bool
not (OccName
occ OccName -> [OccName] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
External instance of the constraint type Eq OccName
External instance of the constraint type Foldable []
`elem` [OccName]
lhs_occs) ]
new_uniqs :: [Unique]
new_uniqs = UniqSupply -> [Unique]
uniqsFromSupply UniqSupply
uniqs
subst :: TCvSubst
subst = InScopeSet -> TCvSubst
mkEmptyTCvSubst (TyCoVarSet -> InScopeSet
mkInScopeSet ([TyVar] -> TyCoVarSet
mkVarSet [TyVar]
lhs_tvs))
; ([TyConBinder], Type) -> TcM ([TyConBinder], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (SrcSpan
-> [OccName]
-> [Unique]
-> TCvSubst
-> [TyConBinder]
-> Type
-> ([TyConBinder], Type)
go SrcSpan
loc [OccName]
new_occs [Unique]
new_uniqs TCvSubst
subst [] Type
kind) }
where
lhs_tvs :: [TyVar]
lhs_tvs = (TyConBinder -> TyVar) -> [TyConBinder] -> [TyVar]
forall a b. (a -> b) -> [a] -> [b]
map TyConBinder -> TyVar
forall tv argf. VarBndr tv argf -> tv
binderVar [TyConBinder]
tc_bndrs
lhs_occs :: [OccName]
lhs_occs = (TyVar -> OccName) -> [TyVar] -> [OccName]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> OccName
forall a. NamedThing a => a -> OccName
External instance of the constraint type NamedThing TyVar
getOccName [TyVar]
lhs_tvs
go :: SrcSpan
-> [OccName]
-> [Unique]
-> TCvSubst
-> [TyConBinder]
-> Type
-> ([TyConBinder], Type)
go SrcSpan
loc [OccName]
occs [Unique]
uniqs TCvSubst
subst [TyConBinder]
acc Type
kind
= case Type -> Maybe (TyCoBinder, Type)
splitPiTy_maybe Type
kind of
Maybe (TyCoBinder, Type)
Nothing -> ([TyConBinder] -> [TyConBinder]
forall a. [a] -> [a]
reverse [TyConBinder]
acc, HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst Type
kind)
Just (Anon AnonArgFlag
af Type
arg, Type
kind')
-> SrcSpan
-> [OccName]
-> [Unique]
-> TCvSubst
-> [TyConBinder]
-> Type
-> ([TyConBinder], Type)
go SrcSpan
loc [OccName]
occs' [Unique]
uniqs' TCvSubst
subst' (TyConBinder
tcb TyConBinder -> [TyConBinder] -> [TyConBinder]
forall a. a -> [a] -> [a]
: [TyConBinder]
acc) Type
kind'
where
arg' :: Type
arg' = HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst Type
arg
tv :: TyVar
tv = Name -> Type -> TyVar
mkTyVar (Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
uniq OccName
occ SrcSpan
loc) Type
arg'
subst' :: TCvSubst
subst' = TCvSubst -> TyVar -> TCvSubst
extendTCvInScope TCvSubst
subst TyVar
tv
tcb :: TyConBinder
tcb = TyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv (AnonArgFlag -> TyConBndrVis
AnonTCB AnonArgFlag
af)
(Unique
uniq:[Unique]
uniqs') = [Unique]
uniqs
(OccName
occ:[OccName]
occs') = [OccName]
occs
Just (Named (Bndr TyVar
tv ArgFlag
vis), Type
kind')
-> SrcSpan
-> [OccName]
-> [Unique]
-> TCvSubst
-> [TyConBinder]
-> Type
-> ([TyConBinder], Type)
go SrcSpan
loc [OccName]
occs [Unique]
uniqs TCvSubst
subst' (TyConBinder
tcb TyConBinder -> [TyConBinder] -> [TyConBinder]
forall a. a -> [a] -> [a]
: [TyConBinder]
acc) Type
kind'
where
(TCvSubst
subst', TyVar
tv') = HasCallStack => TCvSubst -> TyVar -> (TCvSubst, TyVar)
TCvSubst -> TyVar -> (TCvSubst, TyVar)
substTyVarBndr TCvSubst
subst TyVar
tv
tcb :: TyConBinder
tcb = TyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv' (ArgFlag -> TyConBndrVis
NamedTCB ArgFlag
vis)
data DataSort
= DataDeclSort NewOrData
| DataInstanceSort NewOrData
| DataFamilySort
checkDataKindSig :: DataSort -> Kind -> TcM ()
checkDataKindSig :: DataSort -> Type -> TcM ()
checkDataKindSig DataSort
data_sort Type
kind = do
DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
External instance of the constraint type forall env. ContainsDynFlags env => HasDynFlags (IOEnv env)
External instance of the constraint type forall gbl lcl. ContainsDynFlags (Env gbl lcl)
getDynFlags
Bool -> MsgDoc -> TcM ()
checkTc (DynFlags -> Bool
is_TYPE_or_Type DynFlags
dflags Bool -> Bool -> Bool
|| Bool
is_kind_var) (DynFlags -> MsgDoc
err_msg DynFlags
dflags)
where
pp_dec :: SDoc
pp_dec :: MsgDoc
pp_dec = String -> MsgDoc
text (String -> MsgDoc) -> String -> MsgDoc
forall a b. (a -> b) -> a -> b
$
case DataSort
data_sort of
DataDeclSort NewOrData
DataType -> String
"Data type"
DataDeclSort NewOrData
NewType -> String
"Newtype"
DataInstanceSort NewOrData
DataType -> String
"Data instance"
DataInstanceSort NewOrData
NewType -> String
"Newtype instance"
DataSort
DataFamilySort -> String
"Data family"
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
External instance of the constraint type Eq NewOrData
== NewOrData
NewType
DataInstanceSort NewOrData
new_or_data -> NewOrData
new_or_data NewOrData -> NewOrData -> Bool
forall a. Eq a => a -> a -> Bool
External instance of the constraint type Eq NewOrData
== NewOrData
NewType
DataSort
DataFamilySort -> 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
tYPE_ok :: DynFlags -> Bool
tYPE_ok :: DynFlags -> Bool
tYPE_ok DynFlags
dflags =
(Bool
is_newtype Bool -> Bool -> Bool
&& Extension -> DynFlags -> Bool
xopt Extension
LangExt.UnliftedNewtypes DynFlags
dflags)
Bool -> Bool -> Bool
|| Bool
is_data_family
is_TYPE :: Bool
is_TYPE :: Bool
is_TYPE = Type -> Bool
tcIsRuntimeTypeKind Type
kind
is_TYPE_or_Type :: DynFlags -> Bool
is_TYPE_or_Type :: DynFlags -> Bool
is_TYPE_or_Type DynFlags
dflags | DynFlags -> Bool
tYPE_ok DynFlags
dflags = Bool
is_TYPE
| Bool
otherwise = Type -> Bool
tcIsLiftedTypeKind Type
kind
is_kind_var :: Bool
is_kind_var :: Bool
is_kind_var | Bool
is_data_family = Maybe (TyVar, Coercion) -> Bool
forall a. Maybe a -> Bool
isJust (Type -> Maybe (TyVar, Coercion)
tcGetCastedTyVar_maybe Type
kind)
| Bool
otherwise = Bool
False
err_msg :: DynFlags -> SDoc
err_msg :: DynFlags -> MsgDoc
err_msg DynFlags
dflags =
[MsgDoc] -> MsgDoc
sep [ ([MsgDoc] -> MsgDoc
sep [ MsgDoc
pp_dec MsgDoc -> MsgDoc -> MsgDoc
<+>
String -> MsgDoc
text String
"has non-" MsgDoc -> MsgDoc -> MsgDoc
<>
(if DynFlags -> Bool
tYPE_ok DynFlags
dflags then String -> MsgDoc
text String
"TYPE" else Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
liftedTypeKind)
, (if Bool
is_data_family then String -> MsgDoc
text String
"and non-variable" else MsgDoc
empty) MsgDoc -> MsgDoc -> MsgDoc
<+>
String -> MsgDoc
text String
"return kind" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
kind) ])
, if Bool -> Bool
not (DynFlags -> Bool
tYPE_ok DynFlags
dflags) Bool -> Bool -> Bool
&& Bool
is_TYPE Bool -> Bool -> Bool
&& Bool
is_newtype Bool -> Bool -> Bool
&&
Bool -> Bool
not (Extension -> DynFlags -> Bool
xopt Extension
LangExt.UnliftedNewtypes DynFlags
dflags)
then String -> MsgDoc
text String
"Perhaps you intended to use UnliftedNewtypes"
else MsgDoc
empty ]
checkClassKindSig :: Kind -> TcM ()
checkClassKindSig :: Type -> TcM ()
checkClassKindSig Type
kind = Bool -> MsgDoc -> TcM ()
checkTc (Type -> Bool
tcIsConstraintKind Type
kind) MsgDoc
err_msg
where
err_msg :: SDoc
err_msg :: MsgDoc
err_msg =
String -> MsgDoc
text String
"Kind signature on a class must end with" MsgDoc -> MsgDoc -> MsgDoc
<+> Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
constraintKind MsgDoc -> MsgDoc -> MsgDoc
$$
String -> MsgDoc
text String
"unobscured by type families"
tcbVisibilities :: TyCon -> [Type] -> [TyConBndrVis]
tcbVisibilities :: TyCon -> [Type] -> [TyConBndrVis]
tcbVisibilities TyCon
tc [Type]
orig_args
= Type -> TCvSubst -> [Type] -> [TyConBndrVis]
go (TyCon -> Type
tyConKind TyCon
tc) TCvSubst
init_subst [Type]
orig_args
where
init_subst :: TCvSubst
init_subst = InScopeSet -> TCvSubst
mkEmptyTCvSubst (TyCoVarSet -> InScopeSet
mkInScopeSet ([Type] -> TyCoVarSet
tyCoVarsOfTypes [Type]
orig_args))
go :: Type -> TCvSubst -> [Type] -> [TyConBndrVis]
go Type
_ TCvSubst
_ []
= []
go Type
fun_kind TCvSubst
subst all_args :: [Type]
all_args@(Type
arg : [Type]
args)
| Just (TyCoBinder
tcb, Type
inner_kind) <- Type -> Maybe (TyCoBinder, Type)
splitPiTy_maybe Type
fun_kind
= case TyCoBinder
tcb of
Anon AnonArgFlag
af Type
_ -> AnonArgFlag -> TyConBndrVis
AnonTCB AnonArgFlag
af TyConBndrVis -> [TyConBndrVis] -> [TyConBndrVis]
forall a. a -> [a] -> [a]
: Type -> TCvSubst -> [Type] -> [TyConBndrVis]
go Type
inner_kind TCvSubst
subst [Type]
args
Named (Bndr TyVar
tv ArgFlag
vis) -> ArgFlag -> TyConBndrVis
NamedTCB ArgFlag
vis TyConBndrVis -> [TyConBndrVis] -> [TyConBndrVis]
forall a. a -> [a] -> [a]
: Type -> TCvSubst -> [Type] -> [TyConBndrVis]
go Type
inner_kind TCvSubst
subst' [Type]
args
where
subst' :: TCvSubst
subst' = TCvSubst -> TyVar -> Type -> TCvSubst
extendTCvSubst TCvSubst
subst TyVar
tv Type
arg
| Bool -> Bool
not (TCvSubst -> Bool
isEmptyTCvSubst TCvSubst
subst)
= Type -> TCvSubst -> [Type] -> [TyConBndrVis]
go (HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
subst Type
fun_kind) TCvSubst
init_subst [Type]
all_args
| Bool
otherwise
= String -> MsgDoc -> [TyConBndrVis]
forall a. HasCallStack => String -> MsgDoc -> a
pprPanic String
"addTcbVisibilities" (TyCon -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TyCon
ppr TyCon
tc MsgDoc -> MsgDoc -> MsgDoc
<+> [Type] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type Outputable Type
ppr [Type]
orig_args)
tcHsPartialSigType
:: UserTypeCtxt
-> LHsSigWcType GhcRn
-> TcM ( [(Name, TcTyVar)]
, Maybe TcType
, [(Name,InvisTVBinder)]
, TcThetaType
, TcType )
tcHsPartialSigType :: UserTypeCtxt
-> LHsSigWcType GhcRn
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar 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
ib_ty } <- LHsSigWcType GhcRn
sig_ty
, HsIB { hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -> XHsIB pass thing
hsib_ext = XHsIB GhcRn (LHsKind GhcRn)
implicit_hs_tvs
, hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = LHsKind GhcRn
hs_ty } <- LHsSigType GhcRn
ib_ty
, ([LHsTyVarBndr Specificity GhcRn]
explicit_hs_tvs, L SrcSpan
_ [LHsKind GhcRn]
hs_ctxt, LHsKind GhcRn
hs_tau) <- LHsKind GhcRn
-> ([LHsTyVarBndr Specificity GhcRn], LHsContext GhcRn,
LHsKind GhcRn)
forall pass.
LHsType pass
-> ([LHsTyVarBndr Specificity pass], LHsContext pass, LHsType pass)
splitLHsSigmaTyInvis LHsKind GhcRn
hs_ty
= UserTypeCtxt
-> LHsKind GhcRn
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
forall a. UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsKind GhcRn
hs_ty (TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type))
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
forall a b. (a -> b) -> a -> b
$
do { ([TyVar]
implicit_tvs, ([VarBndr TyVar Specificity]
explicit_tvbndrs, ([(Name, TyVar)]
wcs, Maybe Type
wcx, [Type]
theta, Type
tau)))
<- String
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
forall a. String -> TcM a -> TcM a
solveLocalEqualities String
"tcHsPartialSigType" (TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
forall a b. (a -> b) -> a -> b
$
HsQTvsRn
-> ([(Name, TyVar)]
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
forall a. HsQTvsRn -> ([(Name, TyVar)] -> TcM a) -> TcM a
tcNamedWildCardBinders HsQTvsRn
XHsWC GhcRn (LHsSigType GhcRn)
sig_wcs (([(Name, TyVar)]
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))))
-> ([(Name, TyVar)]
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
forall a b. (a -> b) -> a -> b
$ \ [(Name, TyVar)]
wcs ->
HsQTvsRn
-> TcM
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
forall a. HsQTvsRn -> TcM a -> TcM ([TyVar], a)
bindImplicitTKBndrs_Tv HsQTvsRn
XHsIB GhcRn (LHsKind GhcRn)
implicit_hs_tvs (TcM
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))))
-> TcM
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))
-> TcM
([TyVar],
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
forall a b. (a -> b) -> a -> b
$
[LHsTyVarBndr Specificity GhcRn]
-> TcM ([(Name, TyVar)], Maybe Type, [Type], Type)
-> TcM
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))
forall flag a.
OutputableBndrFlag flag =>
[LHsTyVarBndr flag GhcRn] -> TcM a -> TcM ([VarBndr TyVar flag], a)
External instance of the constraint type OutputableBndrFlag Specificity
bindExplicitTKBndrs_Tv [LHsTyVarBndr Specificity GhcRn]
explicit_hs_tvs (TcM ([(Name, TyVar)], Maybe Type, [Type], Type)
-> TcM
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type)))
-> TcM ([(Name, TyVar)], Maybe Type, [Type], Type)
-> TcM
([VarBndr TyVar Specificity],
([(Name, TyVar)], Maybe Type, [Type], Type))
forall a b. (a -> b) -> a -> b
$
do {
([Type]
theta, Maybe Type
wcx) <- [LHsKind GhcRn] -> TcM ([Type], Maybe Type)
tcPartialContext [LHsKind GhcRn]
hs_ctxt
; Type
tau <- LHsKind GhcRn -> TcM Type
tcHsOpenType LHsKind GhcRn
hs_tau
; ([(Name, TyVar)], Maybe Type, [Type], Type)
-> TcM ([(Name, TyVar)], Maybe Type, [Type], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([(Name, TyVar)]
wcs, Maybe Type
wcx, [Type]
theta, Type
tau) }
; let implicit_tvbndrs :: [VarBndr TyVar Specificity]
implicit_tvbndrs = (TyVar -> VarBndr TyVar Specificity)
-> [TyVar] -> [VarBndr TyVar Specificity]
forall a b. (a -> b) -> [a] -> [b]
map (Specificity -> TyVar -> VarBndr TyVar Specificity
forall vis. vis -> TyVar -> VarBndr TyVar vis
mkTyVarBinder Specificity
SpecifiedSpec) [TyVar]
implicit_tvs
; Type -> TcM ()
kindGeneralizeNone ([VarBndr TyVar Specificity] -> Type -> Type
mkInvisForAllTys [VarBndr TyVar Specificity]
implicit_tvbndrs (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[VarBndr TyVar Specificity] -> Type -> Type
mkInvisForAllTys [VarBndr TyVar Specificity]
explicit_tvbndrs (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[Type] -> Type -> Type
mkPhiTy [Type]
theta (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type
tau)
; ((Name, TyVar) -> TcM ()) -> [(Name, TyVar)] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Foldable []
mapM_ (Name, TyVar) -> TcM ()
emitNamedTypeHole [(Name, TyVar)]
wcs
; [Type]
theta <- (Type -> TcM Type) -> [Type] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM Type -> TcM Type
zonkTcType [Type]
theta
; Type
tau <- Type -> TcM Type
zonkTcType Type
tau
; let tv_prs :: [(Name, VarBndr TyVar Specificity)]
tv_prs = (HsQTvsRn
XHsIB GhcRn (LHsKind GhcRn)
implicit_hs_tvs HsQTvsRn
-> [VarBndr TyVar Specificity]
-> [(Name, VarBndr TyVar Specificity)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [VarBndr TyVar Specificity]
implicit_tvbndrs)
[(Name, VarBndr TyVar Specificity)]
-> [(Name, VarBndr TyVar Specificity)]
-> [(Name, VarBndr TyVar Specificity)]
forall a. [a] -> [a] -> [a]
++ ([LHsTyVarBndr Specificity GhcRn] -> [IdP GhcRn]
forall flag (p :: Pass).
[LHsTyVarBndr flag (GhcPass p)] -> [IdP (GhcPass p)]
hsLTyVarNames [LHsTyVarBndr Specificity GhcRn]
explicit_hs_tvs HsQTvsRn
-> [VarBndr TyVar Specificity]
-> [(Name, VarBndr TyVar Specificity)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [VarBndr TyVar Specificity]
explicit_tvbndrs)
; String -> MsgDoc -> TcM ()
traceTc String
"tcHsPartialSigType" ([(Name, VarBndr TyVar Specificity)] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall a b. (Outputable a, Outputable b) => Outputable (a, b)
External instance of the constraint type Outputable Name
External instance of the constraint type forall tv. Outputable tv => Outputable (VarBndr tv Specificity)
External instance of the constraint type Outputable TyVar
ppr [(Name, VarBndr TyVar Specificity)]
tv_prs)
; ([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
-> TcM
([(Name, TyVar)], Maybe Type, [(Name, VarBndr TyVar Specificity)],
[Type], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([(Name, TyVar)]
wcs, Maybe Type
wcx, [(Name, VarBndr TyVar Specificity)]
tv_prs, [Type]
theta, Type
tau) }
tcPartialContext :: HsContext GhcRn -> TcM (TcThetaType, Maybe TcType)
tcPartialContext :: [LHsKind GhcRn] -> TcM ([Type], Maybe Type)
tcPartialContext [LHsKind GhcRn]
hs_theta
| Just ([LHsKind GhcRn]
hs_theta1, LHsKind GhcRn
hs_ctxt_last) <- [LHsKind GhcRn] -> Maybe ([LHsKind GhcRn], LHsKind GhcRn)
forall a. [a] -> Maybe ([a], a)
snocView [LHsKind GhcRn]
hs_theta
, L SrcSpan
wc_loc wc :: HsType GhcRn
wc@(HsWildCardTy XWildCardTy GhcRn
_) <- LHsKind GhcRn -> LHsKind GhcRn
forall pass. LHsType pass -> LHsType pass
ignoreParens LHsKind GhcRn
hs_ctxt_last
= do { Type
wc_tv_ty <- SrcSpan -> TcM Type -> TcM Type
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
wc_loc (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
HsType GhcRn -> Type -> TcM Type
tcAnonWildCardOcc HsType GhcRn
wc Type
constraintKind
; [Type]
theta <- (LHsKind GhcRn -> TcM Type) -> [LHsKind GhcRn] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM LHsKind GhcRn -> TcM Type
tcLHsPredType [LHsKind GhcRn]
hs_theta1
; ([Type], Maybe Type) -> TcM ([Type], Maybe Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([Type]
theta, Type -> Maybe Type
forall a. a -> Maybe a
Just Type
wc_tv_ty) }
| Bool
otherwise
= do { [Type]
theta <- (LHsKind GhcRn -> TcM Type) -> [LHsKind GhcRn] -> TcM [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM LHsKind GhcRn -> TcM Type
tcLHsPredType [LHsKind GhcRn]
hs_theta
; ([Type], Maybe Type) -> TcM ([Type], Maybe Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([Type]
theta, Maybe Type
forall a. Maybe a
Nothing) }
tcHsPatSigType :: UserTypeCtxt
-> HsPatSigType GhcRn
-> TcM ( [(Name, TcTyVar)]
, [(Name, TcTyVar)]
, TcType)
tcHsPatSigType :: UserTypeCtxt
-> HsPatSigType GhcRn
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
tcHsPatSigType UserTypeCtxt
ctxt
(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 = LHsKind GhcRn
hs_ty })
= UserTypeCtxt
-> LHsKind GhcRn
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
forall a. UserTypeCtxt -> LHsKind GhcRn -> TcM a -> TcM a
addSigCtxt UserTypeCtxt
ctxt LHsKind GhcRn
hs_ty (TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type))
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
forall a b. (a -> b) -> a -> b
$
do { [(Name, TyVar)]
sig_tkv_prs <- (Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TyVar))
-> HsQTvsRn -> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TyVar)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Traversable []
mapM Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TyVar)
new_implicit_tv HsQTvsRn
sig_ns
; ([(Name, TyVar)]
wcs, Type
sig_ty)
<- String
-> TcM ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type)
forall a. String -> TcM a -> TcM a
solveLocalEqualities String
"tcHsPatSigType" (TcM ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type))
-> TcM ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type)
forall a b. (a -> b) -> a -> b
$
HsQTvsRn
-> ([(Name, TyVar)] -> TcM ([(Name, TyVar)], Type))
-> TcM ([(Name, TyVar)], Type)
forall a. HsQTvsRn -> ([(Name, TyVar)] -> TcM a) -> TcM a
tcNamedWildCardBinders HsQTvsRn
sig_wcs (([(Name, TyVar)] -> TcM ([(Name, TyVar)], Type))
-> TcM ([(Name, TyVar)], Type))
-> ([(Name, TyVar)] -> TcM ([(Name, TyVar)], Type))
-> TcM ([(Name, TyVar)], Type)
forall a b. (a -> b) -> a -> b
$ \ [(Name, TyVar)]
wcs ->
[(Name, TyVar)]
-> TcM ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type)
forall r. [(Name, TyVar)] -> TcM r -> TcM r
tcExtendNameTyVarEnv [(Name, TyVar)]
sig_tkv_prs (TcM ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type))
-> TcM ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type)
forall a b. (a -> b) -> a -> b
$
do { Type
sig_ty <- LHsKind GhcRn -> TcM Type
tcHsOpenType LHsKind GhcRn
hs_ty
; ([(Name, TyVar)], Type) -> TcM ([(Name, TyVar)], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([(Name, TyVar)]
wcs, Type
sig_ty) }
; ((Name, TyVar) -> TcM ()) -> [(Name, TyVar)] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
External instance of the constraint type forall m. Monad (IOEnv m)
External instance of the constraint type Foldable []
mapM_ (Name, TyVar) -> TcM ()
emitNamedTypeHole [(Name, TyVar)]
wcs
; Type -> TcM ()
kindGeneralizeNone Type
sig_ty
; Type
sig_ty <- Type -> TcM Type
zonkTcType Type
sig_ty
; UserTypeCtxt -> Type -> TcM ()
checkValidType UserTypeCtxt
ctxt Type
sig_ty
; String -> MsgDoc -> TcM ()
traceTc String
"tcHsPatSigType" ([(Name, TyVar)] -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall a. Outputable a => Outputable [a]
External instance of the constraint type forall a b. (Outputable a, Outputable b) => Outputable (a, b)
External instance of the constraint type Outputable Name
External instance of the constraint type Outputable TyVar
ppr [(Name, TyVar)]
sig_tkv_prs)
; ([(Name, TyVar)], [(Name, TyVar)], Type)
-> TcM ([(Name, TyVar)], [(Name, TyVar)], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([(Name, TyVar)]
wcs, [(Name, TyVar)]
sig_tkv_prs, Type
sig_ty) }
where
new_implicit_tv :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TyVar)
new_implicit_tv Name
name
= do { Type
kind <- TcM Type
newMetaKindVar
; TyVar
tv <- case UserTypeCtxt
ctxt of
RuleSigCtxt {} -> Name -> Type -> TcM TyVar
newSkolemTyVar Name
name Type
kind
UserTypeCtxt
_ -> Name -> Type -> TcM TyVar
newPatSigTyVar Name
name Type
kind
; (Name, TyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return (Name
name, TyVar
tv) }
unifyKinds :: [LHsType GhcRn] -> [(TcType, TcKind)] -> TcM ([TcType], TcKind)
unifyKinds :: [LHsKind GhcRn] -> [(Type, Type)] -> TcM ([Type], Type)
unifyKinds [LHsKind GhcRn]
rn_tys [(Type, Type)]
act_kinds
= do { Type
kind <- TcM Type
newMetaKindVar
; let check :: LHsKind GhcRn -> (Type, Type) -> TcM Type
check LHsKind GhcRn
rn_ty (Type
ty, Type
act_kind)
= HasDebugCallStack =>
HsType GhcRn -> Type -> Type -> Type -> TcM Type
HsType GhcRn -> Type -> Type -> Type -> TcM Type
External instance of the constraint type HasDebugCallStack
checkExpectedKind (LHsKind GhcRn -> HsType GhcRn
forall l e. GenLocated l e -> e
unLoc LHsKind GhcRn
rn_ty) Type
ty Type
act_kind Type
kind
; [Type]
tys' <- (LHsKind GhcRn -> (Type, Type) -> TcM Type)
-> [LHsKind GhcRn] -> [(Type, Type)] -> TcM [Type]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
External instance of the constraint type forall m. Applicative (IOEnv m)
zipWithM LHsKind GhcRn -> (Type, Type) -> TcM Type
check [LHsKind GhcRn]
rn_tys [(Type, Type)]
act_kinds
; ([Type], Type) -> TcM ([Type], Type)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return ([Type]
tys', Type
kind) }
tcLHsKindSig :: UserTypeCtxt -> LHsKind GhcRn -> TcM Kind
tcLHsKindSig :: UserTypeCtxt -> LHsKind GhcRn -> TcM Type
tcLHsKindSig UserTypeCtxt
ctxt LHsKind GhcRn
hs_kind
= do { Type
kind <- String -> TcM Type -> TcM Type
forall a. String -> TcM a -> TcM a
solveLocalEqualities String
"tcLHsKindSig" (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> TcM Type
tc_lhs_kind TcTyMode
kindLevelMode LHsKind GhcRn
hs_kind
; String -> MsgDoc -> TcM ()
traceTc String
"tcLHsKindSig" (LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
hs_kind MsgDoc -> MsgDoc -> MsgDoc
$$ Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
kind)
; Type -> TcM ()
kindGeneralizeNone Type
kind
; Type
kind <- Type -> TcM Type
zonkTcType Type
kind
; UserTypeCtxt -> Type -> TcM ()
checkValidType UserTypeCtxt
ctxt Type
kind
; String -> MsgDoc -> TcM ()
traceTc String
"tcLHsKindSig2" (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
kind)
; Type -> TcM Type
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return Type
kind }
tc_lhs_kind :: TcTyMode -> LHsKind GhcRn -> TcM Kind
tc_lhs_kind :: TcTyMode -> LHsKind GhcRn -> TcM Type
tc_lhs_kind TcTyMode
mode LHsKind GhcRn
k
= MsgDoc -> TcM Type -> TcM Type
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (String -> MsgDoc
text String
"In the kind" MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (LHsKind GhcRn -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type forall l e.
(Outputable l, Outputable e) =>
Outputable (GenLocated l e)
External instance of the constraint type Outputable SrcSpan
External instance of the constraint type forall (p :: Pass).
OutputableBndrId p =>
Outputable (HsType (GhcPass p))
External instance of the constraint type OutputableBndr Name
External instance of the constraint type OutputableBndr Name
External instance of the constraint type IsPass 'Renamed
ppr LHsKind GhcRn
k)) (TcM Type -> TcM Type) -> TcM Type -> TcM Type
forall a b. (a -> b) -> a -> b
$
TcTyMode -> LHsKind GhcRn -> Type -> TcM Type
tc_lhs_type (TcTyMode -> TcTyMode
kindLevel TcTyMode
mode) LHsKind GhcRn
k Type
liftedTypeKind
promotionErr :: Name -> PromotionErr -> TcM a
promotionErr :: Name -> PromotionErr -> TcM a
promotionErr Name
name PromotionErr
err
= MsgDoc -> TcM a
forall a. MsgDoc -> TcM a
failWithTc (MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang (PromotionErr -> MsgDoc
pprPECategory PromotionErr
err MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr Name
name) MsgDoc -> MsgDoc -> MsgDoc
<+> String -> MsgDoc
text String
"cannot be used here")
Arity
2 (MsgDoc -> MsgDoc
parens MsgDoc
reason))
where
reason :: MsgDoc
reason = case PromotionErr
err of
ConstrainedDataConPE Type
pred
-> String -> MsgDoc
text String
"it has an unpromotable context"
MsgDoc -> MsgDoc -> MsgDoc
<+> MsgDoc -> MsgDoc
quotes (Type -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Type
ppr Type
pred)
PromotionErr
FamDataConPE -> String -> MsgDoc
text String
"it comes from a data family instance"
PromotionErr
NoDataKindsTC -> String -> MsgDoc
text String
"perhaps you intended to use DataKinds"
PromotionErr
NoDataKindsDC -> String -> MsgDoc
text String
"perhaps you intended to use DataKinds"
PromotionErr
PatSynPE -> String -> MsgDoc
text String
"pattern synonyms cannot be promoted"
PromotionErr
_ -> String -> MsgDoc
text String
"it is defined and used in the same recursive group"
failIfEmitsConstraints :: TcM a -> TcM a
failIfEmitsConstraints :: TcM a -> TcM a
failIfEmitsConstraints TcM a
thing_inside
= TcM a -> TcM a
forall a. TcM a -> TcM a
checkNoErrs (TcM a -> TcM a) -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$
do { (a
res, WantedConstraints
lie) <- TcM a -> TcM (a, WantedConstraints)
forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints TcM a
thing_inside
; WantedConstraints -> TcM ()
reportAllUnsolved WantedConstraints
lie
; a -> TcM a
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type forall m. Monad (IOEnv m)
return a
res
}
funAppCtxt :: (Outputable fun, Outputable arg) => fun -> arg -> Int -> SDoc
funAppCtxt :: fun -> arg -> Arity -> MsgDoc
funAppCtxt fun
fun arg
arg Arity
arg_no
= MsgDoc -> Arity -> MsgDoc -> MsgDoc
hang ([MsgDoc] -> MsgDoc
hsep [ String -> MsgDoc
text String
"In the", Arity -> MsgDoc
speakNth Arity
arg_no, PtrString -> MsgDoc
ptext (String -> PtrString
sLit String
"argument of"),
MsgDoc -> MsgDoc
quotes (fun -> MsgDoc
forall a. Outputable a => a -> MsgDoc
Evidence bound by a type signature of the constraint type Outputable fun
ppr fun
fun) MsgDoc -> MsgDoc -> MsgDoc
<> String -> MsgDoc
text String
", namely"])
Arity
2 (MsgDoc -> MsgDoc
quotes (arg -> MsgDoc
forall a. Outputable a => a -> MsgDoc
Evidence bound by a type signature of the constraint type Outputable arg
ppr arg
arg))
addTyConFlavCtxt :: Name -> TyConFlavour -> TcM a -> TcM a
addTyConFlavCtxt :: Name -> TyConFlavour -> TcM a -> TcM a
addTyConFlavCtxt Name
name TyConFlavour
flav
= MsgDoc -> TcM a -> TcM a
forall a. MsgDoc -> TcM a -> TcM a
addErrCtxt (MsgDoc -> TcM a -> TcM a) -> MsgDoc -> TcM a -> TcM a
forall a b. (a -> b) -> a -> b
$ [MsgDoc] -> MsgDoc
hsep [ String -> MsgDoc
text String
"In the", TyConFlavour -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable TyConFlavour
ppr TyConFlavour
flav
, String -> MsgDoc
text String
"declaration for", MsgDoc -> MsgDoc
quotes (Name -> MsgDoc
forall a. Outputable a => a -> MsgDoc
External instance of the constraint type Outputable Name
ppr Name
name) ]