<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 12, 2016, at 17:03, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">on Tue Jul 12 2016, Jordan Rose &lt;jordan_rose-</span><a href="http://at-apple.com/" 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-stroke-width: 0px;" class="">AT-apple.com</a><span 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-stroke-width: 0px; float: none; display: inline !important;" class="">&gt; wrote:</span><br 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-stroke-width: 0px;" class=""><br 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-stroke-width: 0px;" 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-stroke-width: 0px;" class=""><blockquote type="cite" class="">On Jun 30, 2016, at 12:30, Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><br class="">on Wed Jun 29 2016, Erica Sadun &lt;<a href="http://erica-at-ericasadun.com" class="">erica-AT-ericasadun.com</a>&gt; wrote:<br class=""><br class=""></blockquote><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Jun 29, 2016, at 3:59 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">On Wed, Jun 29, 2016 at 4:50 PM, David Sweeris &lt;<a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a> &lt;<a href="mailto:davesweeris@mac.com" class="">mailto:davesweeris@mac.com</a>&gt;&gt; wrote:<br class="">That’s the “as proposed” usage for getting the size of a value (from<br class=""><a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a><br class=""></blockquote><br class=""><blockquote type="cite" class="">&lt;<a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a>&gt;)<br class="">// Types<br class="">MemoryLayout&lt;Int&gt;.size // 8<span class="Apple-converted-space">&nbsp;</span><br class="">MemoryLayout&lt;Int&gt;.arraySpacing // 8<br class="">MemoryLayout&lt;Int&gt;.alignment // 8<br class=""><br class="">// Value<br class="">let x: UInt8 = 5<br class="">MemoryLayout(x).dynamicType.size // 1<br class="">MemoryLayout("hello").dynamicType.arraySpacing // 24<br class="">MemoryLayout(29.2).dynamicType.alignment // 8<br class=""><br class=""><br class="">At least, I thought that was the latest version of the proposal. Maybe I’ve gotten confused.<br class=""><br class="">There must be a typo in these examples. `MemoryLayout(x.dynamicType).size` perhaps?<br class=""></blockquote><br class="">I have listened. I have updated.<br class=""><br class=""><a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a><br class=""><br class="">// Types<br class="">MemoryLayout&lt;Int&gt;.size // 8<br class="">MemoryLayout&lt;Int&gt;.arraySpacing // 8<br class="">MemoryLayout&lt;Int&gt;.alignment // 8<br class=""><br class="">// Value<br class="">let x: UInt8 = 5<br class="">MemoryLayout.of(x).size // 1<br class="">MemoryLayout.of(1).size // 8<br class="">MemoryLayout.of("hello").arraySpacing // 24<br class="">MemoryLayout.of(29.2).alignment // 8<br class=""></blockquote><br class="">I am still very skeptical that anyone needs the “Value” version, and as<br class="">long as we're resyntaxing I am inclined to take it away and see how many<br class="">people complain. &nbsp;You can still always write it yourself.<br class=""></blockquote><br class="">Sorry to only come across this now. The proposed implementation does not work.<br class=""><br class="">public static func of(_ candidate : @autoclosure () -&gt; T) -&gt; MemoryLayout&lt;T&gt;.Type {<br class="">&nbsp;return MemoryLayout.init(candidate).dynamicType<br class="">}<br class=""><br class="">let value: Any = 2 // dynamicType is Int<br class="">let layout = MemoryLayout(value).dynamicType // inlined from above<br class="">let arrayType = [value].dynamicType<br class=""><br class="">‘layout’ here is still 'MemoryLayout&lt;Any&gt;', not 'MemoryLayout&lt;Int&gt;',<br class="">for the same reason that ‘arrayType’ is ‘Array&lt;Any&gt;’ rather than<br class="">‘Array&lt;Int&gt;’.<br class=""></blockquote><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">That is the right answer. &nbsp;If you want to store an array of things with</span><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">the same type as “value” (== Any) you need that MemoryLayout.</span><br 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-stroke-width: 0px;" class=""><br 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-stroke-width: 0px;" 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-stroke-width: 0px;" class="">If we want to support sizeofValue et al, we’d need to make these<br class="">instance properties rather than static properties, and may then want<br class="">to give up on the struct being generic.<br class=""></blockquote><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">That wouldn't change anything. &nbsp;Nothing can possibly unwrap the Any and</span><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">find out the size of the thing. &nbsp;The current sizeofValue() doesn't work</span><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">that way either:</span><br 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-stroke-width: 0px;" class=""><br 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">&nbsp;print(sizeofValue(1 as Int8 as Any))</span></div></blockquote><br class=""></div><div>Okay, I didn’t realize it was still looking for a static type. In that case there’s an even simpler implementation:</div><br class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">public static func of(_ candidate : @autoclosure () -&gt; T) -&gt; MemoryLayout&lt;T&gt;.Type {</div><div class="">&nbsp; return MemoryLayout&lt;T&gt;.self</div><div class="">}</div></blockquote><br class=""><div class="">Jordan</div></body></html>