unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#59540: Calling length on a very long improper list is disastrous.
@ 2022-11-24 10:52 Jeremy Phelps
  2022-12-10 17:27 ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Phelps @ 2022-11-24 10:52 UTC (permalink / raw)
  To: 59540

[-- Attachment #1: Type: text/plain, Size: 795 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 1687 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#59540: Calling length on a very long improper list is disastrous.
  2022-11-24 10:52 bug#59540: Calling length on a very long improper list is disastrous Jeremy Phelps
@ 2022-12-10 17:27 ` Ludovic Courtès
  2022-12-12  9:25   ` lloda
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2022-12-10 17:27 UTC (permalink / raw)
  To: Jeremy Phelps; +Cc: 59540

Hi Jeremy,

Jeremy Phelps <jeremyphelps077@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’.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#59540: Calling length on a very long improper list is disastrous.
  2022-12-10 17:27 ` Ludovic Courtès
@ 2022-12-12  9:25   ` lloda
  2022-12-12 11:45     ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: lloda @ 2022-12-12  9:25 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Jeremy Phelps, 59540


> On 10 Dec 2022, at 18:27, Ludovic Courtès <ludo@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.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#59540: Calling length on a very long improper list is disastrous.
  2022-12-12  9:25   ` lloda
@ 2022-12-12 11:45     ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2022-12-12 11:45 UTC (permalink / raw)
  To: lloda; +Cc: Jeremy Phelps, 59540

Hi,

lloda <lloda@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’.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-12 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-24 10:52 bug#59540: Calling length on a very long improper list is disastrous Jeremy Phelps
2022-12-10 17:27 ` Ludovic Courtès
2022-12-12  9:25   ` lloda
2022-12-12 11:45     ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).