-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Turn off SWIFT_ENABLE_REFLECTION on the stdlib_minimal preset #39030
Turn off SWIFT_ENABLE_REFLECTION on the stdlib_minimal preset #39030
Conversation
@swift-ci please test |
stdlib/public/core/Mirror.swift
Outdated
|
||
#else // SWIFT_ENABLE_REFLECTION | ||
|
||
@available(*, unavailable) |
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.
Would it be possible to only #if-else
the @availability
annotation instead of duplicating all of the Mirror declarations here?
target.write("(reflection not available)") | ||
} | ||
|
||
#endif |
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.
The patch makes sense to me, but I was a bit disheartened by the sheer number of #if SWIFT_ENABLE_REFLECTION
directives needed (77 files touched).
Would it be possible to leave Mirror declarations and uses intact, but "compile out" its implementation and return dummy values or crash. Similarly to what we do here for String.
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.
Not sure what you're actually proposing. I think the @available
attribute is required here, otherwise your code still compiles. I need to make let m = Mirror(x)
not compile. Given that we can't #ifdef-out only the attribute, I'm not sure how else can I 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.
Could we use availability macros for this? -define-availability 'SwiftReflection *'
normally, and -define-availability 'SwiftReflection unavailable'
when this stuff is turned off, then annotate everything with @available(SwiftReflection)
. I'm not entirely sure that availability macros actually work this way....
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.
Very cool idea, though I don't think -define-availability
lets us specify either "*" or "unavailable", I think it today only accepts specific platform names/versions:
-define-availability argument:1:18: error: expected version number
Dummy:unavailable
^
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.
Well nuts. I wonder if it would be worth extending this feature to work here, or otherwise modifying @available
or #if
so that we can accomplish 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.
It would be interesting to see if there's some way to just tell the compiler "Mirror and associated types are unavailable, propagate that unavailability to everything that uses them in this module, but let us pretend to implement the stuff" so we can avoid sticking an #if
on every single bit of code that deals with reflection.
I'm kinda on the fence about this change. Conceptually, I think that the change is good, but practically, I think that I agree with @yln. I think that adding an extension to extension String {
public init<T: Error>(reflecting object: T) {
self = "\(object)"
}
} You already change a few places the case where you reflect error into the error's |
Could I redirect the conversation to #33617 where I'm trying to separate land the first half of this change? This PR is just a follow up to actually turn the flag off for stdlib_minimal. |
4615df6
to
7e54210
Compare
@swift-ci please test |
preset=stdlib_S_standalone_minimal_macho_x86_64,build,test |
[SR-15661] Tests with "// REQUIRES: reflection" are unsupported |
No description provided.