<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>No, you’re totally right there. The mentioned <code>class</code> keyword is the protocol constraint-keyword such as <code>protocol X : >> class << { … }</code>. Instead we would like to generalize <code>AnyObject</code></p>
<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_1487003696527886848" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 13. Februar 2017 um 17:34:18, Alejandro Martinez via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>On class vs. AnyObject, probablt a dumb question but maybe worth<br>clarifying, we don't pretend to change it in a class declaration<br>right?<br><br>like<br><br>AnyObject A {<br> var ....<br>}<br><br>apart from that looking forward for this!<br><br><br>On Sun, Feb 12, 2017 at 8:32 PM, David Hart via swift-evolution<br><swift-evolution@swift.org> wrote:<br>> Hi Matthew,<br>><br>> Your arguments made sense to me. I modified the proposal to choose strategy<br>> number 3: deprecating and removing class over several versions to favour<br>> AnyObject. Mind having another proof read?<br>><br>> https://github.com/hartbit/swift-evolution/blob/subclass-existentials/proposals/XXXX-subclass-existentials.md<br>><br>> Anybody has counter arguments?<br>><br>> Class and Subtype existentials<br>><br>> Proposal: SE-XXXX<br>> Authors: David Hart, Austin Zheng<br>> Review Manager: TBD<br>> Status: TBD<br>><br>> Introduction<br>><br>> This proposal brings more expressive power to the type system by allowing<br>> Swift to represent existentials of classes and subtypes which conform to<br>> protocols.<br>><br>> Motivation<br>><br>> Currently, the only existentials which can be represented in Swift are<br>> conformances to a set of protocols, using the &protocol composition syntax:<br>><br>> Protocol1 & Protocol2<br>><br>> On the other hand, Objective-C is capable of expressing existentials of<br>> classes and subclasses conforming to protocols with the following syntax:<br>><br>> id<Protocol1, Protocol2><br>> Base<Protocol>*<br>><br>> We propose to provide similar expressive power to Swift, which will also<br>> improve the bridging of those types from Objective-C.<br>><br>> Proposed solution<br>><br>> The proposal keeps the existing & syntax but allows the first element, and<br>> only the first, to be either the AnyObjectkeyword or of class type. The<br>> equivalent to the above Objective-C types would look like this:<br>><br>> AnyObject & Protocol1 & Protocol2<br>> Base & Protocol<br>><br>> As in Objective-C, the first line is an existential of classes which conform<br>> to Protocol1 and Protocol2, and the second line is an existential of<br>> subtypes of Base which conform to Protocol.<br>><br>> Here are the new proposed rules for what is valid in a existential<br>> conjunction syntax:<br>><br>> 1. The first element in the protocol composition syntax can be the AnyObject<br>> keyword to enforce a class constraint:<br>><br>> protocol P {}<br>> struct S : P {}<br>> class C : P {}<br>> let t: P & AnyObject // Compiler error: AnyObject requirement must be in<br>> first position<br>> let u: AnyObject & P = S() // Compiler error: S is not of class type<br>> let v: AnyObject & P = C() // Compiles successfully<br>><br>> 2. The first element in the protocol composition syntax can be a class type<br>> to enforce the existential to be a subtype of the class:<br>><br>> protocol P {}<br>> struct S {}<br>> class C {}<br>> class D : P {}<br>> class E : C, P {}<br>> let t: P & C // Compiler error: subclass constraint must be in first<br>> position<br>> let u: S & P // Compiler error: S is not of class type<br>> let v: C & P = D() // Compiler error: D is not a subtype of C<br>> let w: C & P = E() // Compiles successfully<br>><br>> 3. When a protocol composition type contains a typealias, the validity of<br>> the type is determined using the following steps:<br>><br>> Expand the typealias<br>> Normalize the type by removing duplicate constraints and replacing less<br>> specific constraints by more specific constraints (a class constraint is<br>> less specific than a class type constraint, which is less specific than a<br>> constraint of a subclass of that class).<br>> Check that the type does not contain two class-type constraints<br>><br>> class C {}<br>> class D : C {}<br>> class E {}<br>> protocol P1 {}<br>> protocol P2 {}<br>> typealias TA1 = AnyObject & P1<br>> typealias TA2 = AnyObject & P2<br>> typealias TA3 = C & P2<br>> typealias TA4 = D & P2<br>> typealias TA5 = E & P2<br>><br>> typealias TA5 = TA1 & TA2<br>> // Expansion: typealias TA5 = AnyObject & P1 & AnyObject & P2<br>> // Normalization: typealias TA5 = AnyObject & P1 & P2<br>> // TA5 is valid<br>><br>> typealias TA6 = TA1 & TA3<br>> // Expansion: typealias TA6 = AnyObject & P1 & C & P2<br>> // Normalization (AnyObject < C): typealias TA6 = C & P1 & P2<br>> // TA6 is valid<br>><br>> typealias TA7 = TA3 & TA4<br>> // Expansion: typealias TA7 = C & P2 & D & P2<br>> // Normalization (C < D): typealias TA7 = D & P2<br>> // TA7 is valid<br>><br>> typealias TA8 = TA4 & TA5<br>> // Expansion: typealias TA8 = D & P2 & E & P2<br>> // Normalization: typealias TA8 = D & E & P2<br>> // TA8 is invalid because the D and E constraints are incompatible<br>><br>> class and AnyObject<br>><br>> This proposal merges the concepts of class and AnyObject, which now have the<br>> same meaning: they represent an existential for classes. To get rid of the<br>> duplication, we suggest only keeping AnyObject around. To reduce<br>> source-breakage to a minimum, class could be redefined as typealias class =<br>> AnyObject and give a deprecation warning on class for the first version of<br>> Swift this proposal is implemented in. Later, class could be removed in a<br>> subsequent version of Swift.<br>><br>> Source compatibility<br>><br>> This change will not break Swift 3 compability mode because Objective-C<br>> types will continue to be imported as before. But in Swift 4 mode, all types<br>> bridged from Objective-C which use the equivalent Objective-C existential<br>> syntax could break code which does not meet the new protocol requirements.<br>> For example, the following Objective-C code:<br>><br>> @interface MyViewController<br>> - (void)setup:(nonnull<br>> UIViewController<UITableViewDataSource,UITableViewDelegate>*)tableViewController;<br>> @end<br>><br>> is imported into Swift-3 mode as:<br>><br>> class MyViewController {<br>> func setup(tableViewController: UIViewController) {}<br>> }<br>><br>> which allows calling the function with an invalid parameter:<br>><br>> let myViewController: MyViewController()<br>> myViewController.setup(UIViewController())<br>><br>> The previous code continues to compile but still crashs if the Objective-C<br>> code calls a method of UITableViewDataSource or UITableViewDelegate. But if<br>> this proposal is accepted and implemented as-is, the Objective-C code will<br>> be imported in Swift 4 mode as:<br>><br>> class MyViewController {<br>> func setup(tableViewController: UIViewController & UITableViewDataSource<br>> & UITableViewDelegate) {}<br>> }<br>><br>> That would then cause the Swift code run in version 4 mode to fail to<br>> compile with an error which states that UIViewController does not conform to<br>> the UITableViewDataSource and UITableViewDelegate protocols.<br>><br>> Alternatives considered<br>><br>> An alternative solution to the class/AnyObject duplication was to keep both,<br>> redefine AnyObject as typealias AnyObject = class and favor the latter when<br>> used as a type name.<br>><br>> Acknowledgements<br>><br>> Thanks to Austin Zheng and Matthew Johnson who brought a lot of attention to<br>> existentials in this mailing-list and from whom most of the ideas in the<br>> proposal come from.<br>><br>> On 9 Feb 2017, at 21:50, Matthew Johnson <matthew@anandabits.com> wrote:<br>><br>><br>> On Feb 9, 2017, at 2:44 PM, David Hart <david@hartbit.com> wrote:<br>><br>><br>> On 9 Feb 2017, at 20:43, Matthew Johnson via swift-evolution<br>> <swift-evolution@swift.org> wrote:<br>><br>><br>><br>> Sent from my iPad<br>><br>> On Feb 9, 2017, at 1:30 PM, Hooman Mehr via swift-evolution<br>> <swift-evolution@swift.org> wrote:<br>><br>><br>> On Feb 9, 2017, at 10:47 AM, Joe Groff via swift-evolution<br>> <swift-evolution@swift.org> wrote:<br>><br>> On Feb 9, 2017, at 4:26 AM, Step Christopher via swift-evolution<br>> <swift-evolution@swift.org> wrote:<br>> Looks good. Minor comments below:<br>> The typealias 'T5' is repeated as both an initial composition, and as a<br>> demonstration of combining typealiases.<br>><br>> This proposal merges the concepts of class and AnyObject, which now have the<br>> same meaning: they represent an existential for classes. They are four<br>> solutions to this dilemna:<br>><br>> Do nothing.<br>> Replace all uses of AnyObject by class, breaking source compatibility.<br>> Replace all uses of class by AnyObject, breaking source compatibility.<br>> Redefine AnyObject as typealias AnyObject = class.<br>><br>> I agree with other comments on recommending 4 here, and covering the others<br>> as alternatives<br>><br>> I agree that we need the typealias for compatibility. I think it's still<br>> worth discussing whether the `AnyObject` typealias should *only* be there<br>> for compatibility; it could be deprecated or obsoleted in Swift 4 or future<br>> language versions.<br>><br>><br>> I think it might be worth keeping to provide a more sensible capitalization<br>> alternative than lower case “class” when used as a type name:<br>><br>> var obj: class // this looks weird because of capitalization.<br>><br>> var obj: AnyObject // this looks better.<br>><br>><br>> I agree that it looks better and would choose AnyObject if source<br>> compatibility weren't an issue. One option that wasn't listed was to drop<br>> 'class' but use a multi-release deprecation strategy and a fix-it to<br>> facilitate a smooth transition. If the community is willing to adopt this<br>> approach it would be my first choice.<br>><br>><br>> You mean option 3?<br>><br>><br>> Pretty much, but option 3 does not make it clear that it won’t break source<br>> immediately in Swift 4. I think it becomes much more reasonable if Swift<br>> 3.1 code still compiles in Swift 4 mode, but with a deprecation warning.<br>><br>> The reason I prefer `AnyObject` to `class` is because I think it’s ugly to<br>> have `class` as the name of an existential type. Type names are uppercase<br>> in Swift. It is also used to compose with protocols which also use<br>> uppercase names in Swift. Because it appears in contexts which use an<br>> uppercase convention it makes sense for this to have an uppercase name.<br>> `AnyObject` seems like the obvious choice if we’re going to go in that<br>> direction.<br>><br>><br>><br>><br>> -Joe<br>> _______________________________________________<br>> swift-evolution mailing list<br>> swift-evolution@swift.org<br>> https://lists.swift.org/mailman/listinfo/swift-evolution<br>><br>><br>> _______________________________________________<br>> swift-evolution mailing list<br>> swift-evolution@swift.org<br>> https://lists.swift.org/mailman/listinfo/swift-evolution<br>><br>> _______________________________________________<br>> swift-evolution mailing list<br>> swift-evolution@swift.org<br>> https://lists.swift.org/mailman/listinfo/swift-evolution<br>><br>><br>><br>><br>> _______________________________________________<br>> swift-evolution mailing list<br>> swift-evolution@swift.org<br>> https://lists.swift.org/mailman/listinfo/swift-evolution<br>><br><br><br><br>-- <br>Alejandro Martinez<br>http://alejandromp.com<br>_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></div><div class="bloop_markdown"><p></p></div></body></html>