You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?)
The text was updated successfully, but these errors were encountered:
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:
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!
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.
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:
publicstructMyType {
publicinit(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.")
publicvarpath: String? = nilpublicvaruri: DocumentUri? = nil
}
Additional Detail from JIRA
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?)
The text was updated successfully, but these errors were encountered: