refactor: simplify native-comp detection

Reduce cases where native-comp procedures were executed in
non-native-comp contexts (somehow).

Also:
- Adds a NATIVECOMP constant for statically detecting the feature.
- Remove native-comp-* -> comp-* aliases (Emacs HEAD has long since
  moved on from these).
- Add 'no-native-compile: t' to autoloads file.
This commit is contained in:
Henrik Lissner 2021-11-22 16:01:02 +01:00
parent c8484838a7
commit cc3be7cb44
3 changed files with 28 additions and 49 deletions

View file

@ -76,7 +76,7 @@ one wants that.")
(print-quoted t) (print-quoted t)
(print-level nil) (print-level nil)
(print-length nil)) (print-length nil))
(insert ";; -*- lexical-binding: t; coding: utf-8; -*-\n" (insert ";; -*- lexical-binding: t; coding: utf-8; no-native-compile: t -*-\n"
";; This file is autogenerated by 'doom sync', DO NOT EDIT IT!!\n") ";; This file is autogenerated by 'doom sync', DO NOT EDIT IT!!\n")
(dolist (form (delq nil forms)) (dolist (form (delq nil forms))
(mapc #'prin1 form)) (mapc #'prin1 form))

View file

@ -1,6 +1,12 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; core/cli/packages.el ;;; core/cli/packages.el
(require 'comp nil t)
;;
;;; Commands
(defcli! (update u) (&rest _) (defcli! (update u) (&rest _)
"This command was removed." "This command was removed."
:hidden t :hidden t
@ -210,7 +216,7 @@ list remains lean."
(comp-async-runnings)) (comp-async-runnings))
0)) 0))
(defun doom--wait-for-compile-jobs () (defun doom--wait-for-native-compile-jobs ()
"Wait for all pending async native compilation jobs." "Wait for all pending async native compilation jobs."
(cl-loop for pending = (doom--native-compile-jobs) (cl-loop for pending = (doom--native-compile-jobs)
with previous = 0 with previous = 0
@ -224,8 +230,7 @@ list remains lean."
(defun doom--write-missing-eln-errors () (defun doom--write-missing-eln-errors ()
"Write .error files for any expected .eln files that are missing." "Write .error files for any expected .eln files that are missing."
(when (and (require 'comp nil t) (when NATIVECOMP
(ignore-errors (native-comp-available-p)))
(cl-loop for file in doom--eln-output-expected (cl-loop for file in doom--eln-output-expected
for eln-name = (doom--eln-file-name file) for eln-name = (doom--eln-file-name file)
for eln-file = (doom--eln-output-file eln-name) for eln-file = (doom--eln-output-file eln-name)
@ -239,8 +244,7 @@ list remains lean."
(defun doom--compile-site-packages () (defun doom--compile-site-packages ()
"Queue async compilation for all non-doom Elisp files." "Queue async compilation for all non-doom Elisp files."
(when (and (featurep 'comp) (when NATIVECOMP
(ignore-errors (native-comp-available-p)))
(cl-loop with paths = (cl-loop for path in load-path (cl-loop with paths = (cl-loop for path in load-path
unless (string-prefix-p doom-local-dir path) unless (string-prefix-p doom-local-dir path)
collect path) collect path)
@ -288,8 +292,9 @@ declaration) or dependency thereof that hasn't already been."
(signal 'doom-package-error (list package e)))))) (signal 'doom-package-error (list package e))))))
(progn (progn
(doom--compile-site-packages) (doom--compile-site-packages)
(doom--wait-for-compile-jobs) (when NATIVECOMP
(doom--write-missing-eln-errors) (doom--wait-for-native-compile-jobs)
(doom--write-missing-eln-errors))
(print! (success "\033[KInstalled %d packages") (length built))) (print! (success "\033[KInstalled %d packages") (length built)))
(print! (info "No packages need to be installed")) (print! (info "No packages need to be installed"))
nil)))) nil))))
@ -334,8 +339,7 @@ declaration) or dependency thereof that hasn't already been."
(and (eq (car-safe build) :not) (and (eq (car-safe build) :not)
(setq want-byte-compile (not want-byte-compile) (setq want-byte-compile (not want-byte-compile)
want-native-compile (not want-native-compile))) want-native-compile (not want-native-compile)))
(or (and (require 'comp nil t) (unless NATIVECOMP
(ignore-errors (native-comp-available-p)))
(setq want-native-compile nil)) (setq want-native-compile nil))
(and (or want-byte-compile want-native-compile) (and (or want-byte-compile want-native-compile)
(or (file-newer-than-file-p repo-dir build-dir) (or (file-newer-than-file-p repo-dir build-dir)
@ -352,8 +356,9 @@ declaration) or dependency thereof that hasn't already been."
(straight-use-package (intern package)))) (straight-use-package (intern package))))
(progn (progn
(doom--compile-site-packages) (doom--compile-site-packages)
(doom--wait-for-compile-jobs) (when NATIVECOMP
(doom--write-missing-eln-errors) (doom--wait-for-native-compile-jobs)
(doom--write-missing-eln-errors))
;; HACK Every time you save a file in a package that straight tracks, ;; HACK Every time you save a file in a package that straight tracks,
;; it is recorded in ~/.emacs.d/.local/straight/modified/. ;; it is recorded in ~/.emacs.d/.local/straight/modified/.
;; Typically, straight will clean these up after rebuilding, but ;; Typically, straight will clean these up after rebuilding, but
@ -637,8 +642,7 @@ If ELPA-P, include packages installed with package.el (M-x package-install)."
(if (not regraft-repos-p) (if (not regraft-repos-p)
(ignore (print! (info "Skipping regrafting"))) (ignore (print! (info "Skipping regrafting")))
(doom--cli-packages-regraft-repos repos-to-regraft)) (doom--cli-packages-regraft-repos repos-to-regraft))
(when (and (require 'comp nil t) (when NATIVECOMP
(native-comp-available-p))
(if (not eln-p) (if (not eln-p)
(ignore (print! (info "Skipping native bytecode"))) (ignore (print! (info "Skipping native bytecode")))
(doom--cli-packages-purge-eln)))))))) (doom--cli-packages-purge-eln))))))))

