[Swift-devel] Changes to array closing semantics?
    Mihael Hategan 
    hategan at mcs.anl.gov
       
    Wed Nov 21 15:51:55 CST 2012
    
    
  
On Wed, 2012-11-21 at 12:12 -0700, Justin M Wozniak wrote:
> I don't think this is currently an issue in the Swift/T implementation 
> but I can check.  In Swift/T, we have the restriction that you cannot 
> assign to an array A=f() and also do piecemeal assignments A[i]=g() .  
> We do track potential write accesses to arrays to keep them open until 
> there are no more possible writes.
> 
> http://www.mcs.anl.gov/exm/local/guides/swift.html#_arrays
That restriction should also be in swift/k, and I don't think it is.
There is a problem with the current implementation. It fails to properly
execute the following code:
int[] a;
if (true) {
  if (true) {
    a[0] = 1;
  }
  else {
   a[0] = 2;
  }
  f(a);
}
This is because a is closed in the scope in which it's declared, but
that won't be done until f(a) completes, which it can't because a is not
closed. That needs fixing. An additional complexity is that the
following should also be allowed and function correctly:
int[] a;
if (true) {
  if (condition) {
    a[0] = 1;
  }
  f(a);
}
There's also the issue of:
int[] a;
foreach i in [0:10] {
  a[i] = 1;
  f(a);
}
That shouldn't be allowed. It is, and it leads to a deadlock.
There are some subtleties:
int[] a;
if (true) {
  foreach i in [0:10] {
    if (true) {
      a[i] = 0;
    }
    else {
      a[i] = 1;
    }
  }
  f(a);
}
Closing of a can only happen after the foreach is done.
All these cases need to be correctly handled by the compiler, and I
think none of them are.
    
    
More information about the Swift-devel
mailing list