<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thanks Howard. You’re right asyncs don’t return values unless through a callback block. The internal compiler view for this constant is more meant to illustrate that the value can be read from multiple threads simultaneously safely. This almost certainly not the ideal way to represent it.<div class=""><br class=""></div><div class="">However, memory access to an immutable value is unlikely to ever race for access between 2 threads (as per SPL - Memory Safety:&nbsp;<a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/MemorySafety.html#//apple_ref/doc/uid/TP40014097-CH46-ID567" class="">https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/MemorySafety.html#//apple_ref/doc/uid/TP40014097-CH46-ID567</a>).&nbsp;&nbsp;I think my thought pattern was that anytime a getter is called that it is actually a function in Swift, and that we should represent the idea of an ‘async’ like prevention of the unlikely simultaneous access; but I’m probably prematurely preventing possible violations of Exclusive Access. I’m open to ideas and edits that make this idea more clear.<div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 16, 2017, at 8:01 PM, Howard Lovatt &lt;<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Sorry I don't get the code. In particular:<div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class=""><div class="">// Compiler View - of a Constant Property on a Concurrent type</div></div><div class=""><div class="">struct Person: Concurrent {</div></div><div class=""><div class="">&nbsp; &nbsp; /* Variable Property */</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class="">&nbsp; &nbsp; // Constant Property</div></div><div class=""><div class="">&nbsp; &nbsp; let birthday: Date {</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; internalQueue.async { // Immediately returns on calling thread</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return underlying_Birthday_Date_Value_Storage</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div class=""><div class="">&nbsp; &nbsp; }</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class="">&nbsp; &nbsp; /* Computed Property */</div></div><div class=""><div class="">}</div></div><div class=""><br class=""></div></blockquote>Doesn't make sense `async`'s closure doesn't return anything.<div class=""><br class=""></div><div class="">What am I missing?</div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature">&nbsp; -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 17 November 2017 at 10:50, Christopher Heath via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Good evening all,</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">I had a little idea and thought I’d pitch it. So here goes!</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Synthesizing Concurrency aims to provide a foundation by which, regardless of concurrency implementation (however current proposal uses GCD examples for design), concurrency can be synthesized by the compiler and remove many lines of boilerplate code. Offering benefits to Application, Server and OS Developers alike; with easy and intelligent concurrency conformance. Also, should the community decide to head in another direction with concurrency this should be a relatively mappable idea to any Synchronization Primitive with a little work.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Thanks for looking, and I hope you like and want to contribute to the discussion of the Synthesizing Concurrency proposal. I’ve added a printout below. Please give it a read or check out the gist: <a href="https://gist.github.com/XNUPlay/a0d6f6c0afdb3286e324c480cb5c4290" target="_blank" class=""><span style="color:#e4af0a" class="">https://gist.github.com/<wbr class="">XNUPlay/<wbr class="">a0d6f6c0afdb3286e324c480cb5c42<wbr class="">90</span></a></div><ul class=""><li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Chris</li>
</ul><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Printout :</div><div style="margin:0px;font-stretch:normal;font-size:17px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Synthesizing Concurrency</b></div>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Proposal: <a href="https://gist.github.com/XNUPlay/a0d6f6c0afdb3286e324c480cb5c4290" target="_blank" class=""><span style="color:#e4af0a" class="">SE-NNNN</span></a></li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(228,175,10)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo;color:rgb(69,69,69)" class=""></span><span style="color:#454545" class="">Author: <a href="https://github.com/xnuplay" target="_blank" class=""><span style="color:#e4af0a" class="">Christopher Heath: XNUPlay</span></a></span></li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Review Manager: TBD</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Status: <b class="">Pending Discussion</b></li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Implementation: <b class="">Awaiting Implementation</b></li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Decision Notes: TBD</li>
</ul><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Introduction</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Developers have to write large amounts of boilerplate code to support concurrency in complex types. This proposal offers a way for the compiler to automatically synthesize conformance to a high-level Concurrent protocol to reduce concurrent boilerplate code, in a set of scenarios where generating the correct implementation is known to be possible.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Specifically:</div>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>It aims to provide a high-level Swift protocol that offers opt-in concurrency support for any conformable type</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>It aims to provide a well-defined set of thread-safe, concurrent implementations for types, their properties, and methods.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>It aims to provide a language/library compatible implementation with deadlock prevention.</li>
</ul><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Motivation</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Building robust types in Swift can involve writing significant boilerplate code to support concurrency. By eliminating the complexity for the users, we make Concurrent types much more appealing to users and allow them to use their own types in optimized concurrent and parallel environments that require thread safety with no added effort on their part (beyond declaring the conformance).</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Concurrency is typically not pervasive across many types, and for each one users must implement the concurrent code such that it performs some form of synchronization to prevent unexpected behavior.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:15px" class=""><b class=""></b><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Note: Due to it's current status in Swift and use in the </b><a href="https://github.com/apple/swift/blob/master/stdlib/public/runtime/Once.cpp#L31" target="_blank" class=""><span style="color:#e4af0a" class=""><b class="">Runtime</b></span></a><b class="">, examples are written in </b><a href="https://github.com/apple/swift-corelibs-libdispatch" target="_blank" class=""><span style="color:#e4af0a" class=""><b class="">Grand Central Dispatch</b></span></a></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:15px" class=""><b class=""></b><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Concurrent Protocol - Dispatch Example</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">protocol Concurrent {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Synthesized Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var internalQueue: DispatchQueue { get }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">What's worse is that if any functions or properties are added, removed, or changed, they must each have their own concurrency code and since it must be manually written, it's possible to get it wrong, either by omission or typographical error (async vs. sync).</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Likewise, it becomes necessary when one wishes to modify an existing type that implements concurrency to do so without introducing bottlenecks or different forms of synchronization for some functions and not others, this leads to illegible and inefficient code that may defeat the purpose of implementing concurrency.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Crafting high-performance, readable concurrency code can be difficult and inconvenient to write.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Swift already derives conformance to a number of protocols, automatically synthesizing their inner-workings when possible. Since there is precedent for synthesized conformances in Swift, we propose extending it to concurrency in predictable circumstances.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Proposed solution</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">In general, we propose that a type synthesize conformance to Concurrent as long as the compiler has reasonable insight into the type. We describe the specific conditions under which these conformances are synthesized below, followed by the details of how the conformance requirements are implemented.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Requesting synthesis is opt-in</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Users must <i class="">opt-in</i> to automatic synthesis by declaring their type as Concurrent without implementing any of its requirements. This conformance must be part of the <i class="">original type declaration</i> and not on an extension (see Synthesis in extensions below for more on this).</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Any type that declares such conformance and satisfies the conditions below will cause the compiler to synthesize an implementation of an internalQueue and async or sync for all properties and methods on that type.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Making the synthesis opt-in—as opposed to automatic derivation without an explicit declaration—provides a number of benefits:</div>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>The syntax for opting in is natural; there is no clear analogue in Swift today for having a type opt out of a feature.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>It requires users to make a conscious decision about the public API surfaced by their types. Types cannot accidentally "fall into" conformances that the user does not wish them to; a type that does not initially support Concurrent can be made to at a later date, but the reverse is a potentially breaking change.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>The conformances supported by a type can be clearly seen by examining its source code; nothing is hidden from the user.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>We reduce the work done by the compiler and the amount of code generated by not synthesizing conformances that are not desired and not used.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>As will be discussed later, explicit conformance significantly simplifies the implementation for recursive types.</li>
</ul><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Overriding synthesized conformances</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Any user-provided implementations of an internalQueue and use of async or sync will override the default implementations that would be provided by the compiler.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Defining conditions where synthesis is allowed</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">For example take the struct below, which contains all-kinds of properties; variable, constant, and computed.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var name: String // Variable Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; let birthday: Date // Constant Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var age: Int { // Computed Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; /* - */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Synthesized Requirements</b></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Constant Properties</b></p>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Constants are <b class="">always</b> accessed asynchronously.</li>
</ul><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">A Constant is guaranteed to be immutable and therefore able to be read from any thread without concern for unexpected mutation.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">The compiler sees this Constant as storage for a value.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Constant Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Variable Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Constant Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; let birthday: Date {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return underlying_Birthday_Date_<wbr class="">Value_Storage</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Computed Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">After opting-in to the Concurrent protocol, the compiler synthesizes this implementation, adding an asynchronous access point to any Constant on a Concurrent type.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Constant Property on a Concurrent type</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person: Concurrent {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Variable Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Constant Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; let birthday: Date {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; internalQueue.async { // Immediately returns on calling thread</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return underlying_Birthday_Date_<wbr class="">Value_Storage</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Computed Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Synthesized requirements for Variable Properties</b></p>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Variables are <b class="">always</b> accessed synchronously.</li>
</ul><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">A Variable is mutable and therefore each thread must schedule writes and reads separately out of concern for possible mutation.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Just like a Constant, the compiler sees this Variable as storage for a value.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Variable Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Variable Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var name: String {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return underlying_Name_String_Value_<wbr class="">Storage</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; set (newValue) {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; underlying_Name_String_Value_<wbr class="">Storage = newValue</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Constant Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Computed Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Here the compiler synthesizes synchronous access (read or write) to any Variable on a Concurrent type.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Variable Property on a Concurrent type</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person: Concurrent {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Variable Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var name: String {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; internalQueue.sync { // Wait to ensure all mutation has finished</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return underlying_Name_String_Value_<wbr class="">Storage</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; set (newValue) {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; internalQueue.sync { // Schedule this mutation to happen, in order</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; underlying_Name_String_Value_<wbr class="">Storage = newValue</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Constant Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Computed Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Synthesized requirements for Computed Properties</b></p>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>Computed Properties are <b class="">always</b> accessed synchronously.</li>
</ul><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">A Computed Property is essentially a function that gets called to create a value from other values. These other values can be mutable and therefore each thread must schedule writes and reads separately out of concern for possible mutation. (Note: If a computed property only accesses Constants, it should probably be a one-time set Constant; <a href="https://github.com/apple/swift" target="_blank" class=""><span style="color:#e4af0a" class="">Swift</span></a> could use a few proposals in this area.)</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Variable Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Variable Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Constant Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Computed Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var age: Int {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; // Compute age from birthday; return</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Here the compiler synthesizes synchronous access (read or write) to any Computed Property on a Concurrent type.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Variable Property on a Concurrent type</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">struct Person: Concurrent {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Variable Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; /* Constant Property */</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Computed Property</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var age: Int {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; internalQueue.sync { // Wait to ensure all mutation has finished</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Compute age from birthday; return</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Considerations for recursive types and abstraction</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">By making the synthesized conformances opt-in, recursive types have their requirements fall into place with no extra effort. In any cycle belonging to a recursive type, every type in that cycle must declare its conformance explicitly. If a type does so but cannot have its conformance synthesized because it does not satisfy the conditions above, then it is simply an error for <i class="">that</i> type and not something that must be detected earlier by the compiler in order to reason about <i class="">all</i> the other types involved in the cycle. (On the other hand, if conformance were implicit, the compiler would have to fully traverse the entire cycle to determine eligibility, which would make implementation much more complex).</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">With respect to abstraction, the idea that a synchronous function or property can access another synchronous function or property, introduces a problem: Deadlocking.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">The Deadlock Problem</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Or just Deadlocking, is a problem where a complex program cannot continue execution because one or more threads is waiting on a resource to become available or for another task to complete.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Anytime a synchronous function or property accesses another synchronous function or property; this is defined as a Deadlock, because the first cannot finish without the second being run and the second cannot execute without the first being finished.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Solving the Deadlock Problem</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">In complex functions where any number of synchronous and asynchronous calls can happen inside a larger scope it is required that the compiler know how to handle compilation of such functions, that may access many concurrent objects through a multitude of calls. Much like <a href="https://en.wikipedia.org/wiki/Automatic_Reference_Counting" target="_blank" class=""><span style="color:#e4af0a" class="">Automatic Reference Counting</span></a> increments and decrements a counter to determine whether an object should be marked for deallocation, we suggest that during compilation a call or set of calls is handled by evaluating their concurrent requirements.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">I.e. When a call nests as such:</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Compiler View - of a Complex Function on a Concurrent type</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">func heavyLift() {</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; syncFunction() // 1 Sync</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; async() // 1 Async</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; syncSomeFunction() // 2 Sync</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; syncSomeOtherFunction() // 3 Sync</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; asyncSomeFunction() // 2 Async</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; asyncSomeOtherFunction() // 3 Async</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">The compiler should implement a non-modified function, exactly as it would today, and wrap each usage in-scope with an asynchronous or synchronous requirement.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Specifically:</div>
<ul class="">
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>If a higher-level function accesses only asynchronous functions or properties internally, that function can be executed in-order as a single asynchronous call and inlining access to all non-modified calls.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>The same is true of synchronous functions or properties. They can be executed in-order as a single synchronous call and inlining access to existing non-modified calls.</li>
<li style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="font-stretch:normal;font-size:10px;line-height:normal;font-family:Menlo" class=""></span>If at any point a function or property, accesses an asynchronous and synchronous call then that function must be run as a single synchronous call.</li>
</ul><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:15px" class=""><b class=""></b><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Implementation details</b></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Deadlock Prevention is then inherent by synthesis. The following example explains this through a chunk of modified, disassembled Swift code.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Disassembly View - of an Integer Assignment without Thread-Safety</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">int __<wbr class="">T07Project14ConcurrentTypeC21f<wbr class="">unctionWithoutSafetyySi5value_<wbr class="">tF(int arg0) { // Standard</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; _swift_beginAccess(__<wbr class="">T07Project6objectSiv, &amp;var_30, 0x1, 0x0);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; *__T07Project6objectSiv = arg0;</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; rax = _swift_endAccess(&amp;var_30);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; return rax;</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Disassembly View - of an Integer Assignment with Asynchronous Access</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">int __<wbr class="">T07Project14ConcurrentTypeC17f<wbr class="">unctionWithAsyncySi5value_tF(<wbr class="">int arg0) { // AsyncCall</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; _swift_beginAccess(r13 + 0x10, &amp;var_30, 0x0, 0x0);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; _swift_endAccess(&amp;var_30, &amp;var_30, 0x0, 0x0);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; rax = _swift_rt_swift_allocObject();</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Call the Standard Function</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; __<wbr class="">T07Project14ConcurrentTypeC21f<wbr class="">unctionWithoutSafetyySi5value_<wbr class="">tF(int arg0)</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var_60 = __NSConcreteStackBlock;</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var_98 = _Block_copy(&amp;var_60);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var_A0 = __<wbr class="">T0So13DispatchQueueC0A0E5async<wbr class="">ySo0A5GroupCSg5group_<wbr class="">AC0A3QoSV3qosAC0A13WorkItemFla<wbr class="">gsV5flagsyyXB7executetFfA_(&amp;<wbr class="">var_60, 0x18, __NSConcreteStackBlock);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var_A1 = __<wbr class="">T0So13DispatchQueueC0A0E5async<wbr class="">ySo0A5GroupCSg5group_<wbr class="">AC0A3QoSV3qosAC0A13WorkItemFla<wbr class="">gsV5flagsyyXB7executetFfA0_();</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; __<wbr class="">T0So13DispatchQueueC0A0E5async<wbr class="">ySo0A5GroupCSg5group_<wbr class="">AC0A3QoSV3qosAC0A13WorkItemFla<wbr class="">gsV5flagsyyXB7executetF(var_<wbr class="">A0, var_A1 &amp; 0xff, __NSConcreteStackBlock, __<wbr class="">T0So13DispatchQueueC0A0E5async<wbr class="">ySo0A5GroupCSg5group_<wbr class="">AC0A3QoSV3qosAC0A13WorkItemFla<wbr class="">gsV5flagsyyXB7executetFfA1_(&amp;<wbr class="">var_60, 0x18), var_98);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; rax = _swift_rt_swift_release(rax, var_A1 &amp; 0xff);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; return rax;</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">// Disassembly View - of an Integer Assignment with Synchronous Access</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">int __<wbr class="">T07Project14ConcurrentTypeC16f<wbr class="">unctionWithSyncySi5value_tF(<wbr class="">int arg0) { // SyncCall</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; _swift_beginAccess(r13 + 0x10, &amp;var_28, 0x0, 0x0);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; _swift_endAccess(&amp;var_28, &amp;var_28, 0x0, &amp;var_28);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; rax = _swift_rt_swift_allocObject();</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Call the Standard Function</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; __<wbr class="">T07Project14ConcurrentTypeC21f<wbr class="">unctionWithoutSafetyySi5value_<wbr class="">tF(int arg0)</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Helvetica Neue&quot;; color: rgb(69, 69, 69); min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="m_3190066406160969240webkit-block-placeholder"></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var_58 = __NSConcreteStackBlock;</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; var_90 = _Block_copy(&amp;var_58);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; _swift_rt_swift_release(rax, 0x18);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; dispatch_sync(*(r13 + 0x10), var_90);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; rax = _Block_release(var_90);</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; return rax;</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">}</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Here are 3 functions, one which assigns a value to an integer without any safety, like a non-concurrent type. As well as two more which call that function using asynchronous and synchronous access respectively.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">The compiler determines which access should be used in a given scope, and places that scope inside a synchronous or asynchronous call.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Take a function which assigns this integer twice asynchronously:</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Standard Call</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | TwoAsyncs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; |&nbsp; AsyncCall&nbsp; | &nbsp; |&nbsp; AsyncCall&nbsp; |&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">One might reason that this function would fire-and-forget those calls, but instead the compiler is rectifying them as a single async.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Single Asynchronous Call</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | TwoAsyncs (Actually)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; |&nbsp; Standard &nbsp; | &nbsp; | &nbsp; Standard&nbsp; |&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">This behavior is the same for synchronous-only functions; however, instead of rehashing lets look at the more interesting complex case. We start with this:</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Standard Call</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | AnyAsync/SyncCombination&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; |&nbsp; AsyncCall&nbsp; | &nbsp; | &nbsp; SyncCall&nbsp; |&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">But in actuality the compiler has composed a single synchronous call, since there is a sync call at any point in the function.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; // Single Synchronous Call</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | AnyAsync/SyncCombination (Actually) &nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; |&nbsp; Standard &nbsp; | &nbsp; | &nbsp; Standard&nbsp; |&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">----------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Let's do one more for added clarity.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">------------------------------<wbr class="">--------------------------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | Combination &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | +-----------------------------<wbr class="">----------+ +-----------------------------<wbr class="">----------+ |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | | TwoAsyncs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | | AnyAsync/SyncCombination&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | |&nbsp; &nbsp; |&nbsp; AsyncCall&nbsp; | &nbsp; |&nbsp; AsyncCall&nbsp; |&nbsp; | |&nbsp; &nbsp; |&nbsp; AsyncCall&nbsp; | &nbsp; | &nbsp; SyncCall&nbsp; |&nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | +-----------------------------<wbr class="">----------+ +-----------------------------<wbr class="">----------+ |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">------------------------------<wbr class="">--------------------------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Becomes:</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">------------------------------<wbr class="">--------------------------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | Combination //Sync&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | +-----------------------------<wbr class="">----------+ +-----------------------------<wbr class="">----------+ |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | | TwoAsyncs //Async &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | | AnyAsync/SyncCombination //Sync &nbsp; &nbsp; &nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | |&nbsp; &nbsp; |&nbsp; Standard &nbsp; | &nbsp; | &nbsp; Standard&nbsp; |&nbsp; | |&nbsp; &nbsp; |&nbsp; Standard &nbsp; | &nbsp; | &nbsp; Standard&nbsp; |&nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |&nbsp; &nbsp; +-------------+ &nbsp; +-------------+&nbsp; | |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; | +-----------------------------<wbr class="">----------+ +-----------------------------<wbr class="">----------+ |</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">&nbsp; &nbsp; +-----------------------------<wbr class="">------------------------------<wbr class="">--------------------------+</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:15px" class=""><b class=""></b><br class=""></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">We've already made great decisions about thread-safety by implementing </b><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0035-limit-inout-capture.md" target="_blank" class=""><span style="color:#e4af0a" class=""><b class="">SE-0035</b></span></a><b class=""> for Value Types</b></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span style="color:#e4af0a" class=""><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0035-limit-inout-capture.md" target="_blank" class="">SE-0035 Limiting Inout Capture</a></span> actually provides us with a proof-of-concept as to why Value Types should not be asynchronously mutated inside a closure.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Source compatibility</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">By making the conformance opt-in, this is a purely additive change that should not affect existing code and should be easily applicable to stdlib types.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Some current types using <a href="https://github.com/apple/swift-corelibs-libdispatch" target="_blank" class=""><span style="color:#e4af0a" class="">Grand Central Dispatch</span></a> should be audited for recursive-implementation, if a user wishes to replace their own implementation with this synthesized one.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Effect on ABI stability</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">This feature is purely additive and should not change ABI.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">(Additionally, see Explicit Manglings for Sync/Async below for more on this.)</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Effect on API resilience</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">N/A.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Alternatives considered</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">In order to realistically scope this proposal, we considered but ultimately deferred the following items, some of which could be proposed additively in the future.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Synthesis in extensions</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Requirements will be synthesized only for protocol conformances that are <i class="">part of the type declaration itself;</i> conformances added in extensions will not be synthesized.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">However, to align with Codable in the context of <a href="https://bugs.swift.org/browse/SR-4920" target="_blank" class=""><span style="color:#e4af0a" class="">SR-4920</span></a>, we will also currently forbid synthesized requirements in extensions in the same file; this specific case can be revisited later for all derived conformances.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Explicit Manglings</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Because accesses are compiled and their async or sync wrappers are deterministic from use case, it may be useful to create specific Manglings; this is <b class="">optional</b>.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Embedding or Building Dispatch</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Dispatch already provides us with a very powerful and exacting standard for concurrency in Swift, it would be even more useful if embedded directly in the runtime with replacements like that currently in the <a href="https://github.com/apple/swift/blob/master/stdlib/public/runtime/Once.cpp#L31" target="_blank" class=""><span style="color:#e4af0a" class="">Runtime</span></a>.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">I feel as if most of the reason this would be frowned upon is a Swift desire for style, code cleanliness and some hope of a 'better' (whatever that means to you) solution.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Yet, we could add the existing library to the Runtime or even rewrite <a href="https://github.com/apple/swift-corelibs-libdispatch" target="_blank" class=""><span style="color:#e4af0a" class="">Grand Central Dispatch</span></a> as a Swift project and embed it in the Standard Library.</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Ideally, this would be deferred to a separate Swift Evolution Proposal.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Keyword Overrides</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">It is worth mentioning a Keyword could be used for overriding a function and defining explicit behavior as sync or async. However, this opens the door to misuse and incorrect code that can only be debugged at runtime with TSAN. And while we love TSAN:</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span class="m_3190066406160969240Apple-tab-span" style="white-space:pre-wrap">        </span>TSAN how I love thee. Let me non atomically count the ways…</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><span class="m_3190066406160969240Apple-tab-span" style="white-space:pre-wrap">                                                                </span>- Philippe Hausler</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">This is <b class="">not</b> a good idea.</div><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:17px" class=""><b class=""></b><br class=""></p><p style="margin:0px 0px 2px;font-stretch:normal;font-size:14px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class=""><b class="">Acknowledgments</b></p><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)" class="">Thanks to everyone in the Swift Community working to make it an even more vibrant place. And especially to those who worked on <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md" target="_blank" class=""><span style="color:#e4af0a" class="">SE-0166</span></a> and <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0185-synthesize-equatable-hashable.md" target="_blank" class=""><span style="color:#e4af0a" class="">SE-0185</span></a>. Whom might notice large parts of a shared ideal, that made this proposal much easier to write.</div><div class=""><br class=""></div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></body></html>