[swift-evolution] [Pitch] Normalize Slice Types for Unsafe Buffers

Dave Abrahams dabrahams at apple.com
Fri Dec 9 12:24:41 CST 2016

on Thu Dec 08 2016, Ben Cohen <ben_cohen-AT-apple.com> wrote:

>> On Dec 8, 2016, at 4:35 PM, Jordan Rose via swift-evolution 
>> <swift-evolution at swift.org> wrote:
>> Um, Sequence doesn’t have a subscript (or indexes). Sequences 
>> are single-pass. So if this is
> important, it needs to stay a Collection.
> Just because something fulfills one of the requirements of a 
> Collection does not mean it should be
> one. 

Um, it sorta does.

> It needs to tick all the boxes before its allowed to be 
> elevated.
> But it’s still allowed to have subscripts (UnsafePointer has 
> subscripting but isn’t a collection) or
> be multi-pass (strides are multiples but are only 
> sequences). That’s OK

A sequence that is multipass can always be a collection, and 
there's no
good reason to limit its expressivity by keeping it a sequence.

> In this case, yes it’s multi-pass, yes it has a subscript, but 
> no it
> isn’t a collection because it doesn’t meet the requirements for
> slicing i.e. that indices of the slice be indices of the parent.

But it could.  It's just a bug that we failed to get that right.

> (relatedly… it appears this requirement is documented on the 
> concrete
> Slice type rather than on Collection… which is a documentation 
> bug we
> should fix).


More information about the swift-evolution mailing list