all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* pcase generates an unprintable expansion for a form in test erc--restore-initialize-priors
@ 2024-05-26 15:30 Alan Mackenzie
  2024-05-26 21:19 ` Michael Heerdegen via Emacs development discussions.
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Alan Mackenzie @ 2024-05-26 15:30 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier

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).



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-06-04  0:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-26 15:30 pcase generates an unprintable expansion for a form in test erc--restore-initialize-priors Alan Mackenzie
2024-05-26 21:19 ` 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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.