From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: pcase generates an unprintable expansion for a form in test erc--restore-initialize-priors Date: Sun, 26 May 2024 15:30:19 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1371"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 26 17:31:36 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sBFqS-0000Fn-Oh for ged-emacs-devel@m.gmane-mx.org; Sun, 26 May 2024 17:31:36 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBFpf-00081O-Gl; Sun, 26 May 2024 11:30:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBFpd-00080k-C8 for emacs-devel@gnu.org; Sun, 26 May 2024 11:30:45 -0400 Original-Received: from mail.muc.de ([193.149.48.3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBFpa-0003MG-Jp for emacs-devel@gnu.org; Sun, 26 May 2024 11:30:45 -0400 Original-Received: (qmail 91316 invoked by uid 3782); 26 May 2024 17:30:23 +0200 Original-Received: from muc.de (pd953a556.dip0.t-ipconnect.de [217.83.165.86]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 26 May 2024 17:30:22 +0200 Original-Received: (qmail 31728 invoked by uid 1000); 26 May 2024 15:30:19 -0000 Content-Disposition: inline X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.3; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319586 Archived-At: 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).