Add 'inhibit-native-compilation'
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 3 Oct 2022 13:26:04 +0000 (15:26 +0200)
committerSean Whitton <spwhitton@spwhitton.name>
Sun, 18 Dec 2022 21:35:33 +0000 (14:35 -0700)
The following upstream patch has been backported:

  Add new variable 'inhibit-native-compilation'

  * lisp/startup.el (normal-top-level): Set
  inhibit-native-compilation from environment variable.

  * lisp/emacs-lisp/comp.el (comp-trampoline-compile): Don't write
  trampolines to disk.

  * lisp/progmodes/elisp-mode.el
  (emacs-lisp-native-compile-and-load): Adjust.

  * src/comp.c (syms_of_comp): New variable
  inhibit-native-compilation.
  (maybe_defer_native_compilation): Use it.

Origin: upstream, commit: 5fec9182dbeffa88cef6651d8c798ef9665d6681
Forwarded: not-needed

lisp/emacs-lisp/comp.el
lisp/progmodes/elisp-mode.el
lisp/startup.el
src/comp.c

index 8a3429c9b6753b96abd5c5d9bbfaa0fae7f5b596..37abd886b495d4809d0080fb7dd775ef4be15ecc 100644 (file)
@@ -3793,22 +3793,25 @@ Return the trampoline if found or nil otherwise."
          (lexical-binding t))
     (comp--native-compile
      form nil
-     (cl-loop
-      for dir in (if native-compile-target-directory
-                     (list (expand-file-name comp-native-version-dir
-                                             native-compile-target-directory))
-                   (comp-eln-load-path-eff))
-      for f = (expand-file-name
-               (comp-trampoline-filename subr-name)
-               dir)
-      unless (file-exists-p dir)
-        do (ignore-errors
-             (make-directory dir t)
-             (cl-return f))
-      when (file-writable-p f)
-        do (cl-return f)
-      finally (error "Cannot find suitable directory for output in \
-`native-comp-eln-load-path'")))))
+     ;; If we've disabled nativecomp, don't write the trampolines to
+     ;; the eln cache (but create them).
+     (and (not inhibit-native-compilation)
+          (cl-loop
+           for dir in (if native-compile-target-directory
+                          (list (expand-file-name comp-native-version-dir
+                                                  native-compile-target-directory))
+                        (comp-eln-load-path-eff))
+           for f = (expand-file-name
+                    (comp-trampoline-filename subr-name)
+                    dir)
+           unless (file-exists-p dir)
+           do (ignore-errors
+                (make-directory dir t)
+                (cl-return f))
+           when (file-writable-p f)
+           do (cl-return f)
+           finally (error "Cannot find suitable directory for output in \
+`native-comp-eln-load-path'"))))))
 
 \f
 ;; Some entry point support code.
index bdd7751fc0c1ef2d7000fedbbb6ea63f70884b95..2af174ff752f1e911bee757af4f02b90e394f079 100644 (file)
@@ -218,7 +218,7 @@ All commands in `lisp-mode-shared-map' are inherited by this map.")
 Load the compiled code when finished.
 
 Use `emacs-lisp-byte-compile-and-load' in combination with
-`native-comp-deferred-compilation' set to t to achieve asynchronous
+`inhibit-native-compilation' set to nil to achieve asynchronous
 native compilation."
   (interactive nil emacs-lisp-mode)
   (emacs-lisp--before-compile-buffer)
index 0f5de5affc38d4191cbcf945a19fdc2dce958a88..9e09a051c531bd5ff281a38c44cc5a347c222163 100644 (file)
@@ -524,7 +524,7 @@ DIRS are relative."
      (t emacs-d-dir))))
 
 (defvar native-comp-eln-load-path)
-(defvar native-comp-deferred-compilation)
+(defvar inhibit-native-compilation)
 (defvar comp-enable-subr-trampolines)
 
 (defun normal-top-level ()
@@ -532,6 +532,9 @@ DIRS are relative."
 It sets `command-line-processed', processes the command-line,
 reads the initialization files, etc.
 It is the default value of the variable `top-level'."
+  ;; Allow disabling automatic .elc->.eln processing.
+  (setq inhibit-native-compilation (getenv "EMACS_INHIBIT_NATIVE_COMPILATION"))
+
   (if command-line-processed
       (message internal--top-level-message)
     (setq command-line-processed t)
@@ -550,7 +553,7 @@ It is the default value of the variable `top-level'."
         ;; in this session.  This is necessary if libgccjit is not
         ;; available on MS-Windows, but Emacs was built with
         ;; native-compilation support.
-        (setq native-comp-deferred-compilation nil
+        (setq inhibit-native-compilation t
               comp-enable-subr-trampolines nil))
 
       ;; Form `native-comp-eln-load-path'.
index dc0359acdae8aadaf53a3a39bf89f0eb08e315cf..5600339581a675d85d8521e9d93c6b9bd2bc7036 100644 (file)
@@ -4826,6 +4826,7 @@ maybe_defer_native_compilation (Lisp_Object function_name,
     return;
 
   if (!native_comp_deferred_compilation
+      || !NILP (Vinhibit_native_compilation)
       || noninteractive
       || !NILP (Vpurify_flag)
       || !COMPILEDP (definition)
@@ -5336,6 +5337,13 @@ syms_of_comp (void)
 {
 #ifdef HAVE_NATIVE_COMP
   /* Compiler control customizes.  */
+  DEFVAR_LISP ("inhibit-native-compilation", Vinhibit_native_compilation,
+              doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files.
+
+After compilation, each function definition is updated to the native
+compiled one.  */);
+  Vinhibit_native_compilation = Qnil;
+
   DEFVAR_BOOL ("native-comp-deferred-compilation",
               native_comp_deferred_compilation,
               doc: /* If non-nil compile loaded .elc files asynchronously.