aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2021-11-30 14:18:58 +0100
committerAndrea Corallo2021-11-30 15:42:41 +0100
commit9b381a95ef6cd9194d64bfb17fd50bb99fa6cd32 (patch)
tree2beaee9f148cae181ff7948dc9fb9ee12f88b839
parent7b235b1ec05c48d70ea44982f04b7b5f4052fa05 (diff)
downloademacs-9b381a95ef6cd9194d64bfb17fd50bb99fa6cd32.tar.gz
emacs-9b381a95ef6cd9194d64bfb17fd50bb99fa6cd32.zip
Improve native compiler startup circular dependecy prevention mechanism
* src/comp.c (maybe_defer_native_compilation): Update to accumulate delayed objects in `comp--delayed-sources'. (syms_of_comp): Add `comp--delayed-sources' and `comp--loadable' vars. * lisp/startup.el (startup--honor-delayed-native-compilations): New function. (normal-top-level): Call it.
-rw-r--r--lisp/startup.el16
-rw-r--r--src/comp.c35
2 files changed, 26 insertions, 25 deletions
diff --git a/lisp/startup.el b/lisp/startup.el
index fc085e6d0ef..d4bb338fc0b 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -519,6 +519,19 @@ DIRS are relative."
519 xdg-dir) 519 xdg-dir)
520 (t emacs-d-dir)))) 520 (t emacs-d-dir))))
521 521
522(defvar comp--delayed-sources)
523(defvar comp--loadable)
524(declare-function native--compile-async "comp.el"
525 (files &optional recursively load selector))
526(defun startup--honor-delayed-native-compilations ()
527 "Honor pending delayed deferred native compilations."
528 (when (and (native-comp-available-p)
529 comp--delayed-sources)
530 (require 'comp)
531 (setq comp--loadable t)
532 (native--compile-async comp--delayed-sources nil 'late)
533 (setq comp--delayed-sources nil)))
534
522(defvar native-comp-eln-load-path) 535(defvar native-comp-eln-load-path)
523(defun normal-top-level () 536(defun normal-top-level ()
524 "Emacs calls this function when it first starts up. 537 "Emacs calls this function when it first starts up.
@@ -785,7 +798,8 @@ It is the default value of the variable `top-level'."
785 (if (string-match "\\`DISPLAY=" varval) 798 (if (string-match "\\`DISPLAY=" varval)
786 (setq display varval)))) 799 (setq display varval))))
787 (when display 800 (when display
788 (delete display process-environment))))) 801 (delete display process-environment))))
802 (startup--honor-delayed-native-compilations))
789 803
790;; Precompute the keyboard equivalents in the menu bar items. 804;; Precompute the keyboard equivalents in the menu bar items.
791;; Command-line options supported by tty's: 805;; Command-line options supported by tty's:
diff --git a/src/comp.c b/src/comp.c
index 5b947fc99b6..ab7006cca64 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4786,10 +4786,6 @@ register_native_comp_unit (Lisp_Object comp_u)
4786/* Deferred compilation mechanism. */ 4786/* Deferred compilation mechanism. */
4787/***********************************/ 4787/***********************************/
4788 4788
4789/* List of sources we'll compile and load after having conventionally
4790 loaded the compiler and its dependencies. */
4791static Lisp_Object delayed_sources;
4792
4793/* Queue an asynchronous compilation for the source file defining 4789/* Queue an asynchronous compilation for the source file defining
4794 FUNCTION_NAME and perform a late load. 4790 FUNCTION_NAME and perform a late load.
4795 4791
@@ -4846,30 +4842,16 @@ maybe_defer_native_compilation (Lisp_Object function_name,
4846 4842
4847 /* This is so deferred compilation is able to compile comp 4843 /* This is so deferred compilation is able to compile comp
4848 dependencies breaking circularity. */ 4844 dependencies breaking circularity. */
4849 if (!NILP (Ffeaturep (Qcomp, Qnil))) 4845 if (comp__loadable)
4850 { 4846 {
4851 /* Comp already loaded. */ 4847 /* Startup is done, comp is usable. */
4852 if (!NILP (delayed_sources)) 4848 Frequire (Qcomp, Qnil, Qnil);
4853 {
4854 CALLN (Ffuncall, intern_c_string ("native--compile-async"),
4855 delayed_sources, Qnil, Qlate);
4856 delayed_sources = Qnil;
4857 }
4858 Fputhash (function_name, definition, Vcomp_deferred_pending_h); 4849 Fputhash (function_name, definition, Vcomp_deferred_pending_h);
4859 CALLN (Ffuncall, intern_c_string ("native--compile-async"), 4850 CALLN (Ffuncall, intern_c_string ("native--compile-async"),
4860 src, Qnil, Qlate); 4851 src, Qnil, Qlate);
4861 } 4852 }
4862 else 4853 else
4863 { 4854 Vcomp__delayed_sources = Fcons (src, Vcomp__delayed_sources);
4864 delayed_sources = Fcons (src, delayed_sources);
4865 /* Require comp only once. */
4866 static bool comp_required = false;
4867 if (!comp_required)
4868 {
4869 comp_required = true;
4870 Frequire (Qcomp, Qnil, Qnil);
4871 }
4872 }
4873} 4855}
4874 4856
4875 4857
@@ -5328,6 +5310,13 @@ void
5328syms_of_comp (void) 5310syms_of_comp (void)
5329{ 5311{
5330#ifdef HAVE_NATIVE_COMP 5312#ifdef HAVE_NATIVE_COMP
5313 DEFVAR_LISP ("comp--delayed-sources", Vcomp__delayed_sources,
5314 doc: /* List of sources to be native compiled when
5315 startup is finished. For internal use. */);
5316 DEFVAR_BOOL ("comp--loadable",
5317 comp__loadable,
5318 doc: /* Non-nil when comp.el can be loaded. For
5319 internal use. */);
5331 /* Compiler control customizes. */ 5320 /* Compiler control customizes. */
5332 DEFVAR_BOOL ("native-comp-deferred-compilation", 5321 DEFVAR_BOOL ("native-comp-deferred-compilation",
5333 native_comp_deferred_compilation, 5322 native_comp_deferred_compilation,
@@ -5468,8 +5457,6 @@ compiled one. */);
5468 staticpro (&comp.func_blocks_h); 5457 staticpro (&comp.func_blocks_h);
5469 staticpro (&comp.emitter_dispatcher); 5458 staticpro (&comp.emitter_dispatcher);
5470 comp.emitter_dispatcher = Qnil; 5459 comp.emitter_dispatcher = Qnil;
5471 staticpro (&delayed_sources);
5472 delayed_sources = Qnil;
5473 staticpro (&loadsearch_re_list); 5460 staticpro (&loadsearch_re_list);
5474 loadsearch_re_list = Qnil; 5461 loadsearch_re_list = Qnil;
5475 5462