As promised here's the patch, sorry for the noise.
On 27 March 2017 at 16:10, lemonboy <[email protected]> wrote:
> Hello hackers,
> while doing some work on the optimizer I ended up noticing something
> weird in how `scan-toplevel-assignments'
> handles some nodes. A quick `git blame' shows that the bug has been
> introduced some years ago in a fixup
> commit [1], I've reverted the code to the previous version and added a
> parameter to scan-each for clearing the
> `previous' variable. I hope that's fine for you.
>
> Cheers,
> LemonBoy
>
> [1]
> http://code.call-cc.org/cgi-bin/gitweb.cgi?p=chicken-core.git;a=commit;h=ac8f2dadd
From 20eea8bf1a8272fc0d193fab3971e7c02a9c6495 Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
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.
---
optimizer.scm | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/optimizer.scm b/optimizer.scm
index 07081e3d..d92e5036 100644
--- a/optimizer.scm
+++ b/optimizer.scm
@@ -56,8 +56,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)]
@@ -74,12 +77,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]
@@ -103,7 +104,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.12.1
_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers