Skip to content

Commit 139e7e1

Browse files
committed
fix a number of bugs in the dynamic link resolver, and add regression tests to UnidocQueryTests
1 parent 7252498 commit 139e7e1

25 files changed

+249
-123
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ let package:Package = .init(
450450

451451
.target(name: "Symbols",
452452
dependencies: [
453+
.target(name: "FNV1"),
453454
.target(name: "Sources"),
454455
]),
455456

Sources/SwiftinitPages/Surfaces/Vertices/Swiftinit.Docs.DeclPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ extension Swiftinit.Docs.DeclPage:Swiftinit.VertexPage
235235
{
236236
$0[.code]
237237
{
238-
let hash:FNV24 = .init(hashing: "\(self.vertex.symbol)")
238+
let hash:FNV24 = .init(truncating: .decl(self.vertex.symbol))
239239
$0 += "FNV24: ["
240240
$0[.span] { $0.class = "fnv24" } = "\(hash)"
241241
$0 += "]"

Sources/SymbolGraphLinker/Resolution/SSGC.Outliner.swift

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -153,32 +153,32 @@ extension SSGC.Outliner
153153
private mutating
154154
func outline(translating link:Markdown.SourceString, to url:Substring) -> Int?
155155
{
156-
self.cache.append(outline: .unresolved(.init(
157-
link: String.init(url),
158-
type: .web,
159-
location: link.source.start)))
156+
self.cache.append(outline: .unresolved(web: String.init(url),
157+
location: link.source.start))
160158
}
161159

162160
private mutating
163161
func outline(link:Markdown.SourceString, code:Bool) -> Int?
164162
{
165163
self.cache(link.string)
166164
{
167-
var type:SymbolGraph.Outline.Unresolved.LinkType? = nil
165+
resolution:
168166
if code
169167
{
170-
if let codelink:Codelink = .init(link.string)
168+
guard
169+
let codelink:Codelink = .init(link.string)
170+
else
171171
{
172-
if let outline:SymbolGraph.Outline = self.resolver.outline(codelink,
173-
at: link.source)
174-
{
175-
return outline
176-
}
177-
else
178-
{
179-
type = .ucf
180-
}
172+
break resolution
181173
}
174+
175+
if let outline:SymbolGraph.Outline = self.resolver.outline(codelink,
176+
at: link.source)
177+
{
178+
return outline
179+
}
180+
181+
return .unresolved(ucf: link.string, location: link.source.start)
182182
}
183183
else if let doclink:Doclink = .init(doc: link.string[...])
184184
{
@@ -195,29 +195,17 @@ extension SSGC.Outliner
195195
{
196196
return outline
197197
}
198-
else
199-
{
200-
self.resolver.diagnostics[link.source] =
201-
Warning.doclinkNotStaticallyResolvable(doclink)
202-
203-
type = .doc
204-
}
205-
}
206198

207-
if let type:SymbolGraph.Outline.Unresolved.LinkType
208-
{
209-
return .unresolved(.init(
210-
link: link.string,
211-
type: type,
212-
location: link.source.start))
213-
}
214-
else
215-
{
216199
self.resolver.diagnostics[link.source] =
217-
InvalidAutolinkError<SSGC.Symbolicator>.init(link)
200+
Warning.doclinkNotStaticallyResolvable(doclink)
218201

219-
return nil
202+
return .unresolved(doc: link.string, location: link.source.start)
220203
}
204+
205+
self.resolver.diagnostics[link.source] =
206+
InvalidAutolinkError<SSGC.Symbolicator>.init(link)
207+
208+
return nil
221209
}
222210
}
223211
}

Sources/SymbolGraphLinker/SSGC.Linker.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ extension SSGC.Linker
169169
self.symbolizer.graph.namespaces[destination.index]
170170
for (scalar, decl) in zip(destination.range, source.decls)
171171
{
172-
let hash:FNV24 = .init(hashing: "\(decl.id)")
172+
let hash:FNV24 = .init(truncating: .decl(decl.id))
173173
// Make the decl visible to codelink resolution.
174174
self.tables.codelinks[qualifier, decl.path].overload(with: .init(
175175
target: .scalar(scalar),
@@ -353,7 +353,7 @@ extension SSGC.Linker
353353
self.tables.codelinks[namespace].overload(with: .init(
354354
target: .scalar(n * .module),
355355
phylum: nil,
356-
hash: .init(hashing: "\(namespace)")))
356+
hash: .init(truncating: .module(namespace))))
357357
}
358358

359359
return articles

Sources/SymbolGraphLinkerTests/Main.LinkResolution.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ extension Main.LinkResolution:TestBattery
133133
tests.expect(value: $0.outline(reference: .code(_string("A.c"))))
134134

135135
tests.expect($0.outlines() ..? [
136-
.unresolved(.init(link: "A.b", type: .ucf, location: nil)),
137-
.unresolved(.init(link: "A.c", type: .ucf, location: nil))
136+
.unresolved(ucf: "A.b", location: nil),
137+
.unresolved(ucf: "A.c", location: nil)
138138
])
139139
}
140140
}

