<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On May 2, 2017, at 4:38 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="" applecontenteditable="true"><div class=""><blockquote type="cite" class=""><div class="">On Apr 28, 2017, at 16:28, John McCall via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">On Apr 28, 2017, at 7:03 AM, Johannes Weiss via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class="">Hi swift-users,<br class=""><br class="">(sorry for the cross post to swift-dev, but wasn't sure where it belongs)<br class=""><br class="">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 :).<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">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.</span></div></div></blockquote><br class=""></div><div class="">Ah, is this true for non-homogeneous tuples? I thought we only guaranteed it for homogeneous ones.</div></div></div></blockquote><br class=""></div><div>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.</div><div><br class=""></div><div>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</div><div> struct MyPair { var object: MyClass; var flag: Bool }</div><div>But that's just the price of supporting dynamic generics.</div><div><br class=""></div><div>John.</div><br class=""></body></html>