<html><head><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></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="bloop_markdown"><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;">This is a follow up proposal to <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md"><span style="color: rgb(0, 0, 0);">SE-0095</span></a> which should be considered for Swift 3 if SE-0095 will be accepted.</div><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><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Here is the formatted draft: <a href="https://github.com/DevAndArtist/swift-evolution/blob/master/proposals/nnnn-ban-redundancy-in-any-existential.md">https://github.com/DevAndArtist/swift-evolution/blob/master/proposals/nnnn-ban-redundancy-in-any-existential.md</a></div><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><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Please provide your feedback in this thread, and don’t make a race who is making a better proposal on the exact same topic.</div><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><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">If you spot any types or other mistakes I’d be happy to see you pointing me to them. ;)</div><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><div id="bloop_sign_1463736639518785024" 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>
<h1 id="disallowredundantany...constructs">Disallow redundant <code>Any<...></code> constructs</h1>
<ul>
<li>Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md">SE-NNNN</a></li>
<li>Author: <a href="https://github.com/DevAndArtist">Adrian Zubarev</a></li>
<li>Status: <a href="#rationale">Awaiting review</a></li>
<li>Review manager: TBD</li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>This is a follow up proposal to <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md">SE–0095</a>, if it will be accepted for Swift 3. The current concept of <code>Any<...></code> introduced in SE–0095 will allow creation of redundant types like <code>Any<A> == A</code>. I propose to disallow such redundancy in Swift 3 to prevent breaking changes in a future version of Swift.</p>
<p>Swift-evolution thread: <a href="">[Proposal] Disallow redundant <code>Any<...></code> constructs</a></p>
<h2 id="motivation">Motivation</h2>
<p>If SE–0095 will be accepted there will be future proposals to enhance its capabilities. Two of these will be <strong>Any-type requirement</strong> (where <em>type</em> could be <code>class</code>, <code>struct</code> or <code>enum</code>) and <strong>Class requirement</strong>. Without any restrictions these will introduce more redundancy. </p>
<p>As said before it is possible to create redundant types like <code>Any<A> == A</code> or endless shadowed redundant nesting:</p>
<pre><code class="swift">typealias A_1 = Any<A>
typealias A_2 = Any<A_1>
typealias A_3 = Any<A_2>
/* and so on */
</code></pre>
<p>This proposal should ban redundancy right from the beginning. If there might be any desire to relax a few things, it won’t introduce any breaking changes for <code>Any<...></code> existential.</p>
<h2 id="proposedsolution">Proposed solution</h2>
<ol>
<li><p>If empty <code>Any<></code> won’t be disallowed in SE–0095, we should disallow nesting empty <code>Any<></code> inside of <code>Any<...></code>.</p></li>
<li><p>Disallow nesting <code>Any</code> (type refers to current <code>typealias Any = protocol<></code>) inside of <code>Any<...></code>.</p></li>
<li><p>Disallow <code>Any<...></code> containing a single <code>Type</code> like <code>Any<Type></code>.</p>
<p>The first three rules will ban constructs like <code>Any<Any<>, Type></code> or <code>Any<Any, Type></code> and force the developer to use <code>Type</code> instead.</p></li>
<li>Disallow nesting a single <code>Any<...></code> inside another <code>Any<...></code>.
<ul>
<li>e.g. <code>Any<Any<FirstType, SecondType>></code></li>
</ul></li>
<li><p>Disallow same type usage like <code>Any<A, A></code> or <code>Any<A, B, A></code> and force the developer to use <code>A</code> or <code>Any<A, B></code> if <code>A</code> and <code>B</code> are distinct.</p></li>
<li><p>Disallow forming redundant types when the provided constraints are not independent.</p>
<pre><code class="swift">// Right now `type` can only be `protocol` but in the future Any<...>
// could also allow `class`, `struct` and `enum`.
// In this example `B` and `C` are distinct.
type A: B, C {}
// all following types are equivalent to `A`
Any<A, Any<B, C>>
Any<Any<A, B>, C>
Any<Any<A, C>, B>
Any<A, B, C>
Any<A, B>
Any<A, C>
</code></pre>
<ul>
<li><p>If all contraints form a known <code>Type</code> provide a <code>Fix-it</code> error depending on the current context. If there is more than one <code>Type</code>, provide all alternatives to the developer.</p></li>
<li><p>Using <code>Any<...></code> in a generic context might not produce a <code>Fix-it</code> error:</p>
<pre><code class="swift">protocol A {}
protocol B {}
protocol C: A, B {}
// there is no need for `Fix-it` in such a context
func foo<T: Any<A, B>>(value: T) {}
</code></pre></li>
</ul></li>
</ol>
<h2 id="impactonexistingcode">Impact on existing code</h2>
<p>These changes will break existing code. Projects abusing <code>Any<...></code> to create redundant types should be reconsidered of usings the equivalent <code>Type</code> the compiler would infer. One would be forced to use <code>A</code> instead of <code>Any<A></code> for example. A <code>Fix-it</code> error message can help the developer to migrate his project.</p>
<h2 id="alternativesconsidered">Alternatives considered</h2>
<ul>
<li>Leave redundancy as-is for Swift 3 and live with it.</li>
<li>Deprecate redundancy in a future version of Swift, which will introduce breaking changes.</li></ul></div></body></html>