guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 01/01: Constant-folding eq? and eqv? uses deduplication


From: Andy Wingo
Subject: [Guile-commits] 01/01: Constant-folding eq? and eqv? uses deduplication
Date: Fri, 24 Jun 2016 15:41:20 +0000 (UTC)

wingo pushed a commit to branch master
in repository guile.

commit 229d062f83d7c79fa08729330406d25755b25080
Author: Andy Wingo <address@hidden>
Date:   Fri Jun 24 17:35:55 2016 +0200

    Constant-folding eq? and eqv? uses deduplication
    
    * test-suite/tests/peval.test ("partial evaluation"): Add tests.
    * module/language/tree-il/peval.scm (peval): Constant-fold eq? and eqv?
      using equal?, anticipating deduplication.
---
 module/language/tree-il/peval.scm |   10 +++++++++-
 test-suite/tests/peval.test       |    8 ++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/module/language/tree-il/peval.scm 
b/module/language/tree-il/peval.scm
index 8e1069d..7d19458 100644
--- a/module/language/tree-il/peval.scm
+++ b/module/language/tree-il/peval.scm
@@ -511,7 +511,15 @@ top-level bindings from ENV and return the resulting 
expression."
         (lambda ()
           (call-with-values
               (lambda ()
-                (apply (module-ref the-scm-module name) args))
+                (case name
+                  ((eq? eqv?)
+                   ;; Constants will be deduplicated later, but eq?
+                   ;; folding can happen now.  Anticipate the
+                   ;; deduplication by using equal? instead of eq?.
+                   ;; Same for eqv?.
+                   (apply equal? args))
+                  (else
+                   (apply (module-ref the-scm-module name) args))))
             (lambda results
               (values #t results))))
         (lambda _
diff --git a/test-suite/tests/peval.test b/test-suite/tests/peval.test
index 3407808..4e2ccf9 100644
--- a/test-suite/tests/peval.test
+++ b/test-suite/tests/peval.test
@@ -1360,6 +1360,14 @@
         (call (toplevel bar) (lexical x _))))))
 
   (pass-if-peval
+      (eq? '(a b) '(a b))
+    (const #t))
+
+  (pass-if-peval
+      (eqv? '(a b) '(a b))
+    (const #t))
+
+  (pass-if-peval
       ((lambda (foo)
          (define* (bar a #:optional (b (1+ a)))
            (list a b))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]