[commit: ghc] wip/T7994-calledArity: Some very prelimary explanations (0a3dacc)
git at git.haskell.org
git at git.haskell.org
Wed Jan 29 15:17:53 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/T7994-calledArity
Link : http://ghc.haskell.org/trac/ghc/changeset/0a3dacc3d19261e9d769313e6d215cb09897bd2f/ghc
>---------------------------------------------------------------
commit 0a3dacc3d19261e9d769313e6d215cb09897bd2f
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Tue Jan 28 11:26:09 2014 +0000
Some very prelimary explanations
>---------------------------------------------------------------
0a3dacc3d19261e9d769313e6d215cb09897bd2f
compiler/coreSyn/CoreArity.lhs | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/compiler/coreSyn/CoreArity.lhs b/compiler/coreSyn/CoreArity.lhs
index d4c0a6b..287087b 100644
--- a/compiler/coreSyn/CoreArity.lhs
+++ b/compiler/coreSyn/CoreArity.lhs
@@ -1031,12 +1031,23 @@ freshEtaId n subst ty
\end{code}
-Call arity anlysis: For let-bound things, find out the minimum arity it is
-called with, so that the value can be eta-expanded to that arity, creating
-better code (main goal: good foldl as foldr).
+%************************************************************************
+%* *
+ Called Arity Analyis
+%* *
+%************************************************************************
+
+
+For let-bound things, find out the minimum arity it is called with, so that the
+value can be eta-expanded to that arity, creating better code (main goal: good
+foldl as foldr).
+
+Main problem: Thunks! We must not lose sharing. So one needs to consider how
+often something is called. We use the following approximation:
-Be sure to only consider tail calls. This allows us to detect that there is at
-most one call to n in
+ Only consider tail calls!
+
+This allows us to detect that there is at most one call to n in
let n = case .. of .. -- A thunk!
in case .. of
@@ -1045,6 +1056,21 @@ most one call to n in
False > n
False -> n
+despite a call from a recursive function, becuase
+
+ A tail-recursive function can make at most one tail-call somewhere else.
+
+
+The following code is not yet very quick. Possible improvements:
+ * Re-use existing information in nested fixed-points.
+ * Upon failure in fixed-pointing, go directly to 0 (or the manifestArity).
+
+Possibe improvements in precision:
+ * Always start with at least the manifestArity.
+ * When analysing a recursive RHS, starting with its manifestArity,
+ even if it calls itself at a lower arity, that is still good enough to stop.
+ * In the above, use exprArity instead of manifestArity.
+
\begin{code}
callArityAnalProgram :: DynFlags -> CoreProgram -> CoreProgram
More information about the ghc-commits
mailing list