[commit: ghc] master: Improve comments about dead code (thanks to Nick Frisby) (54bb2f8)
Simon Peyton Jones
simonpj at microsoft.com
Wed Mar 27 15:24:59 CET 2013
Repository : http://darcs.haskell.org/ghc.git/
On branch : master
https://github.com/ghc/ghc/commit/54bb2f83f5c292f952bf7479f0c3277831fa987d
>---------------------------------------------------------------
commit 54bb2f83f5c292f952bf7479f0c3277831fa987d
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Wed Mar 27 14:24:51 2013 +0000
Improve comments about dead code (thanks to Nick Frisby)
>---------------------------------------------------------------
compiler/simplCore/OccurAnal.lhs | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/compiler/simplCore/OccurAnal.lhs b/compiler/simplCore/OccurAnal.lhs
index 3f09cd6..dccbabc 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]
More information about the ghc-commits
mailing list