import Outputable
import FastString
-import Control.Monad ( liftM, liftM2, mapAndUnzipM, zipWithM_ )
+import Control.Monad ( liftM, liftM2, mapAndUnzipM )
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
+ (types', fam_insts, pa_insts) <- vectTypeEnv (mg_types guts)
+
+ let insts = map painstInstance pa_insts
+ 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')
-
+
+ dicts <- mapM buildPADict pa_insts
binds' <- mapM vectTopBind (mg_binds guts)
return $ guts { mg_types = types'
- , mg_binds = binds'
+ , mg_binds = Rec (concat dicts) : binds'
, mg_inst_env = inst_env'
, mg_fam_inst_env = fam_inst_env'
, mg_insts = mg_insts guts ++ insts
lexpr <- replicatePA vexpr lc
return (vexpr, lexpr)
where
- mk_app e = applyToTypes e =<< mapM vectType tys
-
-abstractOverTyVars :: [TyVar] -> ((CoreExpr -> CoreExpr) -> VM a) -> VM a
-abstractOverTyVars tvs p
- = do
- mdicts <- mapM mk_dict_var tvs
- zipWithM_ (\tv -> maybe (defLocalTyVar tv) (defLocalTyVarWithPA tv . Var)) tvs mdicts
- p (mk_lams mdicts)
- where
- mk_dict_var tv = do
- r <- paDictArgType tv
- case r of
- Just ty -> liftM Just (newLocalVar FSLIT("dPA") ty)
- Nothing -> return Nothing
-
- mk_lams mdicts = mkLams (tvs ++ [dict | Just dict <- mdicts])
-
-applyToTypes :: CoreExpr -> [Type] -> VM CoreExpr
-applyToTypes expr tys
- = do
- dicts <- mapM paDictOfType tys
- return $ expr `mkTyApps` tys `mkApps` dicts
+ mk_app e = polyApply e =<< mapM vectType tys
vectPolyExpr :: CoreExpr -> CoreExprWithFVs -> VM (CoreExpr, CoreExpr)
vectPolyExpr lc expr
- = localV
- . abstractOverTyVars tvs $ \mk_lams ->
+ = polyAbstract tvs $ \mk_lams ->
-- FIXME: shadowing (tvs in lc)
do
(vmono, lmono) <- vectExpr lc mono
res_ty <- vectType (exprType $ deAnnotate body)
-- FIXME: move the functions to the top level
- mono_vfn <- applyToTypes (Var vfn_var) (mkTyVarTys tyvars)
- mono_lfn <- applyToTypes (Var lfn_var) (mkTyVarTys tyvars)
+ mono_vfn <- polyApply (Var vfn_var) (mkTyVarTys tyvars)
+ mono_lfn <- polyApply (Var lfn_var) (mkTyVarTys tyvars)
mk_clo <- builtin mkClosureVar
mk_cloP <- builtin mkClosurePVar
-> VM (CoreExpr, CoreExpr)
mkClosureFns info tyvars arg body
= closedV
- . abstractOverTyVars tyvars
+ . polyAbstract tyvars
$ \mk_tlams ->
do
(vfn, lfn) <- mkClosureMonoFns info arg body