<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I don't see that <span style="background-color: rgba(255, 255, 255, 0);">retroactive conformance needs to be exportable. If it is exported then you cannot prevent clashes from two modules, this is a known problem in C#. Because of this and other problems with C# extensions, this style of extension were rejected by other language communities (notably Java and Scala).&nbsp;</span></div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">A better alternative for export is a new class that encapsulates the standard type but with added methods for the protocol to be added. This way there is no clash between modules. EG:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">&nbsp; &nbsp; public protocol P {</div><div id="AppleMailSignature">&nbsp; &nbsp; &nbsp; &nbsp; func m() -&gt; String</div><div id="AppleMailSignature">&nbsp; &nbsp; }</div><div id="AppleMailSignature">&nbsp; &nbsp; public class PInt: P {</div><div id="AppleMailSignature">&nbsp; &nbsp; &nbsp; &nbsp; var value = 0</div><div id="AppleMailSignature">&nbsp; &nbsp; &nbsp; &nbsp; func m() -&gt; String { return "PI.m" }</div><div id="AppleMailSignature">&nbsp; &nbsp; }<br><br>-- Howard.&nbsp;</div><div><br>On 13 Apr 2017, at 10:31 pm, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>The retroactive conformance needs to be exportable. If one cannot vend a library that conforms standard library types to new protocols, then that is a non-starter.<br><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 13, 2017 at 06:07 Howard Lovatt &lt;<a href="mailto:howard.lovatt@gmail.com">howard.lovatt@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>@Xiaodi,</div><div id="m_6701670277441155718AppleMailSignature"><br></div><div id="m_6701670277441155718AppleMailSignature">You can safely post-hoc add protocols and methods provided that they are final, do not override, and are not exported from the module. See version 2 of the proposal below.&nbsp;<br><br>-- Howard.</div><div id="m_6701670277441155718AppleMailSignature"><br></div><div id="m_6701670277441155718AppleMailSignature"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt"># Proposal: Split extension usage up into implementing methods and adding methods and protocols post-hoc</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Draft 2 (Added support for post-hoc conformance to a protocol - replaced static final extensions with final extensions)</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">## Introduction</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Currently extension methods are confusing because they have different dispatch rules for the same calling syntax. EG:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; public protocol P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func mP() -&gt; String</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp;&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; extension P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func mP() -&gt; String { return "P.mP" }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func mE() -&gt; String { return "P.mE" }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; struct S: P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func mP() -&gt; String { return "S.mP" }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func mE() -&gt; String { return "S.mE" }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; let s = S()</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; s.mP() // S.mP as expected</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; s.mE() // S.mE as expected</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; let p: P = s // Note: s now typed as P</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; p.mP() // S.mP as expected</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; p.mE() // P.mE unexpected!</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Extension methods can also cause compatibility problems between modules, consider:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">In Module A</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; extension Int: P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func m() -&gt; String { print("A.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">In Module B</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; extension Int: P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func m() -&gt; String { print("B.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">In Module C</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; import A</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; import B // Should this be an error</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; let i = 0</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; i.m() // Should it return A.m or B.m?</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">This proposal cures the above two problems by separating extension methods into two seperate use cases: implementations for methods and adding methods and protocols post-hoc.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">## Implementing methods</span></p></div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature">
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">If the extension is in the same file as the protocol/struct/class declaration then it implements the methods and is dispatched using a Vtable. EG:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">File P.swift</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; protocol/struct/class P {</span></p>
</div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; // func m() not declared in type since it is added by the extension, under this proposal it is an error to include a declaration in a type *and* in an extension</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; extension P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func m() { print("P.m") } // m is added to the protocol/struct/class declaration</span></p></div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature">
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Same or other file</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; struct S: P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; override func m() { print("S.m") } // Note override required because m already has an implementation from the extension</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
</div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; let p: P = S() // Note typed as P</span></p></div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature">
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; p.m() // Now prints S.m as expected&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Extensions in the same file as the declaration can have any access, can be final, and can have where clauses and provide inheritable implementations.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
</div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">In a protocol at present there is a difference in behaviour between a protocol that declares a method that is then implemented in an extension and a protocol that just has the method implemented in an extension and no declaration. This situation only applies to protocols, for structs and classes you cannot declare in type and implement in extensions. The proposal unifies the behaviour of protocol/struct/class with extensions and prevents the error of a minor typo between the protocol and extension adding two methods instead of generating an error.</span></p></div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature">
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">The implementation needed to achieve this is that a value instance typed as a protocol is copied onto the heap, a pointer to its Vtable added, and it is passed as a pointer. IE it becomes a class instance. No change needed for a class instance typed as a protocol.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
</div></div><div dir="auto"><div id="m_6701670277441155718AppleMailSignature"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">## Post-hoc adding protocols and methods</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">A new type of extension is proposed, a "final extension", which can be either in or outside the file in which the protocol/struct/class declaration is in. EG:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; protocol P2 {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func m2P()</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; final extension S: P2 { // Note extension marked final</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func m2P() { print("SP2.m2P") } // Implicitly final, completely implements P2</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; &nbsp; &nbsp; func m2E() { print("SP2.m2E") } // Implicitly final, not an existing method</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Which are called as any other method would be called:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; let s = S()</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; s.m2P() // Prints SP2.m2P</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; &nbsp; s.m2E() // Prints SP2.m2E</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">A method added by a final extension is implicitly final, as the name would suggest, and cannot be overridden.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">If the final extension:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; 1. Adds a method, e.g. m2E, that method cannot already exist. IE a final extension cannot override an existing method or implement a protocol declared method that lacks an implementation unless it also post-hoc adds the protocol.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; 2. Adds a protocol then it must implement all the methods in that protocol that are not currently implemented.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">&nbsp; 3. Is outside of the file in which the protocol/struct/class declaration is in then the extension and the methods can only have fileprivate or internal access. This prevents post-hoc extensions from numerous modules clashing, since they are not exported outside of the module.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">## Possible future work (not part of this proposal)</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">This proposal will naturally allow bodies to be added to protocols directly rather than via an extension, since under the proposal the extension adds the declaration to the type so it is a small step to allow the protocol methods to have an implementation.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">In an opposite sense to the above adding bodies to protocols, extensions could be allowed to add method declarations without bodies to protocols.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">The two above future work proposals, if both added, would add symmetry to where declarations and bodies may appear for protocols.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">## In summary.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">The proposal formalises the split use of extensions into their two uses: implementing methods and post-hoc adding protocols and methods. Syntax is added that clarifies the two use cases, the former are termed extensions and must be in the same file as the type is declared, and the latter are termed final extensions and can be in any file, however if they are not in the type's file the they can only have fileprivate or internal access.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px"><span style="font-family:'.SFUIText';font-size:17pt"></span><br></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)"><span style="font-family:'.SFUIText';font-size:17pt">Note the distinction between an extension in the same file and in a separate file is consistent with the philosophy that there is special status to the same file as proposed for private in <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md</a>.</span></p></div></div><div dir="auto"><div><br>On 11 Apr 2017, at 1:26 pm, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>As far as I'm aware, eliminating retroactive conformances is a non-starter.<br><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Apr 10, 2017 at 21:44 Howard Lovatt &lt;<a href="mailto:howard.lovatt@gmail.com" target="_blank">howard.lovatt@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg">@Xiaodi,</div><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg">You make two drugs.&nbsp;</div><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg">1. Deliberately making retroactive conformance outside of the file in which the type is declared illegal because of the problems it causes. See all the questions on Swift Users and watch people learning Swift get caught out.&nbsp;</div><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg">2. Outside of the file in which the type is declared the static final extension is restricted to internal or fileprivate so that multiple modules can add static final extensions without clashes.&nbsp;</div></div><div dir="auto" class="m_6701670277441155718gmail_msg"><div id="m_6701670277441155718m_3934634403776160645AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg">-- Howard.&nbsp;</div></div><div dir="auto" class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg">On 11 Apr 2017, at 8:51 am, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="m_6701670277441155718gmail_msg" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:<br class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><blockquote type="cite" class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg"><div dir="ltr" class="m_6701670277441155718gmail_msg">On Mon, Apr 10, 2017 at 5:35 PM, Howard Lovatt via swift-evolution <span dir="ltr" class="m_6701670277441155718gmail_msg">&lt;<a href="mailto:swift-evolution@swift.org" class="m_6701670277441155718gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br class="m_6701670277441155718gmail_msg"><div class="gmail_extra m_6701670277441155718gmail_msg"><div class="gmail_quote m_6701670277441155718gmail_msg"><blockquote class="gmail_quote m_6701670277441155718gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg">In response to Jordan Rose's comment I suggest the following change:</div><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">Proposal: Split extension usage up into implementing methods and adding static functions</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">Currently extension methods are confusing because they have different dispatch rules for the same syntax. EG:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; protocol P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; func m()</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; extension P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; func m() { print("P.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; struct S: P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; func m() { print("S.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; val p: P = S() // Note typed as P</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; p.m() // Surprisingly prints P.m even though S implements its own m</span></p></div></div></blockquote><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">This is incorrect. This prints "S.m", not "P.m".</div><div class="m_6701670277441155718gmail_msg">&nbsp;</div><blockquote class="gmail_quote m_6701670277441155718gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_6701670277441155718gmail_msg"><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg">
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; val s = S() // Note typed as S</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; s.m() // Prints S.m as expected&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">This proposal cures the above problem by separating extension methods into two seperate use cases: implementations for methods and adding static functions.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">First implementing methods.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">If the extension is in the same file as the protocol/struct/class declaration then it implements the methods and is dispatched using a Vtable. EG:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">File P.swift</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; protocol/struct/class P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; func m()</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; extension P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; func m() { print("P.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">Same or other file</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; struct S: P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; override func m() { print("S.m") } // Note override required because m already has an implementation from the extension</span></p></div></div></blockquote><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">Requiring `override` breaks retroactive conformance of types to protocols. This idea has been brought up over half a dozen times. Each time it fails in not being able to accommodate retroactive conformance.</div><div class="m_6701670277441155718gmail_msg">&nbsp;</div><blockquote class="gmail_quote m_6701670277441155718gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_6701670277441155718gmail_msg"><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg">
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; val p: P = S() // Note typed as P</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; p.m() // Now prints S.m as expected&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">Extensions in the same file as the declaration can have any access, can be final, and can have where clauses and provide inheritable implementations.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">The implementation needed to achieve this is that a value instance typed as a protocol is copied onto the heap, a pointer to its Vtable added, and it is passed as a pointer. IE it becomes a class instance. No change needed for a class instance typed as a protocol.&nbsp;</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">The second use case is adding static functions.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">A new type of extension is proposed, a static final extension, which can be either in or outside the file in which the protocol/struct/class declaration is in. EG:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; static final extension P { // Note extension marked static final</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; func m() { print("P.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">Which is called as any other static function would be called:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; val s = S()</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; P.m(s) // Prints P.m as expected</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">The new static final extension is shorthand, particularly in the case of multiple functions, for:</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; extension P {</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; &nbsp; &nbsp; static final func m(_ this: P) { print("P.m") }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">&nbsp; &nbsp; }</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">If the static final extension is outside of the file in which the protocol/struct/class declaration is in then the extension and the methods can only have fileprivate and internal access.</span></p></div></div></blockquote><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">What is the use case for having this restriction? What is the problem you are trying to solve?&nbsp;</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">&nbsp;</div><blockquote class="gmail_quote m_6701670277441155718gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_6701670277441155718gmail_msg"><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg"><p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">As at present protocol/struct/class can have both a static and instance method of the same name, m in the case of the example, because the usage syntax is distinct. As at present, static final extensions, both the extension and the individual functions, can have where clauses.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">In summary.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">The proposal formalises the split use of extensions into their two uses: implementing methods and adding static functions. Syntax is added that clarifies both for declarations and usage which type of extension is provided/in use.</span></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69);min-height:20.3px" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg"></span><br class="m_6701670277441155718gmail_msg"></p>
<p style="margin:0px;line-height:normal;font-family:'.SF UI Text';color:rgb(69,69,69)" class="m_6701670277441155718gmail_msg"><span style="font-family:'.SFUIText';font-size:17pt" class="m_6701670277441155718gmail_msg">Note the distinction between an extension in the same file and in a separate file is consistent with the proposed use of private in <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md" class="m_6701670277441155718gmail_msg" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md</a>.</span></p><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div>Comments?</div><div id="m_6701670277441155718m_3934634403776160645m_-5335225969984223547AppleMailSignature" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg">-- Howard.</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg">On 7 Apr 2017, at 4:49 am, Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" class="m_6701670277441155718gmail_msg" target="_blank">jordan_rose@apple.com</a>&gt; wrote:<br class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><blockquote type="cite" class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg">[Proposal:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0164-remove-final-support-in-protocol-extensions.md" class="m_6701670277441155718gmail_msg" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0164-remove-final-support-in-protocol-extensions.md</a>]</div><br class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg"><blockquote type="cite" class="m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg">On Apr 5, 2017, at 16:15, Howard Lovatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="m_6701670277441155718gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_6701670277441155718m_3934634403776160645m_-5335225969984223547Apple-interchange-newline m_6701670277441155718gmail_msg"><div class="m_6701670277441155718gmail_msg"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="m_6701670277441155718gmail_msg"><span style="background-color:rgba(255,255,255,0)" class="m_6701670277441155718gmail_msg">The review of SE-0164 "Remove final support in protocol extensions"</span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="m_6701670277441155718gmail_msg"><blockquote type="cite" class="m_6701670277441155718gmail_msg"><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px" class="m_6701670277441155718gmail_msg"><li style="box-sizing:border-box" class="m_6701670277441155718gmail_msg"><font class="m_6701670277441155718gmail_msg"><span style="background-color:rgba(255,255,255,0)" class="m_6701670277441155718gmail_msg">What is your evaluation of the proposal?</span></font></li></ul></blockquote><div class="m_6701670277441155718gmail_msg">The present situation isn't great. People get confused about which method will called with protocol extensions. Seems like every week there is a variation on this confusion on Swift Users mailing list. Therefore something needs to be done.&nbsp;</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">However I am not keen on this proposal since it makes behaviour inconsistent between methods in protocol extensions, classes, and structs.&nbsp;</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">I think a better solution would be one of the following alternatives:</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">&nbsp; 1. Must use final and final means it cannot be overridden; or</div><div class="m_6701670277441155718gmail_msg">&nbsp; 2. If not final dispatches using a table like a class and if marked final cannot be overridden and if marked dynamic uses obj-c dispatching; or</div><div class="m_6701670277441155718gmail_msg">&nbsp; 3. Must be marked dynamic and uses obj-c dispatching.&nbsp;</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">My preference would be option 2 but I think any of the three is superior to the present situation or the proposal.&nbsp;</div></div></div></blockquote><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">People have suggested all of these before, but none of them are obviously correct. It's true that we have a difference between extension members that satisfy requirements and those that don't, and that that confuses people. However, an extension-only member of one protocol can be used to satisfy the requirements of another protocol today, which is a tool for code reuse.</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">(I <i class="m_6701670277441155718gmail_msg">think</i>&nbsp;we managed to convince everyone that it's just a bug that a protocol extension method that satisfies a requirement cannot be overridden in a subclass, so at least that isn't an issue on top of the rest of this.)</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">Oh, and we can't retroactively add members of a protocol extension to existing adopters, which is why protocol extension members cannot be @objc. There are limited circumstances where that would be safe, but that would be a separate proposal.</div><div class="m_6701670277441155718gmail_msg"><br class="m_6701670277441155718gmail_msg"></div><div class="m_6701670277441155718gmail_msg">Jordan</div></div></div></blockquote></div><br class="m_6701670277441155718gmail_msg">_______________________________________________<br class="m_6701670277441155718gmail_msg">
swift-evolution mailing list<br class="m_6701670277441155718gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="m_6701670277441155718gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_6701670277441155718gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="m_6701670277441155718gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="m_6701670277441155718gmail_msg">
<br class="m_6701670277441155718gmail_msg"></blockquote></div><br class="m_6701670277441155718gmail_msg"></div></div>
</div></blockquote></div></blockquote></div>
</div></blockquote></div></blockquote></div>
</div></blockquote></body></html>