<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></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 Feb 23, 2016, at 4:55 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 23, 2016, at 16:54 , Andrew Trick <<a href="mailto:atrick@apple.com" class="">atrick@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 23, 2016, at 1:51 PM, Jordan Rose via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi, all (but especially the perf team). ChrisW and I are working on <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160111/006790.html" class="">importing Objective-C generics as Swift generics</a>, getting at least the bare minimum working. One interesting thing here is that Objective-C generics are type-erased, meaning that there isn't a different Class for, e.g. NSLayoutAnchor<NSLayoutXAxisAnchor *> and NSLayoutAnchor<NSLayoutYAxisAnchor *>. <i class="">That</i> means that the type metadata pointers for those two types will be identical.<div class=""><br class=""></div><div class="">Can anyone think of problems this will cause? Do we rely on different types having different metadata for anything other than downcasting? (See the proposal for a discussion of downcasting.)</div></div></div></blockquote><br class=""></div><div class="">The optimizer might try to materialize a pointer metatype pointer from an AST type and emit direct comparisons with the ‘isa’ pointer. I don’t see why that would be a problem though, since the types are runtime equivalent anyway.</div></div></div></blockquote><br class=""></div><div class="">Right. I can imagine missed opportunities for CSE or even devirtualization, but would not expect miscompiles or changes in formally observable behavior between -O and -Onone</div></div></div></blockquote><br class=""></div><div>If we do materialize the metatype, I think we could actually optimize NSLayoutAnchor<NSLayoutXAxisAnchor *> as if it were NSLayoutAnchor<NSLayoutYAxisAnchor *>. I think would only matter if we had swift extensions of one type that didn’t extend the other, right? …</div><div><br class=""></div>extension NSLayoutAnchor where T : ProtocolThatNSLayoutXAxisAnchorConformsTo {<div class=""> // some additional overrides</div><div class="">}</div><div class=""><br class=""></div><div class="">Is that sort of type extension possible? I think we’re saved by this: </div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class=""><b class="">error: </b></span><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">members of constrained extensions cannot be declared @objc</b></span></div></div><div class=""><br class=""></div><div class="">If this does turn out to be an issue, then maybe we can change the type system’s API so that the optimizer can’t ask for a metatype for an imported generic.</div><div class=""><br class=""></div><div class="">Andy </div></body></html>