... if this same concept were applied to CLR ref return values, the form
would be something like:

[Lifetime("FOO")] ref SomeStruct getStructRefFromObject([Lifetime("Foo")]
SomeClass someObject) {
   return ref someObject.someStructField;
}

This tells the CLR : the ref return value is only valid so long as the
pointer to the object someObject is still held by the caller.

In writing my previous email, I realized that this would only allow the
return of refs to fields held directly within objects passed as arguments,
since these are the only objects we can assert lifetime over. In order to
use this mechanism to allow the return of refs to value-type payloads in
collections, we'd need to return to the caller the actual pointer to the
element containing the payload.. For example:

class LinkedList {
   [Lifetime("node")] ref Payload findElementAfter(Payload afterThis,
[Lifetime("node")] out object lifetimeProxy) { ... }
}

In this example, I'm able to return a ref directly to the payload inside
the linked list only because I *also* explicitly return the GC-object node
which contains that ref. The [Lifetime] attribute tells the compiler that
the ref is only valid so long as the object pointer is held. Some compiler
magic could hide the out argument, making this effectively transparent.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to