From a87b6253938d9893047c89c6044b50811e0f687a Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 27 Mar 2017 16:05:23 +0200 Subject: [PATCH] Fix a bug in scan-toplevel-assignments walk routine Commit [ac8f2dadd] introduced a bug in the node walking routine. We end up evaluating only the first two subexpression for some kind of nodes, this means the else branch for if/cond nodes is never walked and neither is most of ##core#switch since we stop the walk at the first constant node. Signed-off-by: Peter Bex --- optimizer.scm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/optimizer.scm b/optimizer.scm index 63a9b7d..a6df2fd 100644 --- a/optimizer.scm +++ b/optimizer.scm @@ -71,8 +71,11 @@ (set! escaped #t) (set! previous '())) - (define (scan-each ns e) - (for-each (lambda (n) (scan n e)) ns) ) + (define (scan-each ns e clear-previous?) + (for-each (lambda (n) + (when clear-previous? (set! previous '())) + (scan n e)) + ns)) (define (scan n e) (let ([params (node-parameters n)] @@ -89,12 +92,10 @@ [(if ##core#cond ##core#switch) (scan (first subs) e) (touch) - (scan (first subs) e) - (set! previous '()) - (scan (second subs) e)] + (scan-each (cdr subs) e #t)] [(let) - (scan-each (butlast subs) e) + (scan-each (butlast subs) e #f) (scan (last subs) (append params e)) ] [(lambda ##core#lambda) #f] @@ -118,7 +119,7 @@ (unless (memq var e) (mark var)) (remember var n) ) ) ] - [else (scan-each subs e)] ) ) ) + [else (scan-each subs e #f)]))) (debugging 'p "scanning toplevel assignments...") (scan node '()) -- 2.1.4