module VectUtils (
- paDictArgType, paDictOfType
+ collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg,
+ splitClosureTy,
+ mkPADictType, mkPArrayType,
+ paDictArgType, paDictOfType,
+ lookupPArrayFamInst
) where
#include "HsVersions.h"
import CoreSyn
import Type
import TypeRep
+import TyCon
import Var
+import PrelNames
import Outputable
+import Control.Monad ( liftM )
+
+collectAnnTypeArgs :: AnnExpr b ann -> (AnnExpr b ann, [Type])
+collectAnnTypeArgs expr = go expr []
+ where
+ go (_, AnnApp f (_, AnnType ty)) tys = go f (ty : tys)
+ go e tys = (e, tys)
+
+collectAnnTypeBinders :: AnnExpr Var ann -> ([Var], AnnExpr Var ann)
+collectAnnTypeBinders expr = go [] expr
+ where
+ go bs (_, AnnLam b e) | isTyVar b = go (b:bs) e
+ go bs e = (reverse bs, e)
+
+isAnnTypeArg :: AnnExpr b ann -> Bool
+isAnnTypeArg (_, AnnType t) = True
+isAnnTypeArg _ = False
+
+isClosureTyCon :: TyCon -> Bool
+isClosureTyCon tc = tyConUnique tc == closureTyConKey
+
+splitClosureTy :: Type -> (Type, Type)
+splitClosureTy ty
+ | Just (tc, [arg_ty, res_ty]) <- splitTyConApp_maybe ty
+ , isClosureTyCon tc
+ = (arg_ty, res_ty)
+
+ | otherwise = pprPanic "splitClosureTy" (ppr ty)
+
+mkPADictType :: Type -> VM Type
+mkPADictType ty
+ = do
+ tc <- builtin paDictTyCon
+ return $ TyConApp tc [ty]
+
+mkPArrayType :: Type -> VM Type
+mkPArrayType ty
+ = do
+ tc <- builtin parrayTyCon
+ return $ TyConApp tc [ty]
+
paDictArgType :: TyVar -> VM (Maybe Type)
paDictArgType tv = go (TyVarTy tv) (tyVarKind tv)
where
go ty k
| isLiftedTypeKind k
- = do
- tc <- builtin paDictTyCon
- return . Just $ TyConApp tc [ty]
+ = liftM Just (mkPADictType ty)
go ty k = return Nothing
dicts <- mapM paDictOfType tys
return $ mkApps (mkTyApps dfun tys) dicts
+lookupPArrayFamInst :: Type -> VM (TyCon, [Type])
+lookupPArrayFamInst ty = builtin parrayTyCon >>= (`lookupFamInst` [ty])
+