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

John McCall rjmccall at apple.com
Wed Jan 13 17:29:17 CST 2016


> On Jan 13, 2016, at 2:08 PM, Luke Howard via swift-dev <swift-dev at swift.org> wrote:
>> On 14 Jan 2016, at 4:31 AM, Joe Groff <jgroff at apple.com <mailto: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.

You should use a relative reference here instead of an absolute pointer.  We really, really don’t want relocations in reflective metadata. 

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160113/2afdcbbf/attachment.html>


More information about the swift-dev mailing list