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

Turn off SWIFT_ENABLE_REFLECTION on the stdlib_minimal preset #39030

Merged

Conversation

kubamracek
Copy link
Contributor

No description provided.

@kubamracek
Copy link
Contributor Author

@swift-ci please test


#else // SWIFT_ENABLE_REFLECTION

@available(*, unavailable)
Copy link
Contributor

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

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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....

Copy link
Contributor Author

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
                 ^

Copy link
Contributor

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.

Copy link
Contributor

@mikeash mikeash left a 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.

@compnerd
Copy link
Member

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 String and a few other core types might be nice. An example would be:

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 description. This would keep the standard library similar and reduce some of the sprinkled changes.

@kubamracek
Copy link
Contributor Author

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.

@kubamracek kubamracek force-pushed the disable-reflection-on-minimal-stdlib branch from 4615df6 to 7e54210 Compare September 8, 2021 22:24
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

preset=stdlib_S_standalone_minimal_macho_x86_64,build,test
@swift-ci please test with toolchain and preset

@kubamracek kubamracek merged commit 8b189d9 into swiftlang:main Sep 13, 2021
@kubamracek kubamracek deleted the disable-reflection-on-minimal-stdlib branch September 13, 2021 01:54
@benrimmington
Copy link
Contributor

[SR-15661] Tests with "// REQUIRES: reflection" are unsupported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants