Skip to content

Commit

Permalink
remove changes relevant to path contractions + adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theMomax committed Aug 29, 2022
1 parent 97153b8 commit 8eef6cd
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,65 +335,15 @@ final class DocumentationCacheBasedLinkResolver {
let moduleName: String
var languages: Set<SourceLanguage>
}
var pathCollisionInfo = [[String]: [PathCollisionInfo]]()
var pathCollisionInfo = [String: [PathCollisionInfo]]()
pathCollisionInfo.reserveCapacity(totalSymbolCount)

// Group symbols by path from all of the available symbol graphs
for (moduleName, symbolGraph) in unifiedGraphs {
let symbols = Array(symbolGraph.symbols.values)

let referenceMap = symbols.concurrentMap { symbol in
(symbol, referencesWithoutDisambiguationFor(symbol, moduleName: moduleName, bundle: bundle, context: context))
}.reduce(into: [String: [SourceLanguage: ResolvedTopicReference]](), { result, next in
let (symbol, references) = next
for reference in references {
result[symbol.uniqueIdentifier, default: [:]][reference.sourceLanguage] = reference
}
})

let parentMap = symbolGraph.relationshipsByLanguage.reduce(into: [String: [SourceLanguage: String]](), { parentMap, next in
let (selector, relationships) = next
guard let language = SourceLanguage(knownLanguageIdentifier: selector.interfaceLanguage) else {
return
}

for relationship in relationships {
switch relationship.kind {
case .memberOf, .requirementOf, .declaredIn:
parentMap[relationship.source, default: [:]][language] = relationship.target
default:
break
}
}
})

let pathsAndLanguages: [[([String], SourceLanguage)]] = symbols.concurrentMap { symbol in
guard let references = referenceMap[symbol.uniqueIdentifier] else {
return []
}

return references.map { language, reference in
var prefixLength: Int
if let parentId = parentMap[symbol.uniqueIdentifier]?[language],
let parentReference = referenceMap[parentId]?[language] ?? referenceMap[parentId]?.values.first {
// This is a child of some other symbol
prefixLength = parentReference.pathComponents.count
} else {
// This is a top-level symbol or another symbol without parent (e.g. default implementation)
prefixLength = reference.pathComponents.count-1
}

// PathComponents can have prefixes which are not known locally. In that case,
// the "empty" segments will be cut out later on. We follow the same logic here, as otherwise
// some collisions would not be detected.
// E.g. consider an extension to an external nested type `SomeModule.SomeStruct.SomeStruct`. The
// parent of this extended type symbol is `SomeModule`, however, the path for the extended type symbol
// is `SomeModule/SomeStruct/SomeStruct`, later on, this will change to `SomeModule/SomeStruct`. Now, if
// we also extend `SomeModule.SomeStruct`, the paths for both extensions could collide. To recognize (and resolve)
// the collision here, we work with the same, shortened paths.
return ((reference.pathComponents[0..<prefixLength] + [reference.pathComponents.last!]).map{ $0.lowercased() }, reference.sourceLanguage)
}
}
let pathsAndLanguages: [[(String, SourceLanguage)]] = symbols.concurrentMap { referencesWithoutDisambiguationFor($0, moduleName: moduleName, bundle: bundle, context: context).map {
($0.path.lowercased(), $0.sourceLanguage)
} }

for (symbol, symbolPathsAndLanguages) in zip(symbols, pathsAndLanguages) {
for (path, language) in symbolPathsAndLanguages {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,6 @@ struct PathHierarchy {
parent = child
components = components.dropFirst()
}

// Symbols corresponding to nested types may appear outside of their original context, where
// their parent type may not be present. This happens e.g. for extensions to external nested
// types. In such cases, the nested type should be a direct child of whatever its parent is
// in this different context. Any other behavior would lead to truly empty pages.
var titlePrefix = node.symbol!.title.split(separator: ".").dropLast()
while !components.isEmpty && !titlePrefix.isEmpty && components.last! == titlePrefix.last! {
titlePrefix = titlePrefix.dropLast()
components = components.dropLast()
}

for component in components {
let component = Self.parse(pathComponent: component[...])
let nodeWithoutSymbol = Node(name: component.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import SymbolKit
// MARK: Custom Relationship Kind Identifiers

extension SymbolGraph.Relationship.Kind {
/// This relationship connects top-level extended type symbols the
/// respective extended module symbol.
static let declaredIn = Self(rawValue: "declaredIn")

/// This relationship markes a parent-child hierarchy between a nested
/// extended type symbol and its parent extended type symbol. It mirrors the
/// `memberOf` relationship between the two respective original type symbols.
static let inContextOf = Self(rawValue: "inContextOf")
}

Expand Down
Loading

0 comments on commit 8eef6cd

Please sign in to comment.