Fix CodingStyle#Warnings URLs
[ghc-hetmet.git] / compiler / vectorise / VectUtils.hs
index b9c4597..83b482a 100644 (file)
@@ -1,8 +1,14 @@
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 module VectUtils (
   collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg,
   collectAnnValBinders,
-  mkDataConTag,
-  splitClosureTy,
+  mkDataConTag, mkDataConTagLit,
 
   mkBuiltinCo,
   mkPADictType, mkPArrayType, mkPReprType,
@@ -38,6 +44,7 @@ import PrelNames
 import TysWiredIn
 import TysPrim            ( intPrimTy )
 import BasicTypes         ( Boxity(..) )
+import Literal            ( Literal, mkMachInt )
 
 import Outputable
 import FastString
@@ -67,38 +74,12 @@ isAnnTypeArg :: AnnExpr b ann -> Bool
 isAnnTypeArg (_, AnnType t) = True
 isAnnTypeArg _              = False
 
-mkDataConTag :: DataCon -> CoreExpr
-mkDataConTag dc = mkConApp intDataCon [mkIntLitInt $ dataConTag dc]
-
-splitUnTy :: String -> Name -> Type -> Type
-splitUnTy s name ty
-  | Just (tc, [ty']) <- splitTyConApp_maybe ty
-  , tyConName tc == name
-  = ty'
-
-  | otherwise = pprPanic s (ppr ty)
-
-splitBinTy :: String -> Name -> Type -> (Type, Type)
-splitBinTy s name ty
-  | Just (tc, [ty1, ty2]) <- splitTyConApp_maybe ty
-  , tyConName tc == name
-  = (ty1, ty2)
-
-  | otherwise = pprPanic s (ppr ty)
+mkDataConTagLit :: DataCon -> Literal
+mkDataConTagLit con
+  = mkMachInt . toInteger $ dataConTag con - fIRST_TAG
 
-splitFixedTyConApp :: TyCon -> Type -> [Type]
-splitFixedTyConApp tc ty
-  | Just (tc', tys) <- splitTyConApp_maybe ty
-  , tc == tc'
-  = tys
-
-  | otherwise = pprPanic "splitFixedTyConApp" (ppr tc <+> ppr ty)
-
-splitClosureTy :: Type -> (Type, Type)
-splitClosureTy = splitBinTy "splitClosureTy" closureTyConName
-
-splitPArrayTy :: Type -> Type
-splitPArrayTy = splitUnTy "splitPArrayTy" parrayTyConName
+mkDataConTag :: DataCon -> CoreExpr
+mkDataConTag con = mkIntLitInt (dataConTag con - fIRST_TAG)
 
 splitPrimTyCon :: Type -> Maybe TyCon
 splitPrimTyCon ty
@@ -262,10 +243,8 @@ mkPR ty
       dict <- paDictOfType ty
       return $ mkApps (Var fn) [Type ty, dict]
 
-lengthPA :: CoreExpr -> VM CoreExpr
-lengthPA x = liftM (`App` x) (paMethod pa_length ty)
-  where
-    ty = splitPArrayTy (exprType x)
+lengthPA :: Type -> CoreExpr -> VM CoreExpr
+lengthPA ty x = liftM (`App` x) (paMethod pa_length ty)
 
 replicatePA :: CoreExpr -> CoreExpr -> VM CoreExpr
 replicatePA len x = liftM (`mkApps` [len,x])
@@ -359,15 +338,13 @@ mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv)
       return (Var mkv `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, venv],
               Var mkl `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, lenv])
 
-mkClosureApp :: VExpr -> VExpr -> VM VExpr
-mkClosureApp (vclo, lclo) (varg, larg)
+mkClosureApp :: Type -> Type -> VExpr -> VExpr -> VM VExpr
+mkClosureApp arg_ty res_ty (vclo, lclo) (varg, larg)
   = do
       vapply <- builtin applyClosureVar
       lapply <- builtin applyClosurePVar
       return (Var vapply `mkTyApps` [arg_ty, res_ty] `mkApps` [vclo, varg],
               Var lapply `mkTyApps` [arg_ty, res_ty] `mkApps` [lclo, larg])
-  where
-    (arg_ty, res_ty) = splitClosureTy (exprType vclo)
 
 buildClosures :: [TyVar] -> [VVar] -> [Type] -> Type -> VM VExpr -> VM VExpr
 buildClosures tvs vars [] res_ty mk_body
@@ -436,7 +413,7 @@ mkLiftEnv :: Var -> [Type] -> [Var] -> VM (CoreExpr, CoreExpr -> CoreExpr -> VM
 mkLiftEnv lc [ty] [v]
   = return (Var v, \env body ->
                    do
-                     len <- lengthPA (Var v)
+                     len <- lengthPA ty (Var v)
                      return . Let (NonRec v env)
                             $ Case len lc (exprType body) [(DEFAULT, [], body)])