Skip to content

Commit 5d33d3d

Browse files
committed
implement autograph-based link disambiguation
1 parent d63266f commit 5d33d3d

17 files changed

+229
-83
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ let package:Package = .init(
415415
.target(name: "SymbolGraphParts",
416416
dependencies: [
417417
.target(name: "LexicalPaths"),
418+
.target(name: "LinkResolution"),
418419
// This is the point where the symbol graph compiler becomes infected with a
419420
// (non-macro) SwiftSyntax dependency.
420421
//
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import UCF
2+
3+
extension UCF
4+
{
5+
@frozen public
6+
struct Autograph:Equatable, Sendable
7+
{
8+
public
9+
let inputs:[String]
10+
public
11+
let output:[String]
12+
13+
@inlinable public
14+
init(inputs:[String], output:[String])
15+
{
16+
self.inputs = inputs
17+
self.output = output
18+
}
19+
}
20+
}
21+
extension UCF.Autograph
22+
{
23+
static func ~= (predicate:UCF.PatternFilter, self:Self) -> Bool
24+
{
25+
if let inputs:[String?] = predicate.inputs
26+
{
27+
guard self.inputs.count == inputs.count
28+
else
29+
{
30+
return false
31+
}
32+
for case (let required, let provided?) in zip(self.inputs, inputs)
33+
{
34+
if required != provided
35+
{
36+
return false
37+
}
38+
}
39+
}
40+
41+
switch predicate.output
42+
{
43+
case nil:
44+
break
45+
46+
case .single(let output):
47+
guard self.output.count == 1
48+
else
49+
{
50+
return false
51+
}
52+
53+
if let output:String, output != self.output[0]
54+
{
55+
return false
56+
}
57+
58+
case .tuple(let outputs):
59+
guard self.output.count == outputs.count
60+
else
61+
{
62+
return false
63+
}
64+
for case (let required, let provided?) in zip(self.output, outputs)
65+
{
66+
if required != provided
67+
{
68+
return false
69+
}
70+
}
71+
}
72+
73+
return true
74+
}
75+
}

Sources/LinkResolution/UCF.CausalOverload.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ extension UCF
1818

1919
public
2020
let documented:Bool
21+
public
22+
let autograph:Autograph?
2123

2224
@inlinable public
2325
init(phylum:Phylum.Decl,
2426
decl:Symbol.Decl,
2527
heir:Symbol.Decl?,
2628
hash:FNV24,
27-
documented:Bool)
29+
documented:Bool,
30+
autograph:Autograph?)
2831
{
2932
self.phylum = phylum
3033
self.decl = decl
3134
self.heir = heir
3235
self.hash = hash
3336
self.documented = documented
37+
self.autograph = autograph
3438
}
3539
}
3640
}

Sources/LinkResolution/UCF.PackageOverload.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extension UCF
1818

1919
public
2020
let documented:Bool
21+
public
22+
let autograph:Autograph?
2123
/// Used for display purposes. This is not necessarily the symbol from which the
2224
/// ``hash`` was computed.
2325
public
@@ -29,13 +31,15 @@ extension UCF
2931
heir:Int32?,
3032
hash:FNV24,
3133
documented:Bool,
34+
autograph:Autograph?,
3235
id:Symbol.Decl)
3336
{
3437
self.phylum = phylum
3538
self.decl = decl
3639
self.heir = heir
3740
self.hash = hash
3841
self.documented = documented
42+
self.autograph = autograph
3943
self.id = id
4044
}
4145
}

Sources/LinkResolution/UCF.ResolvableOverload.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extension UCF
77
public
88
protocol ResolvableOverload:Identifiable<Symbol.Decl>, Sendable
99
{
10+
var autograph:Autograph? { get }
1011
var phylum:Phylum.Decl { get }
1112
var hash:FNV24 { get }
1213

@@ -71,12 +72,27 @@ extension UCF.ResolvableOverload
7172

7273
switch suffix
7374
{
74-
case .legacy(let filter, nil): return filter ~= self.phylum
75-
case .legacy(_, let hash?): return hash == self.hash
76-
case .hash(let hash): return hash == self.hash
77-
case .filter(let filter): return filter ~= self.phylum
78-
// TODO: unimplemented
79-
case .pattern: return true
75+
case .legacy(let filter, nil):
76+
return filter ~= self.phylum
77+
78+
case .legacy(_, let hash?):
79+
return hash == self.hash
80+
81+
case .hash(let hash):
82+
return hash == self.hash
83+
84+
case .filter(let filter):
85+
return filter ~= self.phylum
86+
87+
case .pattern(let pattern):
88+
if let autograph:UCF.Autograph = self.autograph
89+
{
90+
return pattern ~= autograph
91+
}
92+
else
93+
{
94+
return false
95+
}
8096
}
8197
}
8298
}

Sources/SymbolGraphCompiler/Declarations/SSGC.Decl.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Availability
2+
import LinkResolution
23
import LexicalPaths
34
import Signatures
45
import Sources
56
import SymbolGraphParts
67
import Symbols
8+
import UCF
79

810
extension SSGC
911
{
@@ -17,6 +19,8 @@ extension SSGC
1719
public
1820
let signature:Signature<Symbol.Decl>
1921
public
22+
let autograph:UCF.Autograph?
23+
public
2024
let location:SourceLocation<Symbol.File>?
2125

2226
public
@@ -58,6 +62,7 @@ extension SSGC
5862

5963
init(id:Symbol.Decl,
6064
signature:Signature<Symbol.Decl>,
65+
autograph:UCF.Autograph?,
6166
location:SourceLocation<Symbol.File>?,
6267
phylum:Phylum.Decl,
6368
path:UnqualifiedPath,
@@ -67,6 +72,7 @@ extension SSGC
6772
self.id = id
6873

6974
self.signature = signature
75+
self.autograph = autograph
7076
self.location = location
7177
self.phylum = phylum
7278
self.path = path

Sources/SymbolGraphCompiler/Declarations/SSGC.Declarations.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ extension SSGC.Declarations
8080
access: vertex.acl,
8181
value: .init(id: symbol,
8282
signature: vertex.signature,
83+
autograph: vertex.autograph,
8384
location: vertex.location,
8485
phylum: phylum,
8586
path: vertex.path,

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import LexicalPaths
2+
import LinkResolution
23
import Symbols
4+
import UCF
35

46
extension SSGC.ModuleIndex
57
{
@@ -13,19 +15,28 @@ extension SSGC.ModuleIndex
1315
let path:UnqualifiedPath
1416
public
1517
let documented:Bool
18+
public
19+
let autograph:UCF.Autograph?
1620

17-
init(phylum:Phylum.Decl, path:UnqualifiedPath, documented:Bool)
21+
init(phylum:Phylum.Decl,
22+
path:UnqualifiedPath,
23+
documented:Bool,
24+
autograph:UCF.Autograph?)
1825
{
1926
self.phylum = phylum
2027
self.path = path
2128
self.documented = documented
29+
self.autograph = autograph
2230
}
2331
}
2432
}
2533
extension SSGC.ModuleIndex.Feature
2634
{
2735
init(from decl:borrowing SSGC.Decl)
2836
{
29-
self.init(phylum: decl.phylum, path: decl.path, documented: decl.comment != nil)
37+
self.init(phylum: decl.phylum,
38+
path: decl.path,
39+
documented: decl.comment != nil,
40+
autograph: decl.autograph)
3041
}
3142
}

Sources/SymbolGraphCompiler/UCF.CausalOverload (ext).swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ extension UCF.CausalOverload
1010
decl: decl.id,
1111
heir: heir,
1212
hash: .decl(.init(decl.id, self: heir)),
13-
documented: decl.comment != nil)
13+
documented: decl.comment != nil,
14+
autograph: decl.autograph)
1415
}
1516
static
1617
func decl(_ decl:SSGC.Decl) -> Self
@@ -19,6 +20,7 @@ extension UCF.CausalOverload
1920
decl: decl.id,
2021
heir: nil,
2122
hash: .decl(decl.id),
22-
documented: decl.comment != nil)
23+
documented: decl.comment != nil,
24+
autograph: decl.autograph)
2325
}
2426
}

Sources/SymbolGraphLinker/SSGC.Linker.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ extension SSGC.Linker
239239
heir: nil,
240240
hash: hash,
241241
documented: decl.comment != nil,
242+
autograph: decl.autograph,
242243
id: decl.id))
243244
// Assign the decl a URI, and record the decl’s hash
244245
// so we will know if it has a hash collision.
@@ -337,6 +338,7 @@ extension SSGC.Linker
337338
heir: extendee,
338339
hash: .decl(.init(id, self: $0.extendee.id)),
339340
documented: feature.documented,
341+
autograph: feature.autograph,
340342
id: id)
341343

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

0 commit comments

Comments
 (0)