<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 2, 2017, at 5:35 PM, Gor Gyolchanyan via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Aug 2, 2017, at 5:30 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div dir="auto" class="">Besides the comments below on consensus about how to deal with the documentation aspect, I should point out that your example is incorrect. != is not a protocol requirement of Equatable with a default implementation, but a protocol extension method that cannot be overridden which is *not* a protocol requirement. That is by design.</div><div dir="auto" class=""><br class=""></div></div></div></blockquote></div></div></blockquote><div><br class=""></div><div>Forgot to address this part ๐</div><div>I didn't know Equatable behaved like that. I know that at least some time ago, Comparable behaved similarly (I'm not sure any more). But the primary use case is Collection.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><div class=""><div dir="auto" class="">Additionally, it is unclear to me why default implementations should need be provided in the same file, as your solution requires. There are good reasons why library A that builds upon library B might supply a default implementation in an extension for a protocol B.P that refines B.Q. To the end user, it is just as much of a default that doesnโt need to be implemented when conforming to P, but your proposed solution does nothing to address this issue.</div><div dir="auto" class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">Yes, it is restrictive. My approach to open-ended proposals like this (ones that might have unforeseen consequences) is to start with the bare minimum and work outwards from there. If the default implementation is in the same file, then the meta-information about the protocol requirement can be safely cached after compiling an individual file and it would remain valid when linking against the rest of object files in the module. I may, however, be completely wrong in how this works, so that's why I encourage people to put the proposed limitations to question. By the way, thank you for doing that ๐</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><div class="gmail_quote"><div class="">On Wed, Aug 2, 2017 at 03:54 Gor Gyolchanyan via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;">Good day, swift community!<div class="">This time, I'd like to bring your attention to an everyday problem which, I'm sure, you've all dealt with at some point.</div><div class=""><br class=""></div><div class=""><b class="">Motivation</b></div><div class=""><br class=""></div><div class="">Many protocols have a lot of default-implemented requirements so that they can be customized, which would otherwise be impossible to do.</div><div class="">For example, the<span class="Apple-converted-space"> </span><font color="#4f7a28" face="Menlo" class="">Comparable</font><span class="Apple-converted-space"> </span>protocol, which (considering its inheritance of<span class="Apple-converted-space"> </span><font face="Menlo" color="#4f7a28" class="">Equatable</font>) states a requirement of<span class="Apple-converted-space"> </span><font face="Menlo" class="">==</font>,<span class="Apple-converted-space"> </span><font face="Menlo" class="">!=</font>,<span class="Apple-converted-space"> </span><font face="Menlo" class=""><</font>,<span class="Apple-converted-space"> </span><font face="Menlo" class=""><=</font>,<span class="Apple-converted-space"> </span><font face="Menlo" class="">></font>, and<span class="Apple-converted-space"> </span><font face="Menlo" class="">>=</font>, only requires implementation of <font face="Menlo" class="">==</font> and<span class="Apple-converted-space"> </span><font face="Menlo" class=""><</font>, because all others have default implementations in terms of these two. This forces the user to either memorize the exact set of mandatory requirements or, in case of more complicated protocols like<span class="Apple-converted-space"> </span><font face="Menlo" color="#4f7a28" class="">Collection</font>, constantly look up the documentation and hope that it has a section outlining how to conform to it.</div><div class="">Conversely, the author of the protocol needs to manually keep track of the requirements and their default implementations to ensure that the ones that have to be mandatory stay mandatory and the rest of the requirements stay default-implemented, which is also a tedious and error-prone work.</div><div class=""><br class=""></div><div class=""><b class="">Proposed Solution</b></div><div class=""><br class=""></div><div class="">I'd like to propose the ability to mark select protocol requirements as<span class="Apple-converted-space"> </span><font color="#b92d5d" face="Menlo" class="">default</font>, which would cause the following effects:</div><div class=""><ul class="m_-3206054945558180310MailOutline"><li class="">The compiler will emit a compile-time error if a default implementation is not available in a non-constrained protocol extension in the same file and provide a fix-it for inserting a template.</li><li class="">If a conforming type does not implement all requirements of the protocol, the compiler will not produce fix-its for inserting a template for any<span class="Apple-converted-space"> </span><font color="#b92d5d" face="Menlo" class="">default</font><span class="Apple-converted-space"> </span>requirements.</li></ul></div><div class=""><br class=""></div><div class=""><b class="">Example</b></div><div class=""><br class=""></div><div class=""><font face="Menlo" color="#7a7a7a" class="">// Equatable.swift</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><font color="#b92d5d" class="">protocol</font><span class="Apple-converted-space"> </span><font color="#4f7a28" class="">Equatable</font><span class="Apple-converted-space"> </span>{</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span><font color="#b92d5d" class="">static</font><span class="Apple-converted-space"> </span><font color="#b92d5d" class="">func</font><span class="Apple-converted-space"> </span>== (_ some:<span class="Apple-converted-space"> </span><font color="#b92d5d" class="">Self</font>, _ other:<span class="Apple-converted-space"> </span><font color="#b92d5d" class="">Self</font>) -><span class="Apple-converted-space"> </span><font color="#4f7a28" class="">Bool</font></font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span><font color="#b92d5d" class="">default</font><span class="Apple-converted-space"> </span><font color="#b92d5d" class="">static</font><span class="Apple-converted-space"> </span><font color="#b92d5d" class="">func</font><span class="Apple-converted-space"> </span>!= (_ some:<span class="Apple-converted-space"> </span><font color="#b92d5d" class="">Self</font>, _ other:<span class="Apple-converted-space"> </span><font color="#b92d5d" class="">Self</font>) -><span class="Apple-converted-space"> </span><font color="#4f7a28" class="">Bool</font></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span></font><font color="#e32400" class=""><i class=""><font class="" style="font-family: Menlo;">^ error: missing implementation of a default requirement `!=`; </font><font class="" style="font-family: Menlo;">fix-it: insert a default implementation</font></i></font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><font color="#b92d5d" class="">extension</font><span class="Apple-converted-space"> </span><font color="#4f7a28" class="">Equatable</font><span class="Apple-converted-space"> </span>{</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span></font><font color="#b92d5d" face="Menlo" class="">static</font><span class="" style="font-family: Menlo;"> </span><font color="#b92d5d" face="Menlo" class="">func</font><span class="" style="font-family: Menlo;"> != (_ some: </span><font color="#9a244f" class="" style="font-family: Menlo;">Self</font><span class="" style="font-family: Menlo;">, _ other: </span><font color="#9a244f" class="" style="font-family: Menlo;">Self</font><span class="" style="font-family: Menlo;">) -> </span><font color="#4f7a28" face="Menlo" class="">Bool</font><font face="Menlo" class=""><span class="Apple-converted-space"> </span>{</font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">                </span><b class="">[<font color="#4d22b3" class="">Your Code Here]</font></b></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span>}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" color="#929292" class="">// Something.swift</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><font color="#b92d5d" class="">struct</font><span class="Apple-converted-space"> </span><font color="#4f7a28" class="">Something</font>:<span class="Apple-converted-space"> </span><font color="#4f7a28" class="">Equatable</font><span class="Apple-converted-space"> </span>{</font></div><div class=""><i class=""><font color="#e32400" class="" style="font-family: Menlo;">^ error: missing implementation of a non-default requirement `==`; </font><font color="#e32400" class="" style="font-family: Menlo;">fix-it: insert an implementation</font></i></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""><font color="#b92d5d" class="">extension</font> </font><font color="#4f7a28" face="Menlo" class="">Something</font><font face="Menlo" class=""> {</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span></font><font color="#b92d5d" face="Menlo" class="">static</font><span class="" style="font-family: Menlo;"> </span><font color="#b92d5d" face="Menlo" class="">func</font><span class="" style="font-family: Menlo;"> == (_ some: </span><font color="#4f7a28" face="Menlo" class="">Something</font><span class="" style="font-family: Menlo;">, _ other: </span><font color="#4f7a28" face="Menlo" class="">Something</font><span class="" style="font-family: Menlo;">) -> </span><font color="#4f7a28" face="Menlo" class="">Bool</font><font face="Menlo" class=""> {</font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">                </span><b class="">[<font color="#4d22b3" class="">Your Code Here]</font></b></font></div><div class=""><font face="Menlo" class=""><span class="m_-3206054945558180310Apple-tab-span" style="white-space: pre-wrap;">        </span>}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">}</font></div></div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Gor Gyolchanyan.</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" 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/mailman/listinfo/swift-evolution</a><br class=""></blockquote></div></div></div></blockquote></div><br class="" style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px;"><span style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: AvenirNext-Regular; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: AvenirNext-Regular; font-size: 14px; 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; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: AvenirNext-Regular; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>