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

Luke Howard lukeh at padl.com
Wed Jan 13 16:08:03 CST 2016


> On 14 Jan 2016, at 4:31 AM, Joe Groff <jgroff at apple.com> wrote:
> 
>> 
>> On Jan 12, 2016, at 11:37 PM, Luke Howard via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>> 
>> Also, what’s the best way of doing alignment when emitting C structs from IRGen?
>> 
>> For now I added this to ConstantBuilderBase: 
>> 
>>     void alignToWordBoundary() {
>>       NextOffset = NextOffset.roundUpToAlignment(IGM.getPointerAlignment());
>>     }
> 
> Why do you need to do this?

Emitting this:

struct GenericParameterDescriptor {
  uint32_t Offset;
  uint32_t NumParams;
  uint32_t NumPrimaryParams;
  
  /// A type parameter.
  struct Parameter {
    /// The number of protocol witness tables required by this type parameter.
    size_t NumWitnessTables;
    /// The protocols required by this type parameter. If NumWitnessTables is
    /// zero, this is absent.
    ProtocolDescriptor *Protocols[1];
  };

  /// The parameter descriptors are in a tail-emplaced array of NumParams
  /// elements. Because Parameters are variable length, use getParameterAt()
  /// to access them.
  Parameter Parameters[1];
}

needed to align the start of Parameters correctly (and also Protocols but I changed NumWitnessTables to a size_t for now to make that simpler). But perhaps there’s a way to get LLVM to do the layout for you, I feel I’m doing something wrong here.

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


More information about the swift-dev mailing list