[Swift-devel] Changes to array closing semantics?

Tim Armstrong tim.g.armstrong at gmail.com
Thu Nov 22 10:37:42 CST 2012


It sounds like Mihael and I agree, but maybe I should explain the reasoning
for others' benefit.  I think that this example is one where the serial
imperative interpretation vs. dataflow interpretation actually are
completely different so people probably have different intuitions about
what it should do.  I think this has been a source of confusion since users
of Swift frequently understand their scripts by tracing the execution step
by step as you would an imperative language, which actually works 90% of
the time.

The functional/dataflow interpretation rests on the idea that A refers to a
single value, the complete contents of the array after closing.  So f(A)
always means f applied to the final value of A.

There are a couple of reasons that Swift/T goes with dataflow
interpretation over the serial interpretation:

   - It makes guaranteeing determinism much simpler
   - It means that there are no problems with executing the iterations of
   the loop in parallel independently (this is especially important for
   Swift/T)

I guess this is a bit confusing for some users but I think that the
behaviour is reasonable and consistent.  I'm not sure if there a way to
help users with potentially counter-intuitive behaviour, like a compiler
warning - aside from maybe documenting and explaining it better.

- Tim

On Wed, Nov 21, 2012 at 11:32 PM, Mihael Hategan <hategan at mcs.anl.gov>wrote:

> On Wed, 2012-11-21 at 18:36 -0800, Mihael Hategan wrote:
> [...]
> > >
> > > foreach i in [0:10] {
> > >   a[i] = 1;
> > >   f(a);
> > > }
> >
> > It shouldn't deadlock. Nothing should. It just does in the current
> > swift/k implementation.
> >
> > >
> > > In Swift/T it does the same thing as:
> > > foreach i in [0:10] {
> > >   a[i] = 1;
> > > }
> > > foreach i in [0:10] {
> > >   f(a);
> > > }
> >
> > I don't know if I'd expect that if I wrote that code. Another
> > possibility is that I want f to be invoked successively with [1], [1,
> > 1], [1, 1, 1], etc. So I don't think it's obvious what that code should
> > do, and I'd be inclined to have it forbidden. If the required behaviour
> > is f([10x1]) ten times, then the user can state that explicitly by
> > writing the equivalent code you mention.
>
> I would like to revise my statement. I agree with your proposed solution
> from a dataflow perspective (which I lost there for a bit). When
> invoking f(a) you are saying run f with some array as argument and the
> issue of where that array is built is not relevant.
>
> Mihael
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20121122/9fc6bb07/attachment.html>


More information about the Swift-devel mailing list