* bug#13966: inlining issue?
@ 2013-03-15 12:57 Daniel Llorens
2013-03-22 13:55 ` Ludovic Courtès
2016-06-20 20:06 ` Andy Wingo
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Llorens @ 2013-03-15 12:57 UTC (permalink / raw)
To: 13966
Compare
(define f (lambda (a) a))
(call-with-values (lambda () (values 3 3)) f)
vs
(call-with-values (lambda () (values 3 3)) (lambda (a) a))
The first one fails with
<unnamed port>:1:0: In procedure f:
<unnamed port>:1:0: Wrong number of arguments to #<procedure f (a)>
The second one gives 3.
This is Guile 2.0.7.112-f5ea5.
The behavior of the first case makes (compose f g) fail when f takes less args tan g produces.
Regards
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#13966: inlining issue?
2013-03-15 12:57 bug#13966: inlining issue? Daniel Llorens
@ 2013-03-22 13:55 ` Ludovic Courtès
2016-06-20 20:06 ` Andy Wingo
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2013-03-22 13:55 UTC (permalink / raw)
To: Daniel Llorens; +Cc: 13966
[-- Attachment #1: Type: text/plain, Size: 1557 bytes --]
Hi Daniel,
Daniel Llorens <daniel.llorens@bluewin.ch> skribis:
> Compare
>
> (define f (lambda (a) a))
> (call-with-values (lambda () (values 3 3)) f)
>
> vs
>
> (call-with-values (lambda () (values 3 3)) (lambda (a) a))
>
> The first one fails with
>
> <unnamed port>:1:0: In procedure f:
> <unnamed port>:1:0: Wrong number of arguments to #<procedure f (a)>
>
> The second one gives 3.
>
> This is Guile 2.0.7.112-f5ea5.
>
> The behavior of the first case makes (compose f g) fail when f takes less args tan g produces.
That is unfortunate but I think the former is correct.
R5RS doesn’t say anything about the expected behavior when the producer
returns a number of values incompatible with what the consumer accepts.
R6RS says (Section 5.8):
If the number of return values passed to a continuation created by a
call to call-with-values is not accepted by its consumer that was
passed in that call, then an exception is raised.
and Section 11.5:
Consumer must be a procedure and should accept as many values as
producer returns.
R7RS draft #6 uses equivalent wording (I think):
Calls its producer argument with no values and a continuation that,
when passed some values, calls the consumer procedure with those
values as arguments.
This patch fixes peval to not inline
(call-with-values (lambda () (values vals ...)) (lambda (args ...) ...))
when the length of ‘vals’ differs from that of ‘args’.
However, it’s not very elegant, IMO. Andy?
Ludo’.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1254 bytes --]
diff --git a/module/language/tree-il/peval.scm b/module/language/tree-il/peval.scm
index bf96179..25dded4 100644
--- a/module/language/tree-il/peval.scm
+++ b/module/language/tree-il/peval.scm
@@ -1155,6 +1155,25 @@ top-level bindings from ENV and return the resulting expression."
(simplify-conditional
(make-conditional src c (for-tail subsequent)
(for-tail alternate))))))
+
+ (($ <application> src
+ ($ <primitive-ref> _ '@call-with-values)
+ (($ <lambda> _ _
+ ($ <lambda-case> _
+ () #f #f #f () ()
+ ($ <application> _ ($ <primitive-ref> _ 'values)
+ (produced ...))
+ #f))
+ ($ <lambda> _ _
+ (and consumer
+ ($ <lambda-case> _
+ (? (negate (compose (cute = <> (length produced))
+ length)))
+ #f #f #f () gensyms body #f)))))
+ ;; Producer is (values args ...) but consumer expects a different
+ ;; number of values, which is an error.
+ exp)
+
(($ <application> src
($ <primitive-ref> _ '@call-with-values)
(producer
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#13966: inlining issue?
2013-03-15 12:57 bug#13966: inlining issue? Daniel Llorens
2013-03-22 13:55 ` Ludovic Courtès
@ 2016-06-20 20:06 ` Andy Wingo
1 sibling, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2016-06-20 20:06 UTC (permalink / raw)
To: Daniel Llorens; +Cc: 13966-done
On Fri 15 Mar 2013 13:57, Daniel Llorens <daniel.llorens@bluewin.ch> writes:
> Compare
>
> (define f (lambda (a) a))
> (call-with-values (lambda () (values 3 3)) f)
>
> vs
>
> (call-with-values (lambda () (values 3 3)) (lambda (a) a))
>
> The first one fails with
>
> <unnamed port>:1:0: In procedure f:
> <unnamed port>:1:0: Wrong number of arguments to #<procedure f (a)>
>
> The second one gives 3.
>
> This is Guile 2.0.7.112-f5ea5.
>
> The behavior of the first case makes (compose f g) fail when f takes less args tan g produces.
Fixed in fff013215fb1a5d211df5037dcf52c92063050a8 on master.
Thanks for the report!
Andy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-20 20:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15 12:57 bug#13966: inlining issue? Daniel Llorens
2013-03-22 13:55 ` Ludovic Courtès
2016-06-20 20: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).