-
Notifications
You must be signed in to change notification settings - Fork 131
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
Formally deprecate additionalSymbolGraphFiles
property
#777
Formally deprecate additionalSymbolGraphFiles
property
#777
Conversation
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.
LGTM
@@ -41,7 +41,7 @@ extension ConvertAction { | |||
// into a dictionary. This will throw with a descriptive error upon failure. | |||
let parsedPlatforms = try PlatformArgumentParser.parse(convert.platforms) | |||
|
|||
let additionalSymbolGraphFiles = convert.additionalSymbolGraphFiles + symbolGraphFiles( | |||
let additionalSymbolGraphFiles = (convert as _DeprecatedSymbolGraphFilesAccess).additionalSymbolGraphFiles + symbolGraphFiles( |
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.
Is this a common Swift idiom?
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 really. Normally there's no need to cast a value to one of the protocols that it's known to conform to but here I'm leveraging the downcast to shadow the deprecated API with a non-deprecated API to avoid a deprecation warning. This comment explains how it works in more detail.
private protocol _DeprecatedSymbolGraphFilesAccess { | ||
var additionalSymbolGraphFiles: [URL] { get } | ||
} | ||
extension Docc.Convert: _DeprecatedSymbolGraphFilesAccess {} |
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.
And, how does this actually work? By extending Docc.Convert so it conforms to a private protocol, are we preventing any other code from using the attributes (additionalSymbolGraphFiles
) of this private protocol outside of this file?
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.
IIUC the aim here is to force DocC.Convert
to expose the additionalSymbolGraphFiles
property, for this code here to work (I assume that David audited the code for further uses of additionalSymbolGraphFiles
), Once 5.11 is released then we will go back and remove the property entirely which will cause this code to fail to compile and therefore force us to go remove this use of it. This only works if we don't introduce new uses of the property, but I don't see why we would.
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.
Docc.Convert
already has an additionalSymbolGraphFiles
property but it's marked as deprecated here. Since it's deprecated, any code that accesses it will result in a deprecation warning, even within the same module.
That leaves us with 3 choices:
- Do nothing and live with the added depreciation warnings for a couple of releases.
- Stop accessing the deprecated API property, breaking the behavior for any client who passes this flag
- Write a bit of extra code to be able to avoid the deprecation warning.
I opted for the third choice. The way this private protocol avoids the deprecation warning works in 3 steps:
-
defines a protocol with a property with the same name and type as the deprecated API. This property of this protocol isn't deprecated. This protocol is only available within this source file.
private protocol _DeprecatedSymbolGraphFilesAccess { var additionalSymbolGraphFiles: [URL] { get } }
-
conforms the
extension Docc.Convert: _DeprecatedSymbolGraphFilesAccess {}
Convert
command to this private protocol. SinceConvert
already has a property with this name and type it doesn't need to implement anything new. -
casts the convert value to the deprecated property; thus shadowing the deprecated
(convert as _DeprecatedSymbolGraphFilesAccess).additionalSymbolGraphFiles
Convert.additionalSymbolGraphFiles
with the not deprecated_DeprecatedSymbolGraphFilesAccess.additionalSymbolGraphFiles
It looks rather strange but it allows us to internally call the deprecated API without warnings about it being deprecated. I know that there aren't other places who access Convert.additionalSymbolGraphFiles
because those would result in deprecation warnings. If any new code called Convert.additionalSymbolGraphFiles
it would work but result in a deprecation warning.
@swift-ci please test |
Bug/issue #, if applicable:
Summary
This formally deprecates
Convert.additionalSymbolGraphFiles
. It has long been replaced byadditionalSymbolGraphDirectory
.Dependencies
None
Testing
Run
docc convert Empty.docc --additional-symbol-graph-files /path/to/Something.symbols.json
In SwiftDocCUtilities, access
Convert.additionalSymbolGraphFiles
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
[ ] Added tests./bin/test
script and it succeeded[ ] Updated documentation if necessary