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

Fold eqv? to eq? on exact integers according to target fixnum range

* module/language/tree-il/peval.scm (peval): Fix folding to only reduce
  to eq? for values within both host and target range.
This commit is contained in:
Andy Wingo 2020-08-11 23:07:05 +02:00
parent feafad7958
commit a7f4a6f1c4

View file

@ -26,6 +26,7 @@
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (system base target)
#:use-module (ice-9 control)
#:export (peval))
@ -1352,8 +1353,15 @@ top-level bindings from ENV and return the resulting expression."
;; Already in a reduced state.
(make-primcall src 'eq? (list a b)))
((or (memq v '(#f #t () #nil)) (symbol? v) (char? v)
;; Only fold to eq? value is a fixnum on target and
;; host, as constant folding may have us compare on host
;; as well.
(and (exact-integer? v)
(<= most-negative-fixnum v most-positive-fixnum)))
(<= (max (target-most-negative-fixnum)
most-negative-fixnum)
v
(min (target-most-positive-fixnum)
most-positive-fixnum))))
;; Reduce to eq?. Note that in Guile, characters are
;; comparable with eq?.
(make-primcall src 'eq? (list a b)))