<div dir="ltr"><div>Hi all,</div><div><br></div>A conversation on Twitter last night brought up some interest in this feature and I was encouraged to revive this proposal.<div><br></div><div>Jordan Rose <a href="https://twitter.com/UINT_MIN/status/859922619578986496">mentioned</a> on Twitter that it could possibly make it in by the Swift 4 deadline if others contributed—I have a WIP branch (albeit not currently working because I rebased after a couple months of it being idle) that does the work for enums but I got stuck on the mutually recursive cases. If this got approved, I&#39;d love to collaborate with other interested folks to finish up the implementation.</div><div><br></div><div>Link: <a href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad">https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad</a></div><div><br></div><div><br></div><div><h1 style="box-sizing:border-box;margin:0px 0px 16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;">Deriving<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>for value types</h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><li style="box-sizing:border-box">Proposal:<span class="inbox-inbox-Apple-converted-space"> </span><a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none">SE-0000</a></li><li style="box-sizing:border-box;margin-top:0.25em">Author(s):<span class="inbox-inbox-Apple-converted-space"> </span><a href="https://github.com/allevato" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none">Tony Allevato</a></li><li style="box-sizing:border-box;margin-top:0.25em">Status:<span class="inbox-inbox-Apple-converted-space"> </span><span style="box-sizing:border-box;font-weight:600"><a href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#rationale" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none">Awaiting review</a></span></li><li style="box-sizing:border-box;margin-top:0.25em">Review manager: TBD</li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-introduction" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Value types are prevalent throughout the Swift language, and we encourage developers to think in those terms when writing their own types. Frequently, developers have to write large amounts of boilerplate code to support equatability and hashability of value types. This proposal offers a way for the compiler to automatically derive conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>to reduce this boilerplate, in a subset of scenarios where generating the correct implementation is known to be possible.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Swift-evolution thread:<span class="inbox-inbox-Apple-converted-space"> </span><a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/8919" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none">Universal Equatability, Hashability, and Comparability</a></p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-motivation" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Building robust value types in Swift can involve writing significant boilerplate code to support hashability and equatability. Equality is pervasive across many value types, and for each one users must implement the<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">==</code><span class="inbox-inbox-Apple-converted-space"> </span>operator such that it performs a fairly rote memberwise equality test. As an example, an equality test for a struct looks fairly uninteresting:</p><div class="inbox-inbox-highlight inbox-inbox-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Foo</span>: <span class="inbox-inbox-pl-e" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Equatable</span> </span>{
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">==</span> (<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">lhs</span></span>: Foo, <span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">rhs</span></span>: Foo) <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-&gt;</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Bool</span> {
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> lhs.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">property1</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">==</span> rhs.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">property1</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&amp;&amp;</span>
           lhs.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">property2</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">==</span> rhs.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">property2</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&amp;&amp;</span>
           lhs.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">property3</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">==</span> rhs.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">property3</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&amp;&amp;</span>
           <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">...</span>
  }
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">What&#39;s worse is that this operator must be updated if any properties are added, removed, or changed, and since it must be manually written, it&#39;s possible to get it wrong, either by omission or typographical error.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Likewise, hashability is necessary when one wishes to store a value type in a<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Set</code><span class="inbox-inbox-Apple-converted-space"> </span>or use one as a multi-valued<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Dictionary</code><span class="inbox-inbox-Apple-converted-space"> </span>key. Writing high-quality, well-distributed hash functions is not trivial so developers may not put a great deal of thought into them – especially as the number of properties increases – not realizing that their performance could potentially suffer as a result. And as with equality, writing it manually means there is the potential to get it wrong.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">In particular, the code that must be written to implement equality for enums is quite verbose:</p><div class="inbox-inbox-highlight inbox-inbox-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Token</span>: <span class="inbox-inbox-pl-e" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Equatable</span> </span>{
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>)
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">number</span>(<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>)
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lparen</span>
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">rparen</span>
  
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">==</span> (<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">lhs</span></span>: Token, <span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">rhs</span></span>: Token) <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-&gt;</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Bool</span> {
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> (lhs, rhs) {
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> (.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> lhsString), .<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> rhsString))<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
      <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> lhsString <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">==</span> rhsString
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> (.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">number</span>(<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> lhsNumber), .<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">number</span>(<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> lhsNumber))<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
      <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> lhsNumber <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">==</span> rhsNumber
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> (.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">lparen</span>, .<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">lparen</span>), (.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">rparen</span>, .<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">rparen</span>)<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
      <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">true</span>
    <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">default</span><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
      <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">false</span>
    }
  }
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Crafting a high-quality hash function for this enum would be similarly inconvenient to write.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Swift already derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>conformance for a small subset of enums: those for which the cases have no associated values (including enums with raw types). Two instances of such an enum are equal if they are the same case, and an instance&#39;s hash value is its ordinal:</p><div class="inbox-inbox-highlight inbox-inbox-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Foo</span>  {
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">zero</span>, <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">one</span>, <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">two</span>
}

<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> (Foo.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">one</span> <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">==</span> Foo.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">two</span>)  <span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="inbox-inbox-pl-c" style="box-sizing:border-box">//</span> evaluates to false</span>
<span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> y <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> Foo.<span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">one</span>.<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">hashValue</span>     <span class="inbox-inbox-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="inbox-inbox-pl-c" style="box-sizing:border-box">//</span> evaluates to 1</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Likewise, conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">RawRepresentable</code><span class="inbox-inbox-Apple-converted-space"> </span>is automatically derived for enums with a raw type. Since there is precedent for derived conformances in Swift, we propose extending this support to more value types.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-proposed-solution" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#proposed-solution" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Proposed solution</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">In general, we propose that value types derive conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code>/<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>if all of its members are<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code>/<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code>. We describe the specific conditions under which these conformances are derived below, followed by the details of how the conformance requirements are implemented.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-protocol-derivability-conditions" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#protocol-derivability-conditions" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Protocol derivability conditions</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">For brevity, let<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>represent either the protocol<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>or<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>in the descriptions below.</p><h4 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:16px;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-derived-conformances-for-enums" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#derived-conformances-for-enums" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Derived conformances for<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code>s</h4><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">For an<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code>, derivability of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>is based on the conformances of its cases&#39; associated values. Computed properties are not considered.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">The following rules determine whether conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>can be derived for an<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code>:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><li style="box-sizing:border-box"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px">An<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code><span class="inbox-inbox-Apple-converted-space"> </span>with no cases does not derive conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>, since it is not possible to create instances of such types.</p></li><li style="box-sizing:border-box;margin-top:0.25em"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px">An<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code><span class="inbox-inbox-Apple-converted-space"> </span>with one or more cases derives conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if all of the associated values of all of its cases conform to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>(either explicitly or derived).</p></li></ul><h4 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:16px;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-derived-conformances-for-structs" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#derived-conformances-for-structs" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Derived conformances for<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code>s</h4><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">For a<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code>, derivability of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>is based on the conformances of its stored instance properties<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">only</em>. Neither static properties nor computed instance properties (those with custom getters) are considered.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">The following rules determine whether conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>can be derived for a<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code>:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><li style="box-sizing:border-box"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px">A<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code><span class="inbox-inbox-Apple-converted-space"> </span>with<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">no</em><span class="inbox-inbox-Apple-converted-space"> </span>stored properties does<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">not</em><span class="inbox-inbox-Apple-converted-space"> </span>derive conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>. (Even though it is vacuously true that all instances of a<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code><span class="inbox-inbox-Apple-converted-space"> </span>with no stored properties could be considered equal and hash to the same value, the reality is that such<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code>s are more often used for grouping/nesting of other entities and not for their singular value, and we don&#39;t consider it worthwhile to generate extra code in this case.)</p></li><li style="box-sizing:border-box;margin-top:0.25em"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px">A<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code><span class="inbox-inbox-Apple-converted-space"> </span>with one or more stored properties derives conformance to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if all if the types of all of its stored properties conform to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>(either explicitly or derived).</p></li></ul><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-considerations-for-recursive-types" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#considerations-for-recursive-types" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Considerations for recursive types</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">For brevity in the discussion below, the term<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">members</em><span class="inbox-inbox-Apple-converted-space"> </span>refers only to those members that are checked for deriving conformances:<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">stored properties</em><span class="inbox-inbox-Apple-converted-space"> </span>for<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code>s and<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">associated values</em><span class="inbox-inbox-Apple-converted-space"> </span>for<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code>s.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Recursive value types require a bit more care when determining whether a conformance can be derived. Consider the following<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code><span class="inbox-inbox-Apple-converted-space"> </span>with an<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">indirect</code><span class="inbox-inbox-Apple-converted-space"> </span>case:</p><div class="inbox-inbox-highlight inbox-inbox-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">TreeNode</span> {
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">empty</span>
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">leaf</span>(<span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">value</span></span>: <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>)
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">internal</span>(<span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">left</span></span>: TreeNode, <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="inbox-inbox-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">right</span></span>: TreeNode)
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">When examining the<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">internal</code><span class="inbox-inbox-Apple-converted-space"> </span>case, an application of the rules above implies that &quot;<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">TreeNode</code><span class="inbox-inbox-Apple-converted-space"> </span>derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">TreeNode</code><span class="inbox-inbox-Apple-converted-space"> </span>conforms to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>&quot;—a recursive condition. In this situation, we note that any instance of this type—or of any recursive type—forms a finite tree structure because the recursion must be terminated eventually by using one of the other base cases. Therefore, without changing the outcome,<span class="inbox-inbox-Apple-converted-space"> </span><span style="box-sizing:border-box;font-weight:600">we can assume for the purposes of determining whether<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code><span class="inbox-inbox-Apple-converted-space"> </span>derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>that any members of type<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code><span class="inbox-inbox-Apple-converted-space"> </span>already conform to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>.</span><span class="inbox-inbox-Apple-converted-space"> </span>If any members of different types prohibit deriving<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>, then we know that the whole type cannot derive it; likewise, if all of the other members permit deriving<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>, then we know that<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code><span class="inbox-inbox-Apple-converted-space"> </span>can derive it by recursively applying the derived operation.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">This property can be extended to<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">mutually</em><span class="inbox-inbox-Apple-converted-space"> </span>recursive types as well. Consider this contrived example:</p><div class="inbox-inbox-highlight inbox-inbox-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">A</span> {
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">value</span>(<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>)
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">b</span>(B)
}

<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">B</span> {
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">value</span>(<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>)
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">c</span>(C)
}

<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">C</span> {
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">value</span>(<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Double</span>)
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">a</span>(A)
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">The rules state that—ignoring the trivial cases—&quot;<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">A</code><span class="inbox-inbox-Apple-converted-space"> </span>derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">B</code><span class="inbox-inbox-Apple-converted-space"> </span>conforms to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>,&quot; and &quot;<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">B</code><span class="inbox-inbox-Apple-converted-space"> </span>derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">C</code>conforms to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>,&quot; and &quot;<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">C</code><span class="inbox-inbox-Apple-converted-space"> </span>derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">A</code><span class="inbox-inbox-Apple-converted-space"> </span>conforms to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code>.&quot; The same observation about recursion and the finiteness of instances from above holds here, so we can generalize the rule above as follows:</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><span style="box-sizing:border-box;font-weight:600">A type<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code><span class="inbox-inbox-Apple-converted-space"> </span>can derive<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>if all members of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code><span class="inbox-inbox-Apple-converted-space"> </span>conform to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>or are of types found in cycles that lead back to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code>such that the members of those other types along the cycle also all conform to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">P</code><span class="inbox-inbox-Apple-converted-space"> </span>or are themselves along such a cycle.</span></p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-other-considerations" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#other-considerations" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Other considerations</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">When conditional conformances are supported in Swift, generic types should conditionally derive<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>for type argument substitutions where the rules above are satisfied.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">A notable side effect of this is that<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Optional&lt;Wrapped&gt;</code><span class="inbox-inbox-Apple-converted-space"> </span>would derive<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>conformance when<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Wrapped</code><span class="inbox-inbox-Apple-converted-space"> </span>conforms to those protocols, because it is an<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum</code><span class="inbox-inbox-Apple-converted-space"> </span>that would satisfy the rules described above. Its implementation would not need to be in the standard library (but there is also nothing preventing it from being there).</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Conditional conformances will also significantly improve derivability coverage over other payload/member types. For example, consider a<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code><span class="inbox-inbox-Apple-converted-space"> </span>containing a stored property that is an array of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>types:</p><div class="inbox-inbox-highlight inbox-inbox-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="inbox-inbox-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Foo</span> {
  <span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> values<span class="inbox-inbox-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> [<span class="inbox-inbox-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>]
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Today,<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Array&lt;String&gt;</code><span class="inbox-inbox-Apple-converted-space"> </span>does not conform to<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code>, so its presence would prohibit<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Foo</code><span class="inbox-inbox-Apple-converted-space"> </span>from deriving<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code>. However, once Swift can express the conformance<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Array&lt;Element&gt;: Equatable where Element: Equatable</code>,<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Foo</code><span class="inbox-inbox-Apple-converted-space"> </span>would automatically derive<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>as well. This makes derived conformances significantly more powerful.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-implementation-details" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#implementation-details" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Implementation details</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">An<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum T</code><span class="inbox-inbox-Apple-converted-space"> </span>that derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>will receive a compiler-generated implementation of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">static == (lhs: T, rhs: T) -&gt; Bool</code><span class="inbox-inbox-Apple-converted-space"> </span>that returns<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">true</code><span class="inbox-inbox-Apple-converted-space"> </span>if and only if<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">lhs</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">rhs</code><span class="inbox-inbox-Apple-converted-space"> </span>are the same case and have payloads that are memberwise-equal.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">An<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">enum T</code><span class="inbox-inbox-Apple-converted-space"> </span>that derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>will receive a compiler-generated implementation of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">var hashValue: Int { get }</code>that uses an unspecified hash function<span style="box-sizing:border-box;font-size:12px;line-height:0;vertical-align:baseline">†</span><span class="inbox-inbox-Apple-converted-space"> </span>to compute the hash value by incorporating the case&#39;s ordinal (i.e., definition order) followed by the hash values of its associated values as its terms, also in definition order.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">A<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct T</code><span class="inbox-inbox-Apple-converted-space"> </span>that derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>will receive a compiler-generated implementation of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">static == (lhs: T, rhs: T) -&gt; Bool</code><span class="inbox-inbox-Apple-converted-space"> </span>that returns<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">true</code><span class="inbox-inbox-Apple-converted-space"> </span>if and only if<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">lhs.x == rhs.x</code><span class="inbox-inbox-Apple-converted-space"> </span>for all stored properties in<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">T</code>.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">A<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct T</code><span class="inbox-inbox-Apple-converted-space"> </span>that derives<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>will receive a compiler-generated implementation of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">var hashValue: Int { get }</code><span class="inbox-inbox-Apple-converted-space"> </span>that uses an unspecified hash function<span style="box-sizing:border-box;font-size:12px;line-height:0;vertical-align:baseline">†</span><span class="inbox-inbox-Apple-converted-space"> </span>to compute the hash value by incorporating the hash values of the fields as its terms, in definition order.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><span style="box-sizing:border-box;font-size:12px;line-height:0;vertical-align:baseline">†</span><span class="inbox-inbox-Apple-converted-space"> </span>We intentionally leave the exact definition of the hash function unspecified here. A multiplicative hash function with good distribution is the likely candidate, but we do not rule out other possibilities. Users should not depend on the nature of the generated implementation or rely on particular outputs; we reserve the right to change it in the future.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-overriding-derived-conformances" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#overriding-derived-conformances" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Overriding derived conformances</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Any user-provided implementations of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">==</code><span class="inbox-inbox-Apple-converted-space"> </span>or<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">hashValue</code><span class="inbox-inbox-Apple-converted-space"> </span>will override the default implementations that would be provided by the compiler. This is already the case possible today with raw-value enums so the same behavior should be extended to other value types that are made to implicitly conform to these protocols.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-open-questions" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#open-questions" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Open questions</h3><h4 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:16px;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-omission-of-fields-from-generated-computations" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#omission-of-fields-from-generated-computations" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Omission of fields from generated computations</h4><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Some commenters have expressed a desire to tag certain properties of a<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">struct</code><span class="inbox-inbox-Apple-converted-space"> </span>from being included in automatically generated equality tests or hash value computations. This could be valuable, for example, if a property is merely used as an internal cache and does not actually contribute to the &quot;value&quot; of the instance. Under the rules above, if this cached value was equatable, a user would have to override<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">==</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">hashValue</code><span class="inbox-inbox-Apple-converted-space"> </span>and provide their own implementations to ignore it.</p><h4 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:16px;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-explicit-or-implicit-derivation" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#explicit-or-implicit-derivation" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Explicit or implicit derivation</h4><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">As with raw-value enums today, should the derived conformance be completely implicit, or should users have to explicitly list conformance with<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>in order for the compiler to generate the derived implementation?</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">If derived conformances were made explicit, it could be argued that this should also be done for consistency across raw-value enums as well. This would be a source-breaking change, which should be avoided at this stage.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-impact-on-existing-code" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#impact-on-existing-code" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Impact on existing code</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">This change would make types that satisfy the rules above<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>when they previously were not. It is not expected that there would be any<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">behavioral</em><span class="inbox-inbox-Apple-converted-space"> </span>changes because of this; since<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>have associated type requirements, users cannot be dynamically testing for conformance to them at runtime.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Value types that already provide custom implementations of<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Equatable</code><span class="inbox-inbox-Apple-converted-space"> </span>and<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Hashable</code><span class="inbox-inbox-Apple-converted-space"> </span>would keep the custom implementation because it would override the compiler-provided default.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">This change would potentially increase binary size when it generates conformances that did not exist before, at least for types where it is not possible to know that the conformances are unused and thus cannot be dead-stripped (i.e., public types).</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-alternatives-considered" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#alternatives-considered" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Alternatives considered</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">The original discussion thread also included<span class="inbox-inbox-Apple-converted-space"> </span><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">Comparable</code><span class="inbox-inbox-Apple-converted-space"> </span>as a candidate for automatic generation. Unlike equatability and hashability, however, comparability requires an ordering among the members being compared. Automatically using the definition order here might be too surprising for users, but worse, it also means that reordering properties in the source code changes the code&#39;s behavior at runtime. (This is true for hashability as well if a multiplicative hash function is used, but hash values are not intended to be persistent and reordering the terms does not produce a significant<span class="inbox-inbox-Apple-converted-space"> </span><em style="box-sizing:border-box">behavioral</em><span class="inbox-inbox-Apple-converted-space"> </span>change.)</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-acknowledgments" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#acknowledgments" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Acknowledgments</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px">Thanks to Joe Groff for spinning off the original discussion thread, Jose Cheyo Jimenez for providing great real-world examples of boilerplate needed to support equatability for some value types, and to Mark Sands for necromancing the swift-evolution thread that convinced me to write this up.</p><hr style="box-sizing:content-box;height:0.25em;overflow:hidden;margin:24px 0px;background:rgb(225,228,232);border:0px;padding:0px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px"><h1 style="box-sizing:border-box;margin:24px 0px 16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;"><a id="inbox-inbox-user-content-rationale" class="inbox-inbox-anchor" href="https://gist.github.com/allevato/2fd10290bfa84accfbe977d8ac07daad#rationale" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1"></a>Rationale</h1><p style="box-sizing:border-box;margin-top:0px;color:rgb(36,41,46);font-family:-apple-system,system-ui,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;margin-bottom:0px">On [Date], the core team decided to<span class="inbox-inbox-Apple-converted-space"> </span><span style="box-sizing:border-box;font-weight:600">(TBD)</span><span class="inbox-inbox-Apple-converted-space"> </span>this proposal. When the core team makes a decision regarding this proposal, their rationale for the decision will be written here.</p></div><div><br></div><div><br></div></div>