[project @ 2006-01-06 16:30:17 by simonmar]
[ghc-hetmet.git] / ghc / compiler / ndpFlatten / FlattenMonad.hs
index 4bca818..4540508 100644 (file)
@@ -67,8 +67,7 @@ import Monad      (mplus)
 import Panic        (panic)
 import Outputable   (Outputable(ppr), pprPanic)
 import UniqSupply   (UniqSupply, splitUniqSupply, uniqFromSupply)
-import OccName     (UserFS)
-import Var          (Var(..))
+import Var          (Var, idType)
 import Id          (Id, mkSysLocal)
 import Name        (Name)
 import VarSet       (VarSet, emptyVarSet, extendVarSet, varSetElems )
@@ -86,6 +85,7 @@ import PrimOp     ( PrimOp(..) )
 import PrelInfo            ( primOpId )
 import CoreSyn      (Expr(..), Bind(..), CoreBndr, CoreExpr, CoreBind, mkApps)
 import CoreUtils    (exprType)
+import FastString   (FastString)
 
 -- friends
 import NDPCoreUtils (parrElemTy)
@@ -176,7 +176,7 @@ runFlatten hsc_env eps us m
 -- generate a new local variable whose name is based on the given lexeme and
 -- whose type is as specified in the second argument (EXPORTED)
 --
-newVar           :: UserFS -> Type -> Flatten Var
+newVar           :: FastString -> Type -> Flatten Var
 newVar lexeme ty  = Flatten $ \state ->
   let
     (us1, us2) = splitUniqSupply (us state)
@@ -187,7 +187,7 @@ newVar lexeme ty  = Flatten $ \state ->
 -- generate a non-recursive binding using a new binder whose name is derived
 -- from the given lexeme (EXPORTED)
 --
-mkBind          :: UserFS -> CoreExpr -> Flatten (CoreBndr, CoreBind)
+mkBind          :: FastString -> CoreExpr -> Flatten (CoreBndr, CoreBind)
 mkBind lexeme e  =
   do
     v <- newVar lexeme (exprType e)
@@ -199,18 +199,18 @@ mkBind lexeme e  =
 
 -- extend the parallel context by the given set of variables (EXPORTED)
 --
--- * if there is no parallel context at the moment, the first element of the
+--  * if there is no parallel context at the moment, the first element of the
 --   variable list will be used to determine the new parallel context
 --
--- * the second argument is executed in the current context extended with the
+--  * the second argument is executed in the current context extended with the
 --   given variables
 --
--- * the variables must already have been lifted by transforming their type,
+--  * the variables must already have been lifted by transforming their type,
 --   but they *must* have retained their original name (or, at least, their
 --   unique); this is needed so that they match the original variable in
 --   variable environments
 --
--- * any trace of the given set of variables has to be removed from the state
+--  * any trace of the given set of variables has to be removed from the state
 --   at the end of this operation
 --
 extendContext      :: [Var] -> Flatten a -> Flatten a
@@ -232,12 +232,12 @@ extendContext vs m  = Flatten $ \state ->
 
 -- execute the second argument in a restricted context (EXPORTED)
 --
--- * all variables in the current parallel context are packed according to
+--  * all variables in the current parallel context are packed according to
 --   the permutation vector associated with the variable passed as the first
 --   argument (ie, all elements of vectorised context variables that are
 --   invalid in the restricted context are dropped)
 --
