Problem: BY-REF parameters can escape:

  (define (outer x:'a)
    (define (capture xc:(by-ref 'a))
      (lambda (y)
         (pair y, x)))

Note that "x" is in the call frame of OUTER, it is aliased by "xc", "xc"
is in turn captured by the lambda, and the lambda escapes. This is bad,
because we now have a heap-based object (the closure) that points back
into a stack-based object.

I am inclined to prohibit this by declaring that no by-ref argument is
permitted to be captured by a closure. The alternatives are:

  1. Remove BY-REF, but I don't want to do that because it is extremely
     useful.

  2. Force the compiler to heapify any stack-based argument value that
     is passed to a BY-REF formal parameter, effectively re-writing the
     BY-REF as REF.

     Note that there is no issue here for objects that are already
     heap-based. It is only stack frame capture that is the source of
     concern.

Subjectively, my current feeling is that "magic heapification" would be
the preferred answer in the functional language community, because this
would render BY-REF more "regular", and it does not alter the meaning of
the program.

For a systems programming language, however, we are trying to avoid
constructs that might induce GC. Since the user is always free to
heapify by hand using DUP, my feeling is that the no-capture restriction
is a better resolution of this case given the design objectives of the
language.

Reactions?


shap

_______________________________________________
bitc-dev mailing list
bitc-dev@coyotos.org
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to