-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Swift Opt-In Reflection metadata #34199
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
base: main
Are you sure you want to change the base?
Conversation
9ef4a50 to
b369f74
Compare
17e147b to
bd4f59d
Compare
bd4f59d to
30f709e
Compare
…reflection metadata and adds a new level of metadata emission. Forums Thread: https://forums.swift.org/t/pitch-2-opt-in-reflection-metadata/41696 Implementation: swiftlang/swift#34199
ee8e2c9 to
3feb0d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Protocols should never emit field descriptors because they aren't types by themselves and never have fields. It looks like an oversight that these get emitted in the first place and hopefully nothing will break if we stop emitting them because they're always empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Azoy points out that it isn't even possible to find these field descriptors from the protocol descriptor, so yeah, they're probably unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that those symbols are used by the debugger? I tried to stop emitting field descriptor for protocols, but several tests started failing (like this one - reflect(object: TestGeneric(D() as P))). Not sure how to check what exactly uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Protocol "field descriptors" encode whether the protocol is ObjC or not.
3feb0d9 to
49f17b8
Compare
49f17b8 to
e1a220d
Compare
6fbbc69 to
6f148e5
Compare
|
This is really neat! I like how you handle conditional casting to the marker protocol. Does this handle casting to protocol compositions including |
Good catch, thanks! |
|
Almost 4 years for this MR.. |
db7b541 to
bb0263f
Compare
|
I think instead of adding a new layout constraint (which as you saw requires a lot of new plumbing) this could instead use a marker protocol? |
|
@slavapestov I used a marker protocol in the first iteration of the implementation to make the logic simpler, but the first review feedback made it clear that marker protocols shouldn't affect runtime behaviour therefore it was suggested to create a new non-protocol generic constraint similar to AnyObject, which requires to handle many cases in the code. 🤷 https://forums.swift.org/t/returned-for-revision-se-0379-opt-in-reflection-metadata/62390 |
|
In the year since that was written, Copyable, Escapable and BitwiseCopyable were added as marker protocols. I understand the frustration here in going back and forth, but I really think modeling these kinds of relations as conformances makes the most sense, and in hindsight I sometimes wish AnyObject didn't exist as a special case either. CC @jckarter |
A prototype for a swift evolution proposal that implements opt-in reflection metadata.
Proposal - swiftlang/swift-evolution#1203
Discussion - https://forums.swift.org/t/pitch-2-opt-in-reflection-metadata/41696