Merge alternate symbol declarations across symbol graphs #933
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug/issue #, if applicable: rdar://128573538
Summary
Fixes a bug with platform availability of a symbol's alternate declarations. This bug resulted in alternate symbol declarations only ever showing as having one supported platform, regardless of the symbol being declared across different symbol graphs for different platforms:

The expected behaviour is that

asyncalternate declarations are supported for the same platforms as their completion handler declaration:With these changes, platform names are now merged across alternate declarations from different symbol graphs.
Implementation
The issue was caused because alternate declarations were not being merged across different symbol graphs, so that platform availability information was only stored for the first symbol graph that was processed, and further platform availability information was lost.
To fix this issue,
Symbol.mergeDeclaration(...)now takes an extra parameter which takes in a list of alternate declarations from the symbol being merged in. This was already in place for symbol availability and the symbol's main declaration, but hadn't been added yet for alternate declarations, so information about other platforms was being dropped rather than being merged into the symbol's alternate declarations.Additionally, we now propagate alternate declarations to the new (copied) symbol that is created when resolving references:
https://github.com/apple/swift-docc/blob/037f0bcca7b1aa75551bd9b46825287c159a86b5/Sources/SwiftDocC/Semantics/ReferenceResolver.swift#L481
Dependencies
N/A.
Testing
Steps:
docc previewthe test bundle included in this PR:More generally, this can be reproduced by:
swift run docc preview DummyBundle.doccto preview the documentationpresent(completion:)Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/testscript and it succeededVerification
Unit tests
Modified test
testAlternateDeclarations()to use 2 symbol graphs, one for macOS and one for iOS. The test now expects that the alternate declaration should be available in both platforms.Ran
/bin/test:Site rendering
Verified that the rendered site renders the list of platforms for alternate declarations as expected.
Documentation
Did not need to update the documentation as this is a bug fix, and this was already the intended behaviour of the feature.