<div dir="ltr">While I agree that it would be nice to handle tuples in those contexts, it also adds a fair amount of complexity to the implementation of the synthesis. I imagine that time would be better spent just making tuples conform to Equatable/Hashable properly instead of hacking it, because then the support falls out naturally; I&#39;d strongly prefer not to squeeze in more special cases to the proposal that could be done additively later.<div><br></div><div>Likewise, proposing a new public addition to the standard library would inspire far more design discussion than I believe we have time for if we want this to make Swift 4. :)</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, May 9, 2017 at 3:48 PM Andrew Bennett &lt;<a href="mailto:cacoyi@gmail.com">cacoyi@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="ltr">Also, when implementing this proposal it&#39;s going to be necessary to combine multiple hashes together. It would be awesome if this was done in a reusable way. If it doesn&#39;t slow the proposal down it would be awesome if it also introduced a stdlib function:<br><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> combine_hashes(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">_</span><span style="font-variant-ligatures:no-common-ligatures"> elements: [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">]) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    ...</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div><br></div><div>Thanks!</div><div>Andrew</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 10, 2017 at 8:45 AM, Andrew Bennett <span dir="ltr">&lt;<a href="mailto:cacoyi@gmail.com" target="_blank">cacoyi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>You state that you will not synthesise conformance for tuples, I agree with this, but if a struct or enum holds a tuple it would be nice if it could be hashed if its members are all hashable.</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(4,51,255)"><span style="font-variant-ligatures:no-common-ligatures">struct</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> A {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> a: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">, b: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">, c: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(4,51,255)"><span style="font-variant-ligatures:no-common-ligatures">struct</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> B {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> tuple: (a: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">, b: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">, c: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Int</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div>I&#39;d consider these two to be equivalent as far as this proposal is concerned, it would be nice if the proposal made that explicit.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-6558274819678562613h5">On Tue, May 9, 2017 at 7:17 AM, Tony Allevato via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-6558274819678562613h5"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Mon, May 8, 2017 at 2:11 PM Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" target="_blank">matthew@anandabits.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 style="word-wrap:break-word"><div><blockquote type="cite"><div>On May 8, 2017, at 4:02 PM, Tony Allevato &lt;<a href="mailto:tony.allevato@gmail.com" target="_blank">tony.allevato@gmail.com</a>&gt; wrote:</div><br class="m_-6558274819678562613m_6748490400675392276m_-4206921585179370676m_7114657150419324378Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sat, May 6, 2017 at 4:17 PM Chris Lattner &lt;<a href="mailto:clattner@nondot.org" target="_blank">clattner@nondot.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">On May 5, 2017, at 11:33 AM, Tony Allevato via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><div style="word-wrap:break-word"><div><blockquote type="cite"><br class="m_-6558274819678562613m_6748490400675392276m_-4206921585179370676m_7114657150419324378m_-6169955689964255263Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br><div><br></div></div></div><div style="word-wrap:break-word"><div><div>Can the opt-in conformance be declared in an extension?  If so, can the extension be in a different module than the original declaration?  If so, do you intend any restrictions, such as requiring all members of the type declared in a different module to be public?  My initial thought is that this should be possible as long as all members are visible.</div></div></div></blockquote><div><br></div><div>Declaring the conformance in an extension in the same module should definitely be allowed;</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>Please follow the precedent of the Codable proposal as closely as possible.  If you’d like this to be successful for Swift 4, you should look to scope it as narrowly as possible.  Because it is additive (with opt-in), it can always be extended in the future.</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div> I believe this would currently be the only way to support conditional conformances (such as the `Optional: Hashable where Wrapped: Hashable` example in the updated draft), without requiring deeper syntactic changes.</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>This proposal doesn’t need to cover all cases, since it is just sugaring a (very common) situation.  Conditional conformances to Hashable could be written manually.</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div>I&#39;m less sure about conformances being added in other modules,</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>It is a bad idea, it would break resilience of the extended type.</div></div></div><div style="word-wrap:break-word"><div><div><br></div><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><div>But after writing this all out, I&#39;m inclined to agree that I&#39;d rather see structs/enums make it into Swift 4 even if it meant pushing classes to Swift 4+x.</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>Agreed, keep it narrow to start with.</div><br></div><div>Also, I don’t know how the rest of the core team feels about this, but I suspect that they will be reticent to take an additive proposal at this late point in the schedule, unless someone is willing to step up to provide an implementation.</div></div></blockquote><div><br></div><div>That someone is me :)  I have a branch where it&#39;s working for enums (modulo some weirdness I need to fix after rebasing a two-month-old state), and adapting that logic to structs should hopefully be straightforward after that. Going with the more narrowly-scoped proposal and making conformances explicit simplifies the implementation a great deal as well (I was previously blocked with recursive types when it was implicit).</div><div><br></div><div>Thanks for the feedback—after consideration, I&#39;ve pulled classes out of the proposal completely (even non-final) and mentioned the other limitations so we&#39;d have a record of what was discussed in this thread.</div><div><br></div><div>I&#39;ve created a PR for the proposal text, in the event that the core team is interested in moving this forward: <a href="https://github.com/apple/swift-evolution/pull/706" target="_blank">https://github.com/apple/swift-evolution/pull/706</a></div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div>Thanks for continuing to push this forward Tony!  The current proposal looks like the right approach for getting this into Swift 4.  </div><div><br></div><div>I only have one question which I will present with an example:</div><div><br></div><div>protocol Foo: Equatable {}</div><div>protocol Bar: Hashable {}</div><div><br></div><div>struct FooType: Foo {}</div><div>struct BarType: Bar {}</div><div><br></div><div>Do FooType and BarType receive synthesis?</div></div></blockquote><div><span style="font-size:13px"><br></span></div></span><div><span style="font-size:13px">Great question! Yes they should. It&#39;s &quot;explicit&quot; transitively since the answer to &quot;does FooType/BarType conform to Equatable/Hashable?&quot; is still &quot;yes&quot;. (And I&#39;ve confirmed that my prototype handles this case.)</span><br></div><div style="font-size:13px"><br></div><div><span style="font-size:13px">This is especially helpful since Hashable extends Equatable, so a user only needs to list conformance to the former to get correctly synthesized implementations of both, which helps to guarantee that they&#39;re implemented consistently with respect to each other.</span></div><div><span style="font-size:13px"><br></span></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>-Chris</div><div><br></div><br></div></blockquote></div></div>
</div></blockquote></div><br></div></blockquote></div></div>
<br></div></div><span>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>
</blockquote></div>