Refactoring
[ghc-hetmet.git] / compiler / vectorise / VectType.hs
index d5a1ba1..dfebe18 100644 (file)
@@ -12,6 +12,8 @@ import TyCon
 import Type
 import TypeRep
 import Coercion
+import FamInstEnv        ( FamInst, mkLocalFamInst )
+import InstEnv           ( Instance )
 import OccName
 import MkId
 import BasicTypes        ( StrictnessMark(..), boolToRecFlag )
@@ -66,7 +68,7 @@ vectType ty = pprPanic "vectType:" (ppr ty)
 
 type TyConGroup = ([TyCon], UniqSet TyCon)
 
-vectTypeEnv :: TypeEnv -> VM TypeEnv
+vectTypeEnv :: TypeEnv -> VM (TypeEnv, [FamInst], [Instance])
 vectTypeEnv env
   = do
       cs <- readGEnv $ mk_map . global_tycons
@@ -75,12 +77,16 @@ vectTypeEnv env
       zipWithM_ defTyCon   keep_tcs keep_tcs
       zipWithM_ defDataCon keep_dcs keep_dcs
       vect_tcs <- vectTyConDecls conv_tcs
-      parr_tcs1 <- mapM (\tc -> buildPArrayTyCon (tyConName tc) tc) keep_tcs
-      parr_tcs2 <- zipWithM (buildPArrayTyCon . tyConName) conv_tcs vect_tcs
+      parr_tcs1 <- zipWithM buildPArrayTyCon keep_tcs keep_tcs
+      parr_tcs2 <- zipWithM buildPArrayTyCon conv_tcs vect_tcs
       let new_tcs = vect_tcs ++ parr_tcs1 ++ parr_tcs2
-      return $ extendTypeEnvList env
-                 (map ATyCon new_tcs ++ [ADataCon dc | tc <- new_tcs
-                                                     , dc <- tyConDataCons tc])
+
+      let new_env = extendTypeEnvList env
+                       (map ATyCon new_tcs
+                        ++ [ADataCon dc | tc <- new_tcs
+                                        , dc <- tyConDataCons tc])
+
+      return (new_env, map mkLocalFamInst (parr_tcs1 ++ parr_tcs2), [])
   where
     tycons = typeEnvTyCons env
     groups = tyConGroups tycons
@@ -167,8 +173,8 @@ vectDataCon dc
     rep_arg_tys = dataConRepArgTys dc
     tycon       = dataConTyCon dc
 
-buildPArrayTyCon :: Name -> TyCon -> VM TyCon
-buildPArrayTyCon orig_name vect_tc = fixV $ \repr_tc ->
+buildPArrayTyCon :: TyCon -> TyCon -> VM TyCon
+buildPArrayTyCon orig_tc vect_tc = fixV $ \repr_tc ->
   do
     name'  <- cloneName mkPArrayTyConOcc orig_name
     parent <- buildPArrayParentInfo orig_name vect_tc repr_tc
@@ -185,6 +191,7 @@ buildPArrayTyCon orig_name vect_tc = fixV $ \repr_tc ->
                         False           -- FIXME: no generics
                         False           -- not GADT syntax
   where
+    orig_name = tyConName orig_tc
     name   = tyConName vect_tc
     kind   = tyConKind vect_tc
     tyvars = tyConTyVars vect_tc
@@ -195,7 +202,7 @@ buildPArrayParentInfo :: Name -> TyCon -> TyCon -> VM TyConParent
 buildPArrayParentInfo orig_name vect_tc repr_tc
   = do
       parray_tc <- builtin parrayTyCon
-      co_name <- cloneName mkInstTyCoOcc orig_name
+      co_name <- cloneName mkInstTyCoOcc (tyConName repr_tc)
 
       let inst_tys = [mkTyConApp vect_tc (map mkTyVarTy tyvars)]