2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[Demand]{@Demand@: the amount of demand on a value}
8 Demand(..), Keepity(..), topDmd,
9 StrictSig(..), topSig, botSig, mkStrictSig,
10 DmdType(..), topDmdType, mkDmdFun,
14 #include "HsVersions.h"
16 import BasicTypes ( Arity )
17 import qualified Demand
22 %************************************************************************
24 \subsection{Strictness signatures
26 %************************************************************************
29 data StrictSig = StrictSig Arity DmdType
31 -- Equality needed when comparing strictness
32 -- signatures for fixpoint finding
34 topSig = StrictSig 0 topDmdType
35 botSig = StrictSig 0 botDmdType
37 mkStrictSig :: Arity -> DmdType -> StrictSig
39 = WARN( arity /= dmdTypeDepth ty, ppr arity $$ ppr ty )
42 instance Outputable StrictSig where
43 ppr (StrictSig arity ty) = ppr ty
47 %************************************************************************
49 \subsection{Demand types}
51 %************************************************************************
54 data DmdType = DmdRes Result | DmdFun Demand DmdType
56 -- Equality needed for fixpoints in DmdAnal
58 data Result = TopRes -- Nothing known
59 | RetCPR -- Returns a constructed product
60 | BotRes -- Diverges or errors
62 -- Equality needed for fixpoints in DmdAnal
64 instance Outputable DmdType where
65 ppr (DmdRes TopRes) = char 'T'
66 ppr (DmdRes RetCPR) = char 'M'
67 ppr (DmdRes BotRes) = char 'X'
68 ppr (DmdFun d r) = ppr d <> ppr r
70 topDmdType = DmdRes TopRes
71 botDmdType = DmdRes BotRes
73 mkDmdFun :: [Demand] -> Result -> DmdType
74 mkDmdFun ds res = foldr DmdFun (DmdRes res) ds
76 dmdTypeDepth :: DmdType -> Arity
77 dmdTypeDepth (DmdFun _ ty) = 1 + dmdTypeDepth ty
78 dmdTypeDepth (DmdRes _) = 0
82 %************************************************************************
86 %************************************************************************
90 = Lazy -- L; used for unlifted types too, so that
95 | Seq Keepity -- S/U(ds)
100 -- Equality needed for fixpoints in DmdAnal
102 data Keepity = Keep | Drop
105 topDmd :: Demand -- The most uninformative demand
108 instance Outputable Demand where
114 ppr (Call d) = char 'C' <> parens (ppr d)
115 ppr (Seq k ds) = ppr k <> parens (hcat (map ppr ds))
117 instance Outputable Keepity where