[project @ 2001-09-07 12:42:46 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / IdInfo.lhs
index 24dfce3..36fef2f 100644 (file)
@@ -97,8 +97,8 @@ import FieldLabel     ( FieldLabel )
 import Type            ( usOnce, usMany )
 import Demand          hiding( Demand )
 import qualified Demand
-import NewDemand       ( Demand(..), Keepity(..), Deferredness(..), DmdResult(..),
-                         lazyDmd, topDmd,
+import NewDemand       ( Demand(..), Keepity(..), DmdResult(..),
+                         lazyDmd, topDmd, dmdTypeDepth,
                          StrictSig, mkStrictSig, mkTopDmdType
                        )
 import Outputable      
@@ -134,15 +134,22 @@ To be removed later
 
 \begin{code}
 mkNewStrictnessInfo :: Id -> Arity -> Demand.StrictnessInfo -> CprInfo -> StrictSig
-mkNewStrictnessInfo id arity Demand.NoStrictnessInfo cpr
-  = mkStrictSig id arity $
-    mkTopDmdType (replicate arity lazyDmd) (newRes False cpr)
-
 mkNewStrictnessInfo id arity (Demand.StrictnessInfo ds res) cpr
-  = mkStrictSig id arity $
-    mkTopDmdType (take arity (map newDemand ds)) (newRes res cpr)
+  | length ds <= arity
        -- Sometimes the old strictness analyser has more
        -- demands than the arity justifies
+  = mk_strict_sig id arity $
+    mkTopDmdType (map newDemand ds) (newRes res cpr)
+
+mkNewStrictnessInfo id arity other cpr
+  =    -- Either no strictness info, or arity is too small
+       -- In either case we can't say anything useful
+    mk_strict_sig id arity $
+    mkTopDmdType (replicate arity lazyDmd) (newRes False cpr)
+
+mk_strict_sig id arity dmd_ty
+  = WARN( arity /= dmdTypeDepth dmd_ty, ppr id <+> (ppr arity $$ ppr dmd_ty) )
+    mkStrictSig dmd_ty
 
 newRes True  _                 = BotRes
 newRes False ReturnsCPR = RetCPR
@@ -152,18 +159,18 @@ newDemand :: Demand.Demand -> NewDemand.Demand
 newDemand (WwLazy True)      = Abs
 newDemand (WwLazy False)     = Lazy
 newDemand WwStrict          = Eval
-newDemand (WwUnpack unpk ds) = Seq Drop Now (map newDemand ds)
+newDemand (WwUnpack unpk ds) = Seq Drop (map newDemand ds)
 newDemand WwPrim            = Lazy
 newDemand WwEnum            = Eval
 
 oldDemand :: NewDemand.Demand -> Demand.Demand
-oldDemand Abs         = WwLazy True
-oldDemand Lazy        = WwLazy False
-oldDemand Bot         = WwStrict
-oldDemand Err         = WwStrict
-oldDemand Eval        = WwStrict
-oldDemand (Seq _ _ ds) = WwUnpack True (map oldDemand ds)
-oldDemand (Call _)     = WwStrict
+oldDemand Abs       = WwLazy True
+oldDemand Lazy      = WwLazy False
+oldDemand Bot       = WwStrict
+oldDemand Err       = WwStrict
+oldDemand Eval      = WwStrict
+oldDemand (Seq _ ds) = WwUnpack True (map oldDemand ds)
+oldDemand (Call _)   = WwStrict
 \end{code}