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.bugs Subject: bug#58601: 29.0.50; Infinite loop in byte-compile--first-symbol-with-pos Date: Tue, 18 Oct 2022 17:06:59 +0000 Message-ID: References: <8735bm6nl9.fsf@tcd.ie> <87pmepw0ov.fsf@tcd.ie> 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="10821"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 58601@debbugs.gnu.org, Stefan Monnier To: "Basil L. Contovounesios" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 18 19:10:07 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1okq6R-0002fm-0w for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Oct 2022 19:10:07 +0200 Original-Received: from localhost ([::1]:46940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okq6P-0005EY-HD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Oct 2022 13:10:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okq4S-00054m-4z for bug-gnu-emacs@gnu.org; Tue, 18 Oct 2022 13:08:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okq4Q-0007Sl-UU for bug-gnu-emacs@gnu.org; Tue, 18 Oct 2022 13:08:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1okq4Q-0006n1-G3 for bug-gnu-emacs@gnu.org; Tue, 18 Oct 2022 13:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Oct 2022 17:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58601 X-GNU-PR-Package: emacs Original-Received: via spool by 58601-submit@debbugs.gnu.org id=B58601.166611283426038 (code B ref 58601); Tue, 18 Oct 2022 17:08:02 +0000 Original-Received: (at 58601) by debbugs.gnu.org; 18 Oct 2022 17:07:14 +0000 Original-Received: from localhost ([127.0.0.1]:54004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1okq3d-0006lt-PJ for submit@debbugs.gnu.org; Tue, 18 Oct 2022 13:07:14 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:30841) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1okq3Z-0006ld-BV for 58601@debbugs.gnu.org; Tue, 18 Oct 2022 13:07:12 -0400 Original-Received: (qmail 50650 invoked by uid 3782); 18 Oct 2022 19:07:01 +0200 Original-Received: from acm.muc.de (p4fe15b73.dip0.t-ipconnect.de [79.225.91.115]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 18 Oct 2022 19:07:01 +0200 Original-Received: (qmail 9512 invoked by uid 1000); 18 Oct 2022 17:06:59 -0000 Content-Disposition: inline In-Reply-To: <87pmepw0ov.fsf@tcd.ie> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:245814 Archived-At: Hello, Basil. On Tue, Oct 18, 2022 at 19:34:08 +0300, Basil L. Contovounesios wrote: > Alan Mackenzie [2022-10-18 15:01 +0000] wrote: > > On Tue, Oct 18, 2022 at 02:24:02 +0300, Basil L. Contovounesios wrote: > >> I.e. the 'pure' compile-time form has a cycle, and the DFS of > >> byte-compile--first-symbol-with-pos gets lost. > > What's a DFS? > Depth-First Search. Thanks! > >> Paraphrasing Stefan, it's acceptable if the compiler mishandles > >> circular source code, but it should be able to handle circular data. > > The problem here seems to be feeding macroexp-warn-and-return with data > > as the FORM argument. > That's not the problem, because it's just for illustrative purposes. > Instead of 'arg' being passed unchanged as the FORM argument, it could > just as well have been `(my-frobnicate ,arg). That would not loop, since there is a symbol with position there. > > FORM is intended only to be an executable lisp form. > `(my-frobnicate ,arg) fits that bill, right? The end result is the > same: macroexp-warn-and-return is fed a form containing a cycle, without > any of the code that gives rise to the form being circular itself. This would not loop. > >> I don't know why, but I can reproduce the hang only when the form is inside > >> ert-deftest+should, and not inside a plain defun. > > There is a huge concentration of "advanced" features inside those ~20 > > lines of Lisp code. > Maybe when the compiler detects sufficiently advanced Lisp it should > (signal 'indistinguishable-from-magic (list form)) > > There's eval-and-compile, > That's just a shortcut: one could equivalently put my-cycle and > my-identity in a separate file and 'require' it. The compiler just > needs to know that my-cycle is pure and my-identity has a > compiler-macro before reaching their call sites. > > nconc, a compiler-macro, and ert. ;-) > You forgot 'pure'. We're spoilt for choice! :-) > >> Perhaps byte-compile--first-symbol-with-pos needs to employ something > >> like byte-run--ssp-seen? Or does ERT somehow come into play? > > It wouldn't be difficult, just tedious, to add checking for circular > > lists into byte-compile--first-symbol-with-pos. But a circular list is > > an invalid argument for FORM in macorexp-warn-and-return, see above. > How else should a compiler-macro safely warn about a problematic > function argument? by calling the normal byte compiler warning facilities. If there is a symbol somewhere in the FORM passed to them, it won't loop, even if it is a circular list. You called macroexp-warn-and-return from outside of the byte compiler. >From within the byte compiler, it cannot generate a loop (see above). > > There are surely lots of places in Emacs where feeding a circular > > list as an argument to a function will cause a hang. > Sure, but a subset of those places should reasonably be expected to not > hang... Your circular list containing an ordinary symbol (i.e. without position) is not going to arise in the byte compiler. > > At the moment, I'm not in favour of doing anything here. I don't think > > there's a bug. > ...for instance, when dealing with compile-time constants in real-world > Elisp. Maybe you could construct an example of a circular list without a symbol from code being compiled. Maybe you could cause a warning from a correct call of macroexp-warn-and-return to loop. But I'd be surprised. > Thanks, > -- > Basil -- Alan Mackenzie (Nuremberg, Germany).