----------------------------------
Make exprArity give the right answer
----------------------------------
MERGE INTO 5.00.2
This fixes a fairly long-standing bug in exprArity, dating from
the time we allowed arguments to be non-atoms. If f had arity
2, it was saying that
f (factorial x)
had arity 2, as well, which is plain wrong.
exprArity :: CoreExpr -> Int
exprArity e = go e `max` 0
where
- go (Lam x e) | isId x = go e + 1
- | otherwise = go e
- go (Note _ e) = go e
- go (App e (Type t)) = go e
- go (App f a) = go f - 1
- go (Var v) = idArity v
- go _ = 0
+ go (Lam x e) | isId x = go e + 1
+ | otherwise = go e
+ go (Note _ e) = go e
+ go (App e (Type t)) = go e
+ go (App f a) | exprIsCheap a = go f - 1
+ -- Important! f (fac x) does not have arity 2,
+ -- even if f does!
+ go (Var v) = idArity v
+ go _ = 0
\end{code}