Arity analysis and exprOkForSpeculation
Currently, arity analysis effictively says that every scrutinee that is ok-for-spec is also cheap to duplicate. E.g.,
f :: Double -> Double -> Double
f n = case sqrt n of
0 -> \x -> x
_ -> \x -> 2*x
We will happily eta-expand over sqrt n
to to make f
have arity 2. Undoubtedly that has a heavy performance if f
is called often!
It appears we want a predicate "expr is cheap but non-bottom" in arity analysis, or perhaps have exprIsCheap
be configurable by whether or not bottom should be considered cheap. Then we can instantiate it according to -fpedantic-bottoms
.
The ultimate goal of mine is that we bring some sanity to all these exprIs*
ops. E.g., "expr is cheap but non-bottom" entails ok-for-spec, so that we have a sane model for arity analysis to operate on.
Then "expr is cheap but possibly bottom" means we can defer and duplicate the computation, but not speculate it (e.g., execute early), whereas the non-bottom version also means we may speculate it. ok-for-spec identifies expressions we may defer or speculate but not necessarily duplicate. That makes three operations we can characterise appropriately.