Yes, by nominal tuples I did mean a struct definition somewhere in swift’s 
standard library.

Seems like there are some quirks to tuples in Swift that I’m not aware of. I 
always assumed that they are packed ordinary structures. Since structure member 
offset is a compile-time constant, using tuples for arrays would not really be 
bad for performance, unless I’m missing something.

The C++ style compile-time wizardry is a subpar solution because it’s a hacky 
workaround due to lack of proper compile-time tools. If Swift would some day 
gain ability to execute imperative metaprogramming code that would manipulate 
the types at compile-time, all problems of this sort would be solved forever. 
But depending on how Swift compiler is implemented that may or may not be a 
monumental endeavor.

> On Jul 13, 2017, at 7:27 AM, Daryle Walker <[email protected]> wrote:
> 
> 
> — 
> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com 
> 
>> On Jul 12, 2017, at 4:30 PM, Gor Gyolchanyan <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> I agree, given the current state of Swift, fixed-sized arrays are way too 
>> magical.
> 
> Any more “magical” than the existing primitive types?
> 
>> I’d suggest postponing the idea of fixed-sized arrays (even though I myself 
>> have ached for them for a long time now) until its prerequisites are met.
>> 
>> There are three language features that have been discusses before that are 
>> required for this:
>> Variadic generic parameters.
>> Tuples as nominal types with a variadic generic parameter and a tuple 
>> concatenation ability.
>> Non-type generic parameters (probably, only compile-time value types).
> 
> Improved generics would synergize with fixed-size arrays, but are not a 
> prerequisite.
> 
> Wouldn’t nominal tuples be structures? Not that it matters here since FSAs 
> aren’t quirky tuples. (I mentioned in the proposal that no language that I 
> know of does this; homogenous and heterogenous product types are always 
> distinct kinds of types.)
> 
>> In these terms, a fixed-sized array would be a type that takes an Int as a 
>> generic parameter and uses a variadic tuple for its storage. If C++ 
>> templates has taught us anything is that metaprogramming can be used for 
>> achieving fantastic compile-time wizardry, like converting a single integer 
>> generic parameter and a single generic type parameter  to a generic 
>> homogeneous variadic type parameter (by using a recursively defined variadic 
>> parameter dummy type).
> 
> I thought Swift was to avoid that kind of wizardry. And unless you don’t want 
> any of the optimizations array operations get, then the compiler has to 
> analyze tuple types to trigger “array mode."

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to