]> git.eshelyaron.com Git - emacs.git/commitdiff
comp: Make use of predicates in propagation for non builtin types
authorAndrea Corallo <akrl@sdf.org>
Wed, 24 Aug 2022 21:31:28 +0000 (23:31 +0200)
committerAndrea Corallo <akrl@sdf.org>
Tue, 23 May 2023 14:39:06 +0000 (16:39 +0200)
* lisp/emacs-lisp/comp-cstr.el (comp-cstr-ctxt): Add `pred-type-h'
slot.
* lisp/emacs-lisp/comp.el (comp-known-predicate-p)
(comp-pred-to-cstr): Update.

lisp/emacs-lisp/comp-cstr.el
lisp/emacs-lisp/comp.el

index 869b061916033107a263a30cd5869e1ad429b54a..35e9ac459197419a9171b6914fd8667fbba94efa 100644 (file)
@@ -107,6 +107,14 @@ Integer values are handled in the `range' slot.")
                         (mapcar #'comp--cl-class-hierarchy (comp--all-classes)))
                 :type list
                 :documentation "Type hierarchy.")
+  (pred-type-h (cl-loop with h = (make-hash-table :test #'eq)
+                       for class-name in (comp--all-classes)
+                        for pred = (get class-name 'cl-deftype-satisfies)
+                        when pred
+                          do (puthash pred class-name h)
+                       finally return h)
+               :type hash-table
+               :documentation "Hash pred -> type.")
   (union-typesets-mem (make-hash-table :test #'equal) :type hash-table
                       :documentation "Serve memoization for
 `comp-union-typesets'.")
index 289c5bf2ac41c582fd765c12295c5392c8c0ce5c..fe72f0e73a4e783fd5b316ed3ccfb5e1b2237094 100644 (file)
@@ -641,11 +641,14 @@ Useful to hook into pass checkers.")
 
 (defun comp-known-predicate-p (predicate)
   "Return t if PREDICATE is known."
-  (when (gethash predicate comp-known-predicates-h) t))
+  (when (or (gethash predicate comp-known-predicates-h)
+            (gethash predicate (comp-cstr-ctxt-pred-type-h comp-ctxt)))
+    t))
 
 (defun comp-pred-to-cstr (predicate)
   "Given PREDICATE, return the corresponding constraint."
-  (gethash predicate comp-known-predicates-h))
+  (or (gethash predicate comp-known-predicates-h)
+      (gethash predicate (comp-cstr-ctxt-pred-type-h comp-ctxt))))
 
 (defconst comp-symbol-values-optimizable '(most-positive-fixnum
                                            most-negative-fixnum)