<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-07-13 20:19 GMT+03:00 Adrian Zubarev via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span>:<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"><div><span class=""><p>Am 13. Juli 2016 um 18:30:53, Anton Zhilin (<a href="mailto:antonyzhilin@gmail.com" target="_blank">antonyzhilin@gmail.com</a>) schrieb:</p> <div><blockquote type="cite" style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="margin-top:0px;margin-bottom:0px"><div><div class="gmail_quote" style="color:rgb(0,0,0);font-family:"helvetica Neue",helvetica;font-size:14px;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>I see model of<span> </span><font face="monospace, monospace">Type<T></font><span> </span>as follows:</div><div><ol style="margin:15px 0px"><li style="margin:15px 0px">Values of<span> </span><font face="monospace, monospace">Type<T></font><span> </span>are identifiers of types (8 bytes, I guess)<br></li><li style="margin:15px 0px">All used identifiers are contained in<span> </span><font face="monospace, monospace">Type<Any></font><br></li><li style="margin:15px 0px"><font face="monospace, monospace">Type<T></font><span> </span>contains a subset of those identifiers</li></ol></div></div></div></span></blockquote></div></span><p>I can’t follow your though here. Is this a totally new behavior?</p></div></div></blockquote><div><div>That's how it works right now:</div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">sizeofValue(Bool.self) //=> 0 (optimized away)<br></font></div><div><font face="monospace, monospace">sizeofValue(Bool.self as Any.self) //=> 8</font><br></div><div><br></div><div>I'll put my thoughts another way:</div></div><div><ul><li>Internally, <font face="monospace, monospace">Type<T></font> contains an <font face="monospace, monospace">Int</font>, i.e. identifer of a type. For every type, compiler must choose a different identifier</li><li>API of <font face="monospace, monospace">Type<T></font> is defined so that it can only contain identifiers of subtypes of <font face="monospace, monospace">T</font></li><li>For example, when you get a variable of <font face="monospace, monospace">Type<BaseClass></font>, it can correspond to <font face="monospace, monospace">BaseClass</font><font face="arial, helvetica, sans-serif"> </font>or<font face="arial, helvetica, sans-serif"> </font><font face="monospace, monospace">DerivedClass</font></li></ul></div><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"><div><div><div><span class=""><div><blockquote type="cite" style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="margin-top:0px;margin-bottom:0px"><div><div class="gmail_quote" style="color:rgb(0,0,0);font-family:"helvetica Neue",helvetica;font-size:14px;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><ol style="margin:15px 0px"><li style="margin:15px 0px">Upcasting uses constructor<span> </span><font face="monospace, monospace">init<U: T>(upcasting: Type<U>)</font></li></ol></div></div></div></span></blockquote></div></span><p>It does look neat but I can’t implement it. At least I have no clue how to solve the problem that `T` is not a protocol or a class type.</p></div></div></div></div></blockquote><div>We should add implicit convertion of <font face="monospace, monospace">Type<U></font> to <font face="monospace, monospace">Type<T></font><font face="arial, helvetica, sans-serif">, dulicating current behaviour of </font><font face="monospace, monospace">`as T.Type`</font><font face="arial, helvetica, sans-serif">.</font></div><div><font face="arial, helvetica, sans-serif">That constructor still can be useful, but it will be failable and not that significant in practise.</font></div><div><font face="arial, helvetica, sans-serif">I don't like adding compiler magic, but I guess we really should in this case, because otherwise </font><font face="monospace, monospace">Type<T></font><font face="arial, helvetica, sans-serif"> can't replace </font><font face="monospace, monospace">T.Type</font><font face="arial, helvetica, sans-serif">.</font></div><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"><div><div><div><div><div><span class=""><div><blockquote type="cite" style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="margin-top:0px;margin-bottom:0px"><div><div class="gmail_quote" style="color:rgb(0,0,0);font-family:"helvetica Neue",helvetica;font-size:14px;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><ol style="margin:15px 0px"><li style="margin:15px 0px">Size of<span> </span><font face="monospace, monospace">Type<Type<T>></font><span> </span>is 8, static size of<span> </span><font face="monospace, monospace">Type<SomeProtocol></font><span> </span>is 0</li></ol></div></div></div></span></blockquote></div></span><p>I feel like you mean something different here than this:</p><p>```swift</p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>protocol</span><span> SomeProtocol {}</span></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span></span><br></p><p>
</p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>sizeof</span><span>(</span><span>SomeProtocol</span><span>.</span><span>self</span><span>) == </span><span>40</span></p><p style="margin-top:0px;margin-bottom:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>```</span></p></div></div></div></div></div></div></blockquote><div><br></div><div>That was a mistake. Static size of <font face="monospace, monospace">Type<SomeProtocol></font> will be 40, and size property of its values can be less or greater than 40, depending on internal type identifier.<br></div></div><br></div></div>