unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: pcase generates an unprintable expansion for a form in test erc--restore-initialize-priors
Date: Sun, 26 May 2024 15:30:19 +0000	[thread overview]
Message-ID: <ZlNVi8k59lVzkbnV@ACM> (raw)

Hello, Stefan and Emacs.

The ert test erc--restore-initialize-priors in test/lisp/erc/erc-tests.el
looks like this:

(ert-deftest erc--restore-initialize-priors ()
  (unless (>= emacs-major-version 28)
    (ert-skip "Lisp nesting exceeds `max-lisp-eval-depth'"))
  (should (pcase (macroexpand-1 '(erc--restore-initialize-priors erc-my-mode
                                   foo (ignore 1 2 3)
                                   bar #'spam
                                   baz nil))
            (`(let* ((,p (or erc--server-reconnecting erc--target-priors))
                     (,q (and ,p (alist-get 'erc-my-mode ,p))))
                (unless (local-variable-if-set-p 'erc-my-mode)
                  (error "Not a local minor mode var: %s" 'erc-my-mode))
                (setq foo (if ,q (alist-get 'foo ,p) (ignore 1 2 3))
                      bar (if ,q (alist-get 'bar ,p) #'spam)
                      baz (if ,q (alist-get 'baz ,p) nil)))
             t))))

..  Note that the pcase form is expanding a backquoted form lacking in
pcase features such as nested backquotes, pcase variable names, and the
like.

The pcase expansion thus consists of a deeply nested alternation of forms
like 
    (if (consp x1961) ...)
and
    (let* ((x1962 (car-safe x1961))) ...)
..

The level of nesting is greater than, or close enough to 200 that
printing it can lead to the detection of an apparent circular structure
in print_object in src/print.c.  There PRINT_CIRCLE is #defined as 200.

This leads the printer to printing out the error message:

    Apparently circular structure being printed

and throwing an error.  When this happened to me, the ert structure
containing this expansion was accessible from the stack, so it triggered
the error again recursively, resulting in the log file erc-tests.log
being 131 MB big.  I haven't looked to see what terminated this recursive
exception.

The situation seems to be what triggered bug#71178.

The form being compared using pcase, although not tiny, is not all that
big, and it would be easy to increase its size to cause it to violate any
reasonable value of PRINT_CIRCLE.

Would it be possible and a good idea to amend pcase such that it
generates less deeply nested expansions for forms such as we have here?
Or does anybody have any ideas how better to resolve the problem?

-- 
Alan Mackenzie (Nuremberg, Germany).



             reply	other threads:[~2024-05-26 15:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-26 15:30 Alan Mackenzie [this message]
2024-05-26 21:19 ` pcase generates an unprintable expansion for a form in test erc--restore-initialize-priors Michael Heerdegen via Emacs development discussions.
2024-05-27 17:39 ` Stefan Monnier
2024-05-27 18:23   ` Stefan Monnier
2024-05-27 19:29     ` Michael Heerdegen via Emacs development discussions.
2024-05-27 19:42       ` Stefan Monnier
2024-05-29 15:39         ` Michael Heerdegen
2024-05-30 23:43           ` Stefan Monnier
2024-05-31  7:32             ` Andrea Corallo
2024-05-31 12:45               ` Stefan Monnier
2024-06-03 17:42           ` Stefan Monnier
2024-06-04  0:57             ` Michael Heerdegen
2024-05-27 20:14   ` F. Jason Park
2024-05-27 22:31     ` Stefan Monnier
2024-05-30 23:45 ` Stefan Monnier

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=ZlNVi8k59lVzkbnV@ACM \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.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).