Commit d61adb3d authored by Ryan Scott's avatar Ryan Scott Committed by Marge Bot

Name (tc)SplitForAll- functions more consistently

There is a zoo of `splitForAll-` functions in `GHC.Core.Type` (as well as
`tcSplitForAll-` functions in `GHC.Tc.Utils.TcType`) that all do very similar
things, but vary in the particular form of type variable that they return. To
make things worse, the names of these functions are often quite misleading.
Some particularly egregious examples:

* `splitForAllTys` returns `TyCoVar`s, but `splitSomeForAllTys` returns
  `VarBndr`s.
* `splitSomeForAllTys` returns `VarBndr`s, but `tcSplitSomeForAllTys` returns
  `TyVar`s.
* `splitForAllTys` returns `TyCoVar`s, but `splitForAllTysInvis` returns
  `InvisTVBinder`s. (This in particular arose in the context of #18939, and
  this finally motivated me to bite the bullet and improve the status quo
  vis-à-vis how we name these functions.)

In an attempt to bring some sanity to how these functions are named, I have
opted to rename most of these functions en masse to use consistent suffixes
that describe the particular form of type variable that each function returns.
In concrete terms, this amounts to:

* Functions that return a `TyVar` now use the suffix `-TyVar`.
  This caused the following functions to be renamed:
  * `splitTyVarForAllTys` -> `splitForAllTyVars`
  * `splitForAllTy_ty_maybe` -> `splitForAllTyVar_maybe`
  * `tcSplitForAllTys` -> `tcSplitForAllTyVars`
  * `tcSplitSomeForAllTys` -> `tcSplitSomeForAllTyVars`
* Functions that return a `CoVar` now use the suffix `-CoVar`.
  This caused the following functions to be renamed:
  * `splitForAllTy_co_maybe` -> `splitForAllCoVar_maybe`
* Functions that return a `TyCoVar` now use the suffix `-TyCoVar`.
  This caused the following functions to be renamed:
  * `splitForAllTy` -> `splitForAllTyCoVar`
  * `splitForAllTys` -> `splitForAllTyCoVars`
  * `splitForAllTys'` -> `splitForAllTyCoVars'`
  * `splitForAllTy_maybe` -> `splitForAllTyCoVar_maybe`
* Functions that return a `VarBndr` now use the suffix corresponding to the
  most relevant type synonym. This caused the following functions to be renamed:
  * `splitForAllVarBndrs` -> `splitForAllTyCoVarBinders`
  * `splitForAllTysInvis` -> `splitForAllInvisTVBinders`
  * `splitForAllTysReq` -> `splitForAllReqTVBinders`
  * `splitSomeForAllTys` -> `splitSomeForAllTyCoVarBndrs`
  * `tcSplitForAllVarBndrs` -> `tcSplitForAllTyVarBinders`
  * `tcSplitForAllTysInvis` -> `tcSplitForAllInvisTVBinders`
  * `tcSplitForAllTysReq` -> `tcSplitForAllReqTVBinders`
  * `tcSplitForAllTy_maybe` -> `tcSplitForAllTyVarBinder_maybe`

Note that I left the following functions alone:

* Functions that split apart things besides `ForAllTy`s, such as `splitFunTys`
  or `splitPiTys`. Thankfully, there are far fewer of these functions than
  there are functions that split apart `ForAllTy`s, so there isn't much of a
  pressing need to apply the new naming convention elsewhere.
* Functions that split apart `ForAllCo`s in `Coercion`s, such as
  `GHC.Core.Coercion.splitForAllCo_maybe`. We could theoretically apply the new
  naming convention here, but then we'd have to figure out how to disambiguate
  `Type`-splitting functions from `Coercion`-splitting functions. Ultimately,
  the `Coercion`-splitting functions aren't used nearly as much as the
  `Type`-splitting functions, so I decided to leave the former alone.

