[swift-dev] Type metadata and identity

Jordan Rose jordan_rose at apple.com
Tue Feb 23 18:55:13 CST 2016


> On Feb 23, 2016, at 16:54 , Andrew Trick <atrick at apple.com> wrote:
> 
> 
>> On Feb 23, 2016, at 1:51 PM, Jordan Rose via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>> 
>> Hi, all (but especially the perf team). ChrisW and I are working on importing Objective-C generics as Swift generics <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160111/006790.html>, 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 *>. That means that the type metadata pointers for those two types will be identical.
>> 
>> 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.)
> 
> 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.

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.

Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160223/3fdab412/attachment.html>


More information about the swift-dev mailing list