Skip to content

Commit accb0b0

Browse files
authored
Remove the cache based link resolver (#624)
* Remove the cache based link resolver * Change link resolver property to implicitly unwrapped optional * Remove should-use checks in new tests
1 parent 91f32ae commit accb0b0

File tree

18 files changed

+593
-1809
lines changed

18 files changed

+593
-1809
lines changed

Sources/SwiftDocC/DocumentationService/Convert/Symbol Link Resolution/DocCSymbolRepresentable.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,10 @@ public extension Collection where Element: DocCSymbolRepresentable {
155155
// Disambiguate by kind
156156
return map { currentSymbol in
157157
let kindCount = filter { $0.kindIdentifier == currentSymbol.kindIdentifier }.count
158-
159-
if LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver {
160-
return (
161-
shouldAddIdHash: kindCount > 1,
162-
shouldAddKind: kindCount == 1
163-
)
164-
} else {
165-
return (
166-
shouldAddIdHash: kindCount > 1,
167-
shouldAddKind: true
168-
)
169-
}
158+
return (
159+
shouldAddIdHash: kindCount > 1,
160+
shouldAddKind: kindCount == 1
161+
)
170162
}
171163
}
172164
}

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 97 additions & 398 deletions
Large diffs are not rendered by default.

Sources/SwiftDocC/Infrastructure/DocumentationConverter.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
398398
benchmark(add: Benchmark.ExternalTopicsHash(context: context))
399399
// Log the peak memory.
400400
benchmark(add: Benchmark.PeakMemory())
401-
402-
context.linkResolutionMismatches.reportGatheredMismatchesIfEnabled()
403401

404402
return (analysisProblems: context.problems, conversionProblems: conversionProblems)
405403
}

Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ struct DocumentationCurator {
115115
context.topicGraph.addNode(curatedNode)
116116

117117
// Move the article from the article cache to the documentation
118-
119-
if let hierarchyBasedLinkResolver = context.hierarchyBasedLinkResolver {
120-
hierarchyBasedLinkResolver.addArticle(filename: articleFilename, reference: reference, anchorSections: documentationNode.anchorSections)
121-
}
118+
context.hierarchyBasedLinkResolver.addArticle(filename: articleFilename, reference: reference, anchorSections: documentationNode.anchorSections)
122119

123120
context.documentationCache[reference] = documentationNode
124121
for anchor in documentationNode.anchorSections {

Sources/SwiftDocC/Infrastructure/Link Resolution/DocumentationCacheBasedLinkResolver.swift

Lines changed: 0 additions & 543 deletions
This file was deleted.

Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolutionMigration.swift

Lines changed: 0 additions & 162 deletions
This file was deleted.

Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ private extension PathHierarchy.Node {
11921192
return context.nodeWithSymbolIdentifier(symbol.identifier.precise)!.name.description
11931193
}
11941194
// This only gets called for PathHierarchy error messages, so hierarchyBasedLinkResolver is never nil.
1195-
let reference = context.hierarchyBasedLinkResolver!.resolvedReferenceMap[identifier]!
1195+
let reference = context.hierarchyBasedLinkResolver.resolvedReferenceMap[identifier]!
11961196
if reference.fragment != nil {
11971197
return context.nodeAnchorSections[reference]!.title
11981198
} else {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ enum GeneratedDocumentationTopics {
141141
let inheritedSection = AutomaticTaskGroupSection(title: defaultImplementationGroupTitle, references: [collectionReference], renderPositionPreference: .bottom)
142142
symbol.automaticTaskGroupsVariants[trait]?.append(inheritedSection)
143143
}
144-
if let hierarchyBasedLinkResolver = context.hierarchyBasedLinkResolver {
145-
hierarchyBasedLinkResolver.addTaskGroup(named: title, reference: collectionReference, to: parent)
146-
}
144+
context.hierarchyBasedLinkResolver.addTaskGroup(named: title, reference: collectionReference, to: parent)
147145
}
148146
} else {
149147
fatalError("createCollectionNode() should be used only to add nodes under symbols.")

Sources/SwiftDocC/Semantics/ReferenceResolver.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ func unresolvedReferenceProblem(reference: TopicReference, source: URL?, range:
1616
[DiagnosticNote(source: $0, range: SourceLocation(line: 1, column: 1, source: $0)..<SourceLocation(line: 1, column: 1, source: $0), message: "This article was found but is not available for linking because it's uncurated")]
1717
} ?? []
1818

19-
guard LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver else {
20-
let diagnostic = Diagnostic(source: source, severity: severity, range: range, identifier: "org.swift.docc.unresolvedTopicReference", summary: "Topic reference \(reference.description.singleQuoted) couldn't be resolved. \(errorInfo.message)", notes: notes)
21-
return Problem(diagnostic: diagnostic, possibleSolutions: [])
22-
}
23-
2419
let referenceSourceRange: SourceRange? = range.map { range in
2520
// FIXME: Finding the range for the link's destination is better suited for Swift-Markdown
2621
// https://github.com/apple/swift-markdown/issues/109

Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,13 @@ class DiagnosticTests: XCTestCase {
8989
// Resolve references
9090
_ = resolver.visitMarkup(markup)
9191

92-
if LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver {
93-
XCTAssertEqual(resolver.problems.first?.diagnostic.range, SourceLocation(line: 1, column: 10, source: nil)..<SourceLocation(line: 1, column: 19, source: nil))
94-
} else {
95-
XCTAssertEqual(resolver.problems.first?.diagnostic.range, SourceLocation(line: 1, column: 8, source: nil)..<SourceLocation(line: 1, column: 21, source: nil))
96-
}
92+
XCTAssertEqual(resolver.problems.first?.diagnostic.range, SourceLocation(line: 1, column: 10, source: nil)..<SourceLocation(line: 1, column: 19, source: nil))
9793
let offset = SymbolGraph.LineList.SourceRange(start: .init(line: 10, character: 10), end: .init(line: 10, character: 20))
9894

9995
var problem = try XCTUnwrap(resolver.problems.first)
10096
problem.offsetWithRange(offset)
10197

102-
if LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver {
103-
XCTAssertEqual(problem.diagnostic.range, SourceLocation(line: 11, column: 20, source: nil)..<SourceLocation(line: 11, column: 29, source: nil))
104-
} else {
105-
XCTAssertEqual(problem.diagnostic.range, SourceLocation(line: 11, column: 18, source: nil)..<SourceLocation(line: 11, column: 31, source: nil))
106-
}
98+
XCTAssertEqual(problem.diagnostic.range, SourceLocation(line: 11, column: 20, source: nil)..<SourceLocation(line: 11, column: 29, source: nil))
10799
}
108100

109101
func testFormattedDescription() {

0 commit comments

Comments
 (0)