[Accepted with modifiers] SE-0456: Add `Span`-providing Properties to Standard Library Types

Hello Swift Community,

The review of SE-0456 "Add Span-providing Properties to Standard Library Types" concluded on January 28, 2025. Feedback on the functionality in the proposal was universally positive, with most discussion focusing on potential extensions as well as the name of the introduced properties. The Language Steering Group has decided to accept with modifications.

The proposal introduces a property named storage to various types. This property produces a Span instance that provides direct access to the elements stored within or referenced by self. The review thread and the LSG identified some issues with the name storage that make it unsuitable for the general name of this property:

  • The name storage implies that the resulting Span is the storage itself, rather than a view on the storage. While the distinction is not necessarily meaningful for types that are always views (such as Unsafe(Mutable)BufferPointer), it is misleading for types that have their own storage.
  • There is a class of types that wrap some underlying contiguous data structure and would want to add a Span-producing property with the same name as proposed in SE-0456. For such data structures, storage is an appropriate name to refer to that underlying storage with its actual type (say, ContiguousArray), which would conflict with the introduction of a storage property to produce the Span.

The LSG has decided to adopt the name span for these properties. In the discussion, the arguments against the name span cited the naming guidance that names should emphasize the role that the entity plays, not the type constraints. The LSG feels that the name span here is describing the role in a manner that is more general than storage:

  • The name span emphasizes that the property is producing a view over all of the contiguous elements in self. As previously noted, this isn't necessarily the storage of self.
  • There is precedent of providing views where the property name and type name are similar, such as Dictionary.keys and String.utf8.
  • The purpose of this property is to convert to a common type (Span).

The LSG has decided to retain the name bytes for the proposed RawSpan-producing properties, which will be added to Unsafe(Mutable)RawBufferPointer and Span. The bytes name describes the role of this property well, and the much narrower applicability of this property means that is expected to be free of potential collisions or ambiguities.

Separate from the naming discussion, it was noted that the introduced properties effectively replace the existing withUnsafeBufferPointer operations, but that the proposal did not provide a corresponding property to replace the related Sequence.withContiguousStorageIfAvailable protocol requirement. The subsequent discussion highlighted significant technical differences with replacing this API. The LSG feels that such functionality warrants a separate proposal in the future.

Thank you,

Doug Gregor

Review Manager

24 Likes