GNU bug report logs - #67883
29.1.90; Native compiler hangs when compiling code with circular objects

Previous Next

Package: emacs;

Reported by: hokomo <hokomo <at> disroot.org>

Date: Mon, 18 Dec 2023 18:40:02 UTC

Severity: normal

Tags: confirmed

Merged with 57957, 69872

Found in versions 29.0.50, 29.1.90, 29.2

Done: Andrea Corallo <acorallo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 67883 in the body.
You can then email your comments to 67883 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Mon, 18 Dec 2023 18:40:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to hokomo <hokomo <at> disroot.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 18 Dec 2023 18:40:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: hokomo <hokomo <at> disroot.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.1.90; Native compiler hangs when compiling code with circular
 objects
Date: Mon, 18 Dec 2023 18:22:41 +0100
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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Tue, 19 Dec 2023 12:50:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <acorallo <at> gnu.org>
To: hokomo via "Bug reports for GNU Emacs, the Swiss army knife of text
 editors" <bug-gnu-emacs <at> gnu.org>
Cc: 67883 <at> debbugs.gnu.org, hokomo <hokomo <at> disroot.org>
Subject: Re: bug#67883: 29.1.90; Native compiler hangs when compiling code
 with circular objects
Date: Tue, 19 Dec 2023 07:48:50 -0500
hokomo via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs <at> gnu.org> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Tue, 19 Dec 2023 12:50:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Tue, 19 Dec 2023 13:30:03 GMT) Full text and rfc822 format available.

Message #14 received at 67883 <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <acorallo <at> gnu.org>
To: 67883 <at> debbugs.gnu.org
Cc: hokomo <at> disroot.org
Subject: Re: bug#67883: 29.1.90; Native compiler hangs when compiling code
 with circular objects
Date: Tue, 19 Dec 2023 08:29:44 -0500
Andrea Corallo <acorallo <at> gnu.org> writes:

> hokomo via "Bug reports for GNU Emacs, the Swiss army knife of text
> editors" <bug-gnu-emacs <at> gnu.org> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Sun, 24 Dec 2023 19:42:02 GMT) Full text and rfc822 format available.

Message #17 received at 67883 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Andrea Corallo <acorallo <at> gnu.org>, 67883 <at> debbugs.gnu.org
Cc: hokomo <at> disroot.org
Subject: Re: bug#67883: 29.1.90; Native compiler hangs when compiling code
 with circular objects
Date: Sun, 24 Dec 2023 11:41:12 -0800
Andrea Corallo <acorallo <at> gnu.org> writes:

> Okay I believe this most likely is a duplicate of bug#57957.

Should the bugs be merged?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Tue, 26 Dec 2023 08:24:02 GMT) Full text and rfc822 format available.

Message #20 received at 67883 <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <acorallo <at> gnu.org>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 67883 <at> debbugs.gnu.org, hokomo <at> disroot.org
Subject: Re: bug#67883: 29.1.90; Native compiler hangs when compiling code
 with circular objects
Date: Tue, 26 Dec 2023 03:23:07 -0500
Stefan Kangas <stefankangas <at> gmail.com> writes:

> Andrea Corallo <acorallo <at> gnu.org> writes:
>
>> Okay I believe this most likely is a duplicate of bug#57957.
>
> Should the bugs be merged?

Hi Stefan,

yes I think so.

  Andrea




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Tue, 26 Dec 2023 16:06:02 GMT) Full text and rfc822 format available.

Message #23 received at 67883 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Andrea Corallo <acorallo <at> gnu.org>
Cc: 67883 <at> debbugs.gnu.org, hokomo <at> disroot.org
Subject: Re: bug#67883: 29.1.90; Native compiler hangs when compiling code
 with circular objects
Date: Tue, 26 Dec 2023 09:36:16 -0600
forcemerge 57957 67883
thanks

Andrea Corallo <acorallo <at> gnu.org> writes:

> Stefan Kangas <stefankangas <at> gmail.com> writes:
>
>> Andrea Corallo <acorallo <at> gnu.org> writes:
>>
>>> Okay I believe this most likely is a duplicate of bug#57957.
>>
>> Should the bugs be merged?
>
> Hi Stefan,
>
> yes I think so.
>
>   Andrea

Done.




Forcibly Merged 57957 67883. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 26 Dec 2023 16:09:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67883; Package emacs. (Wed, 27 Dec 2023 19:55:01 GMT) Full text and rfc822 format available.

Message #28 received at 67883 <at> debbugs.gnu.org (full text, mbox):

From: hokomo <hokomo <at> disroot.org>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 67883 <at> debbugs.gnu.org, Andrea Corallo <acorallo <at> gnu.org>
Subject: Re: bug#67883: 29.1.90; Native compiler hangs when compiling code
 with circular objects
Date: Wed, 27 Dec 2023 19:48:23 +0100
Merging the two indeed seems appropriate.

FWIW, I've read the other thread [1] and agree with Stefan's view 
that circular structures should be handled correctly by the 
compiler. I believe the example with `cycle-pure' shows that this 
is both useful and necessary, since circular structures can appear 
even without being directly present in the source code as 
literals, e.g. after compiler optimizations (which seems to be the 
case here, although I haven't confirmed it 100%).

- [1] <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=57957>

Kind regards,
hokomo




Forcibly Merged 57957 67883 69872. Request was from Andrea Corallo <acorallo <at> gnu.org> to control <at> debbugs.gnu.org. (Mon, 18 Mar 2024 19:58:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 30 Apr 2024 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 4 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.