Sources/SymbolGraphs/Articles/SymbolGraph.Outline.Unresolved.LinkType.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ extension SymbolGraph.Outline.Unresolved
33
@frozen public
44
enum LinkType:Equatable, Hashable, Sendable
55
{
6-
/// The associated text is an unresolved doclink.
6+
/// The associated text is an unresolved doclink. The string does **not** include the
7+
/// `doc:` scheme.
78
case doc
89
/// The associated text is an untranslated web URL. The string does **not** include a
910
/// scheme.

Sources/SymbolGraphs/Articles/SymbolGraph.Outline.Unresolved.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension SymbolGraph.Outline
1212
public
1313
let location:SourceLocation<Int32>?
1414

15-
@inlinable public
15+
@inlinable
1616
init(link:String, type:LinkType, location:SourceLocation<Int32>?)
1717
{
1818
self.link = link

Sources/SymbolGraphs/Articles/SymbolGraph.Outline.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ extension SymbolGraph
1212
case unresolved(Unresolved)
1313
}
1414
}
15+
// These are only here to make it obvious these links do not contain a scheme.
16+
extension SymbolGraph.Outline
17+
{
18+
@inlinable public static
19+
func unresolved(doc link:String, location:SourceLocation<Int32>?) -> Self
20+
{
21+
.unresolved(.init(link: link, type: .doc, location: location))
22+
}
23+
24+
@inlinable public static
25+
func unresolved(web link:String, location:SourceLocation<Int32>?) -> Self
26+
{
27+
.unresolved(.init(link: link, type: .web, location: location))
28+
}
29+
30+
@inlinable public static
31+
func unresolved(ucf link:String, location:SourceLocation<Int32>?) -> Self
32+
{
33+
.unresolved(.init(link: link, type: .ucf, location: location))
34+
}
35+
}
1536
extension SymbolGraph.Outline
1637
{
1738
public

Sources/SymbolGraphs/Grouping/SymbolGraph.Extension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ extension SymbolGraph
88
{
99
public
1010
let conditions:[GenericConstraint<Int32>]
11+
/// The index of the namespace in which the extended type is declared. For extensions
12+
/// that extend types declared in the **same package**, this is the same index as the
13+
/// one you would obtaine by iterating cultural namespaces, and is therefore redundant.
14+
/// For extensions that extend types declared in **other packages**, this is the
15+
/// **only** way to know what namespace the extended type is declared in.
1116
public
1217
let namespace:Int
1318
public
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import FNV1
2+
3+
extension FNV24.Extended
4+
{
5+
@inlinable public static
6+
func decl(_ symbol:Symbol.Decl.Vector) -> Self
7+
{
8+
.init(hashing: "\(symbol)")
9+
}
10+
@inlinable public static
11+
func decl(_ symbol:Symbol.Decl) -> Self
12+
{
13+
// No added prefix, as ``Symbol.Decl.description`` already includes a `s:` prefix.
14+
.init(hashing: "\(symbol)")
15+
}
16+
17+
@inlinable public static
18+
func module(_ symbol:Symbol.Module) -> Self
19+
{
20+
.init(hashing: "s:m:\(symbol)")
21+
}
22+
@inlinable public static
23+
func product(_ name:String) -> Self
24+
{
25+
// Not the ``Symbol.Product``!
26+
.init(hashing: "s:p:\(name)")
27+
}
28+
}

0 commit comments

Comments
 (0)