-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Introduce SWIFT_ENABLE_REFLECTION to turn on/off the support for Mirrors and reflection #33617
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
Conversation
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.
I'd love to see the numbers on this (if you have them) - this can be interesting for other applications.
/// A stdlib-internal protocol modeled by the intrinsic pointer types, | ||
/// UnsafeMutablePointer, UnsafePointer, UnsafeRawPointer, | ||
/// UnsafeMutableRawPointer, and AutoreleasingUnsafeMutablePointer. | ||
public protocol _Pointer | ||
: Hashable, Strideable, CustomDebugStringConvertible, CustomReflectable { | ||
: Hashable, Strideable, CustomDebugStringConvertible, _CustomReflectableOrNone { |
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.
Can you split out the CustomReflectable
into an extension instead? That avoids the need for the new protocol.
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.
You can't actually extend protocols to require conformances to protocols, but couldn't you do:
public protocol _Pointer: protocols
#if SWIFT_ENABLE_REFLECTION
, CustomReflectable
#endif
{
}
maybe the Swift preprocessor doesn't work like C/++ one to be able to do this.
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.
Alas, Swift doesn't do blind text substitutions like C does, and the contents of an #if
block must be valid statements.
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.
Bleh, I missed that _Pointer
itself was a protocol. I suppose you can use a typealias
, but at that point Im not sure if its worth 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.
How would you use the typealias? I'm happy to explore better options, as I don't really like the _CustomReflectableOrNone
thing either, but I couldn't come up with anything nicer that would actually work (as mentioned above, we can't just ifdef this out from the declaration, and we can't do extension on a protocol).
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.
This appears to work:
#if COND
typealias MaybeCustomReflectable = CustomReflectable
#else
typealias MaybeCustomReflectable = Any
#endif
protocol P: MaybeCustomReflectable {}
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.
Yeah, roughly what @mikeash pointed out. I was thinking that we could take the requirements and just typealias
them before the definition, including/excluding the CustomReflectable
instead of an Any
conformance.
Should this include swift-reflection-dump and the associated tests, or is that not intended to be in-scope for this toggle? |
@3405691582 |
As we discussed offline, it would be nice if we could leave behind |
cb8402a
to
016ddcd
Compare
@swift-ci please test |
Build failed |
@swift-ci please test Linux platform |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Errors Detected: Regression test failed Failed Command/usr/local/bin/cmake --build /Users/buildnode/jenkins/workspace/swift-PR-macos/branch-main/buildbot_incremental/swift-macosx-x86_64 -- -j24 -v check-swift-validation-macosx-x86_64
Build Log: Swift Pull Request Test macOS |
Build failed |
Build failed |
@swift-ci please test |
I guess I could gather up most/all of the simple CustomReflectable and CustomDebugStringConvertible extensions on Array, Collection, Dictionary, etc. into a separate place and then it would just be a single #ifdef around that. Would that be better? |
|
Added. Note sure what other case could be handled the same way... suggestions? |
@swift-ci please test |
I've tried exploring using But in order to make progress, I'd like to propose going forward with this current PR, i.e. using |
d9cabb3
to
c3612e6
Compare
@swift-ci please test |
Build failed |
Build failed |
…ors and reflection
c3612e6
to
f9e52e7
Compare
@swift-ci please test |
No description provided.