Skip to content

Commit 46e8700

Browse files
committed
add a heuristic that chooses the documented overload among an ambiguous overload list, if exactly one such overload exists
1 parent 5e79ca2 commit 46e8700

10 files changed

+59
-11
lines changed

Sources/LinkResolution/UCF.CausalOverload.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ extension UCF
1616
public
1717
let hash:FNV24
1818

19+
public
20+
let documented:Bool
21+
1922
@inlinable public
2023
init(phylum:Phylum.Decl,
2124
decl:Symbol.Decl,
2225
heir:Symbol.Decl?,
23-
hash:FNV24)
26+
hash:FNV24,
27+
documented:Bool)
2428
{
2529
self.phylum = phylum
2630
self.decl = decl
2731
self.heir = heir
2832
self.hash = hash
33+
self.documented = documented
2934
}
3035
}
3136
}

Sources/LinkResolution/UCF.PackageOverload.swift

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extension UCF
1616
public
1717
let hash:FNV24
1818

19+
public
20+
let documented:Bool
1921
/// Used for display purposes. This is not necessarily the symbol from which the
2022
/// ``hash`` was computed.
2123
public
@@ -26,12 +28,14 @@ extension UCF
2628
decl:Int32,
2729
heir:Int32?,
2830
hash:FNV24,
31+
documented:Bool,
2932
id:Symbol.Decl)
3033
{
3134
self.phylum = phylum
3235
self.decl = decl
3336
self.heir = heir
3437
self.hash = hash
38+
self.documented = documented
3539
self.id = id
3640
}
3741
}

Sources/LinkResolution/UCF.Resolution.swift

+28
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,31 @@ extension UCF
1111
case module(Symbol.Module)
1212
}
1313
}
14+
extension UCF.Resolution where Overload:UCF.ResolvableOverload
15+
{
16+
static func choose(among overloads:[Symbol.Decl: Overload],
17+
rejected:[Symbol.Decl: Overload]) -> Self
18+
{
19+
var documentedOverload:Overload?
20+
var documentedCount:Int = 0
21+
22+
for candidate:Overload in overloads.values
23+
{
24+
if candidate.documented
25+
{
26+
documentedOverload = candidate
27+
documentedCount += 1
28+
}
29+
}
30+
31+
if let documentedOverload:Overload, documentedCount == 1
32+
{
33+
return .overload(documentedOverload)
34+
}
35+
else
36+
{
37+
return .ambiguous(overloads.values.sorted { $0.id < $1.id },
38+
rejected: rejected.values.sorted { $0.id < $1.id })
39+
}
40+
}
41+
}

Sources/LinkResolution/UCF.ResolutionTable.Search.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ extension UCF.ResolutionTable.Search
6767
}
6868
else
6969
{
70-
return .ambiguous(self.selected.values.sorted { $0.id < $1.id },
71-
rejected: self.rejected.values.sorted { $0.id < $1.id })
70+
return .choose(among: self.selected, rejected: self.rejected)
7271
}
7372
}
7473

@@ -81,8 +80,7 @@ extension UCF.ResolutionTable.Search
8180
}
8281
else
8382
{
84-
return .ambiguous(self.selected.values.sorted { $0.id < $1.id },
85-
rejected: self.rejected.values.sorted { $0.id < $1.id })
83+
return .choose(among: self.selected, rejected: self.rejected)
8684
}
8785
}
8886
}

Sources/LinkResolution/UCF.ResolvableOverload.swift

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ extension UCF
99
{
1010
var phylum:Phylum.Decl { get }
1111
var hash:FNV24 { get }
12+
13+
var documented:Bool { get }
1214
}
1315
}
1416
extension UCF.ResolvableOverload

Sources/SymbolGraphCompiler/Extensions/SSGC.ModuleIndex.Feature.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ extension SSGC.ModuleIndex
1111
let phylum:Phylum.Decl
1212
public
1313
let path:UnqualifiedPath
14+
public
15+
let documented:Bool
1416

