<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>As unfocussed as original</div><div id="AppleMailSignature"><div>Regards</div>(From<span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); "> mobile)</span></div><div><br>On Jul 22, 2016, at 12:40 AM, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><style>
body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        padding:1em;
        margin:auto;
        background:#fefefe;
}
h1, h2, h3, h4, h5, h6 {
        font-weight: bold;
}
h1 {
        color: #000000;
        font-size: 28pt;
}
h2 {
        border-bottom: 1px solid #CCCCCC;
        color: #000000;
        font-size: 24px;
}
h3 {
        font-size: 18px;
}
h4 {
        font-size: 16px;
}
h5 {
        font-size: 14px;
}
h6 {
        color: #777777;
        background-color: inherit;
        font-size: 14px;
}
hr {
        height: 0.2em;
        border: 0;
        color: #CCCCCC;
        background-color: #CCCCCC;
display: inherit;
}
p, blockquote, ul, ol, dl, li, table, pre {
        margin: 15px 0;
}
a, a:visited {
        color: #4183C4;
        background-color: inherit;
        text-decoration: none;
}
#message {
        border-radius: 6px;
        border: 1px solid #ccc;
        display:block;
        width:100%;
        height:60px;
        margin:6px 0px;
}
button, #ws {
        font-size: 12 pt;
        padding: 4px 6px;
        border-radius: 5px;
        border: 1px solid #bbb;
        background-color: #eee;
}
code, pre, #ws, #message {
        font-family: Monaco;
        font-size: 10pt;
        border-radius: 3px;
        background-color: #F8F8F8;
        color: inherit;
}
code {
        border: 1px solid #EAEAEA;
        margin: 0 2px;
        padding: 0 5px;
}
pre {
        border: 1px solid #CCCCCC;
        overflow: auto;
        padding: 4px 8px;
}
pre > code {
        border: 0;
        margin: 0;
        padding: 0;
}
#ws { background-color: #f8f8f8; }
.bloop_markdown table {
border-collapse: collapse;
font-family: Helvetica, arial, freesans, clean, sans-serif;
color: rgb(51, 51, 51);
font-size: 15px; line-height: 25px;
padding: 0; }
.bloop_markdown table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
.bloop_markdown table tr:nth-child(2n) {
background-color: #f8f8f8; }
.bloop_markdown table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
.bloop_markdown table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
.bloop_markdown table tr th :first-child, table tr td :first-child {
margin-top: 0; }
.bloop_markdown table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }
.bloop_markdown blockquote{
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
blockquote > :first-child {
margin-top: 0; }
blockquote > :last-child {
margin-bottom: 0; }
code, pre, #ws, #message {
word-break: normal;
word-wrap: normal;
}
hr {
display: inherit;
}
.bloop_markdown :first-child {
-webkit-margin-before: 0;
}
code, pre, #ws, #message {
font-family: Menlo, Consolas, Liberation Mono, Courier, monospace;
}
.send { color:#77bb77; }
.server { color:#7799bb; }
.error { color:#AA0000; }</style><div class="bloop_markdown"><p><a href="https://github.com/DevAndArtist/swift-evolution/blob/rename_t_dot_type/proposals/0126-rename-t-dot-type.md">https://github.com/DevAndArtist/swift-evolution/blob/rename_t_dot_type/proposals/0126-rename-t-dot-type.md</a></p>
<hr>
<h1 id="renamet.type">Rename <code>T.Type</code></h1>
<ul>
<li>Proposal: <a href="0126-refactor-metatypes-repurpose-t-dot-self-and-mirror.md">SE–0126</a></li>
<li>Authors: <a href="https://github.com/DevAndArtist">Adrian Zubarev</a>, <a href="https://github.com/Anton3">Anton Zhilin</a></li>
<li>Status: <strong>Revision</strong></li>
<li>Review manager: <a href="http://github.com/lattner">Chris Lattner</a></li>
<li>Revision: 2</li>
<li>Previous Revisions: <a href="https://github.com/apple/swift-evolution/blob/83707b0879c83dcde778f8163f5768212736fdc2/proposals/0126-refactor-metatypes-repurpose-t-dot-self-and-mirror.md">1</a></li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>This proposal renames the current metatype <code>T.Type</code> notation and the global function from <strong>SE–0096</strong> to match the changes.</p>
<p>Swift-evolution threads: </p>
<ul>
<li><a href="">[Pitch] Rename <code>T.Type</code></a></li>
<li><a href="">[Review] SE–0126: Refactor Metatypes, repurpose T[dot]self and Mirror</a></li>
<li><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160718/024772.html">[Proposal] Refactor Metatypes, repurpose T[dot]self and Mirror</a></li>
<li><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160704/023818.html">[Discussion] Seal <code>T.Type</code> into <code>Type<T></code></a></li>
</ul>
<h2 id="motivation">Motivation</h2>
<p>In Swift metatypes have the following notation: <strong><code>T.Type</code></strong></p>
<p>As already showed in <strong>SE–0096</strong> and <strong>SE–0090</strong> the Swift community strongly is in favor of (re)moving magical intstance or type properties.</p>
<ul>
<li><p><strong>SE–0096</strong> moves <code>instanceOfT.dynamicType</code> to <code>type<T>(of: T) -> T.Type</code>.</p></li>
<li><p><strong>SE–0090</strong> aims to remove <code>.self</code> completely.</p></li>
</ul>
<p>We propose to rename <code>T.Type</code> to a generic-like notation <code>Metatype<T></code>. To be able to achieve this notation we have to resolve a few issues first.</p>
<h3 id="knownissuesofmetatypes:">Known issues of metatypes:</h3>
<p>Assume this function that checks if an <code>Int</code> type conforms to a specific protocol. This check uses current model of metatypes combined in a generic context:</p>
<pre><code class="swift">func intConforms<T>(to _: T.Type) -> Bool {
return Int.self is T.Type
}
intConforms(to: CustomStringConvertible.self) //=> false
Int.self is CustomStringConvertible.Type //=> true
</code></pre>
<blockquote>
<p>[1] When <code>T</code> is a protocol <code>P</code>, <code>T.Type</code> is the metatype of the protocol type itself, <code>P.Protocol</code>. <code>Int.self</code> is not <code>P.self</code>.</p>
<p>[2] There isn’t a way to generically expression <code>P.Type</code> <strong>yet</strong>.</p>
<p>[3] The syntax would have to be changed in the compiler to get something that behaves like <code>.Type</code> today.</p>
<p>Written by Joe Groff: <a href="https://twitter.com/jckarter/status/754420461404958721">[1]</a> <a href="https://twitter.com/jckarter/status/754420624261472256">[2]</a> <a href="https://twitter.com/jckarter/status/754425573762478080">[3]</a></p>
</blockquote>
<p>A possible workaround might look like the example below, but does not allow to decompose <code>P.Type</code>:</p>
<pre><code class="swift">func intConforms<T>(to _: T.Type) -> Bool {
return Int.self is T
}
intConforms(to: CustomStringConvertible.Type.self) //=> true
</code></pre>
<p>We can extend this issue and find the second problem by checking against the metatype of <code>Any</code>:</p>
<pre><code class="swift">func intConforms<T>(to _: T.Type) -> Bool {
return Int.self is T
}
intConforms(to: Any.Type.self) //=> true
intConforms(to: Any.self) //=> true
Int.self is Any.Type //=> Always true
</code></pre>
<p>When using <code>Any</code> the compiler does not require <code>.Type</code> at all and returns <code>true</code> for both variations.</p>
<p>The third issue will show itself whenever we would try to check protocol relationship with another protocol. Currently there is no way (that we know of) to solve this problem:</p>
<pre><code class="swift">protocol P {}
protocol R : P {}
func rIsSubtype<T>(of _: T.Type) -> Bool {
return R.self is T
}
rIsSubtype(of: P.Type.self) //=> false
R.self is Any.Type //=> Always true
R.self is P.Type //=> true
R.self is R.Type //=> true
</code></pre>
<p>We also believe that this issue is the reason why the current global functions <code>sizeof</code>, <code>strideof</code> and <code>alignof</code> make use of generic <code><T>(_: T.Type)</code> declaration notation instead of <code>(_: Any.Type)</code>.</p>
<h2 id="proposedsolution">Proposed solution</h2>
<ul>
<li><p>Rename any occurrence of <code>T.Type</code> and <code>T.Protocol</code> to <code>Metatype<T></code>.</p></li>
<li><p>Revise metatypes internally. </p></li>
<li><p>When <code>T</code> is a protocol, <code>T.self</code> should always return an instance of <code>Metatype<T></code> (old <code>T.Type</code>) and never a <code>T.Protocol</code>. Furthermore, metatypes should reflect the same type relationship behavior like the actual types themselves. </p></li>
<li><p>To match the correct meaning and usage of the noun ‘Metatype’ from this proposal, we also propose to rename the global function from <strong>SE–0096</strong>:</p>
<ul>
<li>before: <code>public func type<T>(of instance: T) -> T.Type</code></li>
<li>after: <code>public func metatype<T>(of instance: T) -> Metatype<T></code></li>
</ul></li>
</ul>
<h3 id="examples:">Examples:</h3>
<pre><code class="swift">protocol P {}
protocol R : P {}
class A : P {}
class B : A, R {}
func `is`<T>(metatype: Metatype<Any>, also _: Metatype<T> ) -> Bool {
return metatype is Metatype<T>
}
`is`(metatype: R.self, also: Any.self) //=> true | Currently: false
`is`(metatype: R.self, also: P.self) //=> true | Currently: false
`is`(metatype: R.self, also: R.self) //=> true
`is`(metatype: B.self, also: Any.self) //=> true | Currently: false
`is`(metatype: B.self, also: P.self) //=> true | Currently: false
`is`(metatype: B.self, also: R.self) //=> true | Currently: false
`is`(metatype: B.self, also: A.self) //=> true
`is`(metatype: B.self, also: B.self) //=> true
func cast<T>(metatype: Metatype<Any>, to _: Metatype<T>) -> Metatype<T>? {
return metatype as? Metatype<T>
}
cast(metatype: R.self, to: Any.self) //=> an Optional<Metatype<Any>> | Currently: nil
cast(metatype: R.self, to: P.self) //=> an Optional<Metatype<P>> | Currently: nil
cast(metatype: R.self, to: R.self) //=> an Optional<Metatype<R>> | Currently: an Optional<R.Protocol>
let anyR: Any.Type = R.self
let r = cast(metatype: anyR, to: R.self) //=> an Optional<Metatype<R>> | Currently: an Optional<R.Protocol>
cast(metatype: B.self, to: Any.self) //=> an Optional<Metatype<Any>> | Currently: nil
cast(metatype: B.self, to: P.self) //=> an Optional<Metatype<P>> | Currently: nil
cast(metatype: B.self, to: R.self) //=> an Optional<Metatype<R>> | Currently: nil
cast(metatype: B.self, to: A.self) //=> an Optional<Metatype<A>>
cast(metatype: B.self, to: B.self) //=> an Optional<Metatype<B>>
let pB: P.Type = B.self
let b = cast(metatype: pB, to: B.self) //=> an Optional<Metatype<B>>
</code></pre>
<h2 id="impactonexistingcode">Impact on existing code</h2>
<p>This is a source-breaking change that can be automated by a migrator. Any occurrence of <code>T.Type</code> or <code>T.Protocol</code> will be simply renamed to <code>Metatype<T></code>.</p>
<h2 id="alternativesconsidered">Alternatives considered</h2>
<ul>
<li>Alternatively it’s reasonable to consider to rename <code>T.self</code> to <code>T.metatype</code>.</li>
<li>It was considered to reserve <code>Type<T></code> for different usage in the future.</li>
</ul>
<p></p></div><div class="bloop_original_html"><style>body{font-family:Helvetica,Arial;font-size:13px}</style><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><br><div id="bloop_sign_1469140728009710080" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div></div><div class="bloop_markdown"><p></p></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>