<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="">Doesn't it escalate pretty quickly into complex and ad-hoc language constructs?<div class=""><br class=""></div><div class="">Like everybody I like code synthesis. Like some, I'm worried that implicit synthesis would hide a few bugs that are hard to debunk. I also agree that developers who complain about those bugs would rightfully get the "behaves as expected" and "RTFM" classical answers. The problem with those deserved answers is that there's not much lesson to learn. Being bitten one, two, three times does not reduce the probability of being bitten another time. Programmer errors due to carelessness are the most difficult errors to prevent, don't you all agree?</div><div class=""><br class=""></div><div class="">People who use Sourcery are quite happy with AutoEquatable and AutoHashable. I don't know of anybody who complains of those. People are happy. Nobody types `AutoEquatable` by mistake: they get synthesis where they ask for it, and move on their next task without thinking much more about it. Sounds like a developer's dream, isn't it?</div><div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class="">This doesn't align with how Swift views the role of protocols, though. One of the criteria that the core team has said they look for in a protocol is "what generic algorithms would be written using this protocol?" AutoSynthesize doesn't satisfy that—there are no generic algorithms that you would write with AutoEquatable that differ from what you would write with Equatable.</div></blockquote><div class=""><br class=""></div><div class="">And so everybody has to swallow implicit and non-avoidable code synthesis and shut up?</div><div class=""><br class=""></div><div class="">Gwendal</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">Le 11 sept. 2017 à 23:05, Vladimir.S via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On 11.09.2017 21:55, Thorsten Seitz via swift-evolution wrote:</span><br 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; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">I think I do understand Haravikk's argument (actually it seems quite straightforward to me).<br class="">An example should be:<br class="">struct Foo : Equatable {<br class=""> var x: Int<br class=""> var cachedLabel: String? = nil<br class=""> init(x: Int) {<br class=""> self.x = x<br class=""> }<br class=""> mutating func label() {<br class=""> if let label = cachedLabel {<br class=""> return label<br class=""> }<br class=""> let label = calculateLabel()<br class=""> cachedLabel = label<br class=""> return cachedLabel<br class=""> }<br class="">}<br class="">var foo1 = Foo(x: 1)<br class="">var foo2 = Foo(x: 1)<br class="">foo1 == foo2 // true<br class="">var label = foo1.label()<br class="">foo1 == foo2 // now false, due to cachedString being falsely included in the comparison<br class="">The problem is that the developer was not required to implement the protocol and so might forget it.<br class="">The difference to other default implementations is that those use the protocol itself as building blocks and so are correct with regards to the protocol's semantics, whereas the synthesized equality reaches deeply into the private innards of a struct and therefore is much more likely to be wrong as in the example above.<br class="">Why not just write<br class="">*struct* Foo : *deriving* Equatable {...}<br class="">to request the synthesized implementation?<br class=""></blockquote><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">FWIW, +100. The same should be required for Codable. I support the opinion that 'synthesized' methods differs from protocol-default-implementation in what 'kind' of data they use: defined by protocol itself or internals of the conformed type. And this can lead to more un-expected problems.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">If protocol is able to synthesize its requirements, it should require a 'deriving'-like marker when type conforms to it to make it absolutely clear what happens here. It would be not a confusion point, but clarify the intention to better understand the code.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Thinking about *future* custom protocols that could implement requirements in default implementation by using macros/reflection, for me it seems like such protocol should *also* somehow explicitly state that some requirements are auto-synthesized, probably by conforming(derive) to some compiler-magic protocol 'AutoSynthesize'.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">(i.e. 'protocol MySynthesizeable: AutoSynthesize {...}')</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">So each built-in protocol like Equatable/Hashable/Codable will conform to it, and also, each custom "auto-synthesizeable" protocol - also should explicitly conform to AutoSynthesize. So, when type conforms to it - such type should use 'deriving'-like marker if auto-generation of methods is expected.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I also have a question regarding future direction of 'exclusion' of fields from being included into auto-generated implementation of Equatable/Hashable/Codable/other.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">If we'll have this 'deriving'-like marker, it seems naturally if we mark some member with some kind of '@noderiving' marker, like here:</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">struct Foo : deriving Equatable {</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> var x: Int</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> var y: Int</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> var z: Int</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> @noderiving var cachedLabel: String? = nil</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">}</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">this @noderiving directive will work for protocols based on AutoSynthesize magic protocol. I.e., if you construct your own protocol with auto-synthesizeable methods, to be able to *know* which members should be 'excluded' for your implementation, you should base your protocol on AutoSynthesize protocol.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I hope this makes any sense :-)</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Vladimir.</span><br 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; -webkit-text-stroke-width: 0px;" class=""><br 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; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">-Thorsten<br class="">Am 09.09.2017 um 19:42 schrieb Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>>:<br class=""><blockquote type="cite" class=""><br class="">On Sat, Sep 9, 2017 at 06:41 Haravikk via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>> wrote:<br class=""><br class=""><blockquote type="cite" class=""> On 9 Sep 2017, at 09:33, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a><br class=""> <<a href="mailto:xiaodi.wu@gmail.com" class="">mailto:xiaodi.wu@gmail.com</a>>> wrote:<br class=""><br class=""><br class=""> On Sat, Sep 9, 2017 at 02:47 Haravikk via swift-evolution<br class=""> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>> wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class=""> On 9 Sep 2017, at 02:02, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a><br class=""> <<a href="mailto:xiaodi.wu@gmail.com" class="">mailto:xiaodi.wu@gmail.com</a>>> wrote:<br class=""><br class=""> On Fri, Sep 8, 2017 at 4:00 PM, Itai Ferber via<br class=""> swift-evolution<<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""> <<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>>wrote:<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class=""> On Sep 8, 2017, at 12:46 AM, Haravikk via swift-evolution<br class=""> <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>>> wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class=""> On 7 Sep 2017, at 22:02, Itai Ferber <<a href="mailto:iferber@apple.com" class="">iferber@apple.com</a><br class=""> <<a href="mailto:iferber@apple.com" class="">mailto:iferber@apple.com</a>>> wrote:<br class=""><br class=""> |protocol Fooable : Equatable { // Equatable is just a simple<br class=""> example var myFoo: Int { get } } extension Fooable { static func<br class=""> ==(_ lhs: Self, _ rhs: Self) -> Bool { return lhs.myFoo ==<br class=""> rhs.myFoo } } struct X : Fooable { let myFoo: Int let myName:<br class=""> String // Whoops, forgot to give an implementation of == }<br class=""> print(X(myFoo: 42, myName: "Alice") == X(myFoo: 42, myName: "Bob"))<br class=""> // true|<br class=""> This property is/necessary/, but not/sufficient/to provide a<br class=""> correct implementation. A default implementation might be able<br class=""> to/assume/ something about the types that it defines, but it does<br class=""> not necessarily know enough.<br class=""></blockquote><br class=""> Sorry but that's a bit of a contrived example; in this case the<br class=""> protocol should*not* implement the equality operator if more<br class=""> information may be required to define equality. It should only be<br class=""> implemented if the protocol is absolutely clear that .myFoo is the<br class=""> only part of a Fooable that can or should be compared as equatable,<br class=""> e.g- if a Fooable is a database record and .myFoo is a primary key,<br class=""> the data could differ but it would still be a reference to the same<br class=""> record.<br class=""><br class=""> To be clear, I'm not arguing that someone can't create a regular<br class=""> default implementation that also makes flawed assumptions, but that<br class=""> synthesised/reflective implementations*by their very nature have<br class=""> to*, as they cannot under every circumstance guarantee correctness<br class=""> when using parts of a concrete type that they know nothing about.<br class=""></blockquote> You can’t argue this both ways:<br class=""><br class=""> * If you’re arguing this on principle, that in order for<br class=""> synthesized implementations to be correct, they/must/ be able to<br class=""> —/under every circumstance/ — guarantee correctness, then you<br class=""> have to apply the same reasoning to default protocol<br class=""> implementations. Given a default protocol implementation, it is<br class=""> possible to come up with a (no matter how contrived) case where<br class=""> the default implementation is wrong. Since you’re arguing this/on<br class=""> principle/, you cannot reject contrived examples.<br class=""> * If you are arguing this/in practice/, then you’re going to have<br class=""> to back up your argument with evidence that synthesized examples<br class=""> are more often wrong than default implementations. You can’t<br class=""> declare that synthesized implementations are/by nature/incorrect<br class=""> but allow default implementations to slide because/in practice/,<br class=""> many implementations are allowable. There’s a reason why<br class=""> synthesis passed code review and was accepted: in the majority of<br class=""> cases, synthesis was deemed to be beneficial, and would provide<br class=""> correct behavior. If you are willing to say that yes, sometimes<br class=""> default implementations are wrong but overall they’re correct,<br class=""> you’re going to have to provide hard evidence to back up the<br class=""> opposite case for synthesized implementations. You stated in a<br class=""> previous email that "A synthesised/reflective implementation<br class=""> however may return a result that is simply incorrect, because it<br class=""> is based on assumptions made by the protocol developer, with no<br class=""> input from the developer of the concrete type. In this case the<br class=""> developer must override it in to provide *correct* behaviour." —<br class=""> if you can back this up with evidence (say, taking a survey of a<br class=""> large number of model types and see if in the majority of cases<br class=""> synthesized implementation would be incorrect) to provide a<br class=""> compelling argument, then this is something that we should in<br class=""> that case reconsider.<br class=""><br class=""><br class=""> Well put, and I agree with this position 100%. However, to play devil's<br class=""> advocate here, let me summarize what I think Haravikk is saying:<br class=""><br class=""> I think the "synthesized" part of this is a red herring, if I understand<br class=""> Haravikk's argument correctly. Instead, it is this:<br class=""><br class=""> (1) In principle, it is possible to have a default implementation for a<br class=""> protocol requirement that produces the correct result--though not<br class=""> necessarily in the most performant way--for all possible conforming<br class=""> types, where by conforming we mean that the type respects both the<br class=""> syntactic requirements (enforced by the compiler) and the semantic<br class=""> requirements (which may not necessarily be enforceable by the compiler)<br class=""> of the protocol in question.<br class=""><br class=""> (2) However, there exist *some* requirements that, by their very nature,<br class=""> cannot have default implementations which are guaranteed to produce the<br class=""> correct result for all conforming types. In Haravikk's view, no default<br class=""> implementations should be provided in these cases. (I don't necessarily<br class=""> subscribe to this view in absolute terms, but for the sake of argument<br class=""> let's grant this premise.)<br class=""><br class=""> (3) Equatable, Hashable, and Codable requirements are, by their very<br class=""> nature, such requirements that cannot have default implementations<br class=""> guaranteed to be correct for all conforming types. Therefore, they should<br class=""> not have a default implementation. It just so happens that a default<br class=""> implementation cannot currently be written in Swift itself and must be<br class=""> synthesized, but Haravikk's point is that even if they could be written<br class=""> in native Swift through a hypothetical reflection facility, they should<br class=""> not be, just as many other protocol requirements currently could have<br class=""> default implementations written in Swift but should not have them because<br class=""> they cannot be guaranteed to produce the correct result.<br class=""><br class=""> My response to this line of argumentation is as follows:<br class=""><br class=""> For any open protocol (i.e., a protocol for which the universe of<br class=""> possible conforming types cannot be enumerated a priori by the protocol<br class=""> designer) worthy of being a protocol by the Swift standard ("what useful<br class=""> thing can you do with such a protocol that you could not without?"), any<br class=""> sufficiently interesting requirement (i.e., one for which user ergonomics<br class=""> would measurably benefit from a default implementation) either cannot<br class=""> have a universally guaranteed correct implementation or has an<br class=""> implementation which is also going to be the most performant one (which<br class=""> can therefore be a non-overridable protocol extension method rather than<br class=""> an overridable protocol requirement with a default implementation).<span class="Apple-converted-space"> </span><br class=""></blockquote><br class=""> You're close, but still missing key points:<br class=""><br class=""> 1. I am not arguing that features like these should*not* be provided, but<br class=""> that they should*not* be provided implicitly, and that the developer<br class=""> should actually be allowed to request them. That is exactly what this<br class=""> proposal is about, yet no matter what I say everyone seems to be<br class=""> treating me like I'm against these features entirely; *I am not*.<br class=""><br class=""><br class=""> You are entirely against Equatable having a default implementation for ==.<br class=""> This is unequivocally stated. Others favor such a default implementation and<br class=""> feel that in the absence of a way to spell this in Swift itself, it should be<br class=""> magic for the time being. For the purposes of this argument it really is not<br class=""> pertinent that you are not also against something else; you're asking us to<br class=""> discuss why you are against a particular thing that others are for.<br class=""></blockquote><br class=""> FFS, how much clearer can I make this? *I AM NOT AGAINST THE FEATURE.*<br class=""> *<br class=""> *<br class=""> What I am against is the way in which it is being provided implicitly rather<br class=""> than explicitly, in particular as a retroactive change to existing protocols in<br class=""> a way that introduces potential for bugs that are currently impossible, but<br class=""> also in general.<br class=""><br class=""><br class="">You are against a default implementation for ==, i.e. an implementation that is provided for you if you conform a type to the protocol and do nothing else ("implicitly rather than explicitly"), and you are against the default implementation being on the existing protocol Equatable ("retroactive change"). So, to summarize, what you are against is precisely a default implementation for the == requirement on Equatable.<br class=""><br class="">This is the topic of discussion here; I am attempting to convince you that you should be for rather than against these things.<br class=""><br class=""><br class=""><blockquote type="cite" class=""> As repeatedly answered by others, nothing here is specific to synthesized<br class=""> default implementations, as more powerful reflection will gradually allow them<br class=""> to be non-synthesised.<br class=""></blockquote><br class=""> And as repeatedly stated by me; I am not treating synthesised vs. run-time<br class=""> reflection any differently, I specifically included both in the original proposal.<br class=""><br class=""><blockquote type="cite" class=""> As pointed out very cogently by Itai, you assert but offer no evidence, either<br class=""> in principle or empirically, that going too far by reflection is worse than<br class=""> going not far enough without reflection in terms of likelihood of a default<br class=""> implementation being inappropriate for conforming types.<br class=""></blockquote><br class=""> As I have also repeatedly pointed out it is not an issue of "not going far<br class=""> enough" vs. "going too far"; if a default implementation lacks information then<br class=""> it should not be provided, doing so regardless is a flaw in the protocol design<br class=""> and not something that this proposal attempts to address (as such a thing is<br class=""> likely impossible).<br class=""><br class=""><br class="">Right, one must consider the semantics of the specific protocol requirement and ask whether a reasonable default can be provided for it.<br class=""><br class=""> Reflective implementations *necessarily* go too far, because they literally<br class=""> know *nothing* about the concrete type with any certainty, except for the<br class=""> properties that are defined in the protocol (which do not require reflection or<br class=""> synthesis in the first place).<br class=""><br class=""><br class="">I am confused why you are trying to argue in general terms about the universe of all possible default implementations that use reflection. This is necessarily a more difficult argument to make, and if it is to be convincing for all default implementations it must also be convincing for the two specific protocol requirements we are talking about here. Start small:<br class=""><br class="">We have agreed, as a community, that there is a reasonable default implementation for Equatable.== when certain conditions are met (for value types only at the moment, I believe). Namely, given two values of a type that has only Equatable stored properties, those values are equal if their stored properties are all equal. The author of a new value type who wishes to make her type Equatable but chooses not to implement a custom == then benefits from this default when all stored properties are Equatable.<br class=""><br class=""> And precisely what kind of "evidence" am I expected to give? This is a set of<br class=""> features that *do not exist yet*, I am trying to argue in favour of an explicit<br class=""> end-developer centric opt-in rather than an implicit protocol designer centric<br class=""> one. Yet no-one seems interested in the merits of allowing developers to choose<br class=""> what they want, rather than having implicit behaviours appear potentially<br class=""> unexpectedly.<br class=""><br class=""><br class="">Both options were examined for Codable and for Equatable/Hashable. The community and core team decided to prefer the current design. At this point, new insights that arise which could not be anticipated at the time of review could prompt revision. However, so far, you have presented arguments already considered during review.<br class=""><br class=""><blockquote type="cite" class=""> Therefore, your argument reduces to one about which default implementations<br class=""> generally ought or ought not to be provided--that is, that they ought to be<br class=""> provided only when their correctness can be guaranteed for all (rather than<br class=""> almost all) possible conforming types. To which point I sketched a rebuttal above.<br class=""></blockquote><br class=""> If a protocol defines something, and creates a default implementation based<br class=""> only upon those definitions then it must by its very nature be correct. A<br class=""> concrete type may later decided to go further, but that is a feature of the<br class=""> concrete type, not a failure of the protocol itself which can function<br class=""> correctly within the context it created. You want to talk evidence, yet there<br class=""> has been no example given that proves otherwise; thus far only Itai has<br class=""> attempted to do so, but I have already pointed out the flaws with that example.<br class=""><br class=""> The simple fact is that a default implementation may either be flawed or not<br class=""> within the context of the protocol itself; but a reflective or synthetic<br class=""> implementation by its very nature goes beyond what the protocol defines and so<br class=""> is automatically flawed because as it does not rely on the end-developer to<br class=""> confirm correctness, not when provided implicitly at least.<br class=""><br class=""><br class="">Again, if it applies generally, it must apply specifically. What is "automatically flawed" about the very reasonable synthesized default implementation of ==?<br class=""><br class=""><blockquote type="cite" class=""> And all of this continues to be a side-issue to the fact that in the<br class=""> specific case of Equatable/Hashable, which thus far has gone ignored, is<br class=""> that bolting this on retroactively to an existing protocol*hides bugs*.<br class=""> The issue of reflective default implementations is less of a concern on<br class=""> very clearly and well defined*new* protocols, though I still prefer more,<br class=""> rather than less, control, but in the specific case of*existing* protocols<br class=""> this fucking about with behaviours is reckless and foolish in the extreme,<br class=""> yet no-one on the core teams seems willing or able to justify it, which<br class=""> only opens much wider concerns (how am I to have any faith in Swift's<br class=""> development if the core team can't or won't justify the creation of new<br class=""> bugs?).<br class=""><br class=""><br class=""> This has emphatically not gone ignored, as I have myself responded to this<br class=""> point in an earlier thread in which you commented, as well as many others.<br class=""> Crucially, no existing conforming type changes its behavior, as they have all<br class=""> had to implement these requirements themselves. And as I said to you already,<br class=""> the addition of a synthesized default implementation no more "hides bugs"<br class=""> going forward than the addition of a non-synthesized default implementation to<br class=""> an existing protocol, and we do that with some frequency without even Swift<br class=""> Evolution review.<br class=""></blockquote><br class=""> Feel free to a supply a non-synthesised default implementation for Equatable<br class=""> without the use of reflection. Go-on, I'll wait.<br class=""> You insist on suggesting these are the same thing, yet if you can't provide one<br class=""> then clearly they are not.<br class=""><br class=""><br class="">That is not the argument. The argument is that they are indistinguishable in the sense that the author of a type who intends to supply a custom implementation but neglects to do so will have a default implementation supplied for them. It is plainly true that this is no more or less likely to happen simply because the default implementation is synthesized.<br class=""><br class=""><blockquote type="cite" class=""> Put another way, what the proposal about synthesizing implementations for<br class=""> Equatable and Hashable was about can be thought of in two parts: (a) should<br class=""> there be default implementations; and (b) given that it is impossible to write<br class=""> these in Swift, should we use magic? Now, as I said above, adding default<br class=""> implementations isn't (afaik) even considered an API change that requires<br class=""> review on this list. Really, what people were debating was (b), whether it is<br class=""> worth it to implement compiler-supported magic to make these possible. Your<br class=""> disagreement has to do with (a) and not (b).<br class=""></blockquote><br class=""> Wrong. The use of magic in this case produces something else entirely; that's<br class=""> the whole point. It is *not the same*, otherwise it wouldn't be needed at all.<br class=""> It doesn't matter if it's compiler magic, some external script or a native<br class=""> macro, ultimately they are all doing something with a concrete type that is<br class=""> currently not possible.<br class=""><br class=""> And once again; *I am not arguing against a default implementation that cuts<br class=""> boilerplate*, I am arguing against it being implicit. What I want is to be the<br class=""> one asking for it, because it is not reasonable to assume that just throwing it<br class=""> in there is always going to be fine, because it quite simply is not.<br class=""><br class=""><br class="">If you have to ask for it, then it's not a default. You *are* against a default implementation.<br class=""><br class=""> _______________________________________________<br class=""> swift-evolution mailing list<br class=""> <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>><br class=""> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><span class="Apple-converted-space"> </span><<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br 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; -webkit-text-stroke-width: 0px;" class=""><span 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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></div></body></html>