unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: acm@muc.de, Eli Zaretskii <eliz@gnu.org>,
	Protesilaos Stavrou <info@protesilaos.com>,
	55414@debbugs.gnu.org
Subject: bug#55414: 29.0.50; Byte compilation error for the modus-themes
Date: Thu, 26 May 2022 11:20:14 -0400	[thread overview]
Message-ID: <jwv1qwgcoht.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <875ylscxre.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 26 May 2022 13:57:09 +0200")

Lars Ingebrigtsen [2022-05-26 13:57:09] wrote:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> Lars, is it just me, or are you also concerned by a large increase in
>> the default values of these variables?
>
> I'm not really that concerned in general, but in this case, the entire
> problem is apparently due to one function --
> byte-compile--first-symbol-with-pos -- that's very recursive.  It could
> be rewritten to not be recursive, and these problems would go away
> (which we've seen in many contexts now), if I understand correctly.

The patch below should significantly reduce the recursion depth (and
hopefully make it faster, to boot) because the (loop (cdr form)) call is
in tail position (and named-let should hence apply TCO to it).

Does it help for modus-themes?


        Stefan


diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 87798288fb5..6e9ad39c6a7 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1183,28 +1183,23 @@ byte-compile-abbreviate-file
 (defun byte-compile--first-symbol-with-pos (form)
   "Return the \"first\" symbol with position found in form, or 0 if none.
 Here, \"first\" is by a depth first search."
-  (let (sym)
-    (cond
-     ((symbol-with-pos-p form) form)
-     ((consp form)
-      (or (and (symbol-with-pos-p (setq sym (byte-compile--first-symbol-with-pos (car form))))
-               sym)
-          (and (symbolp (setq sym (byte-compile--first-symbol-with-pos (cdr form))))
-               sym)
-          0))
-     ((and (or (vectorp form) (recordp form))
-           (> (length form) 0))
-      (let ((i 0)
-            (len (length form))
-            elt)
-        (catch 'sym
-          (while (< i len)
-            (when (symbol-with-pos-p
-                   (setq elt (byte-compile--first-symbol-with-pos (aref form i))))
-              (throw 'sym elt))
-            (setq i (1+ i)))
-          0)))
-     (t 0))))
+  (or (named-let loop ((form form))
+        (cond
+         ((symbol-with-pos-p form) form)
+         ((consp form)
+          (or (loop (car form))
+              (loop (cdr form))))
+         ((and (or (vectorp form) (recordp form))
+               (> (length form) 0))
+          (let ((i 0)
+                (len (length form))
+                elt)
+            (catch 'sym
+              (while (< i len)
+                (when (setq elt (loop (aref form i)))
+                  (throw 'sym elt))
+                (setq i (1+ i))))))))
+      0))
 
 (defun byte-compile--warning-source-offset ()
   "Return a source offset from `byte-compile-form-stack'.






  parent reply	other threads:[~2022-05-26 15:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-14 18:07 bug#55414: 29.0.50; Byte compilation error for the modus-themes Protesilaos Stavrou
2022-05-15 13:45 ` Lars Ingebrigtsen
     [not found]   ` <87lev296hl.fsf@protesilaos.com>
2022-05-15 15:16     ` Lars Ingebrigtsen
2022-05-16  7:58       ` Alan Mackenzie
2022-05-16  8:21         ` Protesilaos Stavrou
2022-05-16 11:15         ` Eli Zaretskii
2022-05-16 12:03           ` Alan Mackenzie
2022-05-16 12:26             ` Eli Zaretskii
2022-05-16 13:48               ` Alan Mackenzie
2022-05-16 13:56                 ` Eli Zaretskii
2022-05-16 14:52                   ` Protesilaos Stavrou
2022-05-16 15:56                     ` Eli Zaretskii
2022-05-22 13:10                       ` Alan Mackenzie
2022-05-22 13:25                         ` Eli Zaretskii
2022-05-23  3:51                           ` Protesilaos Stavrou
2022-05-23 10:57                             ` Eli Zaretskii
2022-05-24  4:37                               ` Protesilaos Stavrou
2022-05-24 11:09                                 ` Eli Zaretskii
2022-05-25  3:24                                   ` Protesilaos Stavrou
2022-05-25 13:12                                     ` Eli Zaretskii
2022-05-26  5:55                                       ` Protesilaos Stavrou
2022-05-26 11:32                                         ` Eli Zaretskii
2022-05-26 11:57                                           ` Lars Ingebrigtsen
2022-05-26 12:59                                             ` Eli Zaretskii
2022-05-26 15:20                                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-05-26 15:42                                               ` Protesilaos Stavrou
2022-05-27  9:52                                             ` Alan Mackenzie
2022-05-27 10:25                                               ` Lars Ingebrigtsen
2022-05-26 16:02               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-26 15:30 ` Mattias Engdegård
2022-05-27  9:03   ` Mattias Engdegård
2022-05-27 10:23     ` Lars Ingebrigtsen
2022-05-27 10:39       ` Protesilaos Stavrou
2022-05-27 10:42         ` Lars Ingebrigtsen
2022-05-27 11:32           ` Alan Mackenzie
2022-05-27 11:52             ` Lars Ingebrigtsen
2022-05-27 13:42               ` Alan Mackenzie
2022-05-27 13:50                 ` Lars Ingebrigtsen
2022-05-28 23:13                   ` Richard Stallman
2022-05-27 12:15             ` Protesilaos Stavrou
2022-05-27 13:59   ` Alan Mackenzie
2022-05-27 16:53     ` Mattias Engdegård
2022-05-27 18:24       ` Alan Mackenzie
2022-05-29  9:18         ` Mattias Engdegård
2022-05-29 13:38           ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1qwgcoht.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=55414@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=info@protesilaos.com \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).