Function: comp-function-type-spec

comp-function-type-spec is an autoloaded and byte-compiled function defined in comp-common.el.gz.

Signature

(comp-function-type-spec FUNCTION)

Documentation

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 declared. If the symbol is inferred, the type specifier is automatically inferred from the code itself by the native compiler; if it is declared, the type specifier comes from comp-primitive-type-specifiers or the function type declaration itself.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/comp-common.el.gz
;;;###autoload
(defun comp-function-type-spec (function)
  "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 `declared'.  If the symbol is
`inferred', the type specifier is automatically inferred from the code
itself by the native compiler; if it is `declared', the type specifier
comes from `comp-primitive-type-specifiers' or the function type declaration
itself."
  (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))
        (if-let* ((delc-type (function-get function 'function-type)))
            ;; Declared Lisp function
            (setf type-spec delc-type)
          (when (native-comp-function-p f)
            ;; Natively compiled inferred
            (setf kind 'inferred
                  type-spec (subr-type f))))))
    (when type-spec
        (cons type-spec kind))))