unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#14347: reset, shift, continuation values truncated inconsistently
@ 2013-05-04  7:47 Jussi Piitulainen
  2013-05-06 19:06 ` Ian Price
  2016-06-20 21:06 ` Andy Wingo
  0 siblings, 2 replies; 4+ messages in thread
From: Jussi Piitulainen @ 2013-05-04  7:47 UTC (permalink / raw)
  To: 14347

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






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

* bug#14347: reset, shift, continuation values truncated inconsistently
  2013-05-04  7:47 bug#14347: reset, shift, continuation values truncated inconsistently Jussi Piitulainen
@ 2013-05-06 19:06 ` Ian Price
  2013-05-06 21:15   ` Stefan Israelsson Tampe
  2016-06-20 21:06 ` Andy Wingo
  1 sibling, 1 reply; 4+ messages in thread
From: Ian Price @ 2013-05-06 19:06 UTC (permalink / raw)
  To: Jussi Piitulainen; +Cc: 14347

Jussi Piitulainen <jpiitula@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"





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

* bug#14347: reset, shift, continuation values truncated inconsistently
  2013-05-06 19:06 ` Ian Price
@ 2013-05-06 21:15   ` Stefan Israelsson Tampe
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2013-05-06 21:15 UTC (permalink / raw)
  To: Ian Price; +Cc: 14347, Jussi Piitulainen

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

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@googlemail.com> wrote:

> Jussi Piitulainen <jpiitula@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"
>
>
>
>

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

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

* bug#14347: reset, shift, continuation values truncated inconsistently
  2013-05-04  7:47 bug#14347: reset, shift, continuation values truncated inconsistently Jussi Piitulainen
  2013-05-06 19:06 ` Ian Price
@ 2016-06-20 21:06 ` Andy Wingo
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2016-06-20 21:06 UTC (permalink / raw)
  To: Jussi Piitulainen; +Cc: 14347-done

On Sat 04 May 2013 09:47, Jussi Piitulainen <jpiitula@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





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

end of thread, other threads:[~2016-06-20 21:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-04  7:47 bug#14347: reset, shift, continuation values truncated inconsistently Jussi Piitulainen
2013-05-06 19:06 ` Ian Price
2013-05-06 21:15   ` Stefan Israelsson Tampe
2016-06-20 21:06 ` Andy Wingo

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