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 08:29:44 -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="32028"; 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 14:30:22 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 1rFaAv-00085e-JY for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Dec 2023 14:30:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFaAf-0001ep-Er; Tue, 19 Dec 2023 08:30:05 -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 1rFaAb-0001cL-3e for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 08:30:01 -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 1rFaAa-0005YC-RC for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 08:30:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rFaAd-0003cq-Bc for bug-gnu-emacs@gnu.org; Tue, 19 Dec 2023 08:30:03 -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 13:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67883 X-GNU-PR-Package: emacs Original-Received: via spool by 67883-submit@debbugs.gnu.org id=B67883.170299259513790 (code B ref 67883); Tue, 19 Dec 2023 13:30:03 +0000 Original-Received: (at 67883) by debbugs.gnu.org; 19 Dec 2023 13:29:55 +0000 Original-Received: from localhost ([127.0.0.1]:34627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFaAU-0003aL-U7 for submit@debbugs.gnu.org; Tue, 19 Dec 2023 08:29:55 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39948) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFaAS-0003a9-Lk for 67883@debbugs.gnu.org; Tue, 19 Dec 2023 08:29:53 -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 1rFaAK-0005Wd-J7; Tue, 19 Dec 2023 08:29:44 -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=5OsPfYrcoiFbYBwoZ0OJavvPoO86p4AkKO2z9AKDWjk=; b=CcaH2zRMGSV+zWdQKaxB D52Hc+iTGJMDbb/wJi3a+k/WvDsZgMqfPus266DLWd71dZD7bH8xImMSnkhiYp7C5QPVHgmwu4Efw LrDaHERCikSpSu0bJVZYZuPDvEi2aczPsro17+/sHi/td3AoVcb+eaDw9+XayF14/FMfDP3MMp4cr 0s1viVy7vS2vd3BL3hQ55zccF3MZpvINygDr8nVCuMcBvNIIzmhFFQr/nuBTKuT/1Hlpr5ADEIAEn uv9wUn3GlWnoIn7g1YWmFVtEmQpsRvDEUClwNoGaP+fxpTo5TfFySPWeH3ZYpoRUSWIT0YLKwaGp/ btj1eOC6jdCENg==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rFaAK-0007jU-BI; Tue, 19 Dec 2023 08:29:44 -0500 In-Reply-To: (Andrea Corallo's message of "Tue, 19 Dec 2023 07:48:50 -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:276517 Archived-At: Andrea Corallo writes: > 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 Okay I believe this most likely is a duplicate of bug#57957.