Fixes bug 205427 in letrec*.

This commit is contained in:
Abdulaziz Ghuloum 2008-03-23 04:14:53 -04:00
parent 2119f44125
commit 0f55361b19
2 changed files with 34 additions and 28 deletions

View File

@ -745,6 +745,7 @@
body) body)
|# |#
(define scc-letrec (make-parameter #t)) (define scc-letrec (make-parameter #t))
(define (optimize-letrec/scc x) (define (optimize-letrec/scc x)
@ -770,35 +771,38 @@
e*))) e*)))
v* e**) v* e**)
v*)) v*))
(define (compute-sccs! v*) (define (compute-sccs v*) ; Tarjan's algorithm
(define all-sccs '()) (define scc* '())
(define (visit v i) (define (compute-sccs v)
(set-node-lowlink! v i) (define index 0)
(set-node-root! v v) (define stack '())
(set-node-collection! v '()) (define (tarjan v)
(let ([v-index index])
(set-node-root! v v-index)
(set! stack (cons v stack))
(set! index (fx+ index 1))
(for-each (for-each
(lambda (v^) (lambda (v^)
(unless (node-done v^) (unless (node-done v^)
(unless (node-lowlink v^) (unless (node-root v^) (tarjan v^))
(visit v^ (+ i 1))) (set-node-root! v (fxmin (node-root v) (node-root v^)))))
(when (< (node-lowlink v^) (node-lowlink v))
(set-node-lowlink! v (node-lowlink v^))
(set-node-root! v (node-root v^)))))
(node-link* v)) (node-link* v))
(let ([root (node-root v)]) (when (fx= (node-root v) v-index)
(let ([nodes (cons v (node-collection root))]) (set! scc*
(cond (cons
[(eq? v root) (let f ([ls stack])
(set! all-sccs (cons nodes all-sccs)) (let ([v^ (car ls)])
(for-each (lambda (x) (set-node-done! x #t)) nodes)] (set-node-done! v^ #t)
[else (cons v^ (if (eq? v^ v)
(set-node-collection! root (begin (set! stack (cdr ls)) '())
(append (node-collection v) nodes))])))) (f (cdr ls))))))
(for-each (lambda (v) (unless (node-done v) (visit v 0))) v*) scc*)))))
(reverse all-sccs)) (tarjan v))
(for-each (lambda (v) (unless (node-done v) (compute-sccs v))) v*)
(reverse scc*))
(define (get-sccs-in-order n* e** data*) (define (get-sccs-in-order n* e** data*)
(let ([G (create-graph n* e** data*)]) (let ([G (create-graph n* e** data*)])
(let ([sccs (compute-sccs! G)]) (let ([sccs (compute-sccs G)])
(map (lambda (scc) (map node-data scc)) sccs))))) (map (lambda (scc) (map node-data scc)) sccs)))))
(define (gen-letrecs scc* ordered? body) (define (gen-letrecs scc* ordered? body)
(define (mkfix b* body) (define (mkfix b* body)
@ -950,6 +954,8 @@
[(constant) x] [(constant) x]
[(var) [(var)
(mark-free x bc) (mark-free x bc)
(when (var-assigned x)
(mark-complex bc))
x] x]
[(assign lhs rhs) [(assign lhs rhs)
(set-var-assigned! lhs #t) (set-var-assigned! lhs #t)

View File

@ -1 +1 @@
1422 1423