From 98a74c9da8b10a3ba8fa2c261c2e26970c56a811 Mon Sep 17 00:00:00 2001 From: simonpj Date: Fri, 20 Jul 2001 10:05:37 +0000 Subject: [PATCH] [project @ 2001-07-20 10:05:37 by simonpj] -------------------------- Correct a bug in exprArity -------------------------- This long-standing bug meant that exprArity gave over-pessimistic answers. e.g. \x -> f x where nothing is known about f. We were getting 0 (for f) -1 (for the argument) +1 (for the lambda) ----- 0 The right answer is of course 1. --- ghc/compiler/coreSyn/CoreUtils.lhs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ghc/compiler/coreSyn/CoreUtils.lhs b/ghc/compiler/coreSyn/CoreUtils.lhs index bea8316..d483b82 100644 --- a/ghc/compiler/coreSyn/CoreUtils.lhs +++ b/ghc/compiler/coreSyn/CoreUtils.lhs @@ -790,15 +790,17 @@ And in any case it seems more robust to have exprArity be a bit more intelligent \begin{code} exprArity :: CoreExpr -> Int -exprArity e = go e `max` 0 +exprArity e = go e 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) | exprIsCheap a = go f - 1 + go (App f a) | exprIsCheap a = (go f - 1) `max` 0 -- Important! f (fac x) does not have arity 2, -- even if f does! + -- NB: `max 0`! (\x y -> f x) has arity 2, even if f is + -- unknown, hence arity 0 go (Var v) = idArity v go _ = 0 \end{code} -- 1.7.10.4