From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: hokomo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67883: 29.1.90; Native compiler hangs when compiling code with circular objects Date: Mon, 18 Dec 2023 18:22:41 +0100 Message-ID: <87a5q7bc2f.fsf@disroot.org> Reply-To: hokomo Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13296"; mail-complaints-to="usenet@ciao.gmane.io" To: 67883@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 18 19:40:20 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 1rFIXM-0003Ec-FH for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Dec 2023 19:40:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFIX9-0004J2-N0; Mon, 18 Dec 2023 13:40:07 -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 1rFIX7-0004Io-DE for bug-gnu-emacs@gnu.org; Mon, 18 Dec 2023 13:40:06 -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 1rFIX2-000663-AW for bug-gnu-emacs@gnu.org; Mon, 18 Dec 2023 13:40:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rFIX4-00083s-88 for bug-gnu-emacs@gnu.org; Mon, 18 Dec 2023 13:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: hokomo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Dec 2023 18:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 67883 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170292475730887 (code B ref -1); Mon, 18 Dec 2023 18:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Dec 2023 18:39:17 +0000 Original-Received: from localhost ([127.0.0.1]:33597 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFIWK-000824-Pm for submit@debbugs.gnu.org; Mon, 18 Dec 2023 13:39:17 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:36934) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFILZ-0004wF-E2 for submit@debbugs.gnu.org; Mon, 18 Dec 2023 13:28:09 -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 1rFILS-0008Jc-3c for bug-gnu-emacs@gnu.org; Mon, 18 Dec 2023 13:28:02 -0500 Original-Received: from layka.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rFILP-00048L-VM for bug-gnu-emacs@gnu.org; Mon, 18 Dec 2023 13:28:01 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 2314A40C82 for ; Mon, 18 Dec 2023 19:27:56 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Original-Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Td8P6mSB7030 for ; Mon, 18 Dec 2023 19:27:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1702924074; bh=rZ/GJXtIUGXHvL9JXoOkNqDq2iAnL5DWrKP1wJRy3n0=; h=From:To:Subject:Date; b=GZn1MdInNtLJA6tUZ1VJyGazeIu70ORT/JV+Rp+nroa/yoAUC6UPgJYweQoSy+qI+ t1V1Guk0U9y7NFb4wgzt31Z6DQXmY0raUdt2TeXTh1+H2IG7I35vQ6WB3J6zId10TX /9IVUSJv4HuocLIkr6jd787xtwFSdU8/VxMCQpnTqsgOKFomCar8EdyUA+p6biS2Yp rP8cPk3HvWOvsmeGSW85qBYR7MlAA/WbGwcU0CS6XE0fMw5Lk0SUCvs+5pYIzhLRoI NKXhn4zlumHE1/CLh8esM6iUKQ4uxEDdX1meFT2+GcE1zBYXMhX/UI/pnOAb+impDv /tRiQaQoUACCw== Received-SPF: pass client-ip=178.21.23.139; envelope-from=hokomo@disroot.org; helo=layka.disroot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 18 Dec 2023 13:39:15 -0500 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:276478 Archived-At: 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