Function: native--compile-async

native--compile-async is a byte-compiled function defined in comp.el.gz.

Signature

(native--compile-async FILES &optional RECURSIVELY LOAD SELECTOR)

Documentation

Compile FILES asynchronously.

FILES is one filename or a list of filenames or directories.

If optional argument RECURSIVELY is non-nil, recurse into subdirectories of given directories.

If optional argument LOAD is non-nil, request to load the file after compiling.

The optional argument SELECTOR has the following valid values:

nil -- Select all files. a string -- A regular expression selecting files with matching names. a function -- A function selecting files with matching names.

The variable native-comp-async-jobs-number specifies the number of (commands) to run simultaneously.

LOAD can also be the symbol late. This is used internally if the byte code has already been loaded when this function is called. It means that we request the special kind of load necessary in that situation, called "late" loading.

During a "late" load, instead of executing all top-level forms of the original files, only function definitions are loaded (paying attention to have these effective only if the bytecode definition was not changed in the meantime).

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/comp.el.gz
(defun native--compile-async (files &optional recursively load selector)
  "Compile FILES asynchronously.
FILES is one filename or a list of filenames or directories.

If optional argument RECURSIVELY is non-nil, recurse into
subdirectories of given directories.

If optional argument LOAD is non-nil, request to load the file
after compiling.

The optional argument SELECTOR has the following valid values:

nil -- Select all files.
a string -- A regular expression selecting files with matching names.
a function -- A function selecting files with matching names.

The variable `native-comp-async-jobs-number' specifies the number
of (commands) to run simultaneously.

LOAD can also be the symbol `late'.  This is used internally if
the byte code has already been loaded when this function is
called.  It means that we request the special kind of load
necessary in that situation, called \"late\" loading.

During a \"late\" load, instead of executing all top-level forms
of the original files, only function definitions are
loaded (paying attention to have these effective only if the
bytecode definition was not changed in the meantime)."
  (comp-ensure-native-compiler)
  (unless (member load '(nil t late))
    (error "LOAD must be nil, t or 'late"))
  (unless (listp files)
    (setf files (list files)))
  (let (file-list)
    (dolist (path files)
      (cond ((file-directory-p path)
             (dolist (file (if recursively
                               (directory-files-recursively
                                path comp-valid-source-re)
                             (directory-files path t comp-valid-source-re)))
               (push file file-list)))
            ((file-exists-p path) (push path file-list))
            (t (signal 'native-compiler-error
                       (list "Path not a file nor directory" path)))))
    (dolist (file file-list)
      (if-let ((entry (cl-find file comp-files-queue :key #'car :test #'string=)))
          ;; Most likely the byte-compiler has requested a deferred
          ;; compilation, so update `comp-files-queue' to reflect that.
          (unless (or (null load)
                      (eq load (cdr entry)))
            (cl-substitute (cons file load) (car entry) comp-files-queue
                           :key #'car :test #'string=))

        (unless (native-compile-async-skip-p file load selector)
          (let* ((out-filename (comp-el-to-eln-filename file))
                 (out-dir (file-name-directory out-filename)))
            (unless (file-exists-p out-dir)
              (make-directory out-dir t))
            (if (file-writable-p out-filename)
                (setf comp-files-queue
                      (append comp-files-queue `((,file . ,load))))
              (display-warning 'comp
                               (format "No write access for %s skipping."
                                       out-filename)))))))
    (when (zerop (comp-async-runnings))
      (comp-run-async-workers))))