[r6rs-discuss] [Formal] Remove double phase semantics

AndrevanTonder andre at het.brown.edu
Sun Nov 26 17:32:01 EST 2006


On Sun, 26 Nov 2006, dyb at cs.indiana.edu wrote:

> Having done the pointing out, I feel I should clarify.  The obvious
> problem with Andre's transformation is that it introduces additional local
> variables and indirects, so the claim that the multi-phase model can be
> implemented as efficiently as the single-phase model is wrong.  A more
> subtle and potentially more costly problem is that it will cause closures
> to become larger and/or more deeply nested (with more indirects).
> Furthemore, it will also inhibit closure elimination, and optimization
> that Chez Scheme and possibly some other systems do.

After thinking about this some more, I believe the inefficiency can easily be 
eliminated for level-0 (runtime) code where it is likely to matter most.  The 
previous example

     (library bar
       (export g)
       (import (only foo f))
       (define (g) (f)))

can be transformed in the separate-binding model to the pair of procedures

     (define (bar-invoke-at-level>0 level)
       (let ((foo-f ($import-value 'foo-f level)))
         (letrec* ((g (lambda () (foo-f))))
           ($export-value 'bar-g level g)))

     (define bar-g (unspecified))         ; level 0 bar-g is global

     (define (bar-invoke-at-level-0)
       (letrec* ((g (lambda () (foo-f)))) ; level 0 foo-f is global
         (set! bar-g g)))

All the usual optimizations would apply to the second, runtime procedure, which 
is the only one that needs to be included in fully-compiled deliverables.

Andre




More information about the r6rs-discuss mailing list