GNU bug report logs - #20938
make-dynamic-state, with-dynamic-state & exceptions

Previous Next

Package: guile;

Reported by: Josep Portella Florit <jpf <at> primfilat.com>

Date: Tue, 30 Jun 2015 13:51:03 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

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 20938 in the body.
You can then email your comments to 20938 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-guile <at> gnu.org:
bug#20938; Package guile. (Tue, 30 Jun 2015 13:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Josep Portella Florit <jpf <at> primfilat.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Tue, 30 Jun 2015 13:51:04 GMT) Full text and rfc822 format available.

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

From: Josep Portella Florit <jpf <at> primfilat.com>
To: bug-guile <at> gnu.org
Subject: make-dynamic-state, with-dynamic-state & exceptions
Date: Tue, 30 Jun 2015 15:50:30 +0200
This code crashes Guile 2.0.11:

(define x (make-dynamic-state))
(with-dynamic-state x (lambda () (/ 1 0)))


For now I'm using this workaround:

(let ((w-d-s with-dynamic-state))
  (set! with-dynamic-state
        (lambda (s p)
          (let ((e #f))
            (w-d-s s (lambda ()
                       (catch #t p
                         (lambda x (set! e x)))))
            (when e (apply throw e))))))




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Wed, 01 Jul 2015 06:50:03 GMT) Full text and rfc822 format available.

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

From: Josep Portella Florit <jpf <at> primfilat.com>
To: 20938 <at> debbugs.gnu.org
Subject: Improved workaround
Date: Wed, 01 Jul 2015 08:49:04 +0200
The workaround in my other message discards the return value of
`with-dynamic-state'.  I've improved it:

(let ((w-d-s with-dynamic-state))
  (set! with-dynamic-state
        (lambda (s p)
          (let* ((e #f)
                 (r (w-d-s s (lambda ()
                               (catch #t p
                                 (lambda x
                                   (set! e x)))))))
            (if e
                (apply throw e)
                r)))))




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Sun, 13 Mar 2016 14:58:01 GMT) Full text and rfc822 format available.

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

From: Josep Portella Florit <jpf <at> primfilat.com>
To: 20938 <at> debbugs.gnu.org
Subject: More information
Date: Sun, 13 Mar 2016 15:57:17 +0100
It doesn't crash Guile 1.8.8, but it does crash Guile 2.1.2, and this
version outputs the following message about 2150 times: "Warning:
Unwind-only `stack-overflow' exception; skipping pre-unwind handler."




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Fri, 24 Jun 2016 07:12:01 GMT) Full text and rfc822 format available.

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

From: Andy Wingo <wingo <at> pobox.com>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 20938 <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Fri, 24 Jun 2016 09:11:45 +0200
On Tue 30 Jun 2015 15:50, Josep Portella Florit <jpf <at> primfilat.com> writes:

> This code crashes Guile 2.0.11:
>
> (define x (make-dynamic-state))
> (with-dynamic-state x (lambda () (/ 1 0)))

Related: http://thread.gmane.org/gmane.lisp.guile.devel/16953

How are you using dynamic states?

Andy




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Fri, 24 Jun 2016 15:00:03 GMT) Full text and rfc822 format available.

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

From: Josep Portella Florit <jpf <at> primfilat.com>
To: Andy Wingo <wingo <at> pobox.com>
Cc: 20938 <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Fri, 24 Jun 2016 16:58:58 +0200
El 24/06/16 a les 09:11, Andy Wingo ha escrit:
> On Tue 30 Jun 2015 15:50, Josep Portella Florit <jpf <at> primfilat.com> writes:
> 
>> This code crashes Guile 2.0.11:
>>
>> (define x (make-dynamic-state))
>> (with-dynamic-state x (lambda () (/ 1 0)))
> 
> Related: http://thread.gmane.org/gmane.lisp.guile.devel/16953
> 
> How are you using dynamic states?

I have code[1] written in Racket which uses what I think are the
equivalent to Guile's dynamic states: parameterizations.

My code raises exceptions that contain the result of
`(current-parameterization)`[2].  It later handles those exceptions
and passes the parameterization to `call-with-parameterization`[3] in
order to access the value several parameters had before the exception
was raised.

It also accumulates different results of `(current-parameterization)`,
reorders them and for each one it passes the parameterization to
`call-with-parameterization` and calls other code[4].


1: <http://josep-portella.com/en/software/pinaret/>
   <http://josep-portella.com/software/pinaret/pinaret-0.9.zip>

2: File `pinaret/runtime.rkt`, procedure `raise-error/params`.

3: File `pinaret/system.rkt`, procedure `generate`.
   File `pinaret/runtime.rkt`, procedure `print-error/params`.

4: File `pinaret/base.rkt`, there are many examples here, look for
   `(current-parameterization)`.




Reply sent to Andy Wingo <wingo <at> pobox.com>:
You have taken responsibility. (Tue, 28 Feb 2017 14:18:02 GMT) Full text and rfc822 format available.

Notification sent to Josep Portella Florit <jpf <at> primfilat.com>:
bug acknowledged by developer. (Tue, 28 Feb 2017 14:18:02 GMT) Full text and rfc822 format available.

Message #22 received at 20938-done <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 20938-done <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Tue, 28 Feb 2017 15:17:29 +0100
On Tue 30 Jun 2015 15:50, Josep Portella Florit <jpf <at> primfilat.com> writes:

> This code crashes Guile 2.0.11:
>
> (define x (make-dynamic-state))
> (with-dynamic-state x (lambda () (/ 1 0)))

Sad :/ Fixed in 2.2 though, finally.  I don't really know how to fix it
in 2.0 though.  Marking as closed given that we will have a shiny new
2.2.0 soon.

Andy




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Wed, 01 Mar 2017 17:31:02 GMT) Full text and rfc822 format available.

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

From: Andy Wingo <wingo <at> pobox.com>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 20938 <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Wed, 01 Mar 2017 18:30:09 +0100
On Wed 01 Mar 2017 16:11, Josep Portella Florit <jpf <at> primfilat.com> writes:

> Hi Andy,
>
> On 02/28/2017 03:17 PM, Andy Wingo wrote:
>> On Tue 30 Jun 2015 15:50, Josep Portella Florit <jpf <at> primfilat.com> writes:
>> 
>>> This code crashes Guile 2.0.11:
>>>
>>> (define x (make-dynamic-state))
>>> (with-dynamic-state x (lambda () (/ 1 0)))
>> 
>> Sad :/ Fixed in 2.2 though, finally.  I don't really know how to fix it
>> in 2.0 though.  Marking as closed given that we will have a shiny new
>> 2.2.0 soon.
>
> Good work!  Do I have to wait until you release 2.2.0 to test it?
> (Today I've tested it with 2.1.7.22-fcebf and it still crashed.)

Ack, I didn't actually test it!  I thought a related fix in 2.1.7 would
have caught it.  I will have a look.

> BTW, did you change your mind on deprecating dynamic states?
> <http://lists.gnu.org/archive/html/guile-devel/2016-06/msg00104.html>

Yes, with a caveat.  Having captured dynamic states also be mutable
places was untenable, as you could have multiple threads mutating the
same place at one time.  However dynamic states work well as a way to
transport a parameterization from one part of the code to another.  I
rely on them in Fibers for this purpose.  What do you think? :)

See NEWS:

  ** Fix too-broad capture of dynamic stack by delimited continuations

  Guile was using explicit stacks to represent, for example, the chain of
  current exception handlers.  This means that a delimited continuation
  that captured a "catch" expression would capture the whole stack of
  exception handlers, not just the exception handler added by the "catch".
  This led to strangeness when resuming the continuation in some other
  context like other threads; "throw" could see an invalid stack of
  exception handlers.  This has been fixed by the addition of the new
  "fluid-ref*" procedure that can access older values of fluids; in this
  way the exception handler stack is now implicit.  See "Fluids and
  Dynamic States" in the manual, for more on fluid-ref*.

And:

  ** Dynamic states capture values, not locations

  Dynamic states used to capture the locations of fluid-value
  associations.  Capturing the current dynamic state then setting a fluid
  would result in a mutation of that captured state.  Now capturing a
  dynamic state simply captures the current values, and calling
  `with-dynamic-state' copies those values into the Guile virtual machine
  instead of aliasing them in a way that could allow them to be mutated in
  place.  This change allows Guile's fluid variables to be thread-safe.
  To capture the locations of a dynamic state, capture a
  `with-dynamic-state' invocation using partial continuations instead.

Andy




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Fri, 03 Mar 2017 22:16:02 GMT) Full text and rfc822 format available.

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

From: Josep Portella Florit <jpf <at> primfilat.com>
To: Andy Wingo <wingo <at> pobox.com>
Cc: 20938 <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Fri, 3 Mar 2017 23:15:42 +0100
On 03/01/2017 06:30 PM, Andy Wingo wrote:
> On Wed 01 Mar 2017 16:11, Josep Portella Florit <jpf <at> primfilat.com> writes:
>> (Today I've tested it with 2.1.7.22-fcebf and it still crashed.)
> 
> Ack, I didn't actually test it!  I thought a related fix in 2.1.7 would
> have caught it.  I will have a look.

OK, can you reopen the bug?


>> BTW, did you change your mind on deprecating dynamic states?
>> <http://lists.gnu.org/archive/html/guile-devel/2016-06/msg00104.html>
> 
> Yes, with a caveat.  Having captured dynamic states also be mutable
> places was untenable, as you could have multiple threads mutating the
> same place at one time.  However dynamic states work well as a way to
> transport a parameterization from one part of the code to another.  I
> rely on them in Fibers for this purpose.  What do you think? :)

Your use of `current-dynamic-state` in Fibers confused me, until I
realized it works like `make-dynamic-state` in Guile 2.1.  Good, now
dynamic states are more analogous to Racket's parameterizations :-)




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Mon, 06 Mar 2017 19:56:01 GMT) Full text and rfc822 format available.

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

From: Andy Wingo <wingo <at> pobox.com>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 20938 <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Mon, 06 Mar 2017 20:55:18 +0100
reopen
thanks

(Hopefully the above commands will reopen the bug, if not I will do it
via the other address; I am not very good with debbugs :)

On Fri 03 Mar 2017 23:15, Josep Portella Florit <jpf <at> primfilat.com> writes:

> On 03/01/2017 06:30 PM, Andy Wingo wrote:
>> On Wed 01 Mar 2017 16:11, Josep Portella Florit <jpf <at> primfilat.com> writes:
>>> (Today I've tested it with 2.1.7.22-fcebf and it still crashed.)
>> 
>> Ack, I didn't actually test it!  I thought a related fix in 2.1.7 would
>> have caught it.  I will have a look.
>
> OK, can you reopen the bug?





Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Tue, 07 Mar 2017 20:37:01 GMT) Full text and rfc822 format available.

Message #34 received at 20938-done <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Josep Portella Florit <jpf <at> primfilat.com>
Cc: 20938-done <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Tue, 07 Mar 2017 21:36:42 +0100
On Fri 03 Mar 2017 23:15, Josep Portella Florit <jpf <at> primfilat.com> writes:

> On 03/01/2017 06:30 PM, Andy Wingo wrote:
>> On Wed 01 Mar 2017 16:11, Josep Portella Florit <jpf <at> primfilat.com> writes:
>>> (Today I've tested it with 2.1.7.22-fcebf and it still crashed.)
>> 
>> Ack, I didn't actually test it!  I thought a related fix in 2.1.7 would
>> have caught it.  I will have a look.
>
> OK, can you reopen the bug?

Fixed in master now.  Thanks again for the report :)

Andy




Information forwarded to bug-guile <at> gnu.org:
bug#20938; Package guile. (Fri, 10 Mar 2017 22:01:02 GMT) Full text and rfc822 format available.

Message #37 received at 20938-done <at> debbugs.gnu.org (full text, mbox):

From: Josep Portella Florit <jpf <at> primfilat.com>
To: Andy Wingo <wingo <at> pobox.com>
Cc: 20938-done <at> debbugs.gnu.org
Subject: Re: bug#20938: make-dynamic-state, with-dynamic-state & exceptions
Date: Fri, 10 Mar 2017 23:00:47 +0100
On 03/07/2017 09:36 PM, Andy Wingo wrote:
> Fixed in master now.  Thanks again for the report :)

I've just tested it; good work!




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

This bug report was last modified 8 years and 134 days ago.

Previous Next


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