--- * the returned list of core binders contains the operations that perform
+--  * the returned list of core binders contains the operations that perform
 --   the restriction on all variables in the parallel context that *do* occur
 --   during the execution of the second argument (ie, `liftVar' is executed at
 --   least once on any such variable)
@@ -267,14 +267,14 @@ packContext perm m  = Flatten $ \state ->
     (r, packedState') = unFlatten m packedState
     resState         = state {    -- revert to the unpacked context
                          ctxtVar  = ctxtVar state,
-                         ctxtEnv  = ctxtEnv state,
+                         ctxtEnv  = ctxtEnv state
                        }
     bndrs            = map mkCoreBind . varSetElems . usedVars $ packedState'
 
     -- generate a binding for the packed variant of a context variable
     --
     mkCoreBind var    = let
-                         rhs = fst $ unFlatten (mk'bpermuteP (varType var) 
+                         rhs = fst $ unFlatten (mk'bpermuteP (idType var) 
                                                              (Var perm) 
                                                              (Var var)
                                                ) state
@@ -286,14 +286,14 @@ packContext perm m  = Flatten $ \state ->
 
 -- lift a single variable in the current context (EXPORTED)
 --
--- * if the variable does not occur in the context, it's value is vectorised to
+--  * if the variable does not occur in the context, it's value is vectorised to
 --   match the size of the current context
 --
--- * otherwise, the variable is replaced by whatever the context environment
+--  * otherwise, the variable is replaced by whatever the context environment
 --   maps it to (this may either be simply the lifted version of the original
 --   variable or a packed variant of that variable)
 --
--- * the monad keeps track of all lifted variables that occur in the parallel
+--  * the monad keeps track of all lifted variables that occur in the parallel
 --   context, so that `packContext' can determine the correct set of core
 --   bindings
 --
@@ -301,9 +301,9 @@ liftVar     :: Var -> Flatten CoreExpr
 liftVar var  = Flatten $ \s ->
   let 
     v          = ctxtVarErr s
-    v'elemType = parrElemTy . varType $ v
+    v'elemType = parrElemTy . idType $ v
     len        = fst $ unFlatten (mk'lengthP v'elemType (Var v)) s
-    replicated = fst $ unFlatten (mk'replicateP (varType var) len (Var var)) s
+    replicated = fst $ unFlatten (mk'replicateP (idType var) len (Var var)) s
   in case lookupVarEnv (ctxtEnv s) var of
     Just liftedVar -> (Var liftedVar, 
                       s {usedVars = usedVars s `extendVarSet` var})
@@ -311,14 +311,14 @@ liftVar var  = Flatten $ \s ->
 
 -- lift a constant expression in the current context (EXPORTED)
 --
--- * the value of the constant expression is vectorised to match the current
+--  * the value of the constant expression is vectorised to match the current
 --   parallel context
 --
 liftConst   :: CoreExpr -> Flatten CoreExpr
 liftConst e  = Flatten $ \s ->
   let
      v          = ctxtVarErr s
-     v'elemType = parrElemTy . varType $ v
+     v'elemType = parrElemTy . idType $ v
      len        = fst $ unFlatten (mk'lengthP v'elemType (Var v)) s
   in 
   (fst $ unFlatten (mk'replicateP (exprType e) len e ) s, s)
@@ -326,7 +326,7 @@ liftConst e  = Flatten $ \s ->
 -- pick those variables of the given set that occur (if albeit in lifted form)
 -- in the current parallel context (EXPORTED)
 --
--- * the variables returned are from the given set and *not* the corresponding
+--  * the variables returned are from the given set and *not* the corresponding
 --   context variables
 --
 intersectWithContext    :: VarSet -> Flatten [Var]
@@ -382,10 +382,10 @@ mk'neq ty a1 a2  = return (mkApps (Var neqName) [a1, a2])
                   where
                     tc = tyConAppTyCon ty
                     --
-                    neqName {- | name == charPrimTyConName   = neqCharName -}
+                    neqName {-  | name == charPrimTyConName   = neqCharName -}
                             | tc == intPrimTyCon             = primOpId IntNeOp
-                            {- | name == floatPrimTyConName  = neqFloatName -}
-                            {- | name == doublePrimTyConName = neqDoubleName -}
+                            {-  | name == floatPrimTyConName  = neqFloatName -}
+                            {-  | name == doublePrimTyConName = neqDoubleName -}
                             | otherwise                   =
                               pprPanic "FlattenMonad.mk'neq: " (ppr ty)
 
@@ -428,8 +428,7 @@ mk'indexOfP ty a1 a2  = mkFunApp indexOfPName [Type ty, a1, a2]
 --
 ctxtVarErr   :: FlattenState -> Var
 ctxtVarErr s  = case ctxtVar s of
-                 Nothing -> panic "FlattenMonad.ctxtVarErr: No context \
-                                  \variable available!"
+                 Nothing -> panic "FlattenMonad.ctxtVarErr: No context variable available!"
                  Just v  -> v
 
 -- given the name of a known function and a set of arguments (needs to include
@@ -444,7 +443,7 @@ mkFunApp name args  =
 
 -- get the `Id' of a known `Name'
 --
--- * this can be the `Name' of any function that's visible on the toplevel of
+--  * this can be the `Name' of any function that's visible on the toplevel of
 --   the current compilation unit
 --
 lookupName      :: Name -> Flatten Id