emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/func-type-decls 22da320285a 4/6: Make use of Lisp function decla


From: Andrea Corallo
Subject: scratch/func-type-decls 22da320285a 4/6: Make use of Lisp function declarations in the native compiler
Date: Fri, 23 Feb 2024 10:12:13 -0500 (EST)

branch: scratch/func-type-decls
commit 22da320285a9cb3d5635e0f1686a8171ffe30858
Author: Andrea Corallo <acorallo@gnu.org>
Commit: Andrea Corallo <acorallo@gnu.org>

    Make use of Lisp function declarations in the native compiler
---
 lisp/emacs-lisp/comp-common.el | 20 ++++++++++++--------
 lisp/emacs-lisp/comp.el        | 17 +++++++++++++----
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/lisp/emacs-lisp/comp-common.el b/lisp/emacs-lisp/comp-common.el
index 8775c233b9d..0fab976474f 100644
--- a/lisp/emacs-lisp/comp-common.el
+++ b/lisp/emacs-lisp/comp-common.el
@@ -202,21 +202,25 @@ Account for `native-comp-eln-load-path' and 
`comp-native-version-dir'."
   "Return the type specifier of FUNCTION.
 
 This function returns a cons cell whose car is the function
-specifier, and cdr is a symbol, either `inferred' or `know'.
+specifier, and cdr is a symbol, either `inferred' or `declared'.
 If the symbol is `inferred', the type specifier is automatically
 inferred from the code itself by the native compiler; if it is
 `know', the type specifier comes from `comp-primitive-type-specifiers'."
-  (let ((kind 'know)
-        type-spec )
+  (let ((kind 'declared)
+        type-spec)
     (when-let ((res (assoc function comp-primitive-type-specifiers)))
+      ;; Declared primitive
       (setf type-spec (cadr res)))
     (let ((f (and (symbolp function)
                   (symbol-function function))))
-      (when (and f
-                 (null type-spec)
-                 (subr-native-elisp-p f))
-        (setf kind 'inferred
-              type-spec (subr-type f))))
+      (when (and f (null type-spec))
+        (if-let ((delc-type (function-get function 'declared-type)))
+            ;; Declared Lisp function
+            (setf type-spec (cons 'function delc-type))
+          (when (subr-native-elisp-p f)
+            ;; Native compiled inferred
+            (setf kind 'inferred
+                  type-spec (subr-type f))))))
     (when type-spec
         (cons type-spec kind))))
 
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 7440051044a..83130bb3a18 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -178,7 +178,7 @@ For internal use by the test suite only.")
 Each function in FUNCTIONS is run after PASS.
 Useful to hook into pass checkers.")
 
-(defconst comp-known-func-cstr-h
+(defconst comp-primitive-func-cstr-h
   (cl-loop
    with comp-ctxt = (make-comp-cstr-ctxt)
    with h = (make-hash-table :test #'eq)
@@ -188,6 +188,15 @@ Useful to hook into pass checkers.")
    finally return h)
   "Hash table function -> `comp-constraint'.")
 
+(defun comp--get-function-cstr (function)
+  "Given FUNCTION return the corresponding `comp-constraint'."
+  (when (symbolp function)
+    (let ((f (symbol-function function)))
+      (if (subr-primitive-p f)
+          (gethash f comp-primitive-func-cstr-h)
+        (when-let ((delc-type (function-get function 'declared-type)))
+          (comp-type-spec-to-cstr (cons 'function delc-type)))))))
+
 ;; Keep it in sync with the `cl-deftype-satisfies' property set in
 ;; cl-macs.el. We can't use `cl-deftype-satisfies' directly as the
 ;; relation type <-> predicate is not bijective (bug#45576).
@@ -2099,10 +2108,10 @@ TARGET-BB-SYM is the symbol name of the target block."
      (when-let ((match
                  (pcase insn
                    (`(set ,lhs (,(pred comp--call-op-p) ,f . ,args))
-                    (when-let ((cstr-f (gethash f comp-known-func-cstr-h)))
+                    (when-let ((cstr-f (comp--get-function-cstr f)))
                       (cl-values f cstr-f lhs args)))
                    (`(,(pred comp--call-op-p) ,f . ,args)
-                    (when-let ((cstr-f (gethash f comp-known-func-cstr-h)))
+                    (when-let ((cstr-f (comp--get-function-cstr f)))
                       (cl-values f cstr-f nil args))))))
        (cl-multiple-value-bind (f cstr-f lhs args) match
          (cl-loop
@@ -2630,7 +2639,7 @@ Fold the call in case."
                (comp-cstr-imm-vld-p (car args)))
       (setf f (comp-cstr-imm (car args))
             args (cdr args)))
-    (when-let ((cstr-f (gethash f comp-known-func-cstr-h)))
+    (when-let ((cstr-f (comp--get-function-cstr f)))
       (let ((cstr (comp-cstr-f-ret cstr-f)))
         (when (comp-cstr-empty-p cstr)
           ;; Store it to be rewritten as non local exit.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]