<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 13, 2016, at 10:39 AM, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On May 13, 2016, at 8:18 AM, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>> wrote:<br class=""><br class=""><br class=""><br class="">Sent from my iPad<br class=""><br class="">On May 12, 2016, at 9:21 PM, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On May 12, 2016, at 5:49 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">The invariant StaticSelf identifier will always refer to A, unlike Self, which is covarying and refers to<br class="">the type of the actual instance. Since multiple inheritance for non-protocol types is disallowed,<br class="">this establishes this invariant type identifier with no possibility for conflict.<br class=""><br class="">Consider the following example, under the current system:<br class=""><br class="">protocol StringCreatable<span class="Apple-converted-space"> </span><br class="">{<br class=""><br class="">static func createWithString(s: String) -> Self<br class=""><br class="">}<br class=""><br class=""><br class="">extension NSURL: StringCreatable<span class="Apple-converted-space"> </span><br class="">{<br class=""><br class="">// cannot conform because NSURL is non-final<br class=""><br class=""><br class="">// error: method 'createWithString' in non-final class 'NSURL' must return `Self` to conform to protocol 'A'<br class=""><br class="">}<br class=""><br class="">Introducing a static, invariant version of Self permits the desired conformance:<br class=""><br class="">protocol StringCreatable<span class="Apple-converted-space"> </span><br class="">{<br class=""><br class="">static func createWithString(s: String) -> StaticSelf<br class=""><br class="">}<br class=""><br class=""><br class="">extension NSURL: StringCreatable<span class="Apple-converted-space"> </span><br class="">{<br class=""><br class="">// can now conform conform because NSURL is fixed and matches the static<br class=""><br class=""><br class="">// type of the conforming construct. Subclasses need not re-implement<br class=""><br class=""><br class="">// NOTE: the return type can be declared as StaticSelf *or* as NSURL<br class=""><br class=""><br class="">// they are interchangeable<br class=""><br class=""><br class="">static func createWithString(s: String) -> StaticSelf<br class="">{<span class="Apple-converted-space"> </span><br class=""><br class="">// ...<br class=""><br class="">}<br class="">}<br class=""><br class=""><br class=""></blockquote><br class="">As I've noted before, I don't think this makes sense to encode in the protocol. `Self` is already effectively invariant within a protocol.<span class="Apple-converted-space"> </span><br class=""></blockquote><br class="">'Self' is not invariant when used as a return type so I'm not sure what you mean.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">That's a property of a conformance. Class conformances are inherited, so they have to satisfy a protocol's requirements . Within the protocol definition, or in a protocol extension, `Self` is a generic parameter bound to a specific conforming type. When you conform a base class to a type, that means `Self == Base` and `Self == Derived` must be possible, but `Self` is never simultaneously `Base` and `Derived`.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class="">If a protocol doesn't have the foresight to use StaticSelf, then you still have the same problems retroactively conforming class hierarchies to the protocol.<span class="Apple-converted-space"> </span><br class=""></blockquote><br class="">True, but in many use cases we are in control of the protocol. This has always been the case when I have personally encountered this problem.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">That will likely change once resilient Swift frameworks start to exist. Changing `Self` to `StaticSelf` or back would also be a nonresilient change, so if frameworks get this wrong, they wouldn't be able to fix it without breaking ABI, which makes this even more problematic.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div>You can say this about many things. It seems less problematic than having no way to express this. Frameworks would not be required to use it if the authors have concerns about ABI.</div><div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-Joe</span></div></blockquote></div><br class=""></body></html>