Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
typesanitizer opened this issue Jul 8, 2021 · 5 comments
Labels
compiler The Swift compiler in itself new feature

Comments

@typesanitizer
Copy link

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
Copy link
Author

@swift-ci create

@swift-ci
Copy link
Collaborator

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
Copy link
Author

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

  • Figure out a place in the pipeline where the layouts are already computed. E.g. layout information is needed for LLVM IR, so this information should be available when the compiler mode corresponds to -emit-irgen or later.

  • At this point, you need to somehow traverse the different nominal type declarations in the module, then I believe you'd need to do a mapping NominalTypeDecl -> Type -> SILType -> TypeInfo -> TypeLayoutEntry. I believe the TypeLayoutEntry values are the "final" form having all the details about layout, but not 100% sure about this.

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
Copy link
Collaborator

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
Copy link
Author

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

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself new feature
Projects
None yet
Development

No branches or pull requests

2 participants