Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve comments about dead code (thanks to Nick Frisby)

  • Loading branch information...
commit 54bb2f83f5c292f952bf7479f0c3277831fa987d 1 parent 1b37a38
@simonpj simonpj authored
Showing with 13 additions and 22 deletions.
  1. +13 −22 compiler/simplCore/OccurAnal.lhs
View
35 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]
Please sign in to comment.
Something went wrong with that request. Please try again.