<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 9 Sep 2017, at 02:02, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; 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-stroke-width: 0px;" class="">On Fri, Sep 8, 2017 at 4:00 PM, Itai Ferber via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><br class=""><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class="">On Sep 8, 2017, at 12:46 AM, Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-2897067699292549448Apple-interchange-newline"><div class=""><div style="word-wrap: break-word;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 7 Sep 2017, at 22:02, Itai Ferber &lt;<a href="mailto:iferber@apple.com" target="_blank" class="">iferber@apple.com</a>&gt; wrote:</div><div class=""><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=""><br class=""><div class=""><pre class="m_-2897067699292549448language-swift" style="margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(245, 242, 240); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; overflow: auto; padding: 1em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-family: 'SF Mono', Menlo, Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; white-space: pre-wrap; word-break: normal; word-wrap: normal;"><code class="m_-2897067699292549448language-swift" style="margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; font-family: 'SF Mono', Menlo, Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5;">protocol <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Fooable</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Equatable</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">{ // Equatable is just a simple example</span>
    <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">var</span> myFoo<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Int</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">{</span> <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">get</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">}</span>
<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">}</span>

<span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">extension</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Fooable</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">{</span>
    <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">static</span> <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">func</span> <span class="m_-2897067699292549448token m_-2897067699292549448operator" style="color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">==</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">(</span><span class="m_-2897067699292549448token m_-2897067699292549448number" style="color: rgb(153, 0, 85);">_</span> lhs<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">Self</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">,</span> <span class="m_-2897067699292549448token m_-2897067699292549448number" style="color: rgb(153, 0, 85);">_</span> rhs<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">Self</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">)</span> <span class="m_-2897067699292549448token m_-2897067699292549448operator" style="color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">-</span><span class="m_-2897067699292549448token m_-2897067699292549448operator" style="color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">&gt;</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Bool</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">{</span>
        <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">return</span> lhs<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">.</span>myFoo <span class="m_-2897067699292549448token m_-2897067699292549448operator" style="color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">==</span> rhs<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">.</span>myFoo
    <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">}</span>
<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">}</span>

<span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">struct</span> X <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Fooable</span> <span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">{</span>
    <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">let</span> myFoo<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">Int</span>
    <span class="m_-2897067699292549448token m_-2897067699292549448keyword" style="color: rgb(0, 119, 170);">let</span> myName<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448builtin" style="color: rgb(102, 153, 0);">String</span>
    <span class="m_-2897067699292549448token m_-2897067699292549448comment" style="color: rgb(112, 128, 144);">// Whoops, forgot to give an implementation of ==</span>
<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">}</span>

<span class="m_-2897067699292549448token m_-2897067699292549448function" style="color: rgb(221, 74, 104);">print</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">(</span><span class="m_-2897067699292549448token m_-2897067699292549448function" style="color: rgb(221, 74, 104);">X</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">(</span>myFoo<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448number" style="color: rgb(153, 0, 85);">42</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">,</span> myName<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448string" style="color: rgb(102, 153, 0);">"Alice"</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">)</span> <span class="m_-2897067699292549448token m_-2897067699292549448operator" style="color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">==</span> <span class="m_-2897067699292549448token m_-2897067699292549448function" style="color: rgb(221, 74, 104);">X</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">(</span>myFoo<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448number" style="color: rgb(153, 0, 85);">42</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">,</span> myName<span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">:</span> <span class="m_-2897067699292549448token m_-2897067699292549448string" style="color: rgb(102, 153, 0);">"Bob"</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">)</span><span class="m_-2897067699292549448token m_-2897067699292549448punctuation" style="color: rgb(153, 153, 153);">)</span> <span class="m_-2897067699292549448token m_-2897067699292549448comment" style="color: rgb(112, 128, 144);">// true</span></code></pre><div class="">This property is<span class="m_-2897067699292549448Apple-converted-space">&nbsp;</span><i class="">necessary</i>, but not<span class="m_-2897067699292549448Apple-converted-space">&nbsp;</span><i class="">sufficient</i><span class="m_-2897067699292549448Apple-converted-space">&nbsp;</span>to provide a correct implementation. A default implementation might be able to<span class="m_-2897067699292549448Apple-converted-space">&nbsp;</span><i class="">assume</i>&nbsp;something about the types that it defines, but it does not necessarily know enough.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Sorry but that's a bit of a contrived example; in this case the protocol should<span class="Apple-converted-space">&nbsp;</span><b class="">not</b>&nbsp;implement the equality operator if more information may be required to define equality. It should only be implemented if the protocol is absolutely clear that .myFoo is the only part of a Fooable that can or should be compared as equatable, e.g- if a Fooable is a database record and .myFoo is a primary key, the data could differ but it would still be a reference to the same record.</div><div class=""><br class=""></div><div class="">To be clear, I'm not arguing that someone can't create a regular default implementation that also makes flawed assumptions, but that synthesised/reflective implementations<span class="Apple-converted-space">&nbsp;</span><b class="">by their&nbsp;very nature have to</b>, as they cannot under every circumstance guarantee correctness when using parts of a concrete type that they know nothing about.</div></div></div></div></blockquote></span><div class="">You can’t argue this both ways:</div><div class=""><ul class="m_-2897067699292549448MailOutline"><li class="">If you’re arguing this on principle, that in order for synthesized implementations to be correct, they<span class="Apple-converted-space">&nbsp;</span><i class="">must</i>&nbsp;be able to —<span class="Apple-converted-space">&nbsp;</span><i class="">under every circumstance</i>&nbsp;— guarantee correctness, then you have to apply the same reasoning to default protocol implementations. Given a default protocol implementation, it is possible to come up with a (no matter how contrived) case where the default implementation is wrong. Since you’re arguing this<span class="Apple-converted-space">&nbsp;</span><i class="">on principle</i>, you cannot reject contrived examples.</li><li class="">If you are arguing this<span class="Apple-converted-space">&nbsp;</span><i class="">in practice</i>, then you’re going to have to back up your argument with evidence that synthesized examples are more often wrong than default implementations. You can’t declare that synthesized implementations are<span class="Apple-converted-space">&nbsp;</span><i class="">by nature</i><span class="Apple-converted-space">&nbsp;</span>incorrect but allow default implementations to slide because<span class="Apple-converted-space">&nbsp;</span><i class="">in practice</i>, many implementations are allowable. There’s a reason why synthesis passed code review and was accepted: in the majority of cases, synthesis was deemed to be beneficial, and would provide correct behavior. If you are willing to say that yes, sometimes default implementations are wrong but overall they’re correct, you’re going to have to provide hard evidence to back up the opposite case for synthesized implementations. You stated in a previous email that "<span style="font-family: SFHello-Regular;" class="">A synthesised/reflective implementation however may return a result that is simply incorrect, because it is based on assumptions made by the protocol developer, with no input from the developer of the concrete type. In this case the developer must override it in to provide&nbsp;</span><b style="font-family: SFHello-Regular;" class="">correct</b><font face="SFHello-Regular" class="">&nbsp;behaviour." — if you can back this up with evidence (say, taking a survey of a large number of model types and see if in the majority of cases synthesized implementation would be incorrect) to provide a compelling argument, then this is something that we should in that case reconsider.</font></li></ul></div></div></div></blockquote><div class=""><br class=""></div><div class="">Well put, and I agree with this position 100%. However, to play devil's advocate here, let me summarize what I think Haravikk is saying:</div><div class=""><br class=""></div><div class="">I think the "synthesized" part of this is a red herring, if I understand Haravikk's argument correctly. Instead, it is this:</div><div class=""><br class=""></div><div class="">(1) In principle, it is possible to have a default implementation for a protocol requirement that produces the correct result--though not necessarily in the most performant way--for all possible conforming types, where by conforming we mean that the type respects both the syntactic requirements (enforced by the compiler) and the semantic requirements (which may not necessarily be enforceable by the compiler) of the protocol in question.</div><div class=""><br class=""></div><div class="">(2) However, there exist *some* requirements that, by their very nature, cannot have default implementations which are guaranteed to produce the correct result for all conforming types. In Haravikk's view, no default implementations should be provided in these cases. (I don't necessarily subscribe to this view in absolute terms, but for the sake of argument let's grant this premise.)</div><div class=""><br class=""></div><div class="">(3) Equatable, Hashable, and Codable requirements are, by their very nature, such requirements that cannot have default implementations guaranteed to be correct for all conforming types. Therefore, they should not have a default implementation. It just so happens that a default implementation cannot currently be written in Swift itself and must be synthesized, but Haravikk's point is that even if they could be written in native Swift through a hypothetical reflection facility, they should not be, just as many other protocol requirements currently could have default implementations written in Swift but should not have them because they cannot be guaranteed to produce the correct result.</div><div class=""><br class=""></div><div class="">My response to this line of argumentation is as follows:</div><div class=""><br class=""></div><div class="">For any open protocol (i.e., a protocol for which the universe of possible conforming types cannot be enumerated a priori by the protocol designer) worthy of being a protocol by the Swift standard ("what useful thing can you do with such a protocol that you could not without?"), any sufficiently interesting requirement (i.e., one for which user ergonomics would measurably benefit from a default implementation) either cannot have a universally guaranteed correct implementation or has an implementation which is also going to be the most performant one (which can therefore be a non-overridable protocol extension method rather than an overridable protocol requirement with a default implementation).&nbsp;</div></div></div></div></div></blockquote><br class=""></div><div>You're close, but still missing key points:</div><div><br class=""></div><div><ol class="MailOutline"><li class="">I am not arguing that features like these should <b class="">not</b>&nbsp;be provided, but that they should <b class="">not</b>&nbsp;be provided implicitly, and that the developer should actually be allowed to request them. That is exactly what this proposal is about, yet no matter what I say everyone seems to be treating me like I'm against these features entirely;&nbsp;<b class="">I am not</b>.</li><li class="">A non-reflective default implementation can <b class="">only</b> operate on the basis of what the protocol itself defines; this means that it can always be correct within the context of only what the protocol declares. At worst, a "pure" default implementation can only be overly cautious, but strictly speaking this does not make its behaviour incorrect, though, if it is a likely case it suggests that a default implementation is not a good idea (as it is better to ensure the developer provides any further information).</li><li class="">Synthetic/reflective implementations <b class="">by their very nature</b>&nbsp;must <b class="">always</b>&nbsp;make assumptions that are tenuous at best, especially in cases of examining unknown properties defined for an unknown purpose by an unknown type.</li></ol><div class=""><br class=""></div><div class="">Another way of thinking about the difference is that a non-reflective default implementation can only <b class="">omit</b> information that a developer must provide, but this is an easily solved case as that's precisely what unimplemented protocol requirements are for (to ask for more information/specific implementation details).</div><div class=""><br class=""></div><div class="">With reflective behaviour however the default implementation can (and will) go too far in what information it uses; while it might work fine some of the time, this is a fundamental risk, and there is no mechanism through which a protocol may force the developer to alter that behaviour. This makes the behaviour insidious in nature, which is why it is better that a developer specifically opt into it as it keeps the end developer in control, especially since these behaviours are predicated on the idea that they are supposed to be a convenience, but when the protocol is fucking around with properties it knows <b class="">nothing</b>&nbsp;about then <b class="">only</b>&nbsp;the end developer can determine if that is the case.</div><div class=""><br class=""></div><div class="">And all of this continues to be a side-issue to the fact that in the specific case of Equatable/Hashable, which thus far has gone ignored, is that bolting this on retroactively to an existing protocol <b class="">hides bugs</b>. The issue of reflective default implementations is less of a concern on very clearly and well defined <b class="">new</b>&nbsp;protocols, though I still prefer more, rather than less, control, but in the specific case of <b class="">existing</b>&nbsp;protocols this fucking about with behaviours is reckless and foolish in the extreme, yet no-one on the core teams seems willing or able to justify it, which only opens much wider concerns (how am I to have any faith in Swift's development if the core team can't or won't justify the creation of new bugs?).</div></div></body></html>