|
1 | 1 | /*
|
2 | 2 | This source file is part of the Swift.org open source project
|
3 | 3 |
|
4 |
| - Copyright (c) 2022-2023 Apple Inc. and the Swift project authors |
| 4 | + Copyright (c) 2022-2024 Apple Inc. and the Swift project authors |
5 | 5 | Licensed under Apache License v2.0 with Runtime Library Exception
|
6 | 6 |
|
7 | 7 | See https://swift.org/LICENSE.txt for license information
|
@@ -120,7 +120,8 @@ struct PathHierarchy {
|
120 | 120 | }
|
121 | 121 | }
|
122 | 122 |
|
123 |
| - var topLevelCandidates = nodes |
| 123 | + // If there are multiple symbol graphs (for example for different source languages or platforms) then the nodes may have already been added to the hierarchy. |
| 124 | + var topLevelCandidates = nodes.filter { _, node in node.parent == nil } |
124 | 125 | for relationship in graph.relationships where relationship.kind.formsHierarchy {
|
125 | 126 | guard let sourceNode = nodes[relationship.source], let expectedContainerName = sourceNode.symbol?.pathComponents.dropLast().last else {
|
126 | 127 | continue
|
@@ -180,7 +181,14 @@ struct PathHierarchy {
|
180 | 181 | moduleNode.add(symbolChild: topLevelNode)
|
181 | 182 | }
|
182 | 183 |
|
183 |
| - for node in topLevelCandidates.values where node.symbol!.pathComponents.count > 1 { |
| 184 | + assert( |
| 185 | + topLevelCandidates.values.filter({ $0.symbol!.pathComponents.count > 1 }).allSatisfy({ $0.parent == nil }), """ |
| 186 | + Top-level candidates shouldn't already exist in the hierarchy. \ |
| 187 | + This wasn't true for \(topLevelCandidates.filter({ $0.value.symbol!.pathComponents.count > 1 && $0.value.parent != nil }).map(\.key).sorted()) |
| 188 | + """ |
| 189 | + ) |
| 190 | + |
| 191 | + for node in topLevelCandidates.values where node.symbol!.pathComponents.count > 1 && node.parent == nil { |
184 | 192 | var parent = moduleNode
|
185 | 193 | var components = { (symbol: SymbolGraph.Symbol) -> [String] in
|
186 | 194 | let original = symbol.pathComponents
|
|
0 commit comments