Fix bug in generation of environments for vectorisation
[ghc-hetmet.git] / compiler / vectorise / VectUtils.hs
index 3e6143c..fcdcfd9 100644 (file)
@@ -346,6 +346,19 @@ takeHoisted
       setGEnv $ env { global_bindings = [] }
       return $ global_bindings env
 
+boxExpr :: Type -> VExpr -> VM VExpr
+boxExpr ty (vexpr, lexpr)
+  | Just (tycon, []) <- splitTyConApp_maybe ty
+  , isUnLiftedTyCon tycon
+  = do
+      r <- lookupBoxedTyCon tycon
+      case r of
+        Just tycon' -> let [dc] = tyConDataCons tycon'
+                       in
+                       return (mkConApp dc [vexpr], lexpr)
+        Nothing     -> return (vexpr, lexpr)
+
+
 mkClosure :: Type -> Type -> Type -> VExpr -> VExpr -> VM VExpr
 mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv)
   = do
@@ -442,7 +455,7 @@ mkLiftEnv lc tys vs
           
           env = Var (dataConWrapId env_con)
                 `mkTyApps`  env_tyargs
-                `mkVarApps` (lc : vs)
+                `mkApps`    (Var lc : args)
 
           bind env body = let scrut = unwrapFamInstScrut env_tc env_tyargs env
                           in
@@ -453,6 +466,9 @@ mkLiftEnv lc tys vs
   where
     vty = mkCoreTupTy tys
 
+    args  | null vs   = [Var unitDataConId]
+          | otherwise = map Var vs
+
     bndrs | null vs   = [mkWildId unitTy]
           | otherwise = vs