import TyCon ( TyCon(..), tyConFamilySize, isDataTyCon, tyConDataCons,
isFunTyCon, isUnboxedTupleTyCon )
import Class ( Class, classTyCon )
-import Type ( Type, repType, splitRepFunTys )
+import Type ( Type, repType, splitFunTys, dropForAlls )
import Util ( zipEqual, zipWith4Equal, naturalMergeSortLe, nOfThem,
isSingleton, lengthIs )
import DataCon ( dataConRepArity )
maybe_getCCallReturnRep :: Type -> Maybe PrimRep
maybe_getCCallReturnRep fn_ty
- = let (a_tys, r_ty) = splitRepFunTys fn_ty
+ = let (a_tys, r_ty) = splitFunTys (dropForAlls fn_ty)
maybe_r_rep_to_go
= if isSingleton r_reps then Nothing else Just (r_reps !! 1)
(r_tycon, r_reps)
do_arg ids bindings arg@(StgVarArg old_var)
| (not (isLocalVar old_var) || elemVarSet old_var ids)
- && isFunType var_type
+ && isFunTy (dropForAlls var_type)
= -- make a trivial let-binding for the top-level function
getUniqueMM `thenMM` \ uniq ->
let
StgLet (StgNonRec NoSRT{-eeek!!!-} new_var rhs_closure) body
where
bOGUS_LVs = emptyUniqSet -- easier to print than: panic "mk_stg_let: LVs"
-
-isFunType var_type
- = case splitForAllTys var_type of
- (_, ty) -> maybeToBool (splitFunTy_Maybe ty)
#endif
\end{code}
import VarSet
import VarEnv
-import Type ( splitFunTy_maybe, splitForAllTys )
-import Maybes ( maybeToBool, orElse )
+import Type ( isFunTy, dropForAlls )
+import Maybes ( orElse )
import Digraph ( stronglyConnCompR, SCC(..) )
import PrelNames ( buildIdKey, foldrIdKey, runSTRepIdKey, augmentIdKey )
import Unique ( Unique )
-- we didn't stupidly choose d as the loop breaker.
-- But we won't because constructor args are marked "Many".
- not_fun_ty ty = not (maybeToBool (splitFunTy_maybe rho_ty))
- where
- (_, rho_ty) = splitForAllTys ty
+ not_fun_ty ty = not (isFunTy (dropForAlls ty))
\end{code}
@occAnalRhs@ deals with the question of bindings where the Id is marked
)
import NewDemand ( isStrictDmd, isBotRes, splitStrictSig )
import SimplMonad
-import Type ( Type, seqType, splitRepFunTys, isStrictType,
+import Type ( Type, seqType, splitFunTys, dropForAlls, isStrictType,
splitTyConApp_maybe, tyConAppArgs, mkTyVarTys
)
import TcType ( isDictTy )
computed_stricts = zipWith (||) fun_stricts arg_stricts
----------------------------
- (val_arg_tys, _) = splitRepFunTys (idType fun)
+ (val_arg_tys, _) = splitFunTys (dropForAlls (idType fun))
arg_stricts = map isStrictType val_arg_tys ++ repeat False
-- These argument types are used as a cheap and cheerful way to find
-- unboxed arguments, which must be strict. But it's an InType
-- and so there might be a type variable where we expect a function
-- type (the substitution hasn't happened yet). And we don't bother
-- doing the type applications for a polymorphic function.
- -- Hence the split*Rep*FunTys
+ -- Hence the splitFunTys*IgnoringForAlls*
----------------------------
-- If fun_stricts is finite, it means the function returns bottom
import Name ( getSrcLoc )
import ErrUtils ( ErrMsg, Message, addErrLocHdrLine, pprBagOfErrors, dontAddErrLoc )
import Type ( mkFunTys, splitFunTys, splitTyConApp_maybe,
- isUnLiftedType, isTyVarTy, splitForAllTys, Type
+ isUnLiftedType, isTyVarTy, dropForAlls, Type
)
import TyCon ( TyCon, isAlgTyCon, isNewTyCon, tyConDataCons )
import Util ( zipEqual, equalLength )
checkFunApp fun_ty arg_tys msg loc scope errs
= cfa res_ty expected_arg_tys arg_tys
where
- (_, de_forall_ty) = splitForAllTys fun_ty
- (expected_arg_tys, res_ty) = splitFunTys de_forall_ty
+ (expected_arg_tys, res_ty) = splitFunTys (dropForAlls fun_ty)
cfa res_ty expected [] -- Args have run out; that's fine
= (Just (mkFunTys expected res_ty), errs)
| not (null demands)
= getUniquesUs `thenUs` \ wrap_uniqs ->
let
- (tyvars, tau) = splitForAllTys fun_ty
- (arg_tys, body_ty) = splitFunTys tau
+ (tyvars, tau) = splitForAllTys fun_ty
+ (arg_tys, body_ty) = splitFunTys tau
n_demands = length demands
n_arg_tys = length arg_tys
mkAppTy, mkAppTys, splitAppTy, splitAppTys, splitAppTy_maybe,
mkFunTy, mkFunTys, splitFunTy, splitFunTy_maybe, splitFunTys,
- funResultTy, funArgTy, zipFunTys,
+ funResultTy, funArgTy, zipFunTys, isFunTy,
mkTyConApp, mkTyConTy,
tyConAppTyCon, tyConAppArgs,
mkSynTy,
- repType, splitRepFunTys, typePrimRep,
+ repType, typePrimRep,
mkForAllTy, mkForAllTys, splitForAllTy_maybe, splitForAllTys,
- applyTy, applyTys, isForAllTy,
+ applyTy, applyTys, isForAllTy, dropForAlls,
-- Source types
SourceType(..), sourceTypeRep, mkPredTy, mkPredTys,
import Util ( mapAccumL, seqList, lengthIs )
import Outputable
import UniqSet ( sizeUniqSet ) -- Should come via VarSet
+import Maybe ( isJust )
\end{code}
mkFunTys :: [Type] -> Type -> Type
mkFunTys tys ty = foldr FunTy ty tys
+isFunTy :: Type -> Bool
+isFunTy ty = isJust (splitFunTy_maybe ty)
+
splitFunTy :: Type -> (Type, Type)
splitFunTy (FunTy arg res) = (arg, res)
splitFunTy (NoteTy _ ty) = splitFunTy ty
Representation types
~~~~~~~~~~~~~~~~~~~~
-
repType looks through
(a) for-alls, and
(b) synonyms
= repType (newTypeRep tc tys)
repType ty = ty
-splitRepFunTys :: Type -> ([Type], Type)
--- Like splitFunTys, but looks through newtypes and for-alls
-splitRepFunTys ty = split [] (repType ty)
- where
- split args (FunTy arg res) = split (arg:args) (repType res)
- split args ty = (reverse args, ty)
typePrimRep :: Type -> PrimRep
typePrimRep ty = case repType ty of
split orig_ty (NoteTy _ ty) tvs = split orig_ty ty tvs
split orig_ty (SourceTy p) tvs = split orig_ty (sourceTypeRep p) tvs
split orig_ty t tvs = (reverse tvs, orig_ty)
+
+dropForAlls :: Type -> Type
+dropForAlls ty = snd (splitForAllTys ty)
\end{code}
-- (mkPiType now in CoreUtils)