aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2022-01-27 18:18:13 +0100
committerAndrea Corallo2022-01-27 23:02:31 +0100
commit536a57b72ce11b1bb8d1b34b339424fea6ccbcce (patch)
treeb9b191c900d95f0cf6f51c1415a5a82325539dd1
parentce220524fcfcd0b51cb13cd2c15470f1b6ea0baf (diff)
downloademacs-536a57b72ce11b1bb8d1b34b339424fea6ccbcce.tar.gz
emacs-536a57b72ce11b1bb8d1b34b339424fea6ccbcce.zip
Fix potential native compiler circular dependencies during load
* lisp/startup.el (startup--require-comp-safetly): New function. (startup--honor-delayed-native-compilations): Make use of `startup--require-comp-safetly'. * src/comp.c (CALL0I): New define. (maybe_defer_native_compilation): Make use of `startup--require-comp-safetly'.
-rw-r--r--lisp/startup.el26
-rw-r--r--src/comp.c6
2 files changed, 20 insertions, 12 deletions
diff --git a/lisp/startup.el b/lisp/startup.el
index 05d829396d6..856d600e38c 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -519,22 +519,26 @@ 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) 522(defvar comp--loadable)
523(defvar comp--delayed-sources)
524(defun startup--require-comp-safetly ()
525 "Require the native compiler avoiding circular dependencies."
526 (unless (featurep 'comp)
527 ;; Require comp with `comp--loadable' set to nil to break
528 ;; circularity.
529 (let ((comp--loadable nil))
530 (require 'comp))
531 (native--compile-async comp--delayed-sources nil 'late)
532 (setq comp--delayed-sources nil)))
533
524(declare-function native--compile-async "comp.el" 534(declare-function native--compile-async "comp.el"
525 (files &optional recursively load selector)) 535 (files &optional recursively load selector))
526(defun startup--honor-delayed-native-compilations () 536(defun startup--honor-delayed-native-compilations ()
527 "Honor pending delayed deferred native compilations." 537 "Honor pending delayed deferred native compilations."
528 (if (and (native-comp-available-p) 538 (when (and (native-comp-available-p)
529 comp--delayed-sources) 539 comp--delayed-sources)
530 (progn 540 (startup--require-comp-safetly))
531 ;; Require comp before setting `comp--loadable' to break 541 (setq comp--loadable t))
532 ;; circularity.
533 (require 'comp)
534 (setq comp--loadable t)
535 (native--compile-async comp--delayed-sources nil 'late)
536 (setq comp--delayed-sources nil))
537 (setq comp--loadable t)))
538 542
539(defvar native-comp-eln-load-path) 543(defvar native-comp-eln-load-path)
540(defun normal-top-level () 544(defun normal-top-level ()
diff --git a/src/comp.c b/src/comp.c
index d755df802f7..66288988fd8 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -480,6 +480,10 @@ load_gccjit_if_necessary (bool mandatory)
480#define THIRD(x) \ 480#define THIRD(x) \
481 XCAR (XCDR (XCDR (x))) 481 XCAR (XCDR (XCDR (x)))
482 482
483/* Like call0 but stringify and intern. */
484#define CALL0I(fun) \
485 CALLN (Ffuncall, intern_c_string (STR (fun)))
486
483/* Like call1 but stringify and intern. */ 487/* Like call1 but stringify and intern. */
484#define CALL1I(fun, arg) \ 488#define CALL1I(fun, arg) \
485 CALLN (Ffuncall, intern_c_string (STR (fun)), arg) 489 CALLN (Ffuncall, intern_c_string (STR (fun)), arg)
@@ -5128,7 +5132,7 @@ maybe_defer_native_compilation (Lisp_Object function_name,
5128 if (comp__loadable) 5132 if (comp__loadable)
5129 { 5133 {
5130 /* Startup is done, comp is usable. */ 5134 /* Startup is done, comp is usable. */
5131 Frequire (Qcomp, Qnil, Qnil); 5135 CALL0I(startup--require-comp-safetly);
5132 Fputhash (function_name, definition, Vcomp_deferred_pending_h); 5136 Fputhash (function_name, definition, Vcomp_deferred_pending_h);
5133 CALLN (Ffuncall, intern_c_string ("native--compile-async"), 5137 CALLN (Ffuncall, intern_c_string ("native--compile-async"),
5134 src, Qnil, Qlate); 5138 src, Qnil, Qlate);