[project @ 2004-12-22 12:06:13 by simonpj]
[ghc-hetmet.git] / ghc / compiler / cprAnalysis / CprAnalyse.lhs
index 5ae0851..a41e62f 100644 (file)
@@ -2,16 +2,21 @@
 constructed product result}
 
 \begin{code}
+#ifndef OLD_STRICTNESS
+module CprAnalyse ( ) where
+
+#else
+
 module CprAnalyse ( cprAnalyse ) where
 
 #include "HsVersions.h"
 
-import CmdLineOpts     ( opt_D_verbose_core2core, opt_D_dump_cpranal )
-import CoreLint                ( beginPass, endPass )
+import CmdLineOpts     ( DynFlags, DynFlag(..) )
+import CoreLint                ( showPass, endPass )
 import CoreSyn
 import CoreUtils       ( exprIsValue )
 import Id               ( Id, setIdCprInfo, idCprInfo, idArity,
-                         isBottomingId, idDemandInfo )
+                         isBottomingId, idDemandInfo, isImplicitId )
 import IdInfo           ( CprInfo(..) )
 import Demand          ( isStrict )
 import VarEnv
@@ -91,10 +96,6 @@ data AbsVal = Top                -- Not a constructed product
                                  -- we could use appropriate Tuple Vals
      deriving (Eq,Show)
 
-isFun :: AbsVal -> Bool
-isFun (Fun _) = True
-isFun _       = False
-
 -- For pretty debugging
 instance Outputable AbsVal where
   ppr Top      = ptext SLIT("Top")
@@ -134,15 +135,13 @@ ids decorated with their CprInfo pragmas.
 
 \begin{code}
 
-cprAnalyse :: [CoreBind] 
-                -> IO [CoreBind]
-cprAnalyse binds
+cprAnalyse :: DynFlags -> [CoreBind] -> IO [CoreBind]
+cprAnalyse dflags binds
   = do {
-       beginPass "Constructed Product analysis" ;
+       showPass dflags "Constructed Product analysis" ;
        let { binds_plus_cpr = do_prog binds } ;
-       endPass "Constructed Product analysis" 
-               (opt_D_dump_cpranal || opt_D_verbose_core2core)
-               binds_plus_cpr
+       endPass dflags "Constructed Product analysis" 
+               Opt_D_dump_cpranal binds_plus_cpr
     }
   where
     do_prog :: [CoreBind] -> [CoreBind]
@@ -157,6 +156,9 @@ with ids decorated with their CPR info.
 -- Return environment extended with info from this binding 
 cprAnalBind :: CPREnv -> CoreBind -> (CPREnv, CoreBind)
 cprAnalBind rho (NonRec b e) 
+  | isImplicitId b     -- Don't touch the CPR info on constructors, selectors etc
+  = (rho, NonRec b e)  
+  | otherwise
   = (extendVarEnv rho b absval, NonRec b' e')
   where
     (e', absval) = cprAnalExpr rho e
@@ -250,11 +252,11 @@ cprAnalExpr rho (Type t)
 
 cprAnalCaseAlts :: CPREnv -> [CoreAlt] -> ([CoreAlt], AbsVal)
 cprAnalCaseAlts rho alts
-    = foldl anal_alt ([], Bot) alts
+    = foldr anal_alt ([], Bot) alts
       where 
-      anal_alt :: ([CoreAlt], AbsVal) -> CoreAlt -> ([CoreAlt], AbsVal)
-      anal_alt (done, aval) (con, binds, exp) 
-         = (done ++ [(con,binds,exp_cpr)], aval `lub` exp_aval)
+      anal_alt :: CoreAlt -> ([CoreAlt], AbsVal) -> ([CoreAlt], AbsVal)
+      anal_alt (con, binds, exp)  (done, aval)
+         = ((con,binds,exp_cpr) : done, exp_aval `lub` aval)
            where (exp_cpr, exp_aval) = cprAnalExpr rho' exp
                  rho' = rho `extendVarEnvList` (zip binds (repeat Top))
 
@@ -309,4 +311,5 @@ getCprAbsVal v = case idCprInfo v of
                 arity = idArity v
        -- Imported (non-nullary) constructors will have the CPR property
        -- in their IdInfo, so no need to look at their unfolding
+#endif /* OLD_STRICTNESS */
 \end{code}