1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

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.
This commit is contained in:
Andy Wingo 2016-06-24 17:35:55 +02:00
parent ff5cafc77d
commit 229d062f83
2 changed files with 17 additions and 1 deletions

View file

@ -511,7 +511,15 @@ top-level bindings from ENV and return the resulting expression."
(lambda () (lambda ()
(call-with-values (call-with-values
(lambda () (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 (lambda results
(values #t results)))) (values #t results))))
(lambda _ (lambda _

View file

@ -1359,6 +1359,14 @@
(((x) #f #f #f () (_)) (((x) #f #f #f () (_))
(call (toplevel bar) (lexical x _)))))) (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 (pass-if-peval
((lambda (foo) ((lambda (foo)
(define* (bar a #:optional (b (1+ a))) (define* (bar a #:optional (b (1+ a)))