Repository : ssh://darcs.haskell.org//srv/darcs/ghc On branch : cardinality
http://hackage.haskell.org/trac/ghc/changeset/50ac991d208c366b5d654a646d756136de88d171 >--------------------------------------------------------------- commit 50ac991d208c366b5d654a646d756136de88d171 Author: Ilya Sergey <[email protected]> Date: Mon Sep 24 13:56:18 2012 +0100 more changes in the analyzer documented >--------------------------------------------------------------- compiler/stranal/DmdAnal.lhs | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/compiler/stranal/DmdAnal.lhs b/compiler/stranal/DmdAnal.lhs index 6eb1970..8b295bd 100644 --- a/compiler/stranal/DmdAnal.lhs +++ b/compiler/stranal/DmdAnal.lhs @@ -79,6 +79,7 @@ dmdAnalTopBind sigs (Rec pairs) -- We get two iterations automatically -- c.f. the NonRec case above +-- See Note [Analysing lambdas at right-hand side] data RhsFlag = MayBeRhsLambda | MereExpr \end{code} @@ -184,8 +185,6 @@ dmdAnal rhs_flag env dmd (Lam var body) (lam_ty, Lam var' body') | Just (body_dmd, Many) <- peelCallDmd dmd - -- A call demand, also a one-shot lambda - -- see Note [Analyzing with lazy demand and lambdas] = let env' = extendSigsWithLam env var (body_ty, body') = dmdAnal MereExpr env' body_dmd body @@ -342,6 +341,36 @@ dmdAnalAlt env dmd (con,bndrs,rhs) \end{code} +Note [Analysing lambdas at right-hand side] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +It is safe to analyze a lambda-expression on a right-hand-side of a +let-binding with a usage demand C1(C1...(U)), where the number of C1s +is the same as "visible" arity of the right-hand side. However, this +poses a problem when markin lambda s on-shot. Indeed, both these lambdas: + +let g = \x -> x + 1 in ... + +and + +(\x -> x + 1) 5 + +will be marked as "one-shot", whereas only the latter one is. A +let-bound lambda can be, of course, invoked multiple times, and we +cannot state it to be on-shot just lookting at the definition +site. Therefore, we pass an extra flag to the analysis: + +data RhsFlag = MayBeRhsLambda | MereExpr + +in order to ditinguish, if the currently analyzed expression is a +(possibly nested) lambda, located *immediately* at RHS of som binding +(then the one-shot annotation is not assigned) or just an arbitrary +lambda expression somewhere, e.g. + +build g = g (:) [] +build (\x y -> x () y) -- this lambda is one-shot + + Note [Analyzing with lazy demand and lambdas] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
