# \[Pitch\] Equatable and Hashable conformances for the span family

**URL:** <https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475>\
**Category:** Pitches\
**Created:** [November 4, 2026, 8:57pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475 "2026-11-04T20:57:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![clintonpi](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clintonpi](https://forums.swift.org/u/clintonpi)\
**Post date:** [November 4, 2026, 8:57pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/1 "2026-11-04T20:57:48Z")

</div>

Hello everyone,

`Span`, `MutableSpan` and `OutputSpan` should conform to `Equatable` and `Hashable` when their `Element` does, and `RawSpan`, `MutableRawSpan` and `OutputRawSpan` should conform unconditionally. Values of these types should be considered equal when their elements/bytes are equal (not only when they view the same memory region).

Here is a proposal: [Proposal for `Equatable` and `Hashable` conformances for the span family by clintonpi · Pull Request #3574 · swiftlang/swift-evolution · GitHub](https://github.com/swiftlang/swift-evolution/pull/3574)

---

<div class="post-metadata">

**Author:** ![Nobody1707](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nobody1707/32/2169_2.png) [@Nobody1707](https://forums.swift.org/u/Nobody1707)\
**Post date:** [November 4, 2026, 10:14pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/2 "2026-11-04T22:14:46Z")

</div>

I would be more comfortable with this if `Spans` also supported `===` so I could easily compare the memory regions without having to drop down to unsafe pointers.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [November 4, 2026, 10:28pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/3 "2026-11-04T22:28:36Z")

</div>

Um, they do, just not spelled with an operator:

> **[isIdentical(to:) | Apple Developer Documentation](https://developer.apple.com/documentation/swift/span/isidentical(to:))**
>
> Returns a Boolean value indicating whether two instances refer to the same memory region.

---

<div class="post-metadata">

**Author:** ![Nobody1707](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nobody1707/32/2169_2.png) [@Nobody1707](https://forums.swift.org/u/Nobody1707)\
**Post date:** [November 4, 2026, 10:33pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/4 "2026-11-04T22:33:01Z")

</div>

Well, then. Full steam ahead, I say.

---

<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 4, 2026, 11:37pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/5 "2026-11-04T23:37:17Z")

</div>

> Two `Output(Raw)Span`s with the same initialized content are equal even if their capacities differ.

I feel a little weird about this one, though it's consistent with Array. It's always possible to say `out.span == other.span`, so the cost of omitting it isn't so terrible.

I also was a little surprised to see Hashable here (on all three types), but I suppose that's relevant both for eventually having hash-based data structures that work on data borrowed from backing storage, and for making it easier to implement hashing on custom structures.

---

<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:** [November 5, 2026, 12:25am UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/6 "2026-11-05T00:25:42Z")

</div>

Does `Ref` already conform where its element does? If not, should it be added here?

---

<div class="post-metadata">

**Author:** ![clintonpi](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clintonpi](https://forums.swift.org/u/clintonpi)\
**Post date:** [November 6, 2026, 5:35pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/8 "2026-11-06T17:35:54Z")

</div>

`Ref` and `MutableRef` do not conform and will be included in this pitch. Thanks for pointing that out.

---

<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:** [November 8, 2026, 9:16pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/9 "2026-11-08T21:16:39Z")

</div>

It's odd to me that the `Mutable` variants get implementations.

I think it's OK, because if the `Ref` or `Span` is mutable, there can be only one `Ref` or `Span` to that object, and therefore whatever owns the thing is "in control" of all mutations of the underlying object?

In that sense, `MutableRef`/`MutableSpan` aren't really like reference types at all.

Seems like at least there's intersection between this and the `Cell` proposal — spans of cells being `Hashable` would clearly be bad.

---

<div class="post-metadata">

**Author:** ![clintonpi](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clintonpi](https://forums.swift.org/u/clintonpi)\
**Post date:** [November 10, 2026, 7:43pm UTC](https://forums.swift.org/t/pitch-equatable-and-hashable-conformances-for-the-span-family/90475/10 "2026-11-10T19:43:53Z")

</div>

> [@KeithBauerANZ](#):
>
> therefore whatever owns the thing is "in control" of all mutations of the underlying object?

Quite so.

> [@KeithBauerANZ](#):
>
> In that sense, `MutableRef`/`MutableSpan` aren't really like reference types at all.

Well, they still provide exclusive access to the memory they reference, just that their use is now bounded by what their container defines.

> [@KeithBauerANZ](#):
>
> Seems like at least there's intersection between this and the `Cell` proposal — spans of cells being `Hashable` would clearly be bad.

Indeed, it would be bad. It doesn't seem reasonable for a process to store a value by hashing when the underlying value can be changed by a different process. Classes though have a similar loophole but even they aren't that "volatile".
