On Sun, Apr 02, 2017 at 09:14:01PM +0200, [email protected] wrote:
> I don't fully understand your remark, but the point is that the a conditional
> results in an unknown execution path. A call on the other hand may
> result in all possible things (access of the 1st def of "foo" above, for
> example). As I said, this pass should be rewritten.
> 

Maybe we can do that later.  For now I think this patch is fine, so here's
a signed off copy.  Note that this applies cleanly to master, too.

> > Also, should this also treat the newly added "define-toplevel" core
> > expression like it treats set!?
> 
> Yes, it should.


I just checked, but after canonicalisation, define-toplevel no longer
exists; like ##core#set, ##core#define-toplevel is rewritten to
simply set!, so the optimizer can stay unchanged.

Cheers,
Peter
From a87b6253938d9893047c89c6044b50811e0f687a 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.

Signed-off-by: Peter Bex <[email protected]>
---
 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

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to