<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 9, 2017, at 12:23 AM, Jens Persson &lt;<a href="mailto:jens@bitcycle.com" class="">jens@bitcycle.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><div class="gmail_quote">On Sat, Jul 8, 2017 at 6:28 PM, Chris Lattner via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class="">Hi Susan,<div class=""><br class=""></div><div class="">Swift does not currently specify a layout for Swift structs.&nbsp; You shouldn’t be using them for memory mapped i/o or writing to a file, because their layout can change.&nbsp; When ABI stability for fragile structs lands, you will be able to count on it, but until then something like this is probably a bad idea.</div><div class=""><br class=""></div><div class="">-Chris</div></div></blockquote></div><br class=""></div><div class="gmail_extra">Does this imply that you should never use Swift structs to eg interact with Metal?</div></div></div></blockquote><div><br class=""></div>No.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra">This seems to be a very common practice. Here is a typical example (from a Metal tutorial at <a href="http://raywenderlich.com/" class="">raywenderlich.com</a>):</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra"><div class="gmail_extra">struct Vertex {</div><div class="gmail_extra">&nbsp; var x,y,z: Float &nbsp; &nbsp; // position data</div><div class="gmail_extra">&nbsp; var r,g,b,a: Float &nbsp; // color data</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">&nbsp; func floatBuffer() -&gt; [Float] {</div><div class="gmail_extra">&nbsp; &nbsp; return [x,y,z,r,g,b,a]</div><div class="gmail_extra">&nbsp; }</div><div class="gmail_extra">}</div></div></div></div></blockquote><div><br class=""></div><div>This doesn’t appear to expose the layout of the struct.</div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra">Also, does it imply that we cannot use structs (of only primitive types) like:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">struct RgbaFloatsLinearGamma {</div><div class="gmail_extra">&nbsp; &nbsp; var r, g, b, a: Float</div><div class="gmail_extra">&nbsp; &nbsp; …</div><div class="gmail_extra">}</div><div class="gmail_extra">struct BgraBytesSrgbGamma {</div><div class="gmail_extra">&nbsp; &nbsp; var b, g, r, a: UInt8</div><div class="gmail_extra">}</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">for manipulating raster image data?</div></div></div></blockquote><div><br class=""></div><div>I don’t see why that would be a problem.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra">I vaguely remember a swift evo discussion where it was concluded that such usage was considered OK provided the stored properties of the structs was only primitive types, but I can't find it now.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">Perhaps it could be considered OK at least when the intended platforms are known to be only iOS devices?</div></div></div></blockquote><br class=""></div><div>I think you’re misunderstanding what I’m saying. &nbsp;It isn’t correct to take (e.g.) an unsafepointer to the beginning of a struct, and serialize that out to disk, and expect that the fields are emitted in some order with some specific padding between them. &nbsp;None of the uses above try to do this.</div><div><br class=""></div><div>-Chris</div><div><br class=""></div><br class=""></body></html>