[project @ 2001-06-04 16:49:15 by simonpj]
authorsimonpj <unknown>
Mon, 4 Jun 2001 16:49:15 +0000 (16:49 +0000)
committersimonpj <unknown>
Mon, 4 Jun 2001 16:49:15 +0000 (16:49 +0000)
----------------------------------
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.

ghc/compiler/coreSyn/CoreUtils.lhs

index e16847f..f7130eb 100644 (file)
@@ -791,13 +791,15 @@ And in any case it seems more robust to have exprArity be a bit more intelligent
 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}