View file

@ -45,6 +45,7 @@ envvar will enable this at startup.")
(defconst doom-interactive-p (not noninteractive) (defconst doom-interactive-p (not noninteractive)
"If non-nil, Emacs is in interactive mode.") "If non-nil, Emacs is in interactive mode.")
(defconst NATIVECOMP (if (fboundp 'native-comp-available-p) (native-comp-available-p)))
(defconst EMACS28+ (> emacs-major-version 27)) (defconst EMACS28+ (> emacs-major-version 27))
(defconst IS-MAC (eq system-type 'darwin)) (defconst IS-MAC (eq system-type 'darwin))
(defconst IS-LINUX (eq system-type 'gnu/linux)) (defconst IS-LINUX (eq system-type 'gnu/linux))
@ -155,43 +156,17 @@ users).")
;; ;;
;;; Native Compilation support (http://akrl.sdf.org/gccemacs.html) ;;; Native Compilation support (http://akrl.sdf.org/gccemacs.html)
;; REVIEW Remove after a month (when NATIVECOMP
(when EMACS28+
(mapc (lambda (varset)
(unless (boundp (car varset))
(defvaralias (car varset) (cdr varset))))
'((native-comp-deferred-compilation . comp-deferred-compilation)
(native-comp-deferred-compilation-deny-list . comp-deferred-compilation-deny-list)
(native-comp-eln-load-path . comp-eln-load-path)
(native-comp-warning-on-missing-source . comp-warning-on-missing-source)
(native-comp-driver-options . comp-native-driver-options)
(native-comp-async-query-on-exit . comp-async-query-on-exit)
(native-comp-async-report-warnings-errors . comp-async-report-warnings-errors)
(native-comp-async-env-modifier-form . comp-async-env-modifier-form)
(native-comp-async-all-done-hook . comp-async-all-done-hook)
(native-comp-async-cu-done-functions . comp-async-cu-done-functions)
(native-comp-async-jobs-number . comp-async-jobs-number)
(native-comp-never-optimize-functions . comp-never-optimize-functions)
(native-comp-bootstrap-deny-list . comp-bootstrap-deny-list)
(native-comp-always-compile . comp-always-compile)
(native-comp-verbose . comp-verbose)
(native-comp-debug . comp-debug)
(native-comp-speed . comp-speed)))
;; Don't store eln files in ~/.emacs.d/eln-cache (they are likely to be purged ;; Don't store eln files in ~/.emacs.d/eln-cache (they are likely to be purged
;; when upgrading Doom). ;; when upgrading Doom).
(when (boundp 'native-comp-eln-load-path) (add-to-list 'native-comp-eln-load-path (concat doom-cache-dir "eln/"))
(add-to-list 'native-comp-eln-load-path (concat doom-cache-dir "eln/"))))
(with-eval-after-load 'comp (with-eval-after-load 'comp
;; HACK Disable native-compilation for some troublesome packages ;; HACK Disable native-compilation for some troublesome packages
(mapc (doom-partial #'add-to-list 'native-comp-deferred-compilation-deny-list) (mapc (doom-partial #'add-to-list 'native-comp-deferred-compilation-deny-list)
(let ((local-dir-re (concat "\\`" (regexp-quote doom-local-dir)))) (let ((local-dir-re (concat "\\`" (regexp-quote doom-local-dir))))
(list (concat "\\`" (regexp-quote doom-autoloads-file) "\\'") (list (concat local-dir-re ".*/evil-collection-vterm\\.el\\'")
(concat local-dir-re ".*/evil-collection-vterm\\.el\\'") (concat local-dir-re ".*/with-editor\\.el\\'"))))))
(concat local-dir-re ".*/with-editor\\.el\\'")
;; https://github.com/nnicandro/emacs-jupyter/issues/297
(concat local-dir-re ".*/jupyter-channel\\.el\\'")))))
;; ;;