Memory layout of Swift type metadata?


I have been using Swift for a while now and would like to be more familiar with how it works at a lower level. I was hoping to have some help pointing me in the right direction to understand how type metadata is laid out in memory currently? Previous versions IIRC had a kind value at offset 0. Looking at the GitHub repo layout out type information, I thought that might now be ContextDescriptorFlags. However, casting Any.Type to UnsafePointer<Int> to have a look gives me values I wasn't expecting. E.g., I get 0x0000000000000200 for a basic struct. I was expecting to find 17 (if masked by 0x1f).

I hope this is the right category, thank you for any assistance.

1 Like

What you have is a pointer to the metadata, not the context descriptor. In this case, 0x200 (512) is the kind of metadata (which is for struct).