Skip to content

Conversation

@anferbui
Copy link
Contributor

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:
185a84ce-818c-4786-acf9-41141c18dee8

The expected behaviour is that async alternate declarations are supported for the same platforms as their completion handler declaration:
7ed7dad9-9638-435c-a299-06ea67ec201e

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:

  1. Run docc preview the test bundle included in this PR:
❯ swift run docc preview Tests/SwiftDocCTests/Test\ Bundles/AlternateDeclarations.docc
  1. Preview http://localhost:8080/documentation/alternatedeclarations/myclass/present(completion:) locally, and the platform availability should be the same for both of the symbol declarations on the page (iOS, macOS).

More generally, this can be reproduced by:

  1. Creating a test package which contains an Objective C symbol with a completion handler, e.g.:
@implementation MyClass
- (void)presentWithCompletion:(void (^)(BOOL success))completion {
    NSLog(@"Hello, World!");
}
@end
  1. Compiling the package in Swift for multiple platforms to obtain one symbol graph per platform
  2. Moving the symbol graphs into a folder called DummyBundle.docc
  3. Running swift run docc preview DummyBundle.docc to preview the documentation
  4. Verifying that the same supported platforms show for all declarations of present(completion:)

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • [n/a] Updated documentation if necessary

Verification

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:

Build complete! (22.28s)
[1682/1682] Testing SwiftDocCUtilitiesTests.DirectoryMonitorTests/testMonitorDoesNotTriggerUpdates
=> Checking for unacceptable language… okay.
=> Checking license headers… okay.
=> Validating scripts in bin subdirectory… okay.

Site rendering
Verified that the rendered site renders the list of platforms for alternate declarations as expected.

Before After
185a84ce-818c-4786-acf9-41141c18dee8 7ed7dad9-9638-435c-a299-06ea67ec201e

Documentation
Did not need to update the documentation as this is a bug fix, and this was already the intended behaviour of the feature.

anferbui added 2 commits May 30, 2024 14:19
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 issue was caused by alternate declarations 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. Platform names are now merged across alternate declarations from different symbol graphs.

Resolves rdar://128573538.
Updates `testAlternateDeclarations()` to validate that all supported platforms are propagated from the main declaration to any alternate declarations.

Resolves rdar://128573538.
@anferbui
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus self-requested a review May 30, 2024 14:37
Copy link
Contributor

@QuietMisdreavus QuietMisdreavus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

@anferbui anferbui merged commit fd9a406 into swiftlang:main May 31, 2024
@anferbui anferbui deleted the merge-alternate-symbol-declarations branch May 31, 2024 09:39
anferbui added a commit to anferbui/swift-docc that referenced this pull request May 31, 2024
* Merges alternate symbol declarations across symbol graphs

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 issue was caused by alternate declarations 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. Platform names are now merged across alternate declarations from different symbol graphs.

* Updates alternate declarations test to include multiple platforms

Updates `testAlternateDeclarations()` to validate that all supported platforms are propagated from the main declaration to any alternate declarations.

Resolves rdar://128573538.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants