[Swift-devel] Standard Library Proposal/Discussion Page

Mihael Hategan hategan at mcs.anl.gov
Thu Jan 22 22:34:06 CST 2015


So what do you think the direction should be?

Can we agree that we would generally try to move in the direction of
function pointers (and maybe lambda expressions) and provide some
functional tools based on that to solve these kinds of problems?

I don't personally want to address this now. I think we can have some
decent set of tools that don't try to solve everything. But it would be
nice to know where things are eventually going. It might inform some of
the decisions.

Mihael

On Thu, 2015-01-22 at 10:35 -0800, Mihael Hategan wrote:
> 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
> 
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel





More information about the Swift-devel mailing list