emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 5fec9182db: Add new variable 'inhibit-native-compilation'


From: Lars Ingebrigtsen
Subject: master 5fec9182db: Add new variable 'inhibit-native-compilation'
Date: Mon, 3 Oct 2022 09:26:22 -0400 (EDT)

branch: master
commit 5fec9182dbeffa88cef6651d8c798ef9665d6681
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new variable 'inhibit-native-compilation'
    
    * doc/lispref/compile.texi (Native-Compilation Variables):
    Document it.
    
    * lisp/startup.el (normal-top-level): Set
    inhibit-native-compilation from environment variable.
    
    * lisp/subr.el (native-comp-deferred-compilation): Make obsolete.
    
    * 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.
---
 doc/lispref/compile.texi     | 18 ++++++++++++++++++
 etc/NEWS                     | 15 +++++++++++----
 lisp/emacs-lisp/comp.el      | 36 ++++++++++++++++++++----------------
 lisp/progmodes/elisp-mode.el |  2 +-
 lisp/startup.el              |  7 +++++--
 lisp/subr.el                 |  3 +++
 src/comp.c                   |  8 ++++++++
 7 files changed, 66 insertions(+), 23 deletions(-)

diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi
index 60fc11a22e..e6e9fd1be8 100644
--- a/doc/lispref/compile.texi
+++ b/doc/lispref/compile.texi
@@ -973,6 +973,24 @@ whether native-compilation is available should use this 
predicate.
   This section documents the variables that control
 native-compilation.
 
+@defvar inhibit-native-compilation
+If your Emacs has support for native compilation, Emacs will (by
+default) compile the Lisp files you're loading in the background, and
+then install the native-compiled versions of the functions.  If you
+wish to disable this, you can set this variable to non-@code{nil}.  If
+you want to set it permanently, this should probably be done from the
+early init file, since setting it in the normal init file is probably
+too late.
+
+While setting this variable disables automatic compilation of Lisp
+files, the compiler may still be invoked to install @dfn{trampolines}
+if any built-in functions are redefined.  However, these trampolines
+will not get written to disk.
+
+You can also use the @samp{EMACS_INHIBIT_NATIVE_COMPILATION}
+environment variable to disable native compilation.
+@end defvar
+
 @defopt native-comp-speed
 This variable specifies the optimization level for native compilation.
 Its value should be a number between @minus{}1 and 3.  Values between
diff --git a/etc/NEWS b/etc/NEWS
index d7bc4b0e0c..6e7836e3c0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -170,10 +170,17 @@ time.
 
 ** Native Compilation
 
----
-*** New command 'native-compile-prune-cache'.
-This command deletes older ".eln" cache entries (but not the ones for
-the current Emacs version).
++++
+*** New variable 'inhibit-native-compilation'.
+If set, Emacs will inhibit native compilation (and won't write
+anything to the eln cache automatically).  The variable is initialised
+from the EMACS_INHIBIT_NATIVE_COMPILATION environment variable on
+Emacs startup.
+
+
+--- *** New command 'native-compile-prune-cache'.  This command
+deletes older ".eln" cache entries (but not the ones for the current
+Emacs version).
 
 ---
 *** New function 'startup-redirect-eln-cache'.
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index abab9107ae..759cedddef 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -3801,22 +3801,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'"))))))
 
 
 ;; Some entry point support code.
@@ -4107,6 +4110,7 @@ the deferred compilation mechanism."
                    comp-ctxt
                    (comp-ctxt-output comp-ctxt)
                    (file-exists-p (comp-ctxt-output comp-ctxt)))
+          (message "Deleting %s" (comp-ctxt-output comp-ctxt))
           (delete-file (comp-ctxt-output comp-ctxt)))))))
 
 (defun native-compile-async-skip-p (file load selector)
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 4ada27a1ac..c12453e883 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -220,7 +220,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)
diff --git a/lisp/startup.el b/lisp/startup.el
index 50a8f491d8..03a67cdc0e 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -541,7 +541,7 @@ DIRS are relative."
   (setq comp--compilable t))
 
 (defvar native-comp-eln-load-path)
-(defvar native-comp-deferred-compilation)
+(defvar inhibit-native-compilation)
 (defvar comp-enable-subr-trampolines)
 
 (defvar startup--original-eln-load-path nil
@@ -578,6 +578,9 @@ the updated value."
 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)
@@ -596,7 +599,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'.
diff --git a/lisp/subr.el b/lisp/subr.el
index 4f8273d56f..0c9d94db1c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1876,6 +1876,9 @@ activations.  To prevent runaway recursion, use 
`max-lisp-eval-depth'
 instead; it will indirectly limit the specpdl stack size as well.")
 (make-obsolete-variable 'max-specpdl-size nil "29.1")
 
+(make-obsolete-variable 'native-comp-deferred-compilation
+                        'inhibit-native-compilation "29.1")
+
 
 ;;;; Alternate names for functions - these are not being phased out.
 
diff --git a/src/comp.c b/src/comp.c
index 4813ca04a9..ed64a85072 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -5107,6 +5107,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)
@@ -5610,6 +5611,13 @@ For internal use.  */);
               doc: /* Non-nil when comp.el can be native compiled.
 For internal use. */);
   /* 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]