summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2013-03-27 14:24:51 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2013-03-27 14:24:51 +0000
commit54bb2f83f5c292f952bf7479f0c3277831fa987d (patch)
tree0c26b1af8ef02e9d08d2b594b824d8f38703f623
parent1b37a386d310278096e2697fd8df425587560aee (diff)
downloadhaskell-54bb2f83f5c292f952bf7479f0c3277831fa987d.tar.gz
Improve comments about dead code (thanks to Nick Frisby)
-rw-r--r--compiler/simplCore/OccurAnal.lhs35
1 files changed, 13 insertions, 22 deletions
diff --git a/compiler/simplCore/OccurAnal.lhs b/compiler/simplCore/OccurAnal.lhs
index 3f09cd621d..dccbabcbdb 100644
--- a/compiler/simplCore/OccurAnal.lhs
+++ b/compiler/simplCore/OccurAnal.lhs
@@ -156,35 +156,26 @@ occAnalBind _ env imp_rules_edges (Rec pairs) body_usage
Note [Dead code]
~~~~~~~~~~~~~~~~
-Dropping dead code for recursive bindings is done in a very simple way:
+Dropping dead code for a cyclic Strongly Connected Component is done
+in a very simple way:
- the entire set of bindings is dropped if none of its binders are
- mentioned in its body; otherwise none are.
+ the entire SCC is dropped if none of its binders are mentioned
+ in the body; otherwise the whole thing is kept.
-This seems to miss an obvious improvement.
+The key observation is that dead code elimination happens after
+dependency analysis: so 'occAnalBind' processes SCCs instead of the
+original term's binding groups.
- letrec f = ...g...
- g = ...f...
- in
- ...g...
-===>
- letrec f = ...g...
- g = ...(...g...)...
- in
- ...g...
-
-Now 'f' is unused! But it's OK! Dependency analysis will sort this
-out into a letrec for 'g' and a 'let' for 'f', and then 'f' will get
-dropped. It isn't easy to do a perfect job in one blow. Consider
+Thus 'occAnalBind' does indeed drop 'f' in an example like
letrec f = ...g...
- g = ...h...
- h = ...k...
- k = ...m...
- m = ...m...
+ g = ...(...g...)...
in
- ...m...
+ ...g...
+when 'g' no longer uses 'f' at all (eg 'f' does not occur in a RULE in
+'g'). 'occAnalBind' first consumes 'CyclicSCC g' and then it consumes
+'AcyclicSCC f', where 'body_usage' won't contain 'f'.
------------------------------------------------------------
Note [Forming Rec groups]