<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 29, 2016 at 4:29 PM, David Sweeris via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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"><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:#bb2ca2">extension</span><span style="color:#000000"> </span><span>MemoryLayout</span><span style="color:#000000"> {</span><span> </span><span style="color:rgb(0,132,0)">// assuming `MemoryLayout&lt;T&gt;` is already defined as proposed</span></div><div style="margin:0px;line-height:normal"><span style="font-family:Menlo">    </span><span style="font-family:Menlo;color:rgb(187,44,162)">public</span><span style="font-family:Menlo"> </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 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:#4f8187">MemoryLayout</span><span>&lt;</span><span style="color:#703daa">Int8</span><span>&gt;.</span><span style="color:#4f8187">size</span><span>                       </span><span style="color:#008400">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#4f8187">MemoryLayout</span><span style="color:#000000">(</span><span style="color:#703daa">Int8</span><span style="color:#000000">.</span><span style="color:#bb2ca2">self</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span style="color:#4f8187">size</span><span style="color:#000000">      </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 style="color:#000000">(</span><span style="color:#272ad8">0</span><span style="color:#000000"> </span><span style="color:#bb2ca2">as</span><span style="color:#000000"> </span><span style="color:#703daa">Int8</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span>size</span><span style="color:#000000">      </span><span style="color:#008400">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:#4f8187">MemoryLayout</span><span>&lt;</span><span style="color:#703daa">Int8</span><span>.Type&gt;.</span><span style="color:#4f8187">size</span><span>                  </span><span style="color:#008400">// 8, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#4f8187">MemoryLayout</span><span style="color:#000000">(</span><span style="color:#703daa">Int8</span><span style="color:#000000">.Type.</span><span style="color:#bb2ca2">self</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span style="color:#4f8187">size</span><span style="color:#000000"> </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:#4f8187">MemoryLayout</span><span>&lt;</span><span style="color:#703daa">Int8</span><span>&gt;.</span><span style="color:#4f8187">size</span><span>                       </span><span style="color:#008400">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#4f8187">MemoryLayout</span><span style="color:#000000">(</span><span style="color:#703daa">Int8</span><span style="color:#000000">.</span><span style="color:#bb2ca2">self</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span style="color:#4f8187">size</span><span style="color:#000000">      </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:#4f8187">MemoryLayout</span><span style="color:#000000">(</span><span style="color:#703daa">Int8</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span style="color:#4f8187">size</span><span style="color:#000000">           </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 style="color:#000000">(</span><span style="color:#272ad8">0</span><span style="color:#000000"> </span><span style="color:#bb2ca2">as</span><span style="color:#000000"> </span><span style="color:#703daa">Int8</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span>size</span><span style="color:#000000">      </span><span style="color:#008400">// 1, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:#4f8187">MemoryLayout</span><span>&lt;</span><span style="color:#703daa">Int8</span><span>.Type&gt;.</span><span style="color:#4f8187">size</span><span>                  </span><span style="color:#008400">// 8, correct</span></div><div style="margin:0px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#4f8187">MemoryLayout</span><span style="color:#000000">(</span><span style="color:#703daa">Int8</span><span style="color:#000000">.Type.</span><span style="color:#bb2ca2">self</span><span style="color:#000000">).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span style="color:#4f8187">size</span><span style="color:#000000"> </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 style="color:#000000">(</span><span style="color:#703daa">Int8</span><span style="color:#000000">.Type).</span><span style="color:#bb2ca2">dynamicType</span><span style="color:#000000">.</span><span>size</span><span style="color:#000000">      </span><span style="color:#008400">// 8, correct</span></div><div><span style="color:#008400"><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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div style="margin:0px;line-height:normal"><span class=""><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 &lt;<a href="mailto:dabrahams@apple.com" target="_blank">dabrahams@apple.com</a>&gt; wrote:</div></div></span></div></div></span></div><span class=""><blockquote type="cite"><br><br>on Wed Jun 29 2016, David Sweeris &lt;<a href="http://davesweeris-at-mac.com" target="_blank">davesweeris-AT-mac.com</a>&gt; wrote:<br><br><blockquote type="cite">Would adding a &quot;init(_: T.self) {...}&quot; solve that issue?<br><br></blockquote><br>? I don&#39;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 &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br>My worry is that people will write <br><br>MemoryLayout(Int.self).size <br><br>when they mean<br><br>MemoryLayout&lt;Int&gt;.size <br><br>(often because for some reason they don&#39;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">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><br>
<br></blockquote></div><br></div></div>