]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/comp-cstr.el (comp-cstr-type-p): New function.
authorAndrea Corallo <acorallo@gnu.org>
Wed, 10 Apr 2024 16:15:12 +0000 (18:15 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 20:31:14 +0000 (22:31 +0200)
(cherry picked from commit ee03a73375796feea94bb066cff7d7de680cae32)

lisp/emacs-lisp/comp-cstr.el

index d7d3b12e148527d401ac1144ced328b7d6b33501..adbbaa24a992170dba2b735188f08b301843e82b 100644 (file)
@@ -940,6 +940,17 @@ Non memoized version of `comp-cstr-intersection-no-mem'."
          (null (neg cstr))
          (equal (typeset cstr) '(cons)))))
 
+(define-inline comp-cstr-type-p (cstr type)
+  "Return t if CSTR is certainly of type TYPE."
+  (if-let ((pred (get type 'cl-deftype-satisfies)))
+      (with-comp-cstr-accessors
+        (and (null (range cstr))
+             (null (neg cstr))
+             (and (or (null (typeset cstr))
+                      (equal (typeset cstr) `(,type)))
+                  (cl-every pred (valset cstr)))))
+    (error "Unknown predicate for type %s" type)))
+
 ;; Move to comp.el?
 (defsubst comp-cstr-cl-tag-p (cstr)
   "Return non-nil if CSTR is a CL tag."