Subject: Re: bug#58509: 29.0.50; Synchronous nativecomp

From: Andrea Corallo <[email-masked]>
Date: Tue, 18 Oct 2022 13:55:18 +0000

Eli Zaretskii <[email-masked]> writes:

>> From: Lars Ingebrigtsen <[email-masked]>
>> Cc: [email-masked],  [email-masked]
>> Date: Mon, 17 Oct 2022 21:30:24 +0200
>> 
>> Sure, we can do it via a command-line argument instead.  Perhaps this
>> fits well with the proposed --native-compile-sync switch, even.
>> 
>> That is, instead of that, we could have a --native-compile-mode command
>> line switch with the values --native-compile-mode=none,
>> --native-compile-mode=sync and --native-compile-mode=normal?
>
> I doubt we really need to have an option with 3 values.  The default
> already does TRT in almost all cases, so all we need is to suppress
> async compilation of trampolines, because that could cause trouble.

The attached works for me for fixing the trampoline issue (unless I did
something wrong reproducing).

I named the flag -no-comp-spawn from the variable it controls.  Happy to
rename it if we have something better, but being for internal use only
maybe is already okay?

BR

  Andrea

>From 01e8bc45a34f754af13e6ff05de71b320a15ffc0 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <[email-masked]>
Date: Tue, 18 Oct 2022 15:14:32 +0200
Subject: [PATCH] Set `comp-no-spawn' earlier using -no-comp-spawn

* src/emacs.c (standard_args): Add '-no-comp-spawn' cmd line option.
* lisp/startup.el (command-line): Parse '-no-comp-spawn' cmd line
option.
* lisp/emacs-lisp/comp.el (comp-run-async-workers, comp-final):
Use '-no-comp-spawn'.
---
 lisp/emacs-lisp/comp.el | 10 +++++-----
 lisp/startup.el         |  5 ++++-
 src/emacs.c             |  1 +
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 2c9b79334b..ddfdbf286a 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -3689,8 +3689,7 @@ comp-final
              (print-circle t)
              (print-escape-multibyte t)
              (expr `((require 'comp)
-                     (setf comp-no-spawn t
-                           native-comp-verbose ,native-comp-verbose
+                     (setf native-comp-verbose ,native-comp-verbose
                            comp-libgccjit-reproducer ,comp-libgccjit-reproducer
                            comp-ctxt ,comp-ctxt
                            native-comp-eln-load-path ',native-comp-eln-load-path
@@ -3716,7 +3715,8 @@ comp-final
               (if (zerop
                    (call-process (expand-file-name invocation-name
                                                    invocation-directory)
-				 nil t t "--batch" "-l" temp-file))
+				 nil t t "-no-comp-spawn" "--batch" "-l"
+                                 temp-file))
                   (progn
                     (delete-file temp-file)
                     output)
@@ -3947,7 +3947,6 @@ comp-run-async-workers
                      source-file (comp-el-to-eln-filename source-file))))
          do (let* ((expr `((require 'comp)
                            (setq comp-async-compilation t
-                                 comp-no-spawn t
                                  warning-fill-column most-positive-fixnum)
                            ,(let ((set (list 'setq)))
                               (dolist (var '(comp-file-preloaded-p
@@ -4004,7 +4003,8 @@ comp-run-async-workers
                              :command (list
                                        (expand-file-name invocation-name
                                                          invocation-directory)
-                                       "--batch" "-l" temp-file)
+                                       "-no-comp-spawn" "--batch" "-l"
+                                       temp-file)
                              :sentinel
                              (lambda (process _event)
                                (run-hook-with-args
diff --git a/lisp/startup.el b/lisp/startup.el
index 725984b815..70267fc857 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1198,7 +1198,7 @@ command-line
                          ("--user") ("--iconic") ("--icon-type") ("--quick")
 			 ("--no-blinking-cursor") ("--basic-display")
                          ("--dump-file") ("--temacs") ("--seccomp")
-                         ("--init-directory")))
+                         ("--init-directory" "--no-comp-spawn")))
              (argi (pop args))
              (orig-argi argi)
              argval)
@@ -1255,6 +1255,9 @@ command-line
 	 ((equal argi "-no-site-file")
 	  (setq site-run-file nil)
 	  (put 'site-run-file 'standard-value '(nil)))
+         ((equal argi "-no-comp-spawn")
+          (defvar comp-no-spawn)
+          (setq comp-no-spawn t))
 	 ((equal argi "-debug-init")
 	  (setq init-file-debug t))
 	 ((equal argi "-iconic")
diff --git a/src/emacs.c b/src/emacs.c
index 43e81b912c..8ad70fecd4 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -2564,6 +2564,7 @@ main (int argc, char **argv)
   { "-init-directory", "--init-directory", 30, 1 },
   { "-no-x-resources", "--no-x-resources", 40, 0 },
   { "-no-site-file", "--no-site-file", 40, 0 },
+  { "-no-comp-spawn", "--no-comp-spawn", 60, 0 },
   { "-u", "--user", 30, 1 },
   { "-user", 0, 30, 1 },
   { "-debug-init", "--debug-init", 20, 0 },
-- 
2.25.1