# \[Pitch\] RigidArray and UniqueArray

**URL:** <https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455>\
**Category:** Pitches\
**Tags:** swift-collections\
**Created:** [March 19, 2026, 7:53pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455 "2026-03-19T19:53:27Z")\
**Posts on this page:** 7\
**Page:** 2

<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:** [March 20, 2026, 8:18pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/21 "2026-03-20T20:18:55Z")

</div>

> [@benrimmington](#):
>
> I don't like the name of the `freeCapacity` property (because "free" is also a verb), but `OutputSpan` already has the same API.

It's mitigated somewhat by the fact that it's a _property_, which would be exceedingly unusual a spelling for something if it had the side effect of freeing (all) capacity. That'd be an actively malicious API 👿

That said, since the type introduces the terminology `isFull`, this could be described as `unfilledCapacity`.

* * *

On the topic of specific APIs, though, I worry about this one and similar ones:

```swift
  public mutating func insert(
    moving items: inout OutputSpan<Element>,
    at index: Int
  )

```

To me, `insert(moving:at:)` reads as though the _at_ refers to the index in `items`, the container elements are being moved from, rather than the container elements are being moved to. Perhaps `insert(moving:to:)`? (Yes, there's something non-ideal that we're losing the idiomatic "at" meaning an index.)

---

<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:** [March 20, 2026, 10:19pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/22 "2026-03-20T22:19:33Z")

</div>

`OutputSpan` also has an `isfull` property, so I think that ship has sailed.

---

<div class="post-metadata">

**Author:** ![ben-lev](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@ben-lev](https://forums.swift.org/u/ben-lev)\
**Post date:** [March 22, 2026, 12:02am UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/23 "2026-03-22T00:02:00Z")

</div>

The following isn’t a comment about the exact shape of this proposal, but a related note about enabling developers to use these types without frequent pain + interface mismatches:

I think a crucial part of being able to effectively use these new noncopyable variants of things within the broader ecosystem is the larger adoption of `Span/MutableSpan` (and perhaps `BorrowingSequence` + future inout variant) as the definitive currencies for “I need temporary [immutable/mutable] access to some [contiguous/maybe-noncontiguous] sequence of elements”.

My understanding is that historically the guidance has been “if you need access to some ordered data, do the friendly thing for your callers and take an `Array` (or maybe `Sequence`)". There are surely huge amounts of existing APIs that take `Array`, where if re-written today, they would/should use `[Mutable]Span`.

I hope that these new types come along with some new developer guidance in the form of documentation/talks recommending that existing APIs, especially ones that may be used in performance sensitive contexts, should strongly consider defining new overloads of their interfaces which take spans instead of arrays where applicable.

I think this would also help alleviate some of the concern expressed in this thread around it being a massive issue to make these be new types instead of adding them into `Array`. Much like normal protocol-oriented design, encouraging interfaces to take spans will free up callers to use whatever owned representation makes the most sense for their use case.

---

<div class="post-metadata">

**Author:** ![Dmitriy\_Ignatyev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dmitriy_ignatyev/32/11340_2.png) [@Dmitriy\_Ignatyev](https://forums.swift.org/u/Dmitriy_Ignatyev)\
**Post date:** [March 22, 2026, 2:23pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/24 "2026-03-22T14:23:58Z")

</div>

> [@ben-lev](#):
>
> There are surely huge amounts of existing APIs that take `Array`, where if re-written today, they would/should use `[Mutable]Span`.
> 
> I hope that these new types come along with some new developer guidance in the form of documentation/talks recommending that existing APIs

While many codebases have been updated to Swift 6, they often still follow idioms from Swift 3/4. One such example is the use of `inout Array`, which was the primary method for mutating a bunch of ordered elements at those days.

I agree that we need more clear guidance for developers on how to use `[Mutable]Span` types effectively, as well as these upcoming collections.

There is a great paper [Swift for C++ Practitioners, Part 1: Intro & Value Types | Doug's Compiler Corner](https://www.douggregor.net/posts/swift-for-cxx-practitioners-value-types/) .  
I strongly feel something similar for Swift developers could be incredibly valuable.

With the introduction of `Rigid/Unique` variants for collections like `Array` , `Set` , and `Dictionary` , alongside `Span` types and `Slice`s, it’s important that we provide clear and consistent guidance. This is especially relevant when we consider types like `Array<~Copyable>` and `UniqueArray<~Copyable>`, which appear the same at first glance but have subtle, important differences.

---

<div class="post-metadata">

**Author:** ![lorentey](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lorentey/32/1299_2.png) [@lorentey](https://forums.swift.org/u/lorentey)\
**Post date:** [April 10, 2026, 7:09pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/25 "2026-04-10T19:09:22Z")

</div>

> [@ben-lev](#):
>
> My understanding is that historically the guidance has been “if you need access to some ordered data, do the friendly thing for your callers and take an `Array` (or maybe `Sequence`)". There are surely huge amounts of existing APIs that take `Array`, where if re-written today, they would/should use `[Mutable]Span`.

I do hope that we never had any guidance suggesting to just take an `Array`. The friendly thing for callers is for functions to be generic over a protocol that expresses the abstraction they need.

To me it feels rude to define a function that simply wants to reorder some items as taking an `inout Array`: it would force clients to materialize an `Array` just to be able to call it. Such function definitions are fine as incidental implementation details, but they do not make for a great public interface.

There will always be room to define _some_ functions to take individual concrete types like `Array` or `RigidDeque`, of course -- especially if they want to consume the argument to store it in their own representation. But it is a basic engineering principle to define as flexible interfaces as possible. In many cases, the concrete definitions should just be overloads of generic functions that define the _real_ interface, as an optimization measure.

> [@Dmitriy\_Ignatyev](#):
>
> While many codebases have been updated to Swift 6, they often still follow idioms from Swift 3/4. One such example is the use of `inout Array`, which was the primary method for mutating a bunch of ordered elements at those days.

I do hope that taking `inout some MutableCollection<Foo>` is how we primarily allow a function to mutate a bunch of ordered elements in Swift.

```swift
extension Foo {
  func jiggle(_ items: inout some MutableCollection<Int>) { ... }
}

```

`Array` is just one embodiment of a mutable collection type; `ContiguousArray`, `ArraySlice`, `UnsafeMutableBufferPointer` in the stdlib, and `Deque` and `BitArray` from swift-collections are prominent examples of others.

Note that `MutableCollection` does not just express the mutation of a single contiguous memory region -- it also allows conforming types (1) to have discontiguous storage (as is the case with `Deque`), or (2) to materialize their contents on demand (as is the case with `BitArray`).

Taking an `inout MutableSpan` only allows mutating a single contiguous memory region; this is the modern equivalent of taking an `UnsafeMutableBufferPointer`. Crucially, `MutableSpan` is memory safe, and that turns this classic pattern from an awkwardly discouraged risky/unsafe shortcut into a fully viable, first-class API design pattern:

```swift
extension Foo {
  // BAD, unsafe interface
  func unsafeShuffle(_ items: UnsafeMutableBufferPointer<Int>) { ... }

  // GOOD, safe interface, expressing the same
  func shuffle(_ items: inout MutableSpan<Int>) { ... }
}

```

Taking a `MutableSpan` is _not_ replacing the idea of taking a `MutableCollection`. It "just" allows a crucial high-performance design pattern (taking a reference to a single, mutable memory region) to be expressed with a safe interface that we can wholeheartedly recommend to people.

(The ownership-aware analogue of `MutableCollection` is probably going to be something like the [`MutableContainer` prototype in swift-collections](https://github.com/apple/swift-collections/blob/main/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift). That prototype allows discontiguous storage (roughly along the lines of `BorrowingSequence`), but it doesn't allow on-demand generation (a container has to own its contents; it isn't a factory). Sadly it is too early to talk about details here; they are too much in flux.)

---

<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:** [April 10, 2026, 7:24pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/26 "2026-04-10T19:24:49Z")

</div>

Separate from the other discussion, what happens to the versions of these collections in the `swift-collections` package? Will they be kept? Will they be synced with any changes to the standard library version? Since these types won't back deploy, keeping them somewhere to extend their support would be very appreciated. Otherwise they'll fall into the same bucket as `InlineArray` and other standard library additions: used by Apple internally but not by the community because few people can afford to only deploy to the latest OS versions.

---

<div class="post-metadata">

**Author:** ![ben-lev](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@ben-lev](https://forums.swift.org/u/ben-lev)\
**Post date:** [April 10, 2026, 7:42pm UTC](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455/27 "2026-04-10T19:42:46Z")

</div>

> [@lorentey](#):
>
> I do hope that taking `inout some MutableCollection<Foo>` is how we primarily allow a function to mutate a bunch of ordered elements in Swift.

Agreed for non-resilient libraries/code, but for evolution-enabled libraries where there’s no specialization this can give pretty awful performance. I know there’s the `withContiguousStorageIfAvailable` thing which mitigates this, but that can be easy to forget and also can fallback to really bad performance when not available/used.

Though maybe this won’t be nearly as much of a problem with the future sequence types given the design direction of having them vend the concrete `[Mutable]Span` types as their currency as noted here [SE-0516: Borrowing Sequence - #9 by ben-cohen](https://forums.swift.org/t/se-0516-borrowing-sequence/85122/9)

[Previous page](https://forums.swift.org/t/pitch-rigidarray-and-uniquearray/85455.md?page=1)
