GNU bug report logs - #59540
Calling length on a very long improper list is disastrous.

Previous Next

Package: guile;

Reported by: Jeremy Phelps <jeremyphelps077 <at> gmail.com>

Date: Thu, 24 Nov 2022 11:06:02 UTC

Severity: normal

To reply to this bug, email your comments to 59540 AT debbugs.gnu.org.

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-guile <at> gnu.org:
bug#59540; Package guile. (Thu, 24 Nov 2022 11:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jeremy Phelps <jeremyphelps077 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Thu, 24 Nov 2022 11:06:02 GMT) Full text and rfc822 format available.

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

From: Jeremy Phelps <jeremyphelps077 <at> gmail.com>
To: bug-guile <at> gnu.org
Subject: Calling length on a very long improper list is disastrous.
Date: Thu, 24 Nov 2022 05:52:51 -0500
[Message part 1 (text/plain, inline)]
I lost my Emacs session today because I accidentally called the length
function on an extremely long improper list.

But Guile prints the entire thing when it reports the error that happens
when the length function gets to the improper part of the list. It tried to
print a few million elements just to tell me which list wasn't a proper
list.

To reproduce the error should be easy:

(length

   (let loop ((result 'x)

              (n 50000000))

     (if (= n 0)

         result

         (loop (cons n result) (- n 1)))))


Emacs is more sensitive to the problem because it doesn't throw away any of
the output. It's also really bad over SSH. The above test is enough to dump
output to a local terminal for a minute or two, or to uninterruptibly tie
up an SSH session for several minutes.
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#59540; Package guile. (Sat, 10 Dec 2022 17:28:01 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Jeremy Phelps <jeremyphelps077 <at> gmail.com>
Cc: 59540 <at> debbugs.gnu.org
Subject: Re: bug#59540: Calling length on a very long improper list is
 disastrous.
Date: Sat, 10 Dec 2022 18:27:50 +0100
Hi Jeremy,

Jeremy Phelps <jeremyphelps077 <at> gmail.com> skribis:

> I lost my Emacs session today because I accidentally called the length
> function on an extremely long improper list.
>
> But Guile prints the entire thing when it reports the error that happens
> when the length function gets to the improper part of the list. It tried to
> print a few million elements just to tell me which list wasn't a proper
> list.
>
> To reproduce the error should be easy:
>
> (length
>
>    (let loop ((result 'x)
>
>               (n 50000000))
>
>      (if (= n 0)
>
>          result
>
>          (loop (cons n result) (- n 1)))))
>
>
> Emacs is more sensitive to the problem because it doesn't throw away any of
> the output. It's also really bad over SSH. The above test is enough to dump
> output to a local terminal for a minute or two, or to uninterruptibly tie
> up an SSH session for several minutes.

I think there are several issues here:

  1. ‘length’ takes time linear to the size of the list (for
     non-circular lists).  That’s how it’s specified in the Scheme
     reports.

  2. Guile doesn’t truncate arguments that come after the “Wrong type
     argument” error message.

  3. Emacs poorly handles very long lines, to put it mildly.

Of these only #2 is something we could work on.  However, truncation has
proven to be a hindrance sometimes (in backtraces, objects are
automatically), so I’m not sure we want to enable it by default on
wrong-type-arg error messages.

Thoughts?

Ludo’.




Information forwarded to bug-guile <at> gnu.org:
bug#59540; Package guile. (Mon, 12 Dec 2022 09:26:01 GMT) Full text and rfc822 format available.

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

From: lloda <lloda <at> sarc.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: Jeremy Phelps <jeremyphelps077 <at> gmail.com>, 59540 <at> debbugs.gnu.org
Subject: Re: bug#59540: Calling length on a very long improper list is
 disastrous.
Date: Mon, 12 Dec 2022 10:25:39 +0100
> On 10 Dec 2022, at 18:27, Ludovic Courtès <ludo <at> gnu.org> wrote:
> 
> ...

> Of these only #2 is something we could work on.  However, truncation has
> proven to be a hindrance sometimes (in backtraces, objects are
> automatically), so I’m not sure we want to enable it by default on
> wrong-type-arg error messages.
> 
> Thoughts?
> 
> Ludo’.

There's previous discussion on this, going both ways.

I think excessive output is a more serious problem, because it should be possible to go to a backtrace frame and look at objects directly. On the other hand, it should also be possible to C-c when guile starts to flood the terminal. But neither of these workarounds is reliable :-/ Ultimately this printing should be configurable.

We already have the repl-option system (repl-option-set! repl 'print ...). This system doesn't apply to exception messages nor backtraces. I think if it did, that would mostly solve the problem.

I also think that, besides options to truncate or not, we should have a pager (display at most a page, give options to next/stop/all). That would be the best default.





Information forwarded to bug-guile <at> gnu.org:
bug#59540; Package guile. (Mon, 12 Dec 2022 11:46:01 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: lloda <lloda <at> sarc.name>
Cc: Jeremy Phelps <jeremyphelps077 <at> gmail.com>, 59540 <at> debbugs.gnu.org
Subject: Re: bug#59540: Calling length on a very long improper list is
 disastrous.
Date: Mon, 12 Dec 2022 12:45:08 +0100
Hi,

lloda <lloda <at> sarc.name> skribis:

> I think excessive output is a more serious problem, because it should be possible to go to a backtrace frame and look at objects directly. On the other hand, it should also be possible to C-c when guile starts to flood the terminal. But neither of these workarounds is reliable :-/ Ultimately this printing should be configurable.
>
> We already have the repl-option system (repl-option-set! repl 'print ...). This system doesn't apply to exception messages nor backtraces. I think if it did, that would mostly solve the problem.

Yes.  Right now it’s just $COLUMNS; we should have a documented SRFI-39
parameter for that.

> I also think that, besides options to truncate or not, we should have a pager (display at most a page, give options to next/stop/all). That would be the best default.

Yes!

Ludo’.




This bug report was last modified 1 year and 347 days ago.

Previous Next


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