import VectMonad
import VectUtils
+import VectType
import DynFlags
import HscTypes
import DataCon
import TyCon
import Type
-import TypeRep
+import FamInstEnv ( extendFamInstEnvList )
+import InstEnv ( extendInstEnvList )
import Var
import VarEnv
import VarSet
import Outputable
import FastString
import Control.Monad ( liftM, liftM2, mapAndUnzipM, zipWithM_ )
-import Data.Maybe ( maybeToList )
vectorise :: HscEnv -> UniqSupply -> RuleBase -> ModGuts
-> IO (SimplCount, ModGuts)
vectModule :: ModGuts -> VM ModGuts
vectModule guts
= do
+ (types', fam_insts, insts) <- vectTypeEnv (mg_types guts)
+
+ let fam_inst_env' = extendFamInstEnvList (mg_fam_inst_env guts) fam_insts
+ inst_env' = extendInstEnvList (mg_inst_env guts) insts
+ updGEnv (setInstEnvs inst_env' fam_inst_env')
+
binds' <- mapM vectTopBind (mg_binds guts)
- return $ guts { mg_binds = binds' }
+ return $ guts { mg_types = types'
+ , mg_binds = binds'
+ , mg_inst_env = inst_env'
+ , mg_fam_inst_env = fam_inst_env'
+ , mg_insts = mg_insts guts ++ insts
+ , mg_fam_insts = mg_fam_insts guts ++ fam_insts
+ }
vectTopBind :: CoreBind -> VM CoreBind
vectTopBind b@(NonRec var expr)
res_ty <- vectType (exprType $ deAnnotate body)
-- FIXME: move the functions to the top level
- mono_vfn <- applyToTypes (Var vfn_var) (map TyVarTy tyvars)
- mono_lfn <- applyToTypes (Var lfn_var) (map TyVarTy tyvars)
+ mono_vfn <- applyToTypes (Var vfn_var) (mkTyVarTys tyvars)
+ mono_lfn <- applyToTypes (Var lfn_var) (mkTyVarTys tyvars)
mk_clo <- builtin mkClosureVar
mk_cloP <- builtin mkClosurePVar
vectTyAppExpr lc (_, AnnVar v) tys = vectPolyVar lc v tys
vectTyAppExpr lc e tys = pprPanic "vectTyAppExpr" (ppr $ deAnnotate e)
--- ----------------------------------------------------------------------------
--- Types
-
-vectTyCon :: TyCon -> VM TyCon
-vectTyCon tc
- | isFunTyCon tc = builtin closureTyCon
- | isBoxedTupleTyCon tc = return tc
- | isUnLiftedTyCon tc = return tc
- | otherwise = do
- r <- lookupTyCon tc
- case r of
- Just tc' -> return tc'
-
- -- FIXME: just for now
- Nothing -> pprTrace "ccTyCon:" (ppr tc) $ return tc
-
-vectType :: Type -> VM Type
-vectType ty | Just ty' <- coreView ty = vectType ty'
-vectType (TyVarTy tv) = return $ TyVarTy tv
-vectType (AppTy ty1 ty2) = liftM2 AppTy (vectType ty1) (vectType ty2)
-vectType (TyConApp tc tys) = liftM2 TyConApp (vectTyCon tc) (mapM vectType tys)
-vectType (FunTy ty1 ty2) = liftM2 TyConApp (builtin closureTyCon)
- (mapM vectType [ty1,ty2])
-vectType ty@(ForAllTy _ _)
- = do
- mdicts <- mapM paDictArgType tyvars
- mono_ty' <- vectType mono_ty
- return $ tyvars `mkForAllTys` ([dict | Just dict <- mdicts] `mkFunTys` mono_ty')
- where
- (tyvars, mono_ty) = splitForAllTys ty
-
-vectType ty = pprPanic "vectType:" (ppr ty)
-