GNU bug report logs - #14347
reset, shift, continuation values truncated inconsistently

Previous Next

Package: guile;

Reported by: Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>

Date: Sat, 4 May 2013 14:58:01 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 14347 in the body.
You can then email your comments to 14347 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#14347; Package guile. (Sat, 04 May 2013 14:58:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 04 May 2013 14:58:02 GMT) Full text and rfc822 format available.

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

From: Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>
To: <bug-guile <at> gnu.org>
Subject: reset, shift, continuation values truncated inconsistently
Date: 04 May 2013 10:47:15 +0300
Hi, the following seems at least inconsistent to
me and possibly unintended: I believe it
demonstrates that the continuation captured by
`shift' passes all its values to its continuation
when it's called directly, but truncates them to
the first value when it's bound to a variable
outside the reset expression and then called.

The documentation for reset and shift in the
manual does not quite say, but I believe the
captured continuation in these examples should be
the continuation of the shift expression inside
the reset expression, that is, it should simply
return the three values in all cases.

GNU Guile 2.0.5-deb+1-3
Copyright (C) 1995-2012 Free Software Foundation, Inc.
...
Enter `,help' for help.
scheme@(guile-user)> (use-modules (ice-9 control))
scheme@(guile-user)> (reset (shift k (k)) (values 3.1 2 3))
$1 = 3.1
$2 = 2
$3 = 3
scheme@(guile-user)> ((reset (shift k k) (values 3.1 2 3)))
$4 = 3.1
$5 = 2
$6 = 3
scheme@(guile-user)> (let ((k (reset (shift k k) (values 3.1 2 3)))) (k))
$7 = 3.1
scheme@(guile-user)> (define k (reset (shift k k) (values 3.1 2 3)))
scheme@(guile-user)> (k)
$8 = 3.1
scheme@(guile-user)> (k)
$9 = 3.1

(I installed guile-2.0 with apt-get on Ubuntu and got this.)





Information forwarded to bug-guile <at> gnu.org:
bug#14347; Package guile. (Mon, 06 May 2013 19:08:01 GMT) Full text and rfc822 format available.

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

From: Ian Price <ianprice90 <at> googlemail.com>
To: Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>
Cc: 14347 <at> debbugs.gnu.org
Subject: Re: bug#14347: reset, shift,
	continuation values truncated inconsistently
Date: Mon, 06 May 2013 20:06:30 +0100
Jussi Piitulainen <jpiitula <at> ling.helsinki.fi> writes:

> The documentation for reset and shift in the
> manual does not quite say, but I believe the
> captured continuation in these examples should be
> the continuation of the shift expression inside
> the reset expression, that is, it should simply
> return the three values in all cases.
Totally agree, this is the behaviour I expect

> scheme@(guile-user)> (let ((k (reset (shift k k) (values 3.1 2 3)))) (k))
> $7 = 3.1

scheme@(guile−user)> (import (only (rnrs) let-values))
scheme@(guile−user)> (let ((k (reset (shift k k) (values 3.1 2 3)))) (k))
$40 = 3.1
scheme@(guile−user)> (let-values (((k) (reset (shift k k) (values 3.1 2 3)))) (k))
$41 = 3.1
$42 = 2
$43 = 3

So, my first suspicion was that there is some part of the code that
receives the multiple values in a let or something, but neither the
code, nor the ,expand command revealed that. However, when we check with
,optimize

