Why are fixed-length arrays still not supported in Swift?

As noted in one of the old forum threads, this is a promising error message:


let a: Array<Int>[10] // Compile time error: Fixed-length arrays are not yet supported


Frustratingly, that error message is still present in Swift 2.0.


I'm surprised that fixed-length arrays aren't part of the language yet. It seems like a simple and essential feature for any systems programming language, or rather any language in which you might need control over the memory layout of structs (this includes using Metal from Swift for example, or writing APIs for reading and writing various data formats, etc).


Any ideas about what complications / considerations might lie behind the fact that something so seemingly simple and essential as fixed-length arrays are not yet supported in Swift?


(Hearing / speculating about these complications / considerations would probably teach us one or two interesting things about the philosphy and design of the language, thus making us better Swift programmers. If it's just low priority and not particularly hard to implement, then I'd like to know what kind of code we're supposed write for eg an API for manipulating various data formats, or using Metal in Swift (without having to resort to specifying our MTLBuffer-related structs in C (or relying on unspecified behaviour, since nothing can be guaranteed about the memory layout of Swift's structs, as seems to be the case judging from this old forums thread)).)


EDIT:

For anyone interested, in this other thread there's a very nice example on how to implement a fixed-length array in Swift 2 by Dave Abrahams.

So we can implement and use fixed-length arrays like that, which is great.

I'd still like to know more about the (lack of?) memory layout guarantees for Swift's structs and how that relates to eg using Metal (MTLBuffers) in Swift.

As in your other thread, this needs something like generic types parameterised by integers to be implemented in the type system without special-casing, so you could catch size mismatches at runtime. You can implement fixed sized arrays yourself using manual memory management or ManagedBuffer or similar, but your fundamental issue seems to really be about guaranteed memory layout of structs and this won't really help there.

They could just special-case it. That's what other languages do (for example, Rust). It seems to be worth it.

Why are fixed-length arrays still not supported in Swift?
 
 
Q