[bitc-dev] Capture problem with by-ref
Swaroop Sridhar
swaroop at cs.jhu.edu
Tue Mar 11 17:54:01 EDT 2008
Sam Mason wrote:
> On Tue, Mar 11, 2008 at 09:09:39AM -0400, Jonathan S. Shapiro wrote:
>> 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.
>
> If I understand, once by-ref's have been included you've pretty much
> subverted your value/ref dichotomy. I.e. it's the strong distinction
> between value and ref's that ensure type safety and by-ref allows value
> types to be propagated to refs.
>
> As another, much more complicated solution, how about some limited form
> of region typing. Each pointer would be annotated with the (highest)
> stack frame it came from and if a pointer ever escapes from a frame
> with the same annotation then a compile error is thrown. Some form of
> parametrisation is also needed, which is where the (implementation)
> complexity arises when I think about it.
The by-ref operator is a limited form of the address (&) operator. There
is actually no problem as long as the reference does not escape its
definition. The by-ref model is actually a degenerate form of region
typing, since we do not allow escape at all (rather than allowing it as
long as the target region is guaranteed to be in a later activation).
Swaroop.
More information about the bitc-dev
mailing list