diff options
| author | Stefan Monnier | 2023-07-13 20:11:55 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2023-07-13 20:13:32 -0400 |
| commit | fcade74066d82625e367c561a34971f52cf46a61 (patch) | |
| tree | c496c261380a248d39bcc74a144aba38bd94e47e | |
| parent | 3ffb99f28f29cd98094f359ea316468572535aa0 (diff) | |
| download | emacs-fcade74066d82625e367c561a34971f52cf46a61.tar.gz emacs-fcade74066d82625e367c561a34971f52cf46a61.zip | |
src/comp.c: Use `pending_funcalls` to fix bug#64494
Make sure `comp.el` is never loaded synchronously by simply
delaying all calls to `native--compile-async` via `pending_funcalls`.
* lisp/startup.el (comp--compilable, comp--delayed-sources): Don't declare.
(startup--require-comp-safely)
(startup--honor-delayed-native-compilations): Delete functions.
(normal-top-level): Don't call `startup--honor-delayed-native-compilations`.
* src/comp.c (maybe_defer_native_compilation): Use `pending_funcalls`.
(syms_of_comp): Delete `Vcomp__delayed_sources` and `comp__compilable`.
Define `Qnative__compile_async`.
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 1 | ||||
| -rw-r--r-- | lisp/startup.el | 24 | ||||
| -rw-r--r-- | src/comp.c | 23 |
3 files changed, 7 insertions, 41 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 22fb08e4688..5f5e7f26446 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -4226,6 +4226,7 @@ LOAD and SELECTOR work as described in `native--compile-async'." | |||
| 4226 | (string-match-p re file)) | 4226 | (string-match-p re file)) |
| 4227 | native-comp-jit-compilation-deny-list)))) | 4227 | native-comp-jit-compilation-deny-list)))) |
| 4228 | 4228 | ||
| 4229 | ;;;###autoload | ||
| 4229 | (defun native--compile-async (files &optional recursively load selector) | 4230 | (defun native--compile-async (files &optional recursively load selector) |
| 4230 | ;; BEWARE, this function is also called directly from C. | 4231 | ;; BEWARE, this function is also called directly from C. |
| 4231 | "Compile FILES asynchronously. | 4232 | "Compile FILES asynchronously. |
diff --git a/lisp/startup.el b/lisp/startup.el index 5a389294e78..7f601668369 100644 --- a/lisp/startup.el +++ b/lisp/startup.el | |||
| @@ -520,27 +520,6 @@ DIRS are relative." | |||
| 520 | xdg-dir) | 520 | xdg-dir) |
| 521 | (t emacs-d-dir)))) | 521 | (t emacs-d-dir)))) |
| 522 | 522 | ||
| 523 | (defvar comp--compilable) | ||
| 524 | (defvar comp--delayed-sources) | ||
| 525 | (defun startup--require-comp-safely () | ||
| 526 | "Require the native compiler avoiding circular dependencies." | ||
| 527 | (when (featurep 'native-compile) | ||
| 528 | ;; Require comp with `comp--compilable' set to nil to break | ||
| 529 | ;; circularity. | ||
| 530 | (let ((comp--compilable nil)) | ||
| 531 | (require 'comp)) | ||
| 532 | (native--compile-async comp--delayed-sources nil 'late) | ||
| 533 | (setq comp--delayed-sources nil))) | ||
| 534 | |||
| 535 | (declare-function native--compile-async "comp.el" | ||
| 536 | (files &optional recursively load selector)) | ||
| 537 | (defun startup--honor-delayed-native-compilations () | ||
| 538 | "Honor pending delayed deferred native compilations." | ||
| 539 | (when (and (native-comp-available-p) | ||
| 540 | comp--delayed-sources) | ||
| 541 | (startup--require-comp-safely)) | ||
| 542 | (setq comp--compilable t)) | ||
| 543 | |||
| 544 | (defvar native-comp-eln-load-path) | 523 | (defvar native-comp-eln-load-path) |
| 545 | (defvar native-comp-jit-compilation) | 524 | (defvar native-comp-jit-compilation) |
| 546 | (defvar native-comp-enable-subr-trampolines) | 525 | (defvar native-comp-enable-subr-trampolines) |
| @@ -846,8 +825,7 @@ It is the default value of the variable `top-level'." | |||
| 846 | nil))) | 825 | nil))) |
| 847 | (setq env (cdr env))))) | 826 | (setq env (cdr env))))) |
| 848 | (when display | 827 | (when display |
| 849 | (setq process-environment (delete display process-environment))))) | 828 | (setq process-environment (delete display process-environment)))))) |
| 850 | (startup--honor-delayed-native-compilations)) | ||
| 851 | 829 | ||
| 852 | ;; Precompute the keyboard equivalents in the menu bar items. | 830 | ;; Precompute the keyboard equivalents in the menu bar items. |
| 853 | ;; Command-line options supported by tty's: | 831 | ;; Command-line options supported by tty's: |
diff --git a/src/comp.c b/src/comp.c index 013ac6358c1..3c63cad18c7 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -5199,17 +5199,9 @@ maybe_defer_native_compilation (Lisp_Object function_name, | |||
| 5199 | 5199 | ||
| 5200 | Fputhash (function_name, definition, Vcomp_deferred_pending_h); | 5200 | Fputhash (function_name, definition, Vcomp_deferred_pending_h); |
| 5201 | 5201 | ||
| 5202 | /* This is so deferred compilation is able to compile comp | 5202 | pending_funcalls |
| 5203 | dependencies breaking circularity. */ | 5203 | = Fcons (list (Qnative__compile_async, src, Qnil, Qlate), |
| 5204 | if (comp__compilable) | 5204 | pending_funcalls); |
| 5205 | { | ||
| 5206 | /* Startup is done, comp is usable. */ | ||
| 5207 | CALL0I (startup--require-comp-safely); | ||
| 5208 | CALLN (Ffuncall, intern_c_string ("native--compile-async"), | ||
| 5209 | src, Qnil, Qlate); | ||
| 5210 | } | ||
| 5211 | else | ||
| 5212 | Vcomp__delayed_sources = Fcons (src, Vcomp__delayed_sources); | ||
| 5213 | } | 5205 | } |
| 5214 | 5206 | ||
| 5215 | 5207 | ||
| @@ -5674,13 +5666,6 @@ void | |||
| 5674 | syms_of_comp (void) | 5666 | syms_of_comp (void) |
| 5675 | { | 5667 | { |
| 5676 | #ifdef HAVE_NATIVE_COMP | 5668 | #ifdef HAVE_NATIVE_COMP |
| 5677 | DEFVAR_LISP ("comp--delayed-sources", Vcomp__delayed_sources, | ||
| 5678 | doc: /* List of sources to be native-compiled when startup is finished. | ||
| 5679 | For internal use. */); | ||
| 5680 | DEFVAR_BOOL ("comp--compilable", comp__compilable, | ||
| 5681 | doc: /* Non-nil when comp.el can be native compiled. | ||
| 5682 | For internal use. */); | ||
| 5683 | /* Compiler control customizes. */ | ||
| 5684 | DEFVAR_BOOL ("native-comp-jit-compilation", native_comp_jit_compilation, | 5669 | DEFVAR_BOOL ("native-comp-jit-compilation", native_comp_jit_compilation, |
| 5685 | doc: /* If non-nil, compile loaded .elc files asynchronously. | 5670 | doc: /* If non-nil, compile loaded .elc files asynchronously. |
| 5686 | 5671 | ||
| @@ -5798,6 +5783,8 @@ natively-compiled one. */); | |||
| 5798 | build_pure_c_string ("eln file inconsistent with current runtime " | 5783 | build_pure_c_string ("eln file inconsistent with current runtime " |
| 5799 | "configuration, please recompile")); | 5784 | "configuration, please recompile")); |
| 5800 | 5785 | ||
| 5786 | DEFSYM (Qnative__compile_async, "native--compile-async"); | ||
| 5787 | |||
| 5801 | defsubr (&Scomp__subr_signature); | 5788 | defsubr (&Scomp__subr_signature); |
| 5802 | defsubr (&Scomp_el_to_eln_rel_filename); | 5789 | defsubr (&Scomp_el_to_eln_rel_filename); |
| 5803 | defsubr (&Scomp_el_to_eln_filename); | 5790 | defsubr (&Scomp_el_to_eln_filename); |