master: Better type derivation (truncate x integer-union-with-zero)
stassats via Sbcl-commits <[email protected]>
| Newsgroups | gmane.lisp.steel-bank.cvs |
|---|---|
| Message-ID | <[email protected]> |
The branch "master" has been updated in SBCL:
via 01ab3579451ff4fc3c046542da3cf6390b0c20b6 (commit)
from 1f72eef99e028a04b85e028054cce075a9c73336 (commit)
- Log -----------------------------------------------------------------
commit 01ab3579451ff4fc3c046542da3cf6390b0c20b6
Author: Stas Boukarev <[email protected]>
Date: Wed Apr 8 04:53:59 2026 +0300
Better type derivation (truncate x integer-union-with-zero)
---
src/compiler/srctran.lisp | 6 ++++--
tests/arith-2.pure.lisp | 9 +++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp
index b4cb3145c..de3626fce 100644
--- a/src/compiler/srctran.lisp
+++ b/src/compiler/srctran.lisp
@@ -2383,7 +2383,9 @@
(interval-high number-interval)
(interval-low divisor-interval)
(interval-high divisor-interval))))
- (specifier-type (if (listp res) res 'integer))))
+ (if (eq res t)
+ *empty-type*
+ (specifier-type (if (listp res) res 'integer)))))
(t
(multiple-value-bind (quot conservative)
(if (and (member (interval-high divisor-interval) '(1 1f0 1d0))
@@ -2412,7 +2414,7 @@
(numberp (interval-high divisor-interval))
(zerop (interval-low divisor-interval))
(zerop (interval-high divisor-interval)))
- nil)
+ *empty-type*)
((eq rem-type 'integer)
;; Since the remainder type is INTEGER, both args are
;; INTEGERs.
diff --git a/tests/arith-2.pure.lisp b/tests/arith-2.pure.lisp
index 117e3e122..05172c2d2 100644
--- a/tests/arith-2.pure.lisp
+++ b/tests/arith-2.pure.lisp
@@ -2466,3 +2466,12 @@
`(lambda (x)
(ash (the (signed-byte ,(* 2 sb-vm:n-word-bits)) x)
,(- sb-vm:n-word-bits)))))))
+
+
+(with-test (:name :truncate-by-zero-type)
+ (assert-type
+ (lambda (n x)
+ (declare ((integer -9 9) n)
+ ((and integer (not (member 1 -1))) x))
+ (truncate n x))
+ (values (integer -4 4) (integer -9 9) &optional)))
-----------------------------------------------------------------------
hooks/post-receive
--
SBCL