<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 24 août 2017 à 22:59, Dave DeLong via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi everyone,<div class=""><br class=""></div><div class="">(the standard disclaimer of “I’m neither a compiler engineer nor a language design expert” applies)</div><div class=""><br class=""></div><div class="">I’ve been trying to keep up with all the discussion around concurrency going on, and I’m admittedly not very familiar with async/await or the actor pattern.</div><div class=""><br class=""></div><div class="">However, a couple of things worry me about the direction the conversation seems to be going:</div><div class=""><br class=""></div><div class=""><div class=""><b class="">Keyword Explosion</b></div><div class=""><br class=""></div></div><div class="">During the Great Access Control Wars of Swift 4, one of the points that kept coming up was the reluctance to introduce a bazillion new keywords to address all the cases that were being brought up. The impression I got is that adding new keywords was essentially an <i class="">anti-pattern</i>. And so when I’m reading through this onslaught of emails, I’m troubled by how everything is seeming to require new keywords. There’s the obvious <font face="Menlo" class=""><span style="font-size: 11px;" class="">async</span></font>/<font face="Menlo" class=""><span style="font-size: 11px;" class="">await</span></font>, but there’s also been discussion of <font face="Menlo" class=""><span style="font-size: 11px;" class="">actor</span></font>, <font face="Menlo" class=""><span style="font-size: 11px;" class="">reliable</span></font>, <font face="Menlo" class=""><span style="font-size: 11px;" class="">distributed</span></font>, <font face="Menlo" class=""><span style="font-size: 11px;" class="">behavior</span></font>, <font face="Menlo" class=""><span style="font-size: 11px;" class="">message</span></font>, and <font face="Menlo" class=""><span style="font-size: 11px;" class="">signal</span></font> (and I’ve probably missed others).</div><div class=""><br class=""></div><div class="">I’m not opposed to adding new keywords by any means, but can we get some clarification on some limits of reasonableness? What restraint (if any) should we be exercising as we consider this feature?</div><div class=""><br class=""></div><div class=""><b class="">Language vs Library Feature</b></div><div class=""><b class=""><br class=""></b></div><div class="">Related to the explosion of keywords is the question of whether the concurrency model is going to be a language feature or a library feature. Allow me to explain…</div><div class=""><br class=""></div><div class="">We currently have <i class="">language</i>&nbsp;support for errors with <font face="Menlo" class=""><span style="font-size: 11px;" class="">throws</span></font> and <font face="Menlo" class=""><span style="font-size: 11px;" class="">try</span></font>&nbsp;(and friends):</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">func doSomething() throws → Value { … }</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">let value = try doSomething()</span></font></div><div class=""><br class=""></div><div class="">However, this could be viewed as sugar syntax for a hypothetical <i class="">library</i>&nbsp;feature involving a <font face="Menlo" class=""><span style="font-size: 11px;" class="">Result&lt;T, Error&gt;</span></font> type:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">func doSomething() → Result&lt;Value, Error&gt; { … }</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">let value = doSomething().value! // or however you get the value of a Result</span></font></div><div class=""><br class=""></div><div class="">In other words, <font face="Menlo" class=""><span style="font-size: 11px;" class="">throws</span></font>&nbsp;and <font face="Menlo" class=""><span style="font-size: 11px;" class="">try</span></font> are the language support for silently hiding a <font face="Menlo" class=""><span style="font-size: 11px;" class="">Result&lt;T, Error&gt;</span></font>&nbsp;type.</div></div></div></blockquote><div><br class=""></div><div>It not only hide a Result type, it also allow the compiler to perform some optimization that would not be possible with a pure library implementation, like using a custom calling convention.&nbsp;</div><div><br class=""></div><div>The same probably apply to coroutines.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I would be <i class="">really</i>&nbsp;happy if whatever concurrency model we end up with ends up being sugar syntax for a library feature, such that <font face="Menlo" class=""><span style="font-size: 11px;" class="">async</span></font> and <font face="Menlo" class=""><span style="font-size: 11px;" class="">await</span></font>&nbsp;(or whatever we decide on) become sugar for dealing with a <font face="Menlo" class=""><span style="font-size: 11px;" class="">Future&lt;T&gt;</span></font> type or whatever. Implementing concurrency in this manner would free app developers to handle concurrency in the manner in which they’re familiar. If you wanted, you call the function without <font face="Menlo" class=""><span style="font-size: 11px;" class="">await</span></font> and get back the underlying <font face="Menlo" class=""><span style="font-size: 11px;" class="">Future&lt;T&gt;</span></font>. a<font face="Menlo" class=""><span style="font-size: 11px;" class="">sync</span></font>&nbsp;becomes sugar for simplifying the return type, like in the <font face="Menlo" class=""><span style="font-size: 11px;" class="">throws</span></font> example above. <font face="Menlo" class=""><span style="font-size: 11px;" class="">try await</span></font> becomes sugar for fulfilling the promise or dealing with a cancellation (or other) error, etc.</div></div></div></blockquote><div><br class=""></div><div>I don’t think Future should even exists. As stated in the manifest, it add some cost to all calls with no benefit for most coroutine users.</div></div><br class=""><div class=""><br class=""></div></body></html>