[project @ 2002-11-22 06:54:05 by matthewc]
[ghc-hetmet.git] / ghc / compiler / stranal / DmdAnal.lhs
index c42099d..e02bf5e 100644 (file)
@@ -23,12 +23,12 @@ import TyCon                ( isProductTyCon, isRecursiveTyCon )
 import Id              ( Id, idType, idInlinePragma,
                          isDataConId, isGlobalId, idArity,
 #ifdef OLD_STRICTNESS
-                         idDemandInfo,  idStrictness, idCprInfo,
+                         idDemandInfo,  idStrictness, idCprInfo, idName,
 #endif
                          idNewStrictness, idNewStrictness_maybe,
                          setIdNewStrictness, idNewDemandInfo,
                          idNewDemandInfo_maybe,
-                         setIdNewDemandInfo, idName 
+                         setIdNewDemandInfo
                        )
 #ifdef OLD_STRICTNESS
 import IdInfo          ( newStrictnessFromOld, newDemand )
@@ -270,18 +270,18 @@ dmdAnal sigs dmd (Let (NonRec id rhs) body)
        (body_ty1, id2)               = annotateBndr body_ty id1
        body_ty2                      = addLazyFVs body_ty1 lazy_fv
     in
-#ifdef DEBUG
-       -- If the actual demand is better than the vanilla
-       -- demand, we might do better to re-analyse with the
-       -- stronger demand.
-    (let vanilla_dmd = vanillaCall (idArity id)
-        actual_dmd  = idNewDemandInfo id2
-     in
-     if actual_dmd `betterDemand` vanilla_dmd && actual_dmd /= vanilla_dmd then
-       pprTrace "dmdLet: better demand" (ppr id <+> vcat [text "vanilla" <+> ppr vanilla_dmd,
-                                                          text "actual" <+> ppr actual_dmd])
-     else \x -> x)
-#endif
+       -- If the actual demand is better than the vanilla call
+       -- demand, you might think that we might do better to re-analyse 
+       -- the RHS with the stronger demand.
+       -- But (a) That seldom happens, because it means that *every* path in 
+       --         the body of the let has to use that stronger demand
+       -- (b) It often happens temporarily in when fixpointing, because
+       --     the recursive function at first seems to place a massive demand.
+       --     But we don't want to go to extra work when the function will
+       --     probably iterate to something less demanding.  
+       -- In practice, all the times the actual demand on id2 is more than
+       -- the vanilla call demand seem to be due to (b).  So we don't
+       -- bother to re-analyse the RHS.
     (body_ty2, Let (NonRec id2 rhs') body')    
 
 dmdAnal sigs dmd (Let (Rec pairs) body) 
@@ -487,11 +487,10 @@ We can't start with 'not-demanded' because then consider
 
 In the first iteration we'd have no demand info for x, so assume
 not-demanded; then we'd get TopRes for f's CPR info.  Next iteration
-we'd see that t was demanded, and so give it the CPR property, but
-by now f has TopRes, so it will stay TopRes.  
-ever_in
-Instead, with the Nothing setting the first time round, we say
-'yes t is demanded' the first time.  
+we'd see that t was demanded, and so give it the CPR property, but by
+now f has TopRes, so it will stay TopRes.  Instead, with the Nothing
+setting the first time round, we say 'yes t is demanded' the first
+time.
 
 However, this does mean that for non-recursive bindings we must
 iterate twice to be sure of not getting over-optimistic CPR info,
@@ -729,10 +728,15 @@ extendSigEnvList = extendVarEnvList
 
 extendSigsWithLam :: SigEnv -> Id -> SigEnv
 -- Extend the SigEnv when we meet a lambda binder
---  If the binder is marked demanded with a product demand, then give it a CPR 
+-- If the binder is marked demanded with a product demand, then give it a CPR 
 -- signature, because in the likely event that this is a lambda on a fn defn 
 -- [we only use this when the lambda is being consumed with a call demand],
--- it'll be w/w'd and so it will be CPR-ish.
+-- it'll be w/w'd and so it will be CPR-ish.  E.g.
+--     f = \x::(Int,Int).  if ...strict in x... then
+--                             x
+--                         else
+--                             (a,b)
+-- We want f to have the CPR property because x does, by the time f has been w/w'd
 --
 --     NOTE: see notes [CPR-AND-STRICTNESS]
 --
@@ -853,7 +857,7 @@ argDemand (Defer d) = lazyDmd
 argDemand (Eval ds) = Eval (mapDmds argDemand ds)
 argDemand (Box Bot) = evalDmd
 argDemand (Box d)   = box (argDemand d)
-argDemand Bot      = Abs       -- Don't pass args that are consumed by bottom/err
+argDemand Bot      = Abs       -- Don't pass args that are consumed (only) by bottom
 argDemand d        = d
 \end{code}