Navigation Menu

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

[SR-3357] Omit deprecation warnings for references within the same compilation unit or module? #45945

Open
allevato opened this issue Dec 7, 2016 · 3 comments
Labels
compiler The Swift compiler in itself new feature

Comments

@allevato
Copy link
Collaborator

allevato commented Dec 7, 2016

Previous ID SR-3357
Radar None
Original Reporter @allevato
Type New Feature
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels New Feature
Assignee None
Priority Medium

md5: 3138b6e00a73dbc5171cb15544e0368e

Issue Description:

In the Swift Protobuf project (github.com/apple/swift-protobuf), we generate Swift code from .proto files. These .proto files contain messages (which become structs), enums, and so forth, and some of these entities can contain deprecation options (i.e., [deprecated = true]).

We map the .proto deprecation option to @available(*, deprecated) in Swift, but this causes problems within the generated code itself; if the generated serialization/parsing code touches a deprecated property in order to write/read it, that code produces a warning.

We can cheat by creating shadow properties (e.g., private underscored stored properties) and make the public one a simple computed getter/setter for it, but the same kind of cheat for enums, enum cases, and structs is less obvious.

It's desirable to have the deprecation warnings for outside clients of the code, but this also prevents the generated code itself from compiling cleanly. Would it make sense to have the compiler omit these warnings when the reference is to the deprecated entity is within the same compilation unit (or even module?), or provide a directive that lets us selectively disable them within a code region? (My argument would be that "deprecated" is a statement made about the public/open parts of an API to external users, and that it shouldn't affect internal usage.)

(Does this deserve a Swift Evolution proposal?)

@allevato
Copy link
Collaborator Author

allevato commented May 1, 2017

Does anybody have any opinions on this? The Swift protobuf project would benefit from this; as it is today, we can't generate deprecation annotations for fields because it will produce warning noise from the compiler when the serialization code references those properties. (In the protobuf case, "deprecated" means that users shouldn't use them, but they still need to be encoded/decoded.)

I have a version working locally where references to deprecated declarations in the same file do not emit warnings:

master...allevato:omit-deprecation-same-file

If this is something that the Swift team is interested in allowing, I'm happy to do all the leg work of implementation and writing a Swift evolution proposal. Please let me know!

@belkadan
Copy link
Contributor

belkadan commented May 2, 2017

I think this is risky. People like to use deprecation warnings within their own code to help migrate off of certain APIs, and doing this across the whole module would break that use case. I could see it maybe working within a file.

The other thing people bring up is some kind of "deprecated" block, in which no deprecation warnings are issued, but that seems to conflate deprecations from this module with any deprecations from other modules.

It probably is worth bringing this up on swift-evolution.

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 6, 2017

Comment by David Owens (JIRA)

At the very least, the deprecation warning should not pop for usages within the type that declares it. That's the point of it being deprecated, so others know not to use it, but that type is still required to do so. Adds noise to the build output in tracking down real issues.

Example:

public struct MyType {
    public init(path: String? = nil, uri: DocumentUri? = nil) {
        self.path = path   /// warning: `path` is deprecated: The `uri` member should be used instead.
        self.uri = uri
    }

    @available(*, deprecated:3.0, message: "The `uri` member should be used instead.")
    public var path: String? = nil
    public var uri: DocumentUri? = nil
}

Gee thanks for that warning, I know! 🙂

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself new feature
Projects
None yet
Development

No branches or pull requests

3 participants