CprAnal: Record evaluatedness of result fields
CPR analysis already gathers this information, since it is needed for nested CPR. Recording this information would allow the simplifier to use it to drop redundant evals around call sites. (It would also make the special case for seq#
added for the same reasons in #15226 (closed) not special anymore.)
With !9874 this evaluatedness information will help case-of-known-constructor and the like create fewer redundant evals.
We probably eventually want to use these field-evaluatedness-signatures to improve the evaluatedness detection in CPR analysis, to catch recursive functions like this:
f :: Integer -> Bool -> (Integer, Integer)
f !x True = (expensive x, x)
f x False = case f (x `quot` 2) (even x) of (p, q) -> (p + 1, q)
-- $wf :: Integer -> Bool -> (# Integer, Integer #)
The second field of f
's result is always evaluated, but an induction argument is required to prove it. Tag inference can already detect that the second component of $wf
's result will be evaluated and properly tagged, so in order to replace the tag inference analysis with worker/wrapper as suggested in #23890 our result-component-evaluatedness analysis in Core must catch this, too.