[bitc-dev] Capture problem with by-ref
Swaroop Sridhar
swaroop at cs.jhu.edu
Thu Mar 13 14:19:22 EDT 2008
Jonathan S. Shapiro wrote:
> On Wed, 2008-03-12 at 18:24 -0400, Swaroop Sridhar wrote:
>> Jonathan S. Shapiro wrote:
>>> On Wed, 2008-03-12 at 14:14 -0400, Swaroop Sridhar wrote:
>>> Unfortunately, your statement [2] is wrong. Counter-example:
>>>
>>> (define (g)
>>> (let ((local : (mutable int32) 1)
>>> (letrec ((closure
>>> ((lambda (lref:(by-ref (mutable 'a)))
>>> (lambda (x)
>>> (set! lref (+ lref 1))
>>> (+ lref x))) local)))
>>> (pair (closure 1) (closure 1)))))
>>>
>>> If your theory were correct, the result should be (2, 2). But it is
>>> clear here that the outer lambda has closed over "local" by means of
>>> application, and the correct answer must be (2, 3).
>> I don't see why (2) is wrong here. ...
>>
> (2) is wrong here because we are looking for a pair, so I don't know how
> to respond to this. Can you clarify?
(2) is not the return value of the expression. I was referring to my
condition [2] (since you said [2] was wrong) which was:
>>> 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.
For the above definition, my understanding is that the inner lambda
(with parameter x) escapes because it is being returned, so
[condition 1] is not satisfied. It assigns a non-local by-ref variable
lref so [condition 2] is not satisfied. So, this definition would be
rejected by the compiler.
I am writing this just for the sake of clarification, not that we should
adapt it in lieu of the simplest solution.
Swaroop.
More information about the bitc-dev
mailing list