-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Suppress deprecation warnings in synthesized code #19269
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
[Sema] Suppress deprecation warnings in synthesized code #19269
Conversation
cc @xedin |
@CodaFi has brought this up before and I'm not sure it's correct. We want to know in general if the compiler is synthesizing incorrect code. |
@jrose-apple Right, the solution is not to synthesize at all if something is unavailable, and synthesize with possible corrections if something is deprecated. But if there aren't any deprecation corrections passed with For example, should we synthesize enum Foo: Int {
@available(*, deprecated)
case a
case b
case c
} |
I just found out this doesn't compile: enum Foo: Int {
@available(*, unavailable)
case a
case b
case c
} I'm not sure what |
Oh, I agree we need to synthesize One possibility would be to come up with a compiler-only attribute to silence deprecation warnings, just like. We can put that on synthesized declarations that we know can reference deprecated members without themselves being deprecated. Maybe I'm just being oversensitive, though. I don't know what to do about the |
I don't really understand how an emitted warning will help here, or why synthesized declarations that are themselves deprecated for some reason would cause a problem if the warning isn't emitted. Could you elaborate a bit? First of all, we definitely don't want to emit it in synthesized code, right? |
Here's the example: class Base {
init(good: Int) { }
@available(*, deprecated) init(bad: Int) { }
}
class Sub: Base {
// initializers inherited
}
Sub(bad: 0) // should warn If the compiler implemented this by synthesizing this declaration in Sub: init(bad: Int) {
super.init(bad: bad)
} then we'd get a warning today telling us that that @available(*, deprecated)
init(bad: Int) {
super.init(bad: bad)
} Silencing the warning in all synthesized code would make it less likely that we'd notice this issue; we'd have to wait for a bug report from outside with the original test case. I'm not sure if this is sufficient justification to look for a different answer, but it is why I'm worried. |
I get your point now, thanks. Inheritance is probably the only case when we preserve availability in synthesized code. I feel like ensuring we have a test for that is a better option than adding a new internal attribute. In both cases it all boils down to having an appropriate test if we add anything new regarding code synthesis, so there's only a subtle difference in safety. |
We've had problems in the past with members synthesized in the Clang importer too. The point is that if we forget to test something, are we more likely to notice a warning that wasn't expected or a missing warning that should have been present? …but then again, the people noticing are probably our users, and they'd have to wait for the next release to make the warning go away. So okay. |
@swift-ci Please test |
@swift-ci Please test source compatibility |
I agree that the presence of an unexpected warning is more likely to be noticed, and I perfectly understand why you're worried. It's hard for me to tell what would be better at this point, although it does fix the bug without complicating the compiler. If we decide on landing this, let's at least add a test for |
It's good to add the test, but note that in this case it's not actually related, since we don't synthesize bodies for inherited initializers in Sema. (We take care of it in SILGen.) @swift-ci Please smoke test |
@jrose-apple Any plans to backport this to Swift 4.2.x? |
We generally don't backport fixes to earlier releases if they're not being released for all platforms (especially when there are already beta releases for 5.0), but if this is important to you for Linux you could cherry-pick it and open a PR per the 4.2.x process forum post. |
Actually, no -- I'm writing an iOS/macOS app that uses the LAError enum and was hoping those warnings would go away in Xcode. |
Ah, then you'll have to wait for Xcode 10.2 to GM. |
Resolves SR-8634.