-\subsection{Functions over Demands}
-%* *
-%************************************************************************
-
-\begin{code}
-mAX_WORKER_ARGS :: Int -- ToDo: set via flag
-mAX_WORKER_ARGS = 6
-
-setUnpackStrategy :: [Demand] -> [Demand]
-setUnpackStrategy ds
- = snd (go (mAX_WORKER_ARGS - nonAbsentArgs ds) ds)
- where
- go :: Int -- Max number of args available for sub-components of [Demand]
- -> [Demand]
- -> (Int, [Demand]) -- Args remaining after subcomponents of [Demand] are unpacked
-
- go n (WwUnpack nd _ cs : ds) | n' >= 0
- = WwUnpack nd True cs' `cons` go n'' ds
- | otherwise
- = WwUnpack nd False cs `cons` go n ds
- where
- n' = n + 1 - nonAbsentArgs cs
- -- Add one because we don't pass the top-level arg any more
- -- Delete # of non-absent args to which we'll now be committed
- (n'',cs') = go n' cs
-
- go n (d:ds) = d `cons` go n ds
- go n [] = (n,[])
-
- cons d (n,ds) = (n, d:ds)
-
-nonAbsentArgs :: [Demand] -> Int
-nonAbsentArgs [] = 0
-nonAbsentArgs (WwLazy True : ds) = nonAbsentArgs ds
-nonAbsentArgs (d : ds) = 1 + nonAbsentArgs ds
-
-worthSplitting :: [Demand]
- -> Bool -- Result is bottom
- -> Bool -- True <=> the wrapper would not be an identity function
-worthSplitting ds result_bot = any worth_it ds
- -- We used not to split if the result is bottom.
- -- [Justification: there's no efficiency to be gained.]
- -- But it's sometimes bad not to make a wrapper. Consider
- -- fw = \x# -> let x = I# x# in case e of
- -- p1 -> error_fn x
- -- p2 -> error_fn x
- -- p3 -> the real stuff
- -- The re-boxing code won't go away unless error_fn gets a wrapper too.
-
- where
- worth_it (WwLazy True) = True -- Absent arg
- worth_it (WwUnpack _ True _) = True -- Arg to unpack
- worth_it WwStrict = False -- Don't w/w just because of strictness
- worth_it other = False
-
-allAbsent :: [Demand] -> Bool
-allAbsent ds = all absent ds
- where
- absent (WwLazy is_absent) = is_absent
- absent (WwUnpack _ True cs) = allAbsent cs
- absent other = False
-\end{code}
-
-
-%************************************************************************
-%* *