[bitc-dev] Capture problem with by-ref
Swaroop Sridhar
swaroop at cs.jhu.edu
Thu Mar 13 15:26:12 EDT 2008
Jonathan S. Shapiro wrote:
> On Thu, 2008-03-13 at 14:19 -0400, Swaroop Sridhar wrote:
>>>>> A capture of a by-ref formal variable (x) by an
>>>>> inner lambda (L) is safe only if:
>>>>>
>>>>> (1) L does not escape, or
>>>>> (2) The body of L does not use x as an lvalue that is a target of an
>>>>> assignment.
>
> Consider::
>
> (define i:(mutable int32) 1))
> (define (g x: (by-ref (mutable int32)))
> (lambda ()
> x)) ;
>
> Note that L escapes but the body of L does not use the captured by-ref
> formal parameter as an l-value.
>
> Now consider:
>
> (define captured (g i))
>
> (pair (captured) (begin (set! i (+ i 1)) (captured))
>
> Which must result in (1, 2).
>
> The capture here is actually okay because x is capturing a global, but
> that cannot be determined at the point where G is admitted.
>
> So I think that your conditions are not sufficient to ensure safety.
I see the problem, thanks for the clarification.
Swaroop.
More information about the bitc-dev
mailing list