module VectUtils (
+ collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg,
splitClosureTy,
mkPADictType, mkPArrayType,
- paDictArgType, paDictOfType
+ paDictArgType, paDictOfType,
+ lookupPArrayFamInst,
+ hoistExpr, takeHoisted
) where
#include "HsVersions.h"
import VectMonad
import CoreSyn
+import CoreUtils
import Type
import TypeRep
import TyCon
import PrelNames
import Outputable
+import FastString
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
dicts <- mapM paDictOfType tys
return $ mkApps (mkTyApps dfun tys) dicts
+lookupPArrayFamInst :: Type -> VM (TyCon, [Type])
+lookupPArrayFamInst ty = builtin parrayTyCon >>= (`lookupFamInst` [ty])
+
+hoistExpr :: FastString -> CoreExpr -> VM Var
+hoistExpr fs expr
+ = do
+ var <- newLocalVar fs (exprType expr)
+ updGEnv $ \env ->
+ env { global_bindings = (var, expr) : global_bindings env }
+ return var
+
+takeHoisted :: VM [(Var, CoreExpr)]
+takeHoisted
+ = do
+ env <- readGEnv id
+ setGEnv $ env { global_bindings = [] }
+ return $ global_bindings env
+