[Swift-devel] Standard Library Proposal/Discussion Page

Mihael Hategan hategan at mcs.anl.gov
Thu Jan 22 12:35:43 CST 2015


n Thu, 2015-01-22 at 09:22 -0600, Tim Armstrong wrote:

>  If you reverse it though, then the data flow and implied serial control
> flow don't match.  This code should work according to my understanding of
> Swift's current semantics, but the implementation would have to infer that
> executing the iteration for v=1000 first didn't violate any dependencies
> arising from sequential control flow:
> 
> float a[];
> a[1000] = 10;
> 
> foreach v, k in a {
>   if (a[k] > 0.01) {
>     a[k - 1] = f(a[k]);
>   }
> }

There is no sequential control flow. It's a plain swift foreach. The
only addition is code to detect when the array can be closed, but
absolutely zero code in addition to standard swift in terms of ordering
things.

> 
> If you add in a versioned variable, then the code is definitely going to
> deadlock because the data dependencies and control dependencies go in
> opposite directions:
> 
> float a[];
> a[1000] = 10;
> versioned float x = 1;
> 
> foreach v, k in a {
>   if (a[k] > x) {
>     a[k - 1] = f(a[k]);
>     x += a[k];
>   }
> }

I see. The code would potentially be translated to something like this:

float a[];
a[1000] = 10;

float x[];
x[0] = 1;

foreach v, k in a { // implicit iteration counter z starting at 0
  if (a[k] > x) {
    a[k - 1] = f(a[k]);
    x[z + 1] = x[z] + a[k];
  }
}

There is no way to guarantee that given an iteration with (k, z) you
will have an iteration with (k - 1, z + 1) unless you can guarantee that
only one iteration will be running at a time (but that breaks if you
generate more than one elements of a[] in one iteration).

Got it! :)

Mihael




More information about the Swift-devel mailing list