[swift-evolution] [Pitch] New Version of Array Proposal

Daryle Walker darylew at mac.com
Tue Aug 1 10:13:37 CDT 2017


> On Aug 1, 2017, at 3:21 AM, Tino Heth <2th at gmx.de> wrote:
> 
>> FSAs intentionally don’t conform to Collection, because multi-dimensional arrays shouldn’t have to conform to a linear (by nature, hence the name “Sequence”) standard, at least by default.
> I strongly oppose and think it is a really bad idea:
> Even if arrays are modelled multi-dimensional, there's always a canonical way to iterate through their elements, and this is an essential feature of this data type.

But linear access isn’t an inherent canonical property of multi-dimensional arrays, it’s just a consequence of arrays taking a contiguous block of memory (which is generally treated as linear in computers).

Speaking of which, the “withUnsafe(Mutable)Flattening” functions give Collection access. (And it serves as an equivalent to the “T[]” function parameter interface from C.)

I was going to support Collection for one-dimensional arrays, but I realized that would be a bad idea since that’s the dimensionality that would exploit vector-unit types the most. So you must convert first. (Well, the “conversion” to an Unsafe(Mutable)BufferPointer should just type-pun the address, unless the array was not initially in conventional addressable memory, which (small) objects aren’t by default in Swift, hence the “Unsafe” part of Swift’s pointer interface.)

> Do you have any example for an existing optimisation that is important enough to cripple all fixed size arrays?
> Those would not only be used to represent pixel buffers on a graphics card…

Sequence/Collection have other problems fitting with fixed-size arrays. There needs to be a new set of more basic protocols that both arrays and Sequence or Collection can conform to.

> Also, if FSA have only one dimension (that's still my preference), all those issues are can be solved easily in the multidimensional structure build on top of the array.

Or to flip it, just use multi-dimensional arrays with one bound. Multi-dimensionality does not impose an implementation penalty, especially when declaring a one-dimensional array. Wrapping multi-dimensionality in a type would forfeit it being a compound type, which would forfeit piecemeal initialization. There’s no need for Swift arrays to be limited to C arrays plus Assignability (or be just C arrays plus Assignability plus Collection).

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170801/0ac84da3/attachment.html>


More information about the swift-evolution mailing list