Function: byte-compile-inline-expand

byte-compile-inline-expand is an autoloaded and byte-compiled function defined in byte-opt.el.gz.

Signature

(byte-compile-inline-expand FORM)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-opt.el.gz
(defun byte-compile-inline-expand (form)
  (let* ((name (car form))
         (localfn (cdr (assq name byte-compile-function-environment)))
	 (fn (or localfn (symbol-function name))))
    (when (autoloadp fn)
      (autoload-do-load fn)
      (setq fn (or (symbol-function name)
                   (cdr (assq name byte-compile-function-environment)))))
    (pcase fn
      ('nil
       (byte-compile-warn-x name
                            "attempt to inline `%s' before it was defined"
                            name)
       form)
      (`(autoload . ,_)
       (error "File `%s' didn't define `%s'" (nth 1 fn) name))
      ((and (pred symbolp) (guard (not (eq fn t)))) ;A function alias.
       (byte-compile-inline-expand (cons fn (cdr form))))
      ((pred byte-code-function-p)
       ;; (message "Inlining byte-code for %S!" name)
       ;; The byte-code will be really inlined in byte-compile-unfold-bcf.
       (byte-compile--check-arity-bytecode form fn)
       `(,fn ,@(cdr form)))
      ((pred interpreted-function-p)
       ;; While byte-compile-unfold-bcf can inline dynbind byte-code into
       ;; letbind byte-code (or any other combination for that matter), we
       ;; can only inline dynbind source into dynbind source or lexbind
       ;; source into lexbind source.
       ;; We assume that the function comes from another file (it would
       ;; have already been compiled otherwise) and byte-compile
       ;; the inlined function first, and then inline its byte-code.
       ;; This also has the advantage that the final code does not
       ;; depend on the order of compilation of Elisp files, making
       ;; the build more reproducible.

       ;; Since we are called from inside the optimizer, we need to make
       ;; sure not to propagate lexvar values.
       (let ((byte-optimize--lexvars nil)
             ;; Silence all compilation warnings: the useful ones should
             ;; be displayed when the function's source file will be
             ;; compiled anyway, but more importantly we would otherwise
             ;; emit spurious warnings here because we don't have the full
             ;; context, such as `declare-function's placed earlier in the
             ;; source file's code or `with-suppressed-warnings' that
             ;; surrounded the `defsubst'.
             (byte-compile-warnings nil))
         (byte-compile name))
       (let ((bc (symbol-function name)))
         (byte-compile--check-arity-bytecode form bc)
         `(,bc ,@(cdr form))))

      (_ ;; Give up on inlining.
       form))))