swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.33k stars 10.34k forks source link

[SR-14897] Support dumping type layouts similar to Clang's -fdump-record-layouts #57244

Open typesanitizer opened 3 years ago

typesanitizer commented 3 years ago
Previous ID SR-14897
Radar rdar://problem/80294323
Original Reporter @typesanitizer
Type New Feature
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler | |Labels | New Feature | |Assignee | None | |Priority | Medium | md5: 9ee01c76caeea20f34adfc65e4c6646b

Issue Description:

https://eli.thegreenplace.net/2012/12/17/dumping-a-c-objects-memory-layout-with-clang

Having something similar for Swift would be helpful for people optimizing the code as well as people working on the later stages of the compiler.

typesanitizer commented 3 years ago

@swift-ci create

swift-ci commented 3 years ago

Comment by Rajagopalan Gangadharan (JIRA)

theindigamer (JIRA User) This looks interesting, may I work on this? - if yes please do give me some pointer on where I can get started.

typesanitizer commented 3 years ago

(I'm not sure if implementing this is a good idea right now but) The very high-level idea would be:

You'll see some methods on TypeConverter such as convertType and methods on IRGenModule such as getStorageType, those seem to be relevant. You'll also see a TypeLayoutCache which has methods doing the last part, mapping SILType and TypeInfo values to TypeLayoutEntry} values.

That said, I'm not entirely sure what the cleanest way to get this information out would be.

cc aschwaighofer@apple.com (JIRA User) do you have suggestions here?

swift-ci commented 3 years ago

Comment by Rajagopalan Gangadharan (JIRA)

theindigamer (JIRA User) thank you for the info, looks a bit complicated for my current knowledge set I guess. Let me stick with few more starter bugs before doing this. Thank you and sorry!

typesanitizer commented 3 years ago

No worries. 🙂 What I have written down could be potentially useful to someone else too in the future.