15-
init(phylum:Phylum.Decl, path:UnqualifiedPath)
17+
init(phylum:Phylum.Decl, path:UnqualifiedPath, documented:Bool)
1618
{
1719
self.phylum = phylum
1820
self.path = path
21+
self.documented = documented
1922
}
2023
}
2124
}
2225
extension SSGC.ModuleIndex.Feature
2326
{
2427
init(from decl:borrowing SSGC.Decl)
2528
{
26-
self.init(phylum: decl.phylum, path: decl.path)
29+
self.init(phylum: decl.phylum, path: decl.path, documented: decl.comment != nil)
2730
}
2831
}

Sources/SymbolGraphCompiler/UCF.VerticalOverload (ext).swift renamed to Sources/SymbolGraphCompiler/UCF.CausalOverload (ext).swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ extension UCF.CausalOverload
99
.init(phylum: decl.phylum,
1010
decl: decl.id,
1111
heir: heir,
12-
hash: .decl(.init(decl.id, self: heir)))
12+
hash: .decl(.init(decl.id, self: heir)),
13+
documented: decl.comment != nil)
1314
}
1415
static
1516
func decl(_ decl:SSGC.Decl) -> Self
1617
{
1718
.init(phylum: decl.phylum,
1819
decl: decl.id,
1920
heir: nil,
20-
hash: .decl(decl.id))
21+
hash: .decl(decl.id),
22+
documented: decl.comment != nil)
2123
}
2224
}

Sources/SymbolGraphLinker/SSGC.Linker.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ extension SSGC.Linker
215215
declarations,
216216
destinations)
217217
{
218-
for (i, decl) in zip(destination.range, namespace.decls)
218+
for (i, decl):(Int32, SSGC.Decl) in zip(destination.range, namespace.decls)
219219
{
220220
let hash:FNV24 = .decl(decl.id)
221221
// Make the decl visible to codelink resolution.
@@ -224,6 +224,7 @@ extension SSGC.Linker
224224
decl: i,
225225
heir: nil,
226226
hash: hash,
227+
documented: decl.comment != nil,
227228
id: decl.id))
228229
// Assign the decl a URI, and record the decl’s hash
229230
// so we will know if it has a hash collision.
@@ -306,6 +307,7 @@ extension SSGC.Linker
306307
decl: f,
307308
heir: extendee,
308309
hash: .decl(.init(id, self: $0.extendee.id)),
310+
documented: feature.documented,
309311
id: id)
310312

311313
self.tables.packageLinks[namespace, $0.extendee.path, feature.path.last]

Sources/SymbolGraphLinkerTests/Main.LinkResolution.swift

+4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ extension Main.LinkResolution:TestBattery
3232
decl: 0,
3333
heir: nil,
3434
hash: .init(hashing: "x"),
35+
documented: true,
3536
id: "x"))
3637

3738
tables.packageLinks["ThisModule", .init(["A"], "c")].append(.init(
3839
phylum: .func(.instance),
3940
decl: 1,
4041
heir: nil,
4142
hash: .init(hashing: "y"),
43+
documented: true,
4244
id: "y"))
4345

4446
if let tests:TestGroup = tests / "Unscoped"
@@ -92,13 +94,15 @@ extension Main.LinkResolution:TestBattery
9294
decl: 0,
9395
heir: nil,
9496
hash: .init(hashing: "x"),
97+
documented: true,
9598
id: "x"))
9699

97100
tables.packageLinks["OtherModule", .init(["A"], "c")].append(.init(
98101
phylum: .func(.instance),
99102
decl: 1,
100103
heir: nil,
101104
hash: .init(hashing: "y"),
105+
documented: true,
102106
id: "y"))
103107

104108
if let tests:TestGroup = tests / "Unscoped"

Sources/SymbolGraphs/SymbolGraphABI.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import SemanticVersions
33
@frozen public
44
enum SymbolGraphABI
55
{
6-
@inlinable public static var version:PatchVersion { .v(0, 12, 1) }
6+
@inlinable public static var version:PatchVersion { .v(0, 12, 2) }
77
}

0 commit comments

Comments
 (0)