[plt-scheme] dead code elimination/closure optimization?

From: Dimitris Vyzovitis (vyzo at media.mit.edu)
Date: Sat Apr 7 22:05:48 EDT 2007

On Sat, 7 Apr 2007, Robby Findler wrote:

> (As a meta-point, I suspect that Matthew knows how to do these things,
> but that he hasn't found them to be profitable ...

Well, I am pretty sure he does too :p
For the profitable part, it is not that you write this code by hand
normally; but it may be generated by macros and it can become pretty
expensive (relative to the code in the body).

> also the optimizer
> does iterate to a fixed point already, iiuc.)
>

Uhm, shouldn't the 'this removal comes later' part get fixed then?

> On 4/7/07, Dimitris Vyzovitis <vyzo at media.mit.edu> wrote:
> > >  (comp=? (compile '(letrec ([f (lambda () 10)]) (display 2)))
> > >          (compile '(display 2)))
> > >  ; => #f
> > >  ;  because the optimizer is currently conservative about `letrec'
> >
> > Ok, letrec is trickier. With standard expansion to
> > (let ((f #<undefined>))
> >   (set! f (lambda () 10))
> >   ...)
> >
> > it may be possible to get rid of it with multiple passes, but it requires
> > safe mutation removal of sorts (the computation of the value in the
> > assingment has no direct side effects)
> This is not a correct expansion of letrec, I believe. There is some
> detail in the r5 report that I can't quite recall right now, but that
> expansion doesn't have the same behavior wrt call/cc as the spec in r5
> does. I'm not sure if this has changed in r6 or not.

Well, there is an intermediate temporary normally; but it doesn't matter
in the case in point (the 'safe mutation' part..)

-- vyzo



Posted on the users mailing list.