From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#67883: 29.1.90; Native compiler hangs when compiling code with circular objects Date: Tue, 19 Dec 2023 07:48:50 -0500 Message-ID: References: <87a5q7bc2f.fsf@disroot.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26266"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: hokomo@disroot.org To: 67883@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 19 13:50:18 2023 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 1rFZYA-0006bh-0X for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Dec 2023 13:50:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFZY0-0007Fd-St; Tue, 19 Dec 2023 07:50:10 -0500 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 1rFZXs-0007DT-DQ for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 07:50:00 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rFZXs-0006FI-4m for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 07:50:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rFZXu-0005mI-MA for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 07:50:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Dec 2023 12:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67883 X-GNU-PR-Package: emacs X-Debbugs-Original-To: hokomo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: 67883@debbugs.gnu.org, hokomo Original-Received: via spool by submit@debbugs.gnu.org id=B.170299014822128 (code B ref -1); Tue, 19 Dec 2023 12:50:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Dec 2023 12:49:08 +0000 Original-Received: from localhost ([127.0.0.1]:34585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFZX2-0005kp-GY for submit@debbugs.gnu.org; Tue, 19 Dec 2023 07:49:08 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:56344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFZX1-0005k5-Oz for submit@debbugs.gnu.org; Tue, 19 Dec 2023 07:49:08 -0500 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 1rFZWq-00079J-Jc for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 07:48:56 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFZWq-00069D-8U; Tue, 19 Dec 2023 07:48:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=2UEXrdnFwdVrOYqps1tFOVSIQV2VR2OYmi2JjbiEO1E=; b=Cqmhl7C/aqxTo7Ctlhw3 VseKyPQxC6+AJaeuUJQDOr59iKtncuVGVlyJNM2YwDnGSf483i2WPDd71TmVx3bmKcemIlkro0UHf FRhfPw9tVX81qrzBvWjQTfoHaHxMAZxVODZdZjEtEvu0aM1FcM9gE7joKE159n6MiAa0MBGkps4Fo EQmU2zZvcszmg751oER0Orm7xJQx3w+Ni7xc1BXjCbsL+f20pMlhDi4BpFz5yj2+KiDUDpuvO3v8T XUU71uBrh0ZdcS8MMwstEgFC8+2RDrgkcDmTv8PBsYbP+Nw1hL1hbGsYQcG9ipTCsgv0rp1CUsLj3 IEMwkKYsrtBLSQ==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rFZWo-00019y-4m; Tue, 19 Dec 2023 07:48:55 -0500 In-Reply-To: <87a5q7bc2f.fsf@disroot.org> (hokomo via's message of "Mon, 18 Dec 2023 18:22:41 +0100") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:276510 Archived-At: hokomo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > Hello, > > The Emacs Lisp native compiler goes into an infinite loop when > compiling code that contains circular objects. > > For example, put the following into a file and use M-x > emacs-lisp-native-compile; it should hang: > > (defun test1 () > '#1=(1 2 3 . #1#)) > > It seems like this only happens for certain top-level forms, such as > `defun' (which may be expected behavior, due to the way the file > compiler processes top-level forms). For example, this doesn't hang: > > (lambda () > '#1=(1 2 3 . #1#)) > > Here's a more interesting example, which is how I stumbled upon this > issue in the first place: > > (defun cycle-pure (list) > (declare (pure t) (side-effect-free t)) > (let ((newlist (append list ()))) > (nconc newlist newlist))) > > (defun test2 () > (cycle-pure '(1 2 3))) > > (The definition of `cycle-pure' is copied from the `-cycle' function > from the dash.el package.) > > If `cycle-pure' is not yet defined when compiling, the compiler > doesn't hang. > > However, if `cycle-pure' is defined (e.g. via M-x eval-defun), the > compiler hangs. This is weird because, unlike `test1' above, `test2' > doesn't contain a circular list itself; it only builds it at run-time. > > In contrast, this example doesn't hang, regardless of whether `cycle' > is defined or not (note the removed declarations): > > (defun cycle (list) > (let ((newlist (append list ()))) > (nconc newlist newlist))) > > (defun test3 () > (cycle '(1 2 3))) > > My conjecture is that the `pure' and `side-effect-free' declarations > within `cycle-pure' (which I assume are picked up only once the > function definition is loaded) allow the compiler to do some constant > folding when it sees the expression `(cycle-pure '(1 2 3))'. This > results in the compiler manipulating a circular list at compile-time, > just like in `test1', and leads to a hang. > > Kind regards, > hokomo I'm pretty sure I've investigated this in the past. IIRC this is due some cl- function hanging on a circular list. Can't find the bug number ATM. Andrea