This is purely refactoring and should cause no change in behavior.
parent a2539650
......@@ -215,7 +215,7 @@ module GHC (
FamInst,
-- ** Types and Kinds
Type, splitForAllTys, funResultTy,
Type, splitForAllTyCoVars, funResultTy,
pprParendType, pprTypeApp,
Kind,
PredType,
......
......@@ -427,8 +427,8 @@ decomposePiCos orig_co (Pair orig_k1 orig_k2) orig_args
-- Invariant: co :: subst1(k2) ~ subst2(k2)
go acc_arg_cos (subst1,k1) co (subst2,k2) (ty:tys)
| Just (a, t1) <- splitForAllTy_maybe k1
, Just (b, t2) <- splitForAllTy_maybe k2
| Just (a, t1) <- splitForAllTyCoVar_maybe k1
, Just (b, t2) <- splitForAllTyCoVar_maybe k2
-- know co :: (forall a:s1.t1) ~ (forall b:s2.t2)
-- function :: forall a:s1.t1 (the function is not passed to decomposePiCos)
-- a :: s1
......@@ -1029,7 +1029,7 @@ mkNthCo r n co
go r 0 co
| Just (ty, _) <- isReflCo_maybe co
, Just (tv, _) <- splitForAllTy_maybe ty
, Just (tv, _) <- splitForAllTyCoVar_maybe ty
= -- works for both tyvar and covar
ASSERT( r == Nominal )
mkNomReflCo (varType tv)
......@@ -1080,8 +1080,8 @@ mkNthCo r n co
good_call
-- If the Coercion passed in is between forall-types, then the Int must
-- be 0 and the role must be Nominal.
| Just (_tv1, _) <- splitForAllTy_maybe ty1
, Just (_tv2, _) <- splitForAllTy_maybe ty2
| Just (_tv1, _) <- splitForAllTyCoVar_maybe ty1
, Just (_tv2, _) <- splitForAllTyCoVar_maybe ty2
= n == 0 && r == Nominal
-- If the Coercion passed in is between T tys and T tys', then the Int
......@@ -1140,7 +1140,7 @@ nthCoRole n co
| Just (tc, _) <- splitTyConApp_maybe lty
= nthRole r tc n
| Just _ <- splitForAllTy_maybe lty
| Just _ <- splitForAllTyCoVar_maybe lty
= Nominal
| otherwise
......@@ -2330,7 +2330,7 @@ go_nth d ty
args `getNth` d
| d == 0
, Just (tv,_) <- splitForAllTy_maybe ty
, Just (tv,_) <- splitForAllTyCoVar_maybe ty
= tyVarKind tv
| otherwise
......
......@@ -335,7 +335,7 @@ opt_co4 env _sym rep r (NthCo _r n co)
| Just (ty, _) <- isReflCo_maybe co
, n == 0
, Just (tv, _) <- splitForAllTy_maybe ty
, Just (tv, _) <- splitForAllTyCoVar_maybe ty
-- works for both tyvar and covar
= liftCoSubst (chooseRole rep r) env (varType tv)
......@@ -531,8 +531,8 @@ opt_univ env sym prov role oty1 oty2
-- can't optimize the AppTy case because we can't build the kind coercions.
| Just (tv1, ty1) <- splitForAllTy_ty_maybe oty1
, Just (tv2, ty2) <- splitForAllTy_ty_maybe oty2
| Just (tv1, ty1) <- splitForAllTyVar_maybe oty1
, Just (tv2, ty2) <- splitForAllTyVar_maybe oty2
-- NB: prov isn't interesting here either
= let k1 = tyVarKind tv1
k2 = tyVarKind tv2
......@@ -544,8 +544,8 @@ opt_univ env sym prov role oty1 oty2
in
mkForAllCo tv1' eta' (opt_univ env' sym prov' role ty1 ty2')
| Just (cv1, ty1) <- splitForAllTy_co_maybe oty1
, Just (cv2, ty2) <- splitForAllTy_co_maybe oty2
| Just (cv1, ty1) <- splitForAllCoVar_maybe oty1
, Just (cv2, ty2) <- splitForAllCoVar_maybe oty2
-- NB: prov isn't interesting here either
= let k1 = varType cv1
k2 = varType cv2
......@@ -1121,7 +1121,7 @@ etaForAllCo_ty_maybe co
= Just (tv, kind_co, r)
| Pair ty1 ty2 <- coercionKind co
, Just (tv1, _) <- splitForAllTy_ty_maybe ty1
, Just (tv1, _) <- splitForAllTyVar_maybe ty1
, isForAllTy_ty ty2
, let kind_co = mkNthCo Nominal 0 co
= Just ( tv1, kind_co
......@@ -1137,7 +1137,7 @@ etaForAllCo_co_maybe co
= Just (cv, kind_co, r)
| Pair ty1 ty2 <- coercionKind co
, Just (cv1, _) <- splitForAllTy_co_maybe ty1
, Just (cv1, _) <- splitForAllCoVar_maybe ty1
, isForAllTy_co ty2
= let kind_co = mkNthCo Nominal 0 co
r = coVarRole cv1
......
......@@ -1240,7 +1240,7 @@ checkCaseLinearity ue case_bndr var_w bndr = do
-----------------
lintTyApp :: LintedType -> LintedType -> LintM LintedType
lintTyApp fun_ty arg_ty
| Just (tv,body_ty) <- splitForAllTy_maybe fun_ty
| Just (tv,body_ty) <- splitForAllTyCoVar_maybe fun_ty
= do { lintTyKind tv arg_ty
; in_scope <- getInScope
-- substTy needs the set of tyvars in scope to avoid generating
......@@ -2172,7 +2172,7 @@ lintCoercion co@(TransCo co1 co2)
lintCoercion the_co@(NthCo r0 n co)
= do { co' <- lintCoercion co
; let (Pair s t, r) = coercionKindRole co'
; case (splitForAllTy_maybe s, splitForAllTy_maybe t) of
; case (splitForAllTyCoVar_maybe s, splitForAllTyCoVar_maybe t) of
{ (Just _, Just _)
-- works for both tyvar and covar
| n == 0
......@@ -2214,7 +2214,7 @@ lintCoercion (InstCo co arg)
; lintRole arg Nominal (coercionRole arg')
; case (splitForAllTy_ty_maybe t1, splitForAllTy_ty_maybe t2) of
; case (splitForAllTyVar_maybe t1, splitForAllTyVar_maybe t2) of
-- forall over tvar
{ (Just (tv1,_), Just (tv2,_))
| typeKind s1 `eqType` tyVarKind tv1
......@@ -2223,7 +2223,7 @@ lintCoercion (InstCo co arg)
| otherwise
-> failWithL (text "Kind mis-match in inst coercion1" <+> ppr co)
; _ -> case (splitForAllTy_co_maybe t1, splitForAllTy_co_maybe t2) of
; _ -> case (splitForAllCoVar_maybe t1, splitForAllCoVar_maybe t2) of
-- forall over covar
{ (Just (cv1, _), Just (cv2, _))
| typeKind s1 `eqType` varType cv1
......
......@@ -145,7 +145,7 @@ typeArity ty
= go initRecTc ty
where
go rec_nts ty
| Just (_, ty') <- splitForAllTy_maybe ty
| Just (_, ty') <- splitForAllTyCoVar_maybe ty
= go rec_nts ty'
| Just (_,arg,res) <- splitFunTy_maybe ty
......@@ -1516,7 +1516,7 @@ mkEtaWW orig_oss ppr_orig_expr in_scope orig_ty
go n oss@(one_shot:oss1) subst ty eis -- See Note [exprArity invariant]
----------- Forall types (forall a. ty)
| Just (tcv,ty') <- splitForAllTy_maybe ty
| Just (tcv,ty') <- splitForAllTyCoVar_maybe ty
, (subst', tcv') <- Type.substVarBndr subst tcv
, let oss' | isTyVar tcv = oss
| otherwise = oss1
......@@ -1884,7 +1884,7 @@ etaBodyForJoinPoint need_args body
go 0 _ _ rev_bs e
= (reverse rev_bs, e)
go n ty subst rev_bs e
| Just (tv, res_ty) <- splitForAllTy_maybe ty
| Just (tv, res_ty) <- splitForAllTyCoVar_maybe ty
, let (subst', tv') = substVarBndr subst tv
= go (n-1) res_ty subst' (tv' : rev_bs) (e `App` varToCoreExpr tv')
| Just (mult, arg_ty, res_ty) <- splitFunTy_maybe ty
......
......@@ -1181,7 +1181,7 @@ unsafeEqualityProofRule
= do { [Type rep, Type t1, Type t2] <- getArgs
; guard (t1 `eqType` t2)
; fn <- getFunction
; let (_, ue) = splitForAllTys (idType fn)
; let (_, ue) = splitForAllTyCoVars (idType fn)
tc = tyConAppTyCon ue -- tycon: UnsafeEquality
(dc:_) = tyConDataCons tc -- data con: UnsafeRefl
-- UnsafeRefl :: forall (r :: RuntimeRep) (a :: TYPE r).
......
......@@ -576,7 +576,7 @@ mkArgInfo env fun rules n_val_args call_cont
add_type_strictness fun_ty dmds
| null dmds = []
| Just (_, fun_ty') <- splitForAllTy_maybe fun_ty
| Just (_, fun_ty') <- splitForAllTyCoVar_maybe fun_ty
= add_type_strictness fun_ty' dmds -- Look through foralls
| Just (_, arg_ty, fun_ty') <- splitFunTy_maybe fun_ty -- Add strict-type info
......
......@@ -971,7 +971,7 @@ decreaseSpecCount env n_specs
---------------------------------------------------
-- See Note [Forcing specialisation]
forceSpecBndr :: ScEnv -> Var -> Bool
forceSpecBndr env var = forceSpecFunTy env . snd . splitForAllTys . varType $ var
forceSpecBndr env var = forceSpecFunTy env . snd . splitForAllTyCoVars . varType $ var
forceSpecFunTy :: ScEnv -> Type -> Bool
forceSpecFunTy env = any (forceSpecArgTy env) . map scaledThing . fst . splitFunTys
......
......@@ -434,7 +434,7 @@ mkWWargs subst fun_ty demands
apply_or_bind_then work_fn_args (varToCoreExpr id),
res_ty) }
| Just (tv, fun_ty') <- splitForAllTy_maybe fun_ty
| Just (tv, fun_ty') <- splitForAllTyCoVar_maybe fun_ty
= do { uniq <- getUniqueM
; let (subst', tv') = cloneTyVarBndr subst tv uniq
-- See Note [Freshen WW arguments]
......@@ -1026,7 +1026,7 @@ findTypeShape fam_envs ty
| Just (tc, tc_args) <- splitTyConApp_maybe ty
= go_tc rec_tc tc tc_args
| Just (_, ty') <- splitForAllTy_maybe ty
| Just (_, ty') <- splitForAllTyCoVar_maybe ty
= go rec_tc ty'
| otherwise
......
......@@ -69,7 +69,7 @@ classifyPredType ev_ty = case splitTyConApp_maybe ev_ty of
| Just clas <- tyConClass_maybe tc
-> ClassPred clas tys
_ | (tvs, rho) <- splitForAllTys ev_ty
_ | (tvs, rho) <- splitForAllTyCoVars ev_ty
, (theta, pred) <- splitFunTys rho
, not (null tvs && null theta)
-> ForAllPred tvs (map scaledThing theta) pred
......
......@@ -34,7 +34,7 @@ import {-# SOURCE #-} GHC.Core.DataCon
( dataConFullSig , dataConUserTyVarBinders, DataCon )
import GHC.Core.Type ( pickyIsLiftedTypeKind, pattern One, pattern Many,
splitForAllTysReq, splitForAllTysInvis )
splitForAllReqTVBinders, splitForAllInvisTVBinders )
import GHC.Core.TyCon
import GHC.Core.TyCo.Rep
......@@ -269,7 +269,7 @@ debug_ppr_ty _ (CoercionTy co)
-- Invisible forall: forall {k} (a :: k). t
debug_ppr_ty prec t
| (bndrs, body) <- splitForAllTysInvis t
| (bndrs, body) <- splitForAllInvisTVBinders t
, not (null bndrs)
= maybeParen prec funPrec $
sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <> dot,
......@@ -282,7 +282,7 @@ debug_ppr_ty prec t
-- Visible forall: forall x y -> t
debug_ppr_ty prec t
| (bndrs, body) <- splitForAllTysReq t
| (bndrs, body) <- splitForAllReqTVBinders t
, not (null bndrs)
= maybeParen prec funPrec $
sep [ text "forall" <+> fsep (map ppr_bndr bndrs) <+> arrow,
......@@ -294,7 +294,7 @@ debug_ppr_ty prec t
-- Impossible case: neither visible nor invisible forall.
debug_ppr_ty _ ForAllTy{}
= panic "debug_ppr_ty: neither splitForAllTysInvis nor splitForAllTysReq returned any binders"
= panic "debug_ppr_ty: neither splitForAllInvisTVBinders nor splitForAllReqTVBinders returned any binders"
{-
Note [Infix type variables]
......
......@@ -139,13 +139,13 @@ tidyType env ty@(FunTy _ w arg res) = let { !w' = tidyType env w
in ty { ft_mult = w', ft_arg = arg', ft_res = res' }
tidyType env (ty@(ForAllTy{})) = mkForAllTys' (zip tvs' vis) $! tidyType env' body_ty
where
(tvs, vis, body_ty) = splitForAllTys' ty
(tvs, vis, body_ty) = splitForAllTyCoVars' ty
(env', tvs') = tidyVarBndrs env tvs
tidyType env (CastTy ty co) = (CastTy $! tidyType env ty) $! (tidyCo env co)
tidyType env (CoercionTy co) = CoercionTy $! (tidyCo env co)
-- The following two functions differ from mkForAllTys and splitForAllTys in that
-- The following two functions differ from mkForAllTys and splitForAllTyCoVars in that
-- they expect/preserve the ArgFlag argument. These belong to "GHC.Core.Type", but
-- how should they be named?
mkForAllTys' :: [(TyCoVar, ArgFlag)] -> Type -> Type
......@@ -153,8 +153,8 @@ mkForAllTys' tvvs ty = foldr strictMkForAllTy ty tvvs
where
strictMkForAllTy (tv,vis) ty = (ForAllTy $! ((Bndr $! tv) $! vis)) $! ty
splitForAllTys' :: Type -> ([TyCoVar], [ArgFlag], Type)
splitForAllTys' ty = go ty [] []
splitForAllTyCoVars' :: Type -> ([TyCoVar], [ArgFlag], Type)
splitForAllTyCoVars' ty = go ty [] []
where
go (ForAllTy (Bndr tv vis) ty) tvs viss = go ty (tv:tvs) (vis:viss)
go ty tvs viss = (reverse tvs, reverse viss, ty)
......
......@@ -48,11 +48,11 @@ module GHC.Core.Type (
mkSpecForAllTy, mkSpecForAllTys,
mkVisForAllTys, mkTyCoInvForAllTy,
mkInfForAllTy, mkInfForAllTys,
splitForAllTys,
splitForAllTysReq, splitForAllTysInvis,
splitForAllVarBndrs,
splitForAllTy_maybe, splitForAllTy,
splitForAllTy_ty_maybe, splitForAllTy_co_maybe,
splitForAllTyCoVars,
splitForAllReqTVBinders, splitForAllInvisTVBinders,
splitForAllTyCoVarBinders,
splitForAllTyCoVar_maybe, splitForAllTyCoVar,
splitForAllTyVar_maybe, splitForAllCoVar_maybe,
splitPiTy_maybe, splitPiTy, splitPiTys,
mkTyConBindersPreferAnon,
mkPiTy, mkPiTys,
......@@ -1552,8 +1552,8 @@ mkTyConBindersPreferAnon vars inner_tkvs = ASSERT( all isTyVar vars)
-- | Take a ForAllTy apart, returning the list of tycovars and the result type.
-- This always succeeds, even if it returns only an empty list. Note that the
-- result type returned may have free variables that were bound by a forall.
splitForAllTys :: Type -> ([TyCoVar], Type)
splitForAllTys ty = split ty ty []
splitForAllTyCoVars :: Type -> ([TyCoVar], Type)
splitForAllTyCoVars ty = split ty ty []
where
split _ (ForAllTy (Bndr tv _) ty) tvs = split ty ty (tv:tvs)
split orig_ty ty tvs | Just ty' <- coreView ty = split orig_ty ty' tvs
......@@ -1561,38 +1561,38 @@ splitForAllTys ty = split ty ty []
-- | Splits the longest initial sequence of ForAllTys' that satisfy
-- @argf_pred@, returning the binders transformed by @argf_pred@
splitSomeForAllTys :: (ArgFlag -> Maybe af) -> Type -> ([VarBndr TyCoVar af], Type)
splitSomeForAllTys argf_pred ty = split ty ty []
splitSomeForAllTyCoVarBndrs :: (ArgFlag -> Maybe af) -> Type -> ([VarBndr TyCoVar af], Type)
splitSomeForAllTyCoVarBndrs argf_pred ty = split ty ty []
where
split _ (ForAllTy (Bndr tcv argf) ty) tvs
| Just argf' <- argf_pred argf = split ty ty (Bndr tcv argf' : tvs)
split orig_ty ty tvs | Just ty' <- coreView ty = split orig_ty ty' tvs
split orig_ty _ tvs = (reverse tvs, orig_ty)
-- | Like 'splitForAllTys', but only splits 'ForAllTy's with 'Required' type
-- | Like 'splitForAllTyCoVars', but only splits 'ForAllTy's with 'Required' type
-- variable binders. Furthermore, each returned tyvar is annotated with '()'.
splitForAllTysReq :: Type -> ([ReqTVBinder], Type)
splitForAllTysReq ty = splitSomeForAllTys argf_pred ty
splitForAllReqTVBinders :: Type -> ([ReqTVBinder], Type)
splitForAllReqTVBinders ty = splitSomeForAllTyCoVarBndrs argf_pred ty
where
argf_pred :: ArgFlag -> Maybe ()
argf_pred Required = Just ()
argf_pred (Invisible {}) = Nothing
-- | Like 'splitForAllTys', but only splits 'ForAllTy's with 'Invisible' type
-- | Like 'splitForAllTyCoVars', but only splits 'ForAllTy's with 'Invisible' type
-- variable binders. Furthermore, each returned tyvar is annotated with its
-- 'Specificity'.
splitForAllTysInvis :: Type -> ([InvisTVBinder], Type)
splitForAllTysInvis ty = splitSomeForAllTys argf_pred ty
splitForAllInvisTVBinders :: Type -> ([InvisTVBinder], Type)
splitForAllInvisTVBinders ty = splitSomeForAllTyCoVarBndrs argf_pred ty
where
argf_pred :: ArgFlag -> Maybe Specificity
argf_pred Required = Nothing
argf_pred (Invisible spec) = Just spec
-- | Like splitForAllTys, but split only for tyvars.
-- | Like 'splitForAllTyCoVars', but split only for tyvars.
-- This always succeeds, even if it returns only an empty list. Note that the
-- result type returned may have free variables that were bound by a forall.
splitTyVarForAllTys :: Type -> ([TyVar], Type)
splitTyVarForAllTys ty = split ty ty []
splitForAllTyVars :: Type -> ([TyVar], Type)
splitForAllTyVars ty = split ty ty []
where
split _ (ForAllTy (Bndr tv _) ty) tvs | isTyVar tv = split ty ty (tv:tvs)
split orig_ty ty tvs | Just ty' <- coreView ty = split orig_ty ty' tvs
......@@ -1636,10 +1636,10 @@ isFunTy ty
| otherwise = False
-- | Take a forall type apart, or panics if that is not possible.
splitForAllTy :: Type -> (TyCoVar, Type)
splitForAllTy ty
| Just answer <- splitForAllTy_maybe ty = answer
| otherwise = pprPanic "splitForAllTy" (ppr ty)
splitForAllTyCoVar :: Type -> (TyCoVar, Type)
splitForAllTyCoVar ty
| Just answer <- splitForAllTyCoVar_maybe ty = answer
| otherwise = pprPanic "splitForAllTyCoVar" (ppr ty)
-- | Drops all ForAllTys
dropForAlls :: Type -> Type
......@@ -1651,23 +1651,23 @@ dropForAlls ty = go ty
-- | Attempts to take a forall type apart, but only if it's a proper forall,
-- with a named binder
splitForAllTy_maybe :: Type -> Maybe (TyCoVar, Type)
splitForAllTy_maybe ty
splitForAllTyCoVar_maybe :: Type -> Maybe (TyCoVar, Type)
splitForAllTyCoVar_maybe ty
| ForAllTy (Bndr tv _) inner_ty <- coreFullView ty = Just (tv, inner_ty)
| otherwise = Nothing
-- | Like splitForAllTy_maybe, but only returns Just if it is a tyvar binder.
splitForAllTy_ty_maybe :: Type -> Maybe (TyCoVar, Type)
splitForAllTy_ty_maybe ty
-- | Like 'splitForAllTyCoVar_maybe', but only returns Just if it is a tyvar binder.
splitForAllTyVar_maybe :: Type -> Maybe (TyCoVar, Type)
splitForAllTyVar_maybe ty
| ForAllTy (Bndr tv _) inner_ty <- coreFullView ty
, isTyVar tv
= Just (tv, inner_ty)
| otherwise = Nothing
-- | Like splitForAllTy_maybe, but only returns Just if it is a covar binder.
splitForAllTy_co_maybe :: Type -> Maybe (TyCoVar, Type)
splitForAllTy_co_maybe ty
-- | Like 'splitForAllTyCoVar_maybe', but only returns Just if it is a covar binder.
splitForAllCoVar_maybe :: Type -> Maybe (TyCoVar, Type)
splitForAllCoVar_maybe ty
| ForAllTy (Bndr tv _) inner_ty <- coreFullView ty
, isCoVar tv
= Just (tv, inner_ty)
......@@ -1702,14 +1702,14 @@ splitPiTys ty = split ty ty []
split orig_ty _ bs = (reverse bs, orig_ty)
-- | Like 'splitPiTys' but split off only /named/ binders
-- and returns TyCoVarBinders rather than TyCoBinders
splitForAllVarBndrs :: Type -> ([TyCoVarBinder], Type)
splitForAllVarBndrs ty = split ty ty []
-- and returns 'TyCoVarBinder's rather than 'TyCoBinder's
splitForAllTyCoVarBinders :: Type -> ([TyCoVarBinder], Type)
splitForAllTyCoVarBinders ty = split ty ty []
where
split orig_ty ty bs | Just ty' <- coreView ty = split orig_ty ty' bs
split _ (ForAllTy b res) bs = split res res (b:bs)
split orig_ty _ bs = (reverse bs, orig_ty)
{-# INLINE splitForAllVarBndrs #-}
{-# INLINE splitForAllTyCoVarBinders #-}
invisibleTyBndrCount :: Type -> Int
-- Returns the number of leading invisible forall'd binders in the type
......@@ -2114,7 +2114,7 @@ isValidJoinPointType arity ty
valid_under tvs arity ty
| arity == 0
= tvs `disjointVarSet` tyCoVarsOfType ty
| Just (t, ty') <- splitForAllTy_maybe ty
| Just (t, ty') <- splitForAllTyCoVar_maybe ty
= valid_under (tvs `extendVarSet` t) (arity-1) ty'
| Just (_, _, res_ty) <- splitFunTy_maybe ty
= valid_under tvs (arity-1) res_ty
......@@ -2497,7 +2497,7 @@ typeKind ty@(ForAllTy {})
Nothing -> pprPanic "typeKind"
(ppr ty $$ ppr tvs $$ ppr body <+> dcolon <+> ppr body_kind)
where
(tvs, body) = splitTyVarForAllTys ty
(tvs, body) = splitForAllTyVars ty
body_kind = typeKind body
---------------------------------------------
......@@ -2542,7 +2542,7 @@ tcTypeKind ty@(ForAllTy {})
Nothing -> pprPanic "tcTypeKind"
(ppr ty $$ ppr tvs $$ ppr body <+> dcolon <+> ppr body_kind)
where
(tvs, body) = splitTyVarForAllTys ty
(tvs, body) = splitForAllTyVars ty
body_kind = tcTypeKind body
......
......@@ -346,7 +346,7 @@ resultWrapper result_ty
-- The type might contain foralls (eg. for dummy type arguments,
-- referring to 'Ptr a' is legal).
| Just (tyvar, rest) <- splitForAllTy_maybe result_ty
| Just (tyvar, rest) <- splitForAllTyCoVar_maybe result_ty
= do { (maybe_ty, wrapper) <- resultWrapper rest
; return (maybe_ty, \e -> Lam tyvar (wrapper e)) }
......
......@@ -212,7 +212,7 @@ dsFCall :: Id -> Coercion -> ForeignCall -> Maybe Header
dsFCall fn_id co fcall mDeclHeader = do
let
ty = coercionLKind co
(tv_bndrs, rho) = tcSplitForAllVarBndrs ty
(tv_bndrs, rho) = tcSplitForAllTyVarBinders ty
(arg_tys, io_res_ty) = tcSplitFunTys rho
args <- newSysLocalsDs arg_tys -- no FFI levity-polymorphism
......@@ -316,7 +316,7 @@ dsPrimCall :: Id -> Coercion -> ForeignCall
dsPrimCall fn_id co fcall = do
let
ty = coercionLKind co
(tvs, fun_ty) = tcSplitForAllTys ty
(tvs, fun_ty) = tcSplitForAllTyVars ty
(arg_tys, io_res_ty) = tcSplitFunTys fun_ty
args <- newSysLocalsDs arg_tys -- no FFI levity-polymorphism
......@@ -489,7 +489,7 @@ dsFExportDynamic id co0 cconv = do
where
ty = coercionLKind co0
(tvs,sans_foralls) = tcSplitForAllTys ty
(tvs,sans_foralls) = tcSplitForAllTyVars ty
([Scaled arg_mult arg_ty], fn_res_ty) = tcSplitFunTys sans_foralls
Just (io_tc, res_ty) = tcSplitIOType_maybe fn_res_ty
-- Must have an IO type; hence Just
......
......@@ -656,7 +656,7 @@ classToIfaceDecl env clas
-- op :: (?x :: String) => a -> a
-- and class Baz a where
-- op :: (Ord a) => a -> a
(sel_tyvars, rho_ty) = splitForAllTys (idType sel_id)
(sel_tyvars, rho_ty) = splitForAllTyCoVars (idType sel_id)
op_ty = funResultTy rho_ty
toDmSpec :: (Name, DefMethSpec Type) -> DefMethSpec IfaceType
......
......@@ -1389,4 +1389,4 @@ quantifyType ty = ( filter isTyVar $
tyCoVarsOfTypeWellScoped rho
, rho)
where
(_tvs, rho) = tcSplitForAllTys ty
(_tvs, rho) = tcSplitForAllTyVars ty
......@@ -467,7 +467,7 @@ pprHoleFit (HFDC sWrp sWrpVars sTy sProv sMs) (HoleFit {..}) =
unwrapTypeVars t = vars ++ case splitFunTy_maybe unforalled of
Just (_, _, unfunned) -> unwrapTypeVars unfunned
_ -> []
where (vars, unforalled) = splitForAllVarBndrs t
where (vars, unforalled) = splitForAllTyCoVarBinders t
holeVs = sep $ map (parens . (text "_" <+> dcolon <+>) . ppr) hfMatches
holeDisp = if sMs then holeVs
else sep $ replicate (length hfMatches) $ text "_"
......
......@@ -450,7 +450,7 @@ tcInstFun do_ql inst_final rn_fun fun_sigma rn_args
-- Rule IALL from Fig 4 of the QL paper
go1 delta acc so_far fun_ty args
| (tvs, body1) <- tcSplitSomeForAllTys (inst_fun args) fun_ty
| (tvs, body1) <- tcSplitSomeForAllTyVars (inst_fun args) fun_ty
, (theta, body2) <- tcSplitPhiTy body1
, not (null tvs && null theta)
= do { (inst_tvs, wrap, fun_rho) <- setSrcSpanFromArgs rn_args $
......@@ -556,7 +556,7 @@ tcVTA :: TcType -- Function type
-- Deal with a visible type application
-- The function type has already had its Inferred binders instantiated
tcVTA fun_ty hs_ty
| Just (tvb, inner_ty) <- tcSplitForAllTy_maybe fun_ty
| Just (tvb, inner_ty) <- tcSplitForAllTyVarBinder_maybe fun_ty
, binderArgFlag tvb == Specified
-- It really can't be Inferred, because we've just
-- instantiated those. But, oddly, it might just be Required.
......@@ -969,11 +969,11 @@ findNoQuantVars fun_ty args
go bvs fun_ty (EPrag {} : args) = go bvs fun_ty args
go bvs fun_ty args@(ETypeArg {} : rest_args)
| (tvs, body1) <- tcSplitSomeForAllTys (== Inferred) fun_ty
| (tvs, body1) <- tcSplitSomeForAllTyVars (== Inferred) fun_ty
, (theta, body2) <- tcSplitPhiTy body1
, not (null tvs && null theta)
= go (bvs `extendVarSetList` tvs) body2 args
| Just (_tv, res_ty) <- tcSplitForAllTy_maybe fun_ty
| Just (_tv, res_ty) <- tcSplitForAllTyVarBinder_maybe fun_ty
= go bvs res_ty rest_args
| otherwise
= False -- E.g. head ids @Int
......
......@@ -124,7 +124,7 @@ normaliseFfiType' env ty0 = go Representational initRecTc ty0
| Just (tc, tys) <- splitTyConApp_maybe ty
= go_tc_app role rec_nts tc tys
| (bndrs, inner_ty) <- splitForAllVarBndrs ty
| (bndrs, inner_ty) <- splitForAllTyCoVarBinders ty
, not (null bndrs)
= do (coi, nty1, gres1) <- go role rec_nts inner_ty
return ( mkHomoForAllCos (binderVars bndrs) coi
......
......@@ -554,7 +554,7 @@ tcHsDeriv hs_ty
= do { ty <- checkNoErrs $ -- Avoid redundant error report
-- with "illegal deriving", below
tcTopLHsType DerivClauseCtxt hs_ty
; let (tvs, pred) = splitForAllTys ty
; let (tvs, pred) = splitForAllTyCoVars ty
(kind_args, _) = splitFunTys (tcTypeKind pred)
; case getClassPredTys_maybe pred of
Just (cls, tys) -> return (tvs, cls, tys, map scaledThing kind_args)
......@@ -583,7 +583,7 @@ tcDerivStrategy mb_lds
tc_deriv_strategy NewtypeStrategy = boring_case NewtypeStrategy
tc_deriv_strategy (ViaStrategy ty) = do
ty' <- checkNoErrs $ tcTopLHsType DerivClauseCtxt ty
let (via_tvs, via_pred) = splitForAllTys ty'
let (via_tvs, via_pred) = splitForAllTyCoVars ty'
pure (ViaStrategy via_pred, via_tvs)
boring_case :: ds -> TcM (ds, [TyVar])
......
......@@ -2148,12 +2148,12 @@ reify_for_all :: TyCoRep.ArgFlag -> TyCoRep.Type -> TcM TH.Type
-- Arg of reify_for_all is always ForAllTy or a predicate FunTy
reify_for_all argf ty
| isVisibleArgFlag argf
= do let (req_bndrs, phi) = tcSplitForAllTysReq ty
= do let (req_bndrs, phi) = tcSplitForAllReqTVBinders ty
tvbndrs' <- reifyTyVarBndrs req_bndrs
phi' <- reifyType phi
pure $ TH.ForallVisT tvbndrs' phi'
| otherwise
= do let (inv_bndrs, phi) = tcSplitForAllTysInvis ty
= do let (inv_bndrs, phi) = tcSplitForAllInvisTVBinders ty
tvbndrs' <- reifyTyVarBndrs inv_bndrs
let (cxt, tau) = tcSplitPhiTy phi
cxt' <- reifyCxt cxt
......
......@@ -407,7 +407,7 @@ mkTyConRepBinds :: TypeableStuff -> TypeRepTodo
-> TypeableTyCon -> KindRepM (LHsBinds GhcTc)
mkTyConRepBinds stuff todo (TypeableTyCon {..})
= do -- Make a KindRep
let (bndrs, kind) = splitForAllVarBndrs (tyConKind tycon)
let (bndrs, kind) = splitForAllTyCoVarBinders (tyConKind tycon)
liftTc $ traceTc "mkTyConKindRepBinds"
(ppr tycon $$ ppr (tyConKind tycon) $$ ppr kind)
let ctx = mkDeBruijnContext (map binderVar bndrs)
......
......@@ -549,7 +549,7 @@ mk_strict_superclasses rec_clss (CtGiven { ctev_evar = evar, ctev_loc = loc })
mk_given_desc sel_id sc_pred
= (swizzled_pred, swizzled_evterm)
where
(sc_tvs, sc_rho) = splitForAllTys sc_pred
(sc_tvs, sc_rho) = splitForAllTyCoVars sc_pred
(sc_theta, sc_inner_pred) = splitFunTys sc_rho
all_tvs = tvs `chkAppend` sc_tvs
......@@ -1147,8 +1147,8 @@ can_eq_nc_forall :: CtEvidence -> EqRel
can_eq_nc_forall ev eq_rel s1 s2
| CtWanted { ctev_loc = loc, ctev_dest = orig_dest } <- ev