<div dir="ltr">Pardon my ignorance here, but shouldn’t `foo<T: Protocol>(t: T)` always monomorphize due to being generic? Isn’t that how `T: …` differs from, say `foo(t: Protocol)`?</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 14, 2017 at 7:30 PM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Mar 14, 2017, at 11:27 AM, David Hart <<a href="mailto:david@hartbit.com">david@hartbit.com</a>> wrote:<br>
><br>
><br>
><br>
>> On 14 Mar 2017, at 16:41, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>><br>
>><br>
>>> On Mar 13, 2017, at 8:38 AM, Vincent Esche via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>>><br>
>>> Source compatibility<br>
>>><br>
>>> Making use of "extending protocols to conform to protocols":<br>
>>><br>
>>> extension Hashable: HashVisitable<br>
>>> {<br>
>>><br>
>>> func hash<H: Hasher>(_ hasher: inout<br>
>>> H) {<br>
>>><br>
>>> self.hashValue.hash(&<br>
>>> hasher)<br>
>>> }<br>
>>> }<br>
>><br>
>> We're unlikely to add this feature soon. It seems reasonable to me to instead have `HashVisitable` refine `Hashable` and provide a default implementation of `hashValue` using a default hasher. I think we still want `Hashable` to be the currency protocol most APIs work with for performance in unspecialized code, since we could inline the visitation and hasher implementation together inside the specialized `hashValue` witness.<br>
><br>
> Can you explain the performance argument? How does it fare (in your opinion) compared to the arguments in the proposal?<br>
><br>
> How about:<br>
><br>
> protocol Hashable {<br>
> func hash<H: Hasher>(with hasher: inout H)<br>
> }<br>
><br>
> extension Hashable {<br>
> var hashValue: Int {<br>
> var hasher = StdLibDefaultHasher()<br>
> hash(with: hasher)<br>
> return hash.finish()<br>
> }<br>
> }<br>
<br>
</span>For unspecialized code that takes a generic T: Hashable, that will place the only dynamic dispatch point on `hash`, so that will place an abstraction barrier between the Hasher and Self type being hashed, so would likely mean a dynamic call for every component of the value being hashed. Having `hashValue` be a dynamic dispatch point allows the hasher to be inlined together with the type's visitor implementation.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Joe<br>
</font></span></blockquote></div><br></div>