prune unused letrec bindings
authorAndy Wingo <wingo@pobox.com>
Thu, 22 Sep 2011 22:21:46 +0000 (00:21 +0200)
committerAndy Wingo <wingo@pobox.com>
Sat, 24 Sep 2011 18:37:12 +0000 (20:37 +0200)
* module/language/tree-il/optimize.scm (peval): Prune unused `letrec'
  bindings.

module/language/tree-il/optimize.scm

index 7ac68e9..1f2e17a 100644 (file)
@@ -656,7 +656,18 @@ it does not handle <fix> and <let-values>, it should be called before
                   (body  (maybe-unconst body body*)))
              (if (const? body*)
                  body
-                 (make-letrec src in-order? names gensyms vals body))))
+                 (let*-values
+                     (((stripped) (remove
+                                   (lambda (x)
+                                     (and (constant-expression? (car x))
+                                          (not (hashq-ref
+                                                residual-lexical-references
+                                                (cadr x)))))
+                                   (zip vals gensyms names)))
+                      ((vals gensyms names) (unzip3 stripped)))
+                   (if (null? stripped)
+                       body
+                       (make-letrec src in-order? names gensyms vals body))))))
           (($ <fix> src names gensyms vals body)
            (let* ((vals (map for-value vals))
                   (body* (loop body