[racket-dev] [plt] Push #25216: master branch updated

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Aug 16 17:23:35 EDT 2012

At Thu, 16 Aug 2012 15:12:36 -0600, Neil Toronto wrote:
> > 0452bd7 Matthew Flatt <mflatt at racket-lang.org> 2012-08-16 12:46
> > :
> > | bytecode optimizer improvement
> > |
> > | Treat unsafe functional operations (which never raise an
> > | exception) as omitable, which means that simple `let-values'
> > | combinations can be split into `let' bindings, etc.
> > :
> >    M collects/ffi/unsafe/com.rkt         |  1 +
> >    M collects/racket/private/for.rkt     |  2 +-
> >    M collects/tests/racket/optimize.rktl | 12 ++++++++++++
> >    M src/racket/src/optimize.c           |  8 ++++----
> 
> Suppose I'm writing in Typed Racket, and x1, x2, y1, y2, z1, z2 : Float. 
> Does this optimization mean that this:
> 
>    (let-values ([(x y z)  (values (+ x1 x2) (+ y1 y2) (+ z1 z2))])
>      ...)
> 
> is equivalent to the following?
> 
>    (let ([x  (+ x1 x2)]
>          [y  (+ y1 y2)]
>          [z  (+ z1 z2)])
>      ...)
> 
> If so, I think that will speed up the ray tracer.

Yes, it should.

Trying

 #lang typed/racket

 (define: f : (Float Float Float Float Float Float -> Float)
   (lambda (x1 x2 y1 y2 z1 z2)
     (let-values ([(x y z)  (values (+ x1 x2) (+ y1 y2) (+ z1 z2))])
       (+ x y z))))

then `raco make', `raco dec', and looking at the definition of `f':

    (define-values
     (_f)
     (#%closed
      f12
      (lambda (arg0-17 arg1-18 arg2-19 arg3-20 arg4-21 arg5-22)
        '#(f #<path:/tmp/tr.rkt> 4 2 83 113 #f)
        '(flags: preserves-marks single-result)
        (#%flonum
         unsafe-fl+
         (#%flonum
          unsafe-fl+
          (#%flonum unsafe-fl+ arg0-17 arg1-18)
          (#%flonum unsafe-fl+ arg2-19 arg3-20))
         (#%flonum unsafe-fl+ arg4-21 arg5-22)))))

Contrast with v5.3:

  (define-values
     (_f)
     (#%closed
      f11
      (lambda (arg0-16 arg1-17 arg2-18 arg3-19 arg4-20 arg5-21)
        '#(f #<path:/tmp/tr.rkt> 4 2 83 113 #f)
        '(flags: preserves-marks single-result)
        (let ((localv22 ?) (localv23 ?) (localv24 ?))
          (begin
            (set!-values (localv22 localv23 localv24)
              (values
               (#%flonum unsafe-fl+ arg0-16 arg1-17)
               (#%flonum unsafe-fl+ arg2-18 arg3-19)
               (#%flonum unsafe-fl+ arg4-20 arg5-21)))
            (#%flonum
             unsafe-fl+
             (#%flonum unsafe-fl+ localv22 localv23)
             localv24))))))


Posted on the dev mailing list.