[Swift-devel] Problem with iterate

Mihael Hategan hategan at mcs.anl.gov
Wed Feb 17 16:17:08 CST 2010


I committed a bunch of patches to trunk...

> 
> If anyone is looking at fixing it, I think its something like the iterate 
> statement being tagged as a writer of "all of statePathFiles", which then 
> conflicts with the first line being a partial writer of statePathFiles. 

That one. I'm not sure about the implications of it. Why was that flag
set to "not partial writer"? How did iterate ever work? What am I
missing?

> 
> If anyone is *really* look at fixing it, get rid of foreach and iterate 
> and put in proper dataflow based iteration (map, foldr, whatever) such 
> that arrays are single-assignment.

There's also a bunch of fixes that should enable the use of a normal
foreach for the same purpose.

Basically the code detects if iteration happens on a variable that is
updated in the body of the foreach and sets a special flag on the
foreach when that happens.

The foreach implementation then interprets (with some nasty details
about the concurrency involved which I hopefully got right) situations
with no running iterations as a sign that things are done. So the
following works as expected:

int a[];
a[0] = 50;

foreach v, k in a {
  trace(v);
  if (v > 0) {
    a[k + 1] = v - 1;
  }
}

Unfortunately static analysis fails to detect more complex patterns,
such as when there is an indirect dependence between the iteration
variable and the array that the body writes to. So the following
deadlocks:

int a[];
int b[];
a[0] = 50;

foreach v, k in a {
  trace(v);
  if (v > 0) {
    b[k + 1] = v - 1;
  }
}

foreach v, k in b {
  a[k] = b[k];
}

Ideas?




More information about the Swift-devel mailing list