[swift-dev] Emitting redundant protocol conformances to support type lookup

Luke Howard lukeh at padl.com
Sun Jan 10 05:37:48 CST 2016


I made an experimental patch to IRGen to emit a table of type metadata, independent of the protocol conformance table.

The entry format is a subset of a protocol conformance record:

struct TypeMetadataRecord {
private:
  // Some description of the type that is resolvable at runtime.
  union {
    /// A direct reference to the metadata.
    RelativeIndirectablePointer<Metadata> DirectType;
    
    /// An indirect reference to the metadata.
    RelativeIndirectablePointer<const ClassMetadata *> IndirectClass;
  };

  /// Flags describing the type metadata record.
  TypeMetadataRecordFlags Flags;
}

Otherwise the implementation is pretty similar. They are emitted in irgen::emitXXXMetadata. Mappings for generic types are at runtime when swift_getGenericMetadata() is called.

It seems to work OK and removes the limitation that the conformance table approach had, where one could only resolve the names of types with explicit protocol conformances.

Haven’t tested on Linux yet.

— Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160110/52c8751e/attachment.html>


More information about the swift-dev mailing list