compiler: Don't let continuation-analysis add a cycle...
authorMatt Birkholz <matt@birkholz.chandler.az.us>
Sun, 2 Jun 2013 01:53:24 +0000 (18:53 -0700)
committerMatt Birkholz <matt@birkholz.chandler.az.us>
Sun, 2 Jun 2013 01:53:24 +0000 (18:53 -0700)
...to the block tree, which it would do (causing a "maximum recursion
depth exceeded" abort during block->dbg-block) when compiling crazy
code like:

      (define (fubar param)
(define (closure) param)
(define (loop)
  (closure)
  (loop)
  ;; It doesn't break without this
  (tail-call)))
      (fubar sumpn)

This patch checks that the "Acceptable substitute" for a block's
stack-link is not inside the block.

src/compiler/fgopt/contan.scm

index 3d8825fe457bcbfab2052441a56926e729dd7401..6ff5cec29c068f8caaf331817f01ee47e277c253 100644 (file)
@@ -124,12 +124,14 @@ may change if call-with-current-continuation is handled specially.
             parent
 
             ;; Acceptable substitute: we're a subproblem of someone
-            ;; who is a child of the parent.
+            ;; who is a child of the parent (but not a subproblem of
+            ;; ourselves!).
             (let ((value (lvalue-known-value lvalue)))
               (and value
-                   (let ((block (continuation/block value)))
-                     (and (block-ancestor? block parent)
-                          block))))))))
+                   (let ((link (continuation/block value)))
+                     (and (block-ancestor? link parent)
+                          (not (block-ancestor-or-self? link block))
+                          link))))))))
 \f
 (define (setup-block-static-links! blocks)
   (for-each