[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9b381a9 1/2: Improve native compiler startup circular dependecy p
From: |
Andrea Corallo |
Subject: |
master 9b381a9 1/2: Improve native compiler startup circular dependecy prevention mechanism |
Date: |
Tue, 30 Nov 2021 09:43:01 -0500 (EST) |
branch: master
commit 9b381a95ef6cd9194d64bfb17fd50bb99fa6cd32
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>
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.
---
lisp/startup.el | 16 +++++++++++++++-
src/comp.c | 35 +++++++++++------------------------
2 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/lisp/startup.el b/lisp/startup.el
index fc085e6..d4bb338 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -519,6 +519,19 @@ DIRS are relative."
xdg-dir)
(t emacs-d-dir))))
+(defvar comp--delayed-sources)
+(defvar comp--loadable)
+(declare-function native--compile-async "comp.el"
+ (files &optional recursively load selector))
+(defun startup--honor-delayed-native-compilations ()
+ "Honor pending delayed deferred native compilations."
+ (when (and (native-comp-available-p)
+ comp--delayed-sources)
+ (require 'comp)
+ (setq comp--loadable t)
+ (native--compile-async comp--delayed-sources nil 'late)
+ (setq comp--delayed-sources nil)))
+
(defvar native-comp-eln-load-path)
(defun normal-top-level ()
"Emacs calls this function when it first starts up.
@@ -785,7 +798,8 @@ It is the default value of the variable `top-level'."
(if (string-match "\\`DISPLAY=" varval)
(setq display varval))))
(when display
- (delete display process-environment)))))
+ (delete display process-environment))))
+ (startup--honor-delayed-native-compilations))
;; Precompute the keyboard equivalents in the menu bar items.
;; Command-line options supported by tty's:
diff --git a/src/comp.c b/src/comp.c
index 5b947fc..ab7006c 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4786,10 +4786,6 @@ register_native_comp_unit (Lisp_Object comp_u)
/* Deferred compilation mechanism. */
/***********************************/
-/* List of sources we'll compile and load after having conventionally
- loaded the compiler and its dependencies. */
-static Lisp_Object delayed_sources;
-
/* Queue an asynchronous compilation for the source file defining
FUNCTION_NAME and perform a late load.
@@ -4846,30 +4842,16 @@ maybe_defer_native_compilation (Lisp_Object
function_name,
/* This is so deferred compilation is able to compile comp
dependencies breaking circularity. */
- if (!NILP (Ffeaturep (Qcomp, Qnil)))
+ if (comp__loadable)
{
- /* Comp already loaded. */
- if (!NILP (delayed_sources))
- {
- CALLN (Ffuncall, intern_c_string ("native--compile-async"),
- delayed_sources, Qnil, Qlate);
- delayed_sources = Qnil;
- }
+ /* Startup is done, comp is usable. */
+ Frequire (Qcomp, Qnil, Qnil);
Fputhash (function_name, definition, Vcomp_deferred_pending_h);
CALLN (Ffuncall, intern_c_string ("native--compile-async"),
src, Qnil, Qlate);
}
else
- {
- delayed_sources = Fcons (src, delayed_sources);
- /* Require comp only once. */
- static bool comp_required = false;
- if (!comp_required)
- {
- comp_required = true;
- Frequire (Qcomp, Qnil, Qnil);
- }
- }
+ Vcomp__delayed_sources = Fcons (src, Vcomp__delayed_sources);
}
@@ -5328,6 +5310,13 @@ void
syms_of_comp (void)
{
#ifdef HAVE_NATIVE_COMP
+ DEFVAR_LISP ("comp--delayed-sources", Vcomp__delayed_sources,
+ doc: /* List of sources to be native compiled when
+ startup is finished. For internal use. */);
+ DEFVAR_BOOL ("comp--loadable",
+ comp__loadable,
+ doc: /* Non-nil when comp.el can be loaded. For
+ internal use. */);
/* Compiler control customizes. */
DEFVAR_BOOL ("native-comp-deferred-compilation",
native_comp_deferred_compilation,
@@ -5468,8 +5457,6 @@ compiled one. */);
staticpro (&comp.func_blocks_h);
staticpro (&comp.emitter_dispatcher);
comp.emitter_dispatcher = Qnil;
- staticpro (&delayed_sources);
- delayed_sources = Qnil;
staticpro (&loadsearch_re_list);
loadsearch_re_list = Qnil;