> On May 2, 2017, at 4:38 PM, Jordan Rose <jordan_r...@apple.com> wrote:
>> On Apr 28, 2017, at 16:28, John McCall via swift-users 
>> <swift-us...@swift.org <mailto:swift-us...@swift.org>> wrote:
>> 
>>> On Apr 28, 2017, at 7:03 AM, Johannes Weiss via swift-dev 
>>> <swift-dev@swift.org <mailto:swift-dev@swift.org>> wrote:
>>> Hi swift-users,
>>> 
>>> (sorry for the cross post to swift-dev, but wasn't sure where it belongs)
>>> 
>>> I tried to find guarantees about the memory layout Swift tuples but 
>>> couldn't find anything. The reason I ask is because I'd like to use them as 
>>> fixed sized (stack allocated) arrays. I'm pretty sure they're actually not 
>>> guaranteed to be stack allocated but highly likely I assume :).
>> 
>> Tuples are guaranteed to use a standard C-style layout wherever that layout 
>> is ABI-observable, e.g. when you construct an UnsafePointer to one.
> 
> Ah, is this true for non-homogeneous tuples? I thought we only guaranteed it 
> for homogeneous ones.

It's true of all tuples; we have to have some agreement on tuple layout that 
works generically, and the simple C left-to-right layout is the obvious one.  
Of course, like I said, we totally reserve the right to not actually store 
tuples that way in specific classes, structs, enums, locals, argument, results, 
or whatever else; but in places where a universal ABI is necessary, including 
pointers, we do make that guarantee.

This notion of universal ABI generally also affects things like generic data 
structures, which can mean that e.g. a [(MyClass, Bool)] might be stored less 
efficiently than a [MyPair] where
  struct MyPair { var object: MyClass; var flag: Bool }
But that's just the price of supporting dynamic generics.

John.

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Reply via email to