Generation of DataCons for implicit PArray instances
[ghc-hetmet.git] / compiler / vectorise / VectType.hs
index dd77c12..ebf1797 100644 (file)
@@ -15,6 +15,7 @@ import OccName
 import MkId
 import BasicTypes        ( StrictnessMark(..), boolToRecFlag )
 import NameEnv
+import TysWiredIn
 
 import Unique
 import UniqFM
@@ -139,7 +140,7 @@ vectDataCon dc
       arg_tys  <- mapM vectType rep_arg_tys
       wrk_name <- cloneName mkDataConWorkerOcc name'
 
-      let ids      = mkDataConIds (panic "vectDataCon: wrapped id")
+      let ids      = mkDataConIds (panic "vectDataCon: wrapper id")
                                   wrk_name
                                   data_con
           data_con = mkDataCon name'
@@ -158,9 +159,43 @@ vectDataCon dc
   where
     name        = dataConName dc
     univ_tvs    = dataConUnivTyVars dc
-    rep_arg_tys = dataConOrigArgTys dc
+    rep_arg_tys = dataConRepArgTys dc
     tycon       = dataConTyCon dc
 
+{-
+mkPArrTyCon :: TyCon -> VM TyCon
+mkPArrTyCon tc = fixV $ \repr_tc ->
+  do
+-}
+
+mkPArrayDataCon :: TyCon -> TyCon -> VM DataCon
+mkPArrayDataCon orig_tc repr_tc
+  = do
+      name     <- cloneName mkPArrayDataConOcc (tyConName orig_tc)
+      shape_ty <- mkPArrayType intTy   -- FIXME: we want to unbox this!
+      repr_tys <- mapM mkPArrayType types
+      wrk_name <- cloneName mkDataConWorkerOcc name
+      wrp_name <- cloneName mkDataConWrapperOcc name
+
+      let ids      = mkDataConIds wrp_name wrk_name data_con
+          data_con = mkDataCon name
+                               False
+                               (MarkedStrict : map (const NotMarkedStrict) repr_tys)
+                               []
+                               (tyConTyVars orig_tc)
+                               []
+                               []
+                               []
+                               repr_tys
+                               repr_tc
+                               []
+                               ids
+
+      return data_con
+  where
+    types = [ty | dc <- tyConDataCons orig_tc
+                , ty <- dataConRepArgTys dc]
+
 -- | Split the given tycons into two sets depending on whether they have to be
 -- converted (first list) or not (second list). The first argument contains
 -- information about the conversion status of external tycons:
@@ -209,7 +244,13 @@ tyConsOfType :: Type -> UniqSet TyCon
 tyConsOfType ty
   | Just ty' <- coreView ty    = tyConsOfType ty'
 tyConsOfType (TyVarTy v)       = emptyUniqSet
-tyConsOfType (TyConApp tc tys) = tyConsOfTypes tys `addOneToUniqSet` tc
+tyConsOfType (TyConApp tc tys) = extend (tyConsOfTypes tys)
+  where
+    extend | isUnLiftedTyCon tc
+           || isTupleTyCon   tc = id
+
+           | otherwise          = (`addOneToUniqSet` tc)
+
 tyConsOfType (AppTy a b)       = tyConsOfType a `unionUniqSets` tyConsOfType b
 tyConsOfType (FunTy a b)       = (tyConsOfType a `unionUniqSets` tyConsOfType b)
                                  `addOneToUniqSet` funTyCon