-
Couldn't load subscription status.
- Fork 158
use unified overload data for initial overload variants #907
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
Merged
QuietMisdreavus
merged 8 commits into
swiftlang:main
from
QuietMisdreavus:overload-platforms
May 6, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
20977c0
use unified overload data for initial overload variants
QuietMisdreavus e38d958
update SymbolKit
QuietMisdreavus dd02815
don't drop overload groups from extension symbol graphs
QuietMisdreavus 1c12720
update SymbolKit
QuietMisdreavus 9310a15
review: refactor reduce call to be more performant
QuietMisdreavus 6624f46
reset SymbolKit back to main
QuietMisdreavus 3c7f60f
review: remove unnecessary comment
QuietMisdreavus cbd7e4c
Merge branch 'main' into overload-platforms
QuietMisdreavus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4919,6 +4919,229 @@ let expected = """ | |
| "Unknown feature flag in Info.plist: 'ExperimenalOverloadedSymbolPresentation'. Possible suggestions: 'ExperimentalOverloadedSymbolPresentation'") | ||
| } | ||
|
|
||
| func testContextGeneratesUnifiedOverloadGroupsAcrossPlatforms() throws { | ||
| enableFeatureFlag(\.isExperimentalOverloadedSymbolPresentationEnabled) | ||
|
|
||
| let symbolKind = try XCTUnwrap(SymbolGraph.Symbol.KindIdentifier.allCases.filter({ $0.isOverloadableKind }).first) | ||
|
|
||
| let tempURL = try createTempFolder(content: [ | ||
| Folder(name: "unit-test.docc", content: [ | ||
| JSONFile(name: "ModuleName-macos.symbols.json", content: makeSymbolGraph( | ||
| moduleName: "ModuleName", | ||
| platform: .init(operatingSystem: .init(name: "macosx")), | ||
| symbols: [ | ||
| makeSymbol(identifier: "symbol-1", kind: symbolKind), | ||
| makeSymbol(identifier: "symbol-2", kind: symbolKind), | ||
| ])), | ||
| JSONFile(name: "ModuleName-ios.symbols.json", content: makeSymbolGraph( | ||
| moduleName: "ModuleName", | ||
| platform: .init(operatingSystem: .init(name: "ios")), | ||
| symbols: [ | ||
| makeSymbol(identifier: "symbol-2", kind: symbolKind), | ||
| makeSymbol(identifier: "symbol-3", kind: symbolKind), | ||
| ])), | ||
| ]) | ||
| ]) | ||
| let (_, bundle, context) = try loadBundle(from: tempURL) | ||
| let moduleReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName", sourceLanguage: .swift) | ||
|
|
||
| let overloadGroupNode: DocumentationNode | ||
| let overloadGroupSymbol: Symbol | ||
| let overloadGroupReferences: Symbol.Overloads | ||
|
|
||
| // There should only be one overload group for `SymbolName` - the one from the iOS symbol | ||
| // graph should have been removed during graph collection. | ||
| switch context.resolve(.unresolved(.init(topicURL: .init(symbolPath: "SymbolName"))), in: moduleReference, fromSymbolLink: true) { | ||
| case let .failure(_, errorMessage): | ||
| XCTFail("Could not resolve overload group page. Error message: \(errorMessage)") | ||
| return | ||
| case let .success(overloadGroupReference): | ||
| overloadGroupNode = try context.entity(with: overloadGroupReference) | ||
| overloadGroupSymbol = try XCTUnwrap(overloadGroupNode.semantic as? Symbol) | ||
| overloadGroupReferences = try XCTUnwrap(overloadGroupSymbol.overloadsVariants.firstValue) | ||
|
|
||
| XCTAssertEqual(overloadGroupReferences.displayIndex, 0) | ||
|
|
||
| let unifiedSymbol = try XCTUnwrap(overloadGroupNode.unifiedSymbol) | ||
| XCTAssertEqual(unifiedSymbol.uniqueIdentifier, "symbol-1" + SymbolGraph.Symbol.overloadGroupIdentifierSuffix) | ||
| } | ||
|
|
||
| let overloadedReferences = try ["symbol-1", "symbol-2", "symbol-3"] | ||
| .map { try XCTUnwrap(context.documentationCache.reference(symbolID: $0)) } | ||
|
|
||
| for (index, reference) in overloadedReferences.indexed() { | ||
| let overloadedDocumentationNode = try XCTUnwrap(context.documentationCache[reference]) | ||
| let overloadedSymbol = try XCTUnwrap(overloadedDocumentationNode.semantic as? Symbol) | ||
|
|
||
| let overloads = try XCTUnwrap(overloadedSymbol.overloadsVariants.firstValue) | ||
|
|
||
| // Make sure that each symbol contains all of its sibling overloads. | ||
| XCTAssertEqual(overloads.references.count, overloadedReferences.count - 1) | ||
| for (otherIndex, otherReference) in overloadedReferences.indexed() where otherIndex != index { | ||
| XCTAssert(overloads.references.contains(otherReference)) | ||
| } | ||
|
|
||
| if overloads.displayIndex == 0 { | ||
| // The first declaration in the display list should be the same declaration as | ||
| // the overload group page | ||
| XCTAssertEqual(overloadedSymbol.declaration.first?.value.declarationFragments, overloadGroupSymbol.declaration.first?.value.declarationFragments) | ||
| } else { | ||
| // Otherwise, this reference should also be referenced by the overload group | ||
| XCTAssert(overloadGroupReferences.references.contains(reference)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func testContextGeneratesOverloadGroupsWhenOnePlatformHasNoOverloads() throws { | ||
| enableFeatureFlag(\.isExperimentalOverloadedSymbolPresentationEnabled) | ||
|
|
||
| let symbolKind = try XCTUnwrap(SymbolGraph.Symbol.KindIdentifier.allCases.filter({ $0.isOverloadableKind }).first) | ||
|
|
||
| // This situation used to crash. The macOS symbol graph only has one symbol in the overload | ||
| // group, whereas the iOS graph has two. Due to the way that Symbol loaded the overload | ||
| // mixins, `symbol-1` wouldn't save its overload data, which would trip an assertion in | ||
| // DocumentationContext. We need to ensure that an overload group is properly created, and | ||
| // that both symbols are correctly grouped underneath it. | ||
| let tempURL = try createTempFolder(content: [ | ||
| Folder(name: "unit-test.docc", content: [ | ||
| JSONFile(name: "ModuleName-macos.symbols.json", content: makeSymbolGraph( | ||
| moduleName: "ModuleName", | ||
| platform: .init(operatingSystem: .init(name: "macosx")), | ||
| symbols: [ | ||
| makeSymbol(identifier: "symbol-1", kind: symbolKind), | ||
| ])), | ||
| JSONFile(name: "ModuleName-ios.symbols.json", content: makeSymbolGraph( | ||
| moduleName: "ModuleName", | ||
| platform: .init(operatingSystem: .init(name: "ios")), | ||
| symbols: [ | ||
| makeSymbol(identifier: "symbol-1", kind: symbolKind), | ||
| makeSymbol(identifier: "symbol-2", kind: symbolKind), | ||
| ])), | ||
| ]) | ||
| ]) | ||
| let (_, bundle, context) = try loadBundle(from: tempURL) | ||
| let moduleReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName", sourceLanguage: .swift) | ||
|
|
||
| let overloadGroupNode: DocumentationNode | ||
| let overloadGroupSymbol: Symbol | ||
| let overloadGroupReferences: Symbol.Overloads | ||
|
|
||
| // Even though the macOS symbol graph doesn't contain an overload group, one should still | ||
| // have been created from the iOS symbol graph, and that overload group should reference | ||
| // both symbols. | ||
| switch context.resolve(.unresolved(.init(topicURL: .init(symbolPath: "SymbolName"))), in: moduleReference, fromSymbolLink: true) { | ||
| case let .failure(_, errorMessage): | ||
| XCTFail("Could not resolve overload group page. Error message: \(errorMessage)") | ||
| return | ||
| case let .success(overloadGroupReference): | ||
| overloadGroupNode = try context.entity(with: overloadGroupReference) | ||
| overloadGroupSymbol = try XCTUnwrap(overloadGroupNode.semantic as? Symbol) | ||
| overloadGroupReferences = try XCTUnwrap(overloadGroupSymbol.overloadsVariants.firstValue) | ||
|
|
||
| XCTAssertEqual(overloadGroupReferences.displayIndex, 0) | ||
|
|
||
| let unifiedSymbol = try XCTUnwrap(overloadGroupNode.unifiedSymbol) | ||
| XCTAssertEqual(unifiedSymbol.uniqueIdentifier, "symbol-1" + SymbolGraph.Symbol.overloadGroupIdentifierSuffix) | ||
| } | ||
|
|
||
| let overloadedReferences = try ["symbol-1", "symbol-2"] | ||
| .map { try XCTUnwrap(context.documentationCache.reference(symbolID: $0)) } | ||
|
|
||
| for (index, reference) in overloadedReferences.indexed() { | ||
| let overloadedDocumentationNode = try XCTUnwrap(context.documentationCache[reference]) | ||
| let overloadedSymbol = try XCTUnwrap(overloadedDocumentationNode.semantic as? Symbol) | ||
|
|
||
| let overloads = try XCTUnwrap(overloadedSymbol.overloadsVariants.firstValue) | ||
|
|
||
| // Make sure that each symbol contains all of its sibling overloads. | ||
| XCTAssertEqual(overloads.references.count, overloadedReferences.count - 1) | ||
| for (otherIndex, otherReference) in overloadedReferences.indexed() where otherIndex != index { | ||
| XCTAssert(overloads.references.contains(otherReference)) | ||
| } | ||
|
|
||
| if overloads.displayIndex == 0 { | ||
| // The first declaration in the display list should be the same declaration as | ||
| // the overload group page | ||
| XCTAssertEqual(overloadedSymbol.declaration.first?.value.declarationFragments, overloadGroupSymbol.declaration.first?.value.declarationFragments) | ||
| } else { | ||
| // Otherwise, this reference should also be referenced by the overload group | ||
| XCTAssert(overloadGroupReferences.references.contains(reference)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Ensure that overload groups are correctly loaded into the path hierarchy and create nodes, | ||
| /// even when they came from an extension symbol graph. | ||
| func testContextGeneratesOverloadGroupsForExtensionGraphOverloads() throws { | ||
| enableFeatureFlag(\.isExperimentalOverloadedSymbolPresentationEnabled) | ||
|
|
||
| let symbolKind = try XCTUnwrap(SymbolGraph.Symbol.KindIdentifier.allCases.filter({ $0.isOverloadableKind }).first) | ||
|
|
||
| let tempURL = try createTempFolder(content: [ | ||
| Folder(name: "unit-test.docc", content: [ | ||
| JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph( | ||
| moduleName: "ModuleName", | ||
| platform: .init(operatingSystem: .init(name: "macosx")), | ||
| symbols: [ | ||
| makeSymbol(name: "RegularSymbol", identifier: "RegularSymbol", kind: .class), | ||
| ])), | ||
| JSONFile(name: "[email protected]", content: makeSymbolGraph( | ||
| moduleName: "OtherModule", | ||
| platform: .init(operatingSystem: .init(name: "macosx")), | ||
| symbols: [ | ||
| makeSymbol(identifier: "symbol-1", kind: symbolKind), | ||
| makeSymbol(identifier: "symbol-2", kind: symbolKind), | ||
| ])), | ||
| ]) | ||
| ]) | ||
| let (_, bundle, context) = try loadBundle(from: tempURL) | ||
| let moduleReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName", sourceLanguage: .swift) | ||
|
|
||
| let overloadGroupNode: DocumentationNode | ||
| let overloadGroupSymbol: Symbol | ||
| let overloadGroupReferences: Symbol.Overloads | ||
|
|
||
| switch context.resolve(.unresolved(.init(topicURL: .init(symbolPath: "SymbolName"))), in: moduleReference, fromSymbolLink: true) { | ||
| case let .failure(_, errorMessage): | ||
| XCTFail("Could not resolve overload group page. Error message: \(errorMessage)") | ||
| return | ||
| case let .success(overloadGroupReference): | ||
| overloadGroupNode = try context.entity(with: overloadGroupReference) | ||
| overloadGroupSymbol = try XCTUnwrap(overloadGroupNode.semantic as? Symbol) | ||
| overloadGroupReferences = try XCTUnwrap(overloadGroupSymbol.overloadsVariants.firstValue) | ||
|
|
||
| XCTAssertEqual(overloadGroupReferences.displayIndex, 0) | ||
|
|
||
| let unifiedSymbol = try XCTUnwrap(overloadGroupNode.unifiedSymbol) | ||
| XCTAssertEqual(unifiedSymbol.uniqueIdentifier, "symbol-1" + SymbolGraph.Symbol.overloadGroupIdentifierSuffix) | ||
| } | ||
|
|
||
| let overloadedReferences = try ["symbol-1", "symbol-2"] | ||
| .map { try XCTUnwrap(context.documentationCache.reference(symbolID: $0)) } | ||
|
|
||
| for (index, reference) in overloadedReferences.indexed() { | ||
| let overloadedDocumentationNode = try XCTUnwrap(context.documentationCache[reference]) | ||
| let overloadedSymbol = try XCTUnwrap(overloadedDocumentationNode.semantic as? Symbol) | ||
|
|
||
| let overloads = try XCTUnwrap(overloadedSymbol.overloadsVariants.firstValue) | ||
|
|
||
| // Make sure that each symbol contains all of its sibling overloads. | ||
| XCTAssertEqual(overloads.references.count, overloadedReferences.count - 1) | ||
| for (otherIndex, otherReference) in overloadedReferences.indexed() where otherIndex != index { | ||
| XCTAssert(overloads.references.contains(otherReference)) | ||
| } | ||
|
|
||
| if overloads.displayIndex == 0 { | ||
| // The first declaration in the display list should be the same declaration as | ||
| // the overload group page | ||
| XCTAssertEqual(overloadedSymbol.declaration.first?.value.declarationFragments, overloadGroupSymbol.declaration.first?.value.declarationFragments) | ||
| } else { | ||
| // Otherwise, this reference should also be referenced by the overload group | ||
| XCTAssert(overloadGroupReferences.references.contains(reference)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // A test helper that creates a symbol with a given identifier and kind. | ||
| private func makeSymbol( | ||
| name: String = "SymbolName", | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.