# Unlikely-to-suceed pitch: remove implicit Hashable synthesis for enums without associated values

**URL:** <https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997>\
**Category:** Pitches\
**Created:** [November 14, 2018, 9:31pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997 "2018-11-14T21:31:51Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![timv](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/timv/32/13304_2.png) [@timv](https://forums.swift.org/u/timv)\
**Post date:** [November 15, 2018, 8:48pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/21 "2018-11-15T20:48:20Z")

</div>

> [@Nevin](#):
>
> **Boilerplate**  
> It would be needless boilerplate to require adding `Hashable` conformance to every simple enum just to use it in the only ways it can ever possibly be used.

This is misleading, you can pattern match an enum just fine without relying on `Equatable` or `Hashable` conformance. I expect a very large portion of all user-defined enums to not rely on its `Hashable` conformance.

> [@Nevin](#):
>
> **Convenience**  
> It would be inconvenient to require a `switch` for every enum comparison, when an `if` or `guard` would be better suited sometimes.

The `if case` and `guard case` syntax doesn't require `Equatable`, and usage of `==` could prompt a fixit to add `Equatable` conformance. I don't think this change would increase the number of pointless switches people write.

I don't think it's worthwhile to differentiate between public and non-public enums, IMO the inconsistency with `Codable`/`CaseIterable` would just make things more confusing.

---

<div class="post-metadata">

**Author:** ![duan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/duan/32/40252_2.png) [@duan](https://forums.swift.org/u/duan)\
**Post date:** [November 15, 2018, 9:02pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/22 "2018-11-15T21:02:41Z")

</div>

+1.

I've explained in numerous occasions to people who are new to Swift. Most of the time they got the impression that enums are automatically equitable everywhere, ran into associated values and got confused.

---

<div class="post-metadata">

**Author:** ![nuclearace](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@nuclearace](https://forums.swift.org/u/nuclearace)\
**Post date:** [November 15, 2018, 9:05pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/23 "2018-11-15T21:05:17Z")

</div>

> [@timv](#):
>
> The `if case` and `guard case` syntax doesn't require `Equatable` , and usage of `==` could prompt a fixit to add `Equatable` conformance.

I was under the impression that directly comparing enum cases was an intrinsic part of an enum. And that comparing two enum cases when the type is known to be an enum would still be fine after this proposal. Is that not the case here?

---

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [November 15, 2018, 9:15pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/24 "2018-11-15T21:15:33Z")

</div>

> [@timv](#):
>
> This is misleading, you can pattern match an enum just fine without relying on `Equatable` or `Hashable` conformance. I expect a very large portion of all user-defined enums to not rely on its `Hashable` conformance.

…and when you pattern-match a simple enum, you find out whether or not it is a certain case—ie. whether it is equal to another instance. Literally all you can do with an instance of a simple enum is store it, pass it to a function, or check if it’s the same as another one. That is my whole point.

I am not talking about how it is spelled in source code, nor how it is implemented behind the scenes. I am talking about the fact that a simple enum is a set of mutually-exclusive values, and the only thing that can possibly be done with such a type is to check if two of them are the same.

Even if you define a whole slew of methods on a simple enum, that let you add them or mutate them or whatever, when you get down to brass tacks you’re either going to ignore the value, or you’re going to test which case it equals. Everything else is stamp collecting.

---

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [November 15, 2018, 10:05pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/25 "2018-11-15T22:05:35Z")

</div>

> [@timv](#):
>
> The `if case` and `guard case` syntax doesn't require `Equatable` , and usage of `==` could prompt a fixit to add `Equatable` conformance. I don't think this change would increase the number of pointless switches people write.

This falls under progressive disclosure. The `if case` syntax is not something a beginner should have to learn.

---

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [November 15, 2018, 10:11pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/26 "2018-11-15T22:11:43Z")

</div>

…although, thinking about it again (and apologies for the triple-post), the code-size concern isn’t really _active harm_. And if a library publishes a simple enum, why \*shouldn’t\* clients be able to compare them or store them in a `Set`?

So perhaps Joe Groff is right, and it should only be resilient enums which are exempt from the implicit synthesis.

---

<div class="post-metadata">

**Author:** ![Geordie\_J](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/geordie_j/32/839_2.png) [@Geordie\_J](https://forums.swift.org/u/Geordie_J)\
**Post date:** [November 25, 2018, 3:02pm UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/27 "2018-11-25T15:02:19Z")

</div>

I think we should remove it, if not _only_ for consistency. And add Hashable as a fixit in the code migrator on all previously implicitly-conforming types.

To me there doesn’t seem any good reason to keep this around. If you make your own type, you need to specify what capabilities it has. It’s not like writing `: Hashable` on an enum is conceptually harder than writing it on your own class definition.

---

<div class="post-metadata">

**Author:** ![dabrahams](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dabrahams/32/9815_2.png) [@dabrahams](https://forums.swift.org/u/dabrahams)\
**Post date:** [November 27, 2018, 1:49am UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/28 "2018-11-27T01:49:49Z")

</div>

I don't know if it's been mentioned, but could we solve the resilience problem by making such implicit conformances non-public, and therefore only usable within the module that declares the enum?

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [November 27, 2018, 2:57am UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/29 "2018-11-27T02:57:07Z")

</div>

John did mention it, but we'd have to invent non-public conformances first.

---

<div class="post-metadata">

**Author:** ![dabrahams](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dabrahams/32/9815_2.png) [@dabrahams](https://forums.swift.org/u/dabrahams)\
**Post date:** [November 27, 2018, 3:23am UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/30 "2018-11-27T03:23:52Z")

</div>

Yesplease 😁

---

<div class="post-metadata">

**Author:** ![KeithBauerANZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/keithbaueranz/32/27897_2.png) [@KeithBauerANZ](https://forums.swift.org/u/KeithBauerANZ)\
**Post date:** [May 1, 2024, 1:18am UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/31 "2024-05-01T01:18:34Z")

</div>

I know I'm committing necromancy, and I know it's getting very late in the piece, but maybe we could resurrect this for Swift 6?

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 1, 2024, 1:21am UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/32 "2024-05-01T01:21:40Z")

</div>

Swift 6 is feature complete and branched, there’s now way anything would be added now.

---

<div class="post-metadata">

**Author:** ![beccadax](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/beccadax/32/34217_2.png) [@beccadax](https://forums.swift.org/u/beccadax)\
**Post date:** [May 1, 2024, 1:31am UTC](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997/33 "2024-05-01T01:31:03Z")

</div>

Moreover, Swift 6 has been avoiding source breaks that require widespread migration, even if they can be automated, unless the change is meant to enable concurrency safety. This change would require a lot of types to explicitly declare conformances they used to get for free, and it has nothing to do with concurrency safety, so it wouldn't fit within Swift 6's goals.

The good news on this front, however, is that the `~ProtocolName` syntax introduced by some of the recent ownership proposals could probably be extended to provide an opt-out for implicit `Hashable` synthesis. That wouldn't flip the default the way this pitch would, but it would at least make it possible for maintainers who cared about this feature to control it in some way. Because this wouldn't change the default behavior, it wouldn't be source-breaking and could be introduced in any release, not just one with a language version mode like Swift 6.

[Previous page](https://forums.swift.org/t/unlikely-to-suceed-pitch-remove-implicit-hashable-synthesis-for-enums-without-associated-values/17997.md?page=1)
