summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2017-04-09 13:41:40 -0400
committerJoachim Breitner <mail@joachim-breitner.de>2017-04-09 18:44:38 -0400
commit87377f74eec1567af741737b4b9034d06e3f0698 (patch)
treedca072679c8dcfbfd9975a9d37e8ca3af8dec707 /compiler
parent5282bb1772ba3f1dc999a177965e543822f342a0 (diff)
downloadhaskell-87377f74eec1567af741737b4b9034d06e3f0698.tar.gz
Add a Note [Call Arity and Join Points]
as discussed in #13479.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/simplCore/CallArity.hs24
1 files changed, 23 insertions, 1 deletions
diff --git a/compiler/simplCore/CallArity.hs b/compiler/simplCore/CallArity.hs
index 1eb4fa22fd..2e1de85ad7 100644
--- a/compiler/simplCore/CallArity.hs
+++ b/compiler/simplCore/CallArity.hs
@@ -405,6 +405,26 @@ In practice, there are thunks that do a just little work, such as
pattern-matching on a variable, and the benefits of eta-expansion likely
oughtweigh the cost of doing that repeatedly. Therefore, this implementation of
Call Arity considers everything that is not cheap (`exprIsCheap`) as a thunk.
+
+Note [Call Arity and Join Points]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The Call Arity analysis does not care about joint points, and treats them just
+like normal functions. This is ok.
+
+The analysis *could* make use of the fact that join points are always evaluated
+in the same context as the join-binding they are defined in and are always
+one-shot, and handle join points separately, as suggested in
+https://ghc.haskell.org/trac/ghc/ticket/13479#comment:10.
+This *might* be more efficient (for example, join points would not have to be
+considered interesting variables), but it would also add redundant code. So for
+now we do not do that.
+
+The simplifier never eta-expands join points (it insteads pushes extra arguments from
+an eta-expanded context into the join point’s RHS), so the call arity
+annotation on join points is not actually used. As it would be equally valid
+(though less efficient) to eta-expand join points, this is the simplifier's
+choice, and hence Call Arity sets the call arity for join points as well.
-}
-- Main entry point
@@ -627,7 +647,9 @@ callArityBind boring_vars ae_body int b@(Rec binds)
| safe_arity == 0 = ae_rhs -- If it is not a function, its body is evaluated only once
| otherwise = calledMultipleTimes ae_rhs
- in (True, (i `setIdCallArity` trimmed_arity, Just (called_once, new_arity, ae_rhs'), rhs'))
+ i' = i `setIdCallArity` trimmed_arity
+
+ in (True, (i', Just (called_once, new_arity, ae_rhs'), rhs'))
where
-- See Note [Taking boring variables into account]
(new_arity, called_once) | i `elemVarSet` boring_vars = (0, False)