unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37888: 27.0.50; Streams and errors in element generation
@ 2019-10-23 14:27 Michael Heerdegen
  2019-10-23 14:58 ` Michael Heerdegen
  2019-10-24 11:38 ` Michael Heerdegen
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Heerdegen @ 2019-10-23 14:27 UTC (permalink / raw)
  To: 37888; +Cc: Nicolas Petton


Hi,

consider this case (it appeared to me in real life):

--8<---------------cut here---------------start------------->8---
(defun test-stream (n)
  (stream-cons n (if (< n 0) (error "test") (test-stream (1- n)))))

(setq my-stream (test-stream 10))

(condition-case nil (seq-length my-stream)
  (error (message "Hmm, didn't work so well")))
--8<---------------cut here---------------end--------------->8---

Now, what happened to `my-stream' after evaluating this?  If you try to
use it, you get a quite confusing error:

(seq-length my-stream)

|-- stream--force: Wrong type argument: streamp, (((n . -1) t) nil ...)

i.e. the stream is broken.  I wonder if we could improve this case.  I'm
not sure how, however.  Should referencing the element whose generation
caused the error raise the same error again, or a standardized kind of
error?  Should the whole stream be invalidated in some way?  FWIW, in my
use case I expected the stream to raise the same error again.  Would it
be reasonable to make the stream just retry to calculate the problematic
element?


TIA,

Michael.


In GNU Emacs 27.0.50 (build 27, x86_64-pc-linux-gnu, GTK+ Version 3.24.12)
 of 2019-10-23 built on drachen
Repository revision: 39ba44f18445c7759de5ac91ce25e53123c2abeb
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux bullseye/sid






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

* bug#37888: 27.0.50; Streams and errors in element generation
  2019-10-23 14:27 bug#37888: 27.0.50; Streams and errors in element generation Michael Heerdegen
@ 2019-10-23 14:58 ` Michael Heerdegen
  2019-12-13 13:10   ` Noam Postavsky
  2019-10-24 11:38 ` Michael Heerdegen
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Heerdegen @ 2019-10-23 14:58 UTC (permalink / raw)
  To: 37888; +Cc: Nicolas Petton, Noam Postavsky

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

Michael Heerdegen <michael_heerdegen@web.de> writes:

> (defun test-stream (n)
>   (stream-cons n (if (< n 0) (error "test") (test-stream (1- n)))))
>
> (setq my-stream (test-stream 10))
>
> (condition-case nil (seq-length my-stream)
>   (error (message "Hmm, didn't work so well")))
>
> Now, what happened to `my-stream' after evaluating this?  If you try to
> use it, you get a quite confusing error:
>
> (seq-length my-stream)
>
> |-- stream--force: Wrong type argument: streamp, (((n . -1) t) nil ...)

Would something like this make sense (Noam)?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP-stream-Fix-Bug-37888.patch --]
[-- Type: text/x-diff, Size: 999 bytes --]

From 4c778f26ff8d56d0e7018305aa3d46caa2f9fb38 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Wed, 23 Oct 2019 16:55:01 +0200
Subject: [PATCH] WIP [stream] Fix Bug#37888

---
 packages/stream/stream.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/packages/stream/stream.el b/packages/stream/stream.el
index 9f73e8b861..d401fb7e3c 100644
--- a/packages/stream/stream.el
+++ b/packages/stream/stream.el
@@ -86,8 +86,8 @@ That value is the one passed to `stream-make'."
    ((eq (car-safe stream) stream--evald-identifier)
     (cdr stream))
    ((eq (car-safe stream) stream--fresh-identifier)
-    (setf (car stream) stream--evald-identifier)
-    (setf (cdr stream) (funcall (cdr stream))))
+    (prog1 (setf (cdr stream) (funcall (cdr stream)))
+      (setf (car stream) stream--evald-identifier)))
    (t (signal 'wrong-type-argument (list 'streamp stream)))))

 (defmacro stream-cons (first rest)
--
2.23.0


[-- Attachment #3: Type: text/plain, Size: 11 bytes --]



Michael.

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

* bug#37888: 27.0.50; Streams and errors in element generation
  2019-10-23 14:27 bug#37888: 27.0.50; Streams and errors in element generation Michael Heerdegen
  2019-10-23 14:58 ` Michael Heerdegen
@ 2019-10-24 11:38 ` Michael Heerdegen
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Heerdegen @ 2019-10-24 11:38 UTC (permalink / raw)
  To: 37888; +Cc: Nicolas Petton

Hello again,

Btw, AFAIU this problem pertains any form of nonlocal exit, not only
errors.  Using nonlocal exits in stream element generation (e.g. via
`while-no-input') is a common use case for me.  My suggested should fix
this.


Regards,

Michael.

> consider this case (it appeared to me in real life):
>
> (defun test-stream (n)
>   (stream-cons n (if (< n 0) (error "test") (test-stream (1- n)))))
>
> (setq my-stream (test-stream 10))
>
> (condition-case nil (seq-length my-stream)
>   (error (message "Hmm, didn't work so well")))
>
> Now, what happened to `my-stream' after evaluating this?  If you try to
> use it, you get a quite confusing error:
>
> (seq-length my-stream)
>
> |-- stream--force: Wrong type argument: streamp, (((n . -1) t) nil ...)





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

* bug#37888: 27.0.50; Streams and errors in element generation
  2019-10-23 14:58 ` Michael Heerdegen
@ 2019-12-13 13:10   ` Noam Postavsky
  2020-01-12  7:20     ` Michael Heerdegen
  0 siblings, 1 reply; 6+ messages in thread
From: Noam Postavsky @ 2019-12-13 13:10 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Nicolas Petton, 37888, Noam Postavsky

Michael Heerdegen <michael_heerdegen@web.de> writes:
>
> Would something like this make sense (Noam)?

>     ((eq (car-safe stream) stream--fresh-identifier)
> -    (setf (car stream) stream--evald-identifier)
> -    (setf (cdr stream) (funcall (cdr stream))))
> +    (prog1 (setf (cdr stream) (funcall (cdr stream)))
> +      (setf (car stream) stream--evald-identifier)))

Right, only mark the stream element as evaluated after we (successfully!)
evaluate it.  Makes sense to me.





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

* bug#37888: 27.0.50; Streams and errors in element generation
  2019-12-13 13:10   ` Noam Postavsky
@ 2020-01-12  7:20     ` Michael Heerdegen
  2020-02-08 17:21       ` Michael Heerdegen
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Heerdegen @ 2020-01-12  7:20 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: 37888, Noam Postavsky

Noam Postavsky <npostavs@gmail.com> writes:

> > Would something like this make sense (Noam)?
>
> >     ((eq (car-safe stream) stream--fresh-identifier)
> > -    (setf (car stream) stream--evald-identifier)
> > -    (setf (cdr stream) (funcall (cdr stream))))
> > +    (prog1 (setf (cdr stream) (funcall (cdr stream)))
> > +      (setf (car stream) stream--evald-identifier)))
>
> Right, only mark the stream element as evaluated after we (successfully!)
> evaluate it.  Makes sense to me.

Installed.

@Nicolas: Would you mind when I also bump the version of stream to 2.2.5
and update the copyright years of the files in the stream package?

TIA,

Michael.





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

* bug#37888: 27.0.50; Streams and errors in element generation
  2020-01-12  7:20     ` Michael Heerdegen
@ 2020-02-08 17:21       ` Michael Heerdegen
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Heerdegen @ 2020-02-08 17:21 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: Noam Postavsky, 37888-done

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Installed.
>
> @Nicolas: Would you mind when I also bump the version of stream to
> 2.2.5 and update the copyright years of the files in the stream
> package?

I've done this now.  We are done and I'm closing this bug.


Thanks,

Michael.





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

end of thread, other threads:[~2020-02-08 17:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23 14:27 bug#37888: 27.0.50; Streams and errors in element generation Michael Heerdegen
2019-10-23 14:58 ` Michael Heerdegen
2019-12-13 13:10   ` Noam Postavsky
2020-01-12  7:20     ` Michael Heerdegen
2020-02-08 17:21       ` Michael Heerdegen
2019-10-24 11:38 ` Michael Heerdegen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).