Skip to content

Commit 0397c9d

Browse files
Stop duplicating auto-generated collections per-platform (#325)
Resolves a regression where auto-generated "Protocol Implementations" collections were being duplicated per platform. The immediate fix is to call the `createInheritedSymbolsAPICollection` method a single time with all of the relevant relationships, instead of once per platform. It tracks internal state while building up the API collections so it's important to provide all possible relationships when calling the method. I think there's a likely a longer-term fix we should make here in the way we're handling multi-platform symbol graph information since currently we're handling it similarly to multi-language symbol graph information but don't actually emit variants for it. Resolves rdar://95882462.
1 parent 41f2ac1 commit 0397c9d

File tree

3 files changed

+86
-8
lines changed

3 files changed

+86
-8
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,13 +1261,11 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
12611261
}
12621262

12631263
// Create inherited API collections
1264-
for (_, relationships) in combinedRelationships {
1265-
try GeneratedDocumentationTopics.createInheritedSymbolsAPICollections(
1266-
relationships: relationships,
1267-
context: self,
1268-
bundle: bundle
1269-
)
1270-
}
1264+
try GeneratedDocumentationTopics.createInheritedSymbolsAPICollections(
1265+
relationships: combinedRelationships.flatMap(\.value),
1266+
context: self,
1267+
bundle: bundle
1268+
)
12711269

12721270
// Parse and prepare the nodes' content concurrently.
12731271
let updatedNodes: [(node: DocumentationNode, matchedArticleURL: URL?)] = Array(symbolIndex.values)

Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,17 @@ enum GeneratedDocumentationTopics {
224224
/// ╰ View Implementations
225225
/// ╰ accessibilityValue()
226226
/// ```
227+
///
228+
/// > Warning: This method tracks internal state via an ``InheritedSymbols`` inheritance index.
229+
/// It must be called **once** per symbol by passing in _all_ of the relationships that apply
230+
/// to a symbol.
231+
///
227232
/// - Parameters:
228233
/// - relationships: A set of relationships to inspect.
229234
/// - symbolsURLHierarchy: A symbol graph hierarchy as created during symbol registration.
230235
/// - context: A documentation context to update.
231236
/// - bundle: The current documentation bundle.
232-
static func createInheritedSymbolsAPICollections(relationships: Set<SymbolGraph.Relationship>, context: DocumentationContext, bundle: DocumentationBundle) throws {
237+
static func createInheritedSymbolsAPICollections(relationships: [SymbolGraph.Relationship], context: DocumentationContext, bundle: DocumentationBundle) throws {
233238
var inheritanceIndex = InheritedSymbols()
234239

235240
// Walk the symbol graph relationships and look for parent <-> child links that stem in a different module.

Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorTests.swift

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,81 @@ class RenderNodeTranslatorTests: XCTestCase {
735735
)
736736
}
737737

738+
func testAutomaticImplementationsFromMultiPlatformSymbolGraphs() throws {
739+
let inheritedDefaultImplementationsSGF = Bundle.module.url(
740+
forResource: "InheritedDefaultImplementations.symbols",
741+
withExtension: "json",
742+
subdirectory: "Test Resources"
743+
)!
744+
745+
let symbolGraphWithModifiedPlatform = try String(
746+
contentsOf: inheritedDefaultImplementationsSGF
747+
)
748+
.replacingOccurrences(
749+
of: """
750+
"architecture": "x86_64",
751+
""",
752+
with: """
753+
"architecture": "arm64",
754+
"""
755+
)
756+
.replacingOccurrences(
757+
of: """
758+
"name": "macosx",
759+
""",
760+
with: """
761+
"name": "ios",
762+
"""
763+
)
764+
765+
let testBundle = try Folder(
766+
name: "unit-test.docc",
767+
content: [
768+
InfoPlist(displayName: "TestBundle", identifier: "com.test.example"),
769+
Folder(
770+
name: "x86_64-apple-macos",
771+
content: [
772+
CopyOfFile(original: inheritedDefaultImplementationsSGF),
773+
]
774+
),
775+
Folder(
776+
name: "arm64-apple-ios",
777+
content: [
778+
DataFile(
779+
name: inheritedDefaultImplementationsSGF.lastPathComponent,
780+
data: Data(symbolGraphWithModifiedPlatform.utf8)
781+
),
782+
]
783+
),
784+
]
785+
).write(inside: createTemporaryDirectory())
786+
787+
try assertDefaultImplementationCollectionTitles(
788+
in: try loadRenderNode(at: "/documentation/FirstTarget/Bar", in: testBundle),
789+
[
790+
"Foo Implementations",
791+
]
792+
)
793+
794+
try assertDefaultImplementationCollectionTitles(
795+
in: try loadRenderNode(at: "/documentation/FirstTarget/OtherStruct", in: testBundle),
796+
[
797+
"Comparable Implementations",
798+
"Equatable Implementations",
799+
]
800+
)
801+
802+
try assertDefaultImplementationCollectionTitles(
803+
in: try loadRenderNode(at: "/documentation/FirstTarget/SomeStruct", in: testBundle),
804+
[
805+
"Comparable Implementations",
806+
"Equatable Implementations",
807+
"FancyProtocol Implementations",
808+
"OtherFancyProtocol Implementations",
809+
]
810+
)
811+
}
812+
738813
func assertDefaultImplementationCollectionTitles(
739814
in renderNode: RenderNode,
740815
_ expectedTitles: [String],

0 commit comments

Comments
 (0)