<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 29, 2016 at 4:50 PM, David Sweeris <span dir="ltr"><<a href="mailto:davesweeris@mac.com" target="_blank">davesweeris@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">That’s the “as proposed” usage for getting the size of a value (from <a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" target="_blank">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a>) <div><pre style="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)"><span style="color:rgb(150,152,150)">// Types</span>
MemoryLayout<span style="color:rgb(167,29,93)"><</span><span style="color:rgb(0,134,179)">Int</span><span style="color:rgb(167,29,93)">>.</span>size <span style="color:rgb(150,152,150)">// 8 </span>
MemoryLayout<span style="color:rgb(167,29,93)"><</span><span style="color:rgb(0,134,179)">Int</span><span style="color:rgb(167,29,93)">>.</span>arraySpacing <span style="color:rgb(150,152,150)">// 8</span>
MemoryLayout<span style="color:rgb(167,29,93)"><</span><span style="color:rgb(0,134,179)">Int</span><span style="color:rgb(167,29,93)">>.</span>alignment <span style="color:rgb(150,152,150)">// 8</span>
<span style="color:rgb(150,152,150)">// Value</span>
<span style="color:rgb(167,29,93)">let</span> x: <span style="color:rgb(0,134,179)">UInt8</span> <span style="color:rgb(167,29,93)">=</span> <span style="color:rgb(0,134,179)">5</span>
MemoryLayout(x)<span style="color:rgb(167,29,93)">.</span><span style="color:rgb(167,29,93)">dynamicType</span><span style="color:rgb(167,29,93)">.</span>size <span style="color:rgb(150,152,150)">// 1</span>
MemoryLayout(<span style="color:rgb(24,54,145)"><span>"</span>hello<span>"</span></span>)<span style="color:rgb(167,29,93)">.</span><span style="color:rgb(167,29,93)">dynamicType</span><span style="color:rgb(167,29,93)">.</span>arraySpacing <span style="color:rgb(150,152,150)">// 24</span>
MemoryLayout(<span style="color:rgb(0,134,179)">29</span><span style="color:rgb(167,29,93)">.</span><span style="color:rgb(0,134,179)">2</span>)<span style="color:rgb(167,29,93)">.</span><span style="color:rgb(167,29,93)">dynamicType</span><span style="color:rgb(167,29,93)">.</span>alignment <span style="color:rgb(150,152,150)">// 8</span></pre><div><br></div><div><br></div>At least, I <i>thought</i> that was the latest version of the proposal. Maybe I’ve gotten confused.</div></div></blockquote><div><br></div><div>There must be a typo in these examples. `MemoryLayout(x.dynamicType).size` perhaps?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>- Dave Sweeris<div><div class="h5"><br><div><span style="color:rgb(0,0,0)"><br></span></div><div><blockquote type="cite"><div>On Jun 29, 2016, at 4:36 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><br><div><br><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Wed, Jun 29, 2016 at 4:29 PM, David Sweeris via swift-evolution<span> </span><span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span><span> </span>wrote:<br><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"><div>(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><br></div><div>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)"><span style="color:rgb(187,44,162)">extension</span><span><span> </span></span><span>MemoryLayout</span><span><span> </span>{</span><span> </span><span style="color:rgb(0,132,0)">// assuming `MemoryLayout<T>` is already defined as proposed</span></div><div style="margin:0px;line-height:normal"><span style="font-family:Menlo"> <span> </span></span><span style="font-family:Menlo;color:rgb(187,44,162)">public</span><span style="font-family:Menlo"><span> </span></span><span style="font-family:Menlo;color:rgb(187,44,162)">init</span><span style="font-family:Menlo">(</span><span style="font-family:Menlo;color:rgb(187,44,162)">_</span><span style="font-family:Menlo"><span> </span>:<span> </span></span><span style="font-family:Menlo;color:rgb(79,129,135)">T</span><span style="font-family:Menlo">.Type) {} </span><font color="#008400" face="Menlo">// 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"><span>}</span></div><div><br></div><div><div style="margin:0px;line-height:normal"><div>Here are the results of some quick playgrounding in the WWDC Xcode 8 beta:</div><div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>// without `init(_ : T.Type)` defined</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(79,129,135)">MemoryLayout</span><span><</span><span style="color:rgb(112,61,170)">Int8</span><span>>.</span><span style="color:rgb(79,129,135)">size</span><span><span> </span> <span> </span></span><span style="color:rgb(0,132,0)">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(79,129,135)">MemoryLayout</span><span>(</span><span style="color:rgb(112,61,170)">Int8</span><span>.</span><span style="color:rgb(187,44,162)">self</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span style="color:rgb(79,129,135)">size</span><span> <span> </span></span><span>// 8, almost certainly wrong</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>//MemoryLayout(Int8).dynamicType.size // error</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span>MemoryLayout</span><span>(</span><span style="color:rgb(39,42,216)">0</span><span><span> </span></span><span style="color:rgb(187,44,162)">as</span><span><span> </span></span><span style="color:rgb(112,61,170)">Int8</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span>size</span><span> <span> </span></span><span style="color:rgb(0,132,0)">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(79,129,135)">MemoryLayout</span><span><</span><span style="color:rgb(112,61,170)">Int8</span><span>.Type>.</span><span style="color:rgb(79,129,135)">size</span><span> <span> </span></span><span style="color:rgb(0,132,0)">// 8, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(79,129,135)">MemoryLayout</span><span>(</span><span style="color:rgb(112,61,170)">Int8</span><span>.Type.</span><span style="color:rgb(187,44,162)">self</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span style="color:rgb(79,129,135)">size</span><span><span> </span></span><span>// 8, correct, but is oddly worded</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>//MemoryLayout(Int8.Type).dynamicType.size // error</span></div><div><span><br></span></div></div></div><div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>// with `init(_ : T.Type)` defined</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(79,129,135)">MemoryLayout</span><span><</span><span style="color:rgb(112,61,170)">Int8</span><span>>.</span><span style="color:rgb(79,129,135)">size</span><span><span> </span> <span> </span></span><span style="color:rgb(0,132,0)">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(79,129,135)">MemoryLayout</span><span>(</span><span style="color:rgb(112,61,170)">Int8</span><span>.</span><span style="color:rgb(187,44,162)">self</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span style="color:rgb(79,129,135)">size</span><span> <span> </span></span><span>// 1, almost certainly correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(79,129,135)">MemoryLayout</span><span>(</span><span style="color:rgb(112,61,170)">Int8</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span style="color:rgb(79,129,135)">size</span><span><span> </span> <span> </span></span><span>// 1, almost certainly correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span>MemoryLayout</span><span>(</span><span style="color:rgb(39,42,216)">0</span><span><span> </span></span><span style="color:rgb(187,44,162)">as</span><span><span> </span></span><span style="color:rgb(112,61,170)">Int8</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span>size</span><span> <span> </span></span><span style="color:rgb(0,132,0)">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(79,129,135)">MemoryLayout</span><span><</span><span style="color:rgb(112,61,170)">Int8</span><span>.Type>.</span><span style="color:rgb(79,129,135)">size</span><span> <span> </span></span><span style="color:rgb(0,132,0)">// 8, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(79,129,135)">MemoryLayout</span><span>(</span><span style="color:rgb(112,61,170)">Int8</span><span>.Type.</span><span style="color:rgb(187,44,162)">self</span><span>).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span style="color:rgb(79,129,135)">size</span><span><span> </span></span><span>// 8, correct, but is oddly worded</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span>MemoryLayout</span><span>(</span><span style="color:rgb(112,61,170)">Int8</span><span>.Type).</span><span style="color:rgb(187,44,162)">dynamicType</span><span>.</span><span>size</span><span> <span> </span></span><span style="color:rgb(0,132,0)">// 8, correct</span></div><div><span style="color:rgb(0,132,0)"><br></span></div></div></div><div>The only value that changes (aside from the errors) is the one “typo” that you were worried about.</div><div><br></div><div>Do this change your mind? </div></div></div></div></blockquote><div><br></div><div>These examples make no sense to me. Why are we asking for the size of the dynamicType of MemoryLayout?</div><div> </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"><div><div style="margin:0px;line-height:normal"><span><div><br></div><div><br></div><div><br></div><div><div><span><div style="font-family:Menlo;margin:0px;line-height:normal"><div style="font-family:Helvetica;margin:0px;line-height:normal">On Jun 29, 2016, at 12:34 PM, Dave Abrahams <<a href="mailto:dabrahams@apple.com" target="_blank">dabrahams@apple.com</a>> wrote:</div></div></span></div></div></span></div><span><blockquote type="cite"><br><br>on Wed Jun 29 2016, David Sweeris <<a href="http://davesweeris-at-mac.com/" target="_blank">davesweeris-AT-mac.com</a>> wrote:<br><br><blockquote type="cite">Would adding a "init(_: T.self) {...}" solve that issue?<br><br></blockquote><br>? I don't see how.<br><br><blockquote type="cite"><br>Sent from my iPhone<br><br><blockquote type="cite">On Jun 29, 2016, at 01:54, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br>My worry is that people will write <br><br>MemoryLayout(Int.self).size <br><br>when they mean<br><br>MemoryLayout<Int>.size <br><br>(often because for some reason they don't like angle brackets).<br><br>I prefer to make the uncommon case much harder to write.<br></blockquote></blockquote><br>-- <br>Dave<br></blockquote><br></span></div><br><div>- Dave Sweeris</div><br></div><br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></blockquote></div></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div>