On Mon, Aug 5, 2013 at 8:18 PM, David Jeske <[email protected]> wrote:
> On Mon, Aug 5, 2013 at 5:30 PM, Jonathan S. Shapiro <[email protected]>wrote: > >> It is not. "ref" is merely "pass by reference". It makes no contract >> about escape. Three obvious counter examples: >> >> static T escape1(ref T arg) { return arg; } >> > static void escape2(ref X arg, T t) { arg.t = t } >> static void escape2(ref X arg, ref T t) { arg.t = t } >> > > All of these are creating copies of t, they don't allow the reference to > escape. > None of these are making copies of t. They are all making copied of the * reference* to T. That is: the pointer to the object. If by-reference parameters were borrowed pointers, that is the object reference that must not escape. In a borrowed pointer, it's not that the *binding* must not escape. It's that the *object reference value* must not escape. So if C# had borrowed pointers, the following would both be illegal: static T notlegal1(borrowed T t) { return t; } // not legal - value of t escapes static void notlegal2(ref X arg, borrowed T t) { arg.t = t; } // not legal - value of t escapes > Are you trying to forbid the values from escaping too, like Rust owned > pointers? > If Rust borrowed pointers do not prohibit escape, then they do not guarantee many of the safety properties that your description has assumed. > Wouldn't you have to forbid the values from even being accessed to prevent > their escape? > No, that restriction is not necessary at all. You really need to go read the Tofte paper. > I thought the whole idea of borrowed pointers was that they are not > involved in GC tracing and lifetime, because they are only allowed when > someone else guarantees liveliness for the box. "ref" meets this > definition. > That's only part of the story. The other half of the story is that borrowed pointers must not escape. For example: borrowed pointers are exempt from reference counting. If they can escape, then you can't permit a unique pointer or an ARC pointer to be passed as an actual parameter where the formal parameter is a borrowed pointer. shap
_______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
