<div dir="ltr"><div><div><div><div><div><div><div>I still don't fully understand what distinction you're drawing.  Your example seems functionally identical to the Swift/T example - on all codepaths where an array cell might be written, the code checks whether or not it was previously assigned before the second assignment happens. <br><br></div>From the point of view of language semantics, the only relevant question is "what happens when an array cell is assigned twice".  <br><br></div>1. We can't always/don't detect it at compile time, so the program still runs.<br></div>2. The first assignment A[i] = x; completes fine<br></div>3. Any reads before the second assignment return x;<br></div>4. The second assignment A[i] = y; causes a runtime error and stops the program immediately<br><br></div>It's possible that the assignments happen in the opposite order, so x and y can be swapped.<br><br></div><div>I'm not sure how the implementation details, e.g. how it's divided into objects, matters so long as it implements the above semantics correctly.  Is the question whether the second assignment atomically causes a runtime error?  It does in the current implementation.<br><br></div><div>- Tim<br></div><div><div><div><div><div><div><div><div><br><br></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 21 March 2015 at 10:38, Ketan Maheshwari <span dir="ltr"><<a href="mailto:ketan@mcs.anl.gov" target="_blank">ketan@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Tim,<div><br></div><div>Thanks for the clarification and code snippet. To clarify, in my understanding, the implementation is 'extrinsic'.</div><div><br></div><div>To be intrinsic, I imagined the array is implemented as an object which has a function that monitors and controls its write-once property and gets invoked every time anything is written to any element of the array.</div><div><br></div><div>Very rudimentary code below to clarify the idea:</div><div><br></div><div>bool checklock(val_t val){</div><div>  if (self.item) return ERRNOWRITE;</div><div>  dowrite(self.item, val);</div><div> return OK;</div><div>}</div><div><br></div><div>About Swift semantics work: thanks, I will try to take a look and comment if I can.</div><div><br></div><div>--</div><div>Ketan</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 21, 2015 at 10:14 AM, Tim Armstrong <span dir="ltr"><<a href="mailto:tim.g.armstrong@gmail.com" target="_blank">tim.g.armstrong@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div dir="ltr"><div>Also, if you're curious about semantics of Swift data structures I've been doing some work on that recently, would be happy to talk about it in more detail.<br><br></div>- Tim<br></div></span><div class="gmail_extra"><br><div class="gmail_quote"><span>On 21 March 2015 at 10:06, Tim Armstrong <span dir="ltr"><<a href="mailto:tim.g.armstrong@gmail.com" target="_blank">tim.g.armstrong@gmail.com</a>></span> wrote:<br></span><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi Ketan,<br></div>  I'm not sure that I fully understand the distinction between internal/external implementation.  In terms of externally observable behaviour, writing an already written cell will cause a runtime error immediately.  There's no way you can cause a deadlock or observe inconsistent values.  Deadlocks with array cells should only happen if something is waiting for a cell that has been assigned 0 times.<br></div><div><div style="margin-left:40px"><br></div>If you're curious, i copied and pasted the relevant code fragment for Swift/T (it's in data.c in lb).  It's relatively straightforward, even though it's handling a few cases.  Essentially it's <span style="font-family:monospace,monospace">if (A[i] exists) return error code;</span>.  The data structure is only accessed by a single thread so no race conditions are possible.<br><br>I believe there's something similar in swift/k.<br></div><div><br></div>- Tim<br><div><br><span style="font-family:monospace,monospace">      // Does the link already exist?<br>      adlb_container_val t = NULL;<br>      bool found = container_lookup(c, curr_sub, &t);<br><br>      if (found && (value == NULL || t != NULL))<br>      {<br>        // Can overwrite reserved (unlinked) entries with actual data, but<br>        // cannot double reserve entries.<br><br>        // Don't print error by default: caller may want to handle<br>        DEBUG("already exists: "ADLB_PRIDSUB,<br>              ADLB_PRIDSUB_ARGS(id, d->symbol, subscript));<br>        return ADLB_DATA_ERROR_DOUBLE_WRITE;<br>      }</span><br></div><div><span style="font-family:monospace,monospace">      // Following code actually assigns the array cell<br>      ...</span><br></div><div><br><br><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On 20 March 2015 at 23:33, Ketan Maheshwari <span dir="ltr"><<a href="mailto:ketan@mcs.anl.gov" target="_blank">ketan@mcs.anl.gov</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hi,<div><br></div><div>So, in the meeting today, I was curious about wether the Swift write once array/struct property is enforced via some external function or is it intrinsic to the array/struct. </div><div><br></div><div>In other words, is  the array/struct implemented in such a way that it will automatically not allow anything to write once its i-th item has been written or some external entity keeps track of this property and gets triggered every time a write happens.</div><div><br></div><div>I thought with intrinsic property, write operations will be atomic and free of deadlocks as opposed to externally tracked/enforced property.</div><div><br></div><div>--</div><div>Ketan</div></div>
<br></div></div>_______________________________________________<br>
Swift-devel mailing list<br>
<a href="mailto:Swift-devel@ci.uchicago.edu" target="_blank">Swift-devel@ci.uchicago.edu</a><br>
<a href="https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel" target="_blank">https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div></div><br></div>
<br>_______________________________________________<br>
Swift-devel mailing list<br>
<a href="mailto:Swift-devel@ci.uchicago.edu" target="_blank">Swift-devel@ci.uchicago.edu</a><br>
<a href="https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel" target="_blank">https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>