On Wednesday, 10 April 2013 at 05:21:40 UTC, Manu wrote:
struct X { int *p; }
int* global;

void func(scope X x) // note: is not ref
{
global = x.p; // <- error! scope prevents any part of x escaping, even
though it's a copy.
}

This way, scope has meaning with or without ref.

I think this is a subtle point, but I don't think it's correct. I think there's a difference between 'x.p' above, and what '&x.p' or '&x' would give. I think 'scope' should guarantee that you won't assign the *address* of the passed-in parameter:

void func(scope X x, ref X y) {
  static X* xx = &x; // Error
  static int** xpp = &x.p; // Error
  xx = &y; // unsafe, but pass
  xpp = &y.p; // same
}

I don't think it should guarantee that you won't copy something that is *already* a pointer. Copying the pointer may be dangerous, but I don't think 'scope' will be very useful if it's supposed to track the internal pointers of aggregate types like that. I think somebody else has to make sure that pointer is safe. I could be wrong.

Reply via email to