mit-scheme-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MIT-Scheme-devel] improving integration of VALUES and CALL-WITH-VALUES


From: Taylor R Campbell
Subject: [MIT-Scheme-devel] improving integration of VALUES and CALL-WITH-VALUES
Date: Sun, 20 Sep 2009 01:12:31 -0400
User-agent: IMAIL/1.21; Edwin/3.116; MIT-Scheme/7.7.90.+

(`Integration' in the sense of `open-coding', not in the sense of
integrating multiple return values into the system so that their
implementation is actually correct...)

Short of redesigning great swaths of the system to spread multiple
return values on the stack, it would be nice if the compiler generated
somewhat better code for uses of them that syntactically obviously
don't require extra storage for them, such as

(receive (x y z)
         (let ((foo (fnord)))
           (values foo (mumble foo) (frotz foo)))
  ...).

Currently, SF only expands VALUES and CALL-WITH-VALUES, to transform
that into

((let ((foo (fnord)))
   (let ((value-0 foo) (value-1 (mumble foo)) (value-2 (frotz foo)))
     (lambda (receiver)
       (receiver value-0 value-1 value-2))))
 (lambda (x y z)
   ...),

for which LIAR then generates code to allocate two closures on the
heap and to immediately call them.  I've attached a patch to SF that
makes it instead transform the above code into

(let ((foo (fnord)))
  (let ((value-0 foo) (value-1 (grovel foo)) (value-2 (frotz foo)))
    (let ((x value-0) (y value-1) (z value-2))
      ...))),

for which LIAR naturally generates much better code.  I believe the
transformation is very conservative: not only does it preserve the
semantics of the program, as it of course should, but it also
preserves any ambivalence about order of evaluation, while a more
aggressive transformation might commit to an order of evaluation when
the program specified none in particular.

I sha'n't commit this before Chris has sorted out the macro engine and
apparent compiler bugs, though.  Comments?  Objections?

Attachment: combination-operator.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]