(let ((k (call-with-prompt
           ((@@ (ice-9 control) default-prompt-tag))
           (lambda ()
             (apply abort
                    ((@@ (ice-9 control) default-prompt-tag))
                    (lambda (cont)
                      (call-with-prompt
                        ((@@ (ice-9 control) default-prompt-tag))
                        (lambda ()
                          (lambda vals
                            (call-with-prompt
                              ((@@ (ice-9 control) default-prompt-tag))
                              (lambda () (@apply cont vals))
                              (lambda (cont f) (f cont)))))
                        (lambda (cont f) (f cont))))
                    '())
             3.1)
           (lambda (cont f) (f cont)))))
  (k))

Gotcha. The optimizer is getting rid of the multiple values.
On #guile, mark_weaver reminded me of
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13966 which I think is the
same issue. But I haven't tested that yet.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"




Information forwarded to bug-guile <at> gnu.org:
bug#14347; Package guile. (Mon, 06 May 2013 21:17:02 GMT) Full text and rfc822 format available.

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

From: Stefan Israelsson Tampe <stefan.itampe <at> gmail.com>
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: 14347 <at> debbugs.gnu.org, Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>
Subject: Re: bug#14347: reset, shift,
	continuation values truncated inconsistently
Date: Mon, 6 May 2013 23:15:13 +0200
[Message part 1 (text/plain, inline)]
Hmm, we have

(let ((k (cal-with-prompt tag (-- expr that ends with (values a b c) --)
 (-- expr that is of unknown values length --))))
  (k))

So it looks like peval.scm in language/tree-il does not handle this well.

Looking in that file we have

(($ <prompt> src tag body handler)
       (define (make-prompt-tag? x)
         (match x
           (($ <application> _ ($ <primitive-ref> _ 'make-prompt-tag)
               (or () ((? constant-expression?))))
            #t)
           (_ #f)))

       (let ((tag  (for-value tag))
             (body (for-tail body)))

       ... cases where we can optimize sue to knowledge of prompt-tag ...

       (else
           (make-prompt src tag body (for-value handler))))))

So to me it looks like peval does a for-tail on body, and uses the value
constraint on the body. I'm not sure how to fix this though.

But that this is the problem can be shown by changing the code to

(($ <prompt> src tag body-in handler)
       (define (make-prompt-tag? x)
         (match x
           (($ <application> _ ($ <primitive-ref> _ 'make-prompt-tag)
               (or () ((? constant-expression?))))
            #t)
           (_ #f)))

       (let ((tag  (for-value tag))
             (body (for-tail body-in)))

       ... cases where we can optimize sue to knowledge of prompt-tag ...

       (else

   (make-prompt src tag (for-values body-in) (for-value handler))))))

/Stefan



On Mon, May 6, 2013 at 9:06 PM, Ian Price <ianprice90 <at> googlemail.com> wrote:

> Jussi Piitulainen <jpiitula <at> ling.helsinki.fi> writes:
>
> > The documentation for reset and shift in the
> > manual does not quite say, but I believe the
> > captured continuation in these examples should be
> > the continuation of the shift expression inside
> > the reset expression, that is, it should simply
> > return the three values in all cases.
> Totally agree, this is the behaviour I expect
>
> > scheme@(guile-user)> (let ((k (reset (shift k k) (values 3.1 2 3))))
> (k))
> > $7 = 3.1
>
> scheme@(guile-user)> (import (only (rnrs) let-values))
> scheme@(guile-user)> (let ((k (reset (shift k k) (values 3.1 2 3)))) (k))
> $40 = 3.1
> scheme@(guile-user)> (let-values (((k) (reset (shift k k) (values 3.1 2
> 3)))) (k))
> $41 = 3.1
> $42 = 2
> $43 = 3
>
> So, my first suspicion was that there is some part of the code that
> receives the multiple values in a let or something, but neither the
> code, nor the ,expand command revealed that. However, when we check with
> ,optimize
>
> (let ((k (call-with-prompt
>            ((@@ (ice-9 control) default-prompt-tag))
>            (lambda ()
>              (apply abort
>                     ((@@ (ice-9 control) default-prompt-tag))
>                     (lambda (cont)
>                       (call-with-prompt
>                         ((@@ (ice-9 control) default-prompt-tag))
>                         (lambda ()
>                           (lambda vals
>                             (call-with-prompt
>                               ((@@ (ice-9 control) default-prompt-tag))
>                               (lambda () (@apply cont vals))
>                               (lambda (cont f) (f cont)))))
>                         (lambda (cont f) (f cont))))
>                     '())
>              3.1)
>            (lambda (cont f) (f cont)))))
>   (k))
>
> Gotcha. The optimizer is getting rid of the multiple values.
> On #guile, mark_weaver reminded me of
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13966 which I think is the
> same issue. But I haven't tested that yet.
>
> --
> Ian Price -- shift-reset.com
>
> "Programming is like pinball. The reward for doing it well is
> the opportunity to do it again" - from "The Wizardy Compiled"
>
>
>
>
[Message part 2 (text/html, inline)]

Reply sent to Andy Wingo <wingo <at> pobox.com>:
You have taken responsibility. (Mon, 20 Jun 2016 21:08:02 GMT) Full text and rfc822 format available.

Notification sent to Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>:
bug acknowledged by developer. (Mon, 20 Jun 2016 21:08:02 GMT) Full text and rfc822 format available.

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

From: Andy Wingo <wingo <at> pobox.com>
To: Jussi Piitulainen <jpiitula <at> ling.helsinki.fi>
Cc: 14347-done <at> debbugs.gnu.org
Subject: Re: bug#14347: reset, shift,
 continuation values truncated inconsistently
Date: Mon, 20 Jun 2016 23:06:59 +0200
On Sat 04 May 2013 09:47, Jussi Piitulainen <jpiitula <at> ling.helsinki.fi> writes:

> Hi, the following seems at least inconsistent to
> me and possibly unintended: I believe it
> demonstrates that the continuation captured by
> `shift' passes all its values to its continuation
> when it's called directly, but truncates them to
> the first value when it's bound to a variable
> outside the reset expression and then called.

Thank you for the report, and apologies for taking so long to fix it!
Fixed in a192c336a22b8c9ac354e88c2f2b317dff22b8c9 on stable-2.0.  2.1.3
already had it fixed, but by accident.

Andy




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

This bug report was last modified 7 years and 288 days ago.

Previous Next


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