<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="">That’s the “as proposed” usage for getting the size of a value (from <a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a>) <div class=""><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal; color: rgb(51, 51, 51);" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Types</span>
MemoryLayout<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">>.</span>size <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// 8 </span>
MemoryLayout<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">>.</span>arraySpacing <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// 8</span>
MemoryLayout<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">>.</span>alignment <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// 8</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Value</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> x: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">UInt8</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">5</span>
MemoryLayout(x)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">dynamicType</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>size <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// 1</span>
MemoryLayout(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>hello<span class="pl-pds" style="box-sizing: border-box;">"</span></span>)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">dynamicType</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>arraySpacing <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// 24</span>
MemoryLayout(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">29</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">2</span>)<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">dynamicType</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>alignment <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// 8</span></pre><div class=""><br class=""></div><div class=""><br class=""></div>At least, I <i class="">thought</i> that was the latest version of the proposal. Maybe I’ve gotten confused.</div><div class=""><br class=""></div><div class="">- Dave Sweeris<br class=""><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);"><br class=""></span></div><div><blockquote type="cite" class=""><div class="">On Jun 29, 2016, at 4:36 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><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=""><div class="gmail_quote" 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;">On Wed, Jun 29, 2016 at 4:29 PM, David Sweeris via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class="">(While I was typing this up, I realized that the exact usage you’re worried about, “MemoryLayout(Int.self).size” won’t compile, since `MemoryLayout` currently doesn’t have instance properties. If you’re worried about someone incorrectly typing out “MemoryLayout(Int.self).dynamicType.size”, though…)</div><div class=""><br class=""></div><div class="">I made a rather critical typo in my earlier reply. It should’ve been “init(_: T.Type)”, instead of “init(_: T.self)”, which is to say this:</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="color: rgb(187, 44, 162);" class="">extension</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span class="">MemoryLayout</span><span style="" class=""><span class="Apple-converted-space"> </span>{</span><span class=""> </span><span style="color: rgb(0, 132, 0);" class="">// assuming `MemoryLayout<T>` is already defined as proposed</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo;" class=""> <span class="Apple-converted-space"> </span></span><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">public</span><span style="font-family: Menlo;" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">init</span><span style="font-family: Menlo;" class="">(</span><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">_</span><span style="font-family: Menlo;" class=""><span class="Apple-converted-space"> </span>:<span class="Apple-converted-space"> </span></span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">T</span><span style="font-family: Menlo;" class="">.Type) {} </span><font color="#008400" face="Menlo" class="">// makes it so that `MemoryLayout(T.self)` still has the correct type for `T`</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div class="">Here are the results of some quick playgrounding in the WWDC Xcode 8 beta:</div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="">// without `init(_ : T.Type)` defined</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span class=""><</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span class="">>.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span class=""><span class="Apple-converted-space"> </span> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 1, correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">.</span><span style="color: rgb(187, 44, 162);" class="">self</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span style="" class=""> <span class="Apple-converted-space"> </span></span><span class="">// 8, almost certainly wrong</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="">//MemoryLayout(Int8).dynamicType.size // error</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(39, 42, 216);" class="">0</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span style="color: rgb(187, 44, 162);" class="">as</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span class="">size</span><span style="" class=""> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 1, correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span class=""><</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span class="">.Type>.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span class=""> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 8, correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">.Type.</span><span style="color: rgb(187, 44, 162);" class="">self</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span class="">// 8, correct, but is oddly worded</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="">//MemoryLayout(Int8.Type).dynamicType.size // error</span></div><div class=""><span class=""><br class=""></span></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="">// with `init(_ : T.Type)` defined</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span class=""><</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span class="">>.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span class=""><span class="Apple-converted-space"> </span> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 1, correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">.</span><span style="color: rgb(187, 44, 162);" class="">self</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span style="" class=""> <span class="Apple-converted-space"> </span></span><span class="">// 1, almost certainly correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span style="" class=""><span class="Apple-converted-space"> </span> <span class="Apple-converted-space"> </span></span><span class="">// 1, almost certainly correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(39, 42, 216);" class="">0</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span style="color: rgb(187, 44, 162);" class="">as</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span class="">size</span><span style="" class=""> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 1, correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span class=""><</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span class="">.Type>.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span class=""> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 8, correct</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(79, 129, 135);" class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">.Type.</span><span style="color: rgb(187, 44, 162);" class="">self</span><span style="" class="">).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span style="color: rgb(79, 129, 135);" class="">size</span><span style="" class=""><span class="Apple-converted-space"> </span></span><span class="">// 8, correct, but is oddly worded</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span class="">MemoryLayout</span><span style="" class="">(</span><span style="color: rgb(112, 61, 170);" class="">Int8</span><span style="" class="">.Type).</span><span style="color: rgb(187, 44, 162);" class="">dynamicType</span><span style="" class="">.</span><span class="">size</span><span style="" class=""> <span class="Apple-converted-space"> </span></span><span style="color: rgb(0, 132, 0);" class="">// 8, correct</span></div><div class=""><span style="color: rgb(0, 132, 0);" class=""><br class=""></span></div></div></div><div class="">The only value that changes (aside from the errors) is the one “typo” that you were worried about.</div><div class=""><br class=""></div><div class="">Do this change your mind? </div></div></div></div></blockquote><div class=""><br class=""></div><div class="">These examples make no sense to me. Why are we asking for the size of the dynamicType of MemoryLayout?</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><span class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><span class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><div style="font-family: Helvetica; margin: 0px; line-height: normal;" class="">On Jun 29, 2016, at 12:34 PM, Dave Abrahams <<a href="mailto:dabrahams@apple.com" target="_blank" class="">dabrahams@apple.com</a>> wrote:</div></div></span></div></div></span></div><span class=""><blockquote type="cite" class=""><br class=""><br class="">on Wed Jun 29 2016, David Sweeris <<a href="http://davesweeris-at-mac.com/" target="_blank" class="">davesweeris-AT-mac.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">Would adding a "init(_: T.self) {...}" solve that issue?<br class=""><br class=""></blockquote><br class="">? I don't see how.<br class=""><br class=""><blockquote type="cite" class=""><br class="">Sent from my iPhone<br class=""><br class=""><blockquote type="cite" class="">On Jun 29, 2016, at 01:54, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">My worry is that people will write <br class=""><br class="">MemoryLayout(Int.self).size <br class=""><br class="">when they mean<br class=""><br class="">MemoryLayout<Int>.size <br class=""><br class="">(often because for some reason they don't like angle brackets).<br class=""><br class="">I prefer to make the uncommon case much harder to write.<br class=""></blockquote></blockquote><br class="">-- <br class="">Dave<br class=""></blockquote><br class=""></span></div><br class=""><div class="">- Dave Sweeris</div><br class=""></div><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></blockquote></div></div></blockquote></div><br class=""></div></body></html>