Skip to content

Commit 04fa09c

Browse files
committed
implement a possible optimization in the unidoc linker
1 parent 9a5b0f6 commit 04fa09c

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

Sources/UnidocLinker/Modules/SymbolGraph.ModuleContext.swift

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,15 @@ extension SymbolGraph
2222
private(set)
2323
var imports:[Symbol.Module]
2424

25-
private
26-
let nodes:Set<Unidoc.Scalar>
27-
28-
private
29-
init(conformances:Set<Unidoc.Vector>,
30-
codelinks:CodelinkResolver<Unidoc.Scalar>.Table,
31-
imports:[Symbol.Module],
32-
nodes:Set<Unidoc.Scalar>)
25+
init()
3326
{
34-
self.conformances = conformances
35-
self.codelinks = codelinks
36-
self.imports = imports
37-
self.nodes = nodes
27+
self.conformances = []
28+
self.codelinks = .init()
29+
self.imports = []
3830
}
3931
}
4032
}
4133
extension SymbolGraph.ModuleContext
42-
{
43-
init(nodes:Slice<SymbolGraph.Table<SymbolGraph.Plane.Decl, Unidoc.Scalar?>>)
44-
{
45-
self.init(conformances: [],
46-
codelinks: .init(),
47-
imports: [],
48-
nodes: nodes.reduce(into: [])
49-
{
50-
if let s:Unidoc.Scalar = $1
51-
{
52-
$0.insert(s)
53-
}
54-
})
55-
}
56-
}
57-
extension SymbolGraph.ModuleContext
5834
{
5935
private mutating
6036
func remember(conforms t:Unidoc.Scalar, to p:Unidoc.Scalar)
@@ -159,7 +135,7 @@ extension SymbolGraph.ModuleContext
159135
//
160136
// This is a different condition than only caring about extensions to types
161137
// that are *declared* in the package being linked.
162-
if self.nodes.contains(outer.scalar)
138+
if context.nodes.contains(outer.scalar)
163139
{
164140
for p:Int32 in `extension`.conformances
165141
{

Sources/UnidocLinker/Unidoc.Linker.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ extension Unidoc
2929

3030
let current:Graph
3131

32+
/// The set of all nodes in the current graph. These are the nodes being linked; all
33+
/// other nodes in this structure are merely used for context.
34+
let nodes:Set<Unidoc.Scalar>
35+
3236
private
3337
init(
3438
byPackageIdentifier:[Symbol.Package: Graph],
3539
byPackage:[Package: Graph],
36-
current:Graph)
40+
current:Graph,
41+
nodes:Set<Unidoc.Scalar>)
3742
{
3843
self.byPackageIdentifier = byPackageIdentifier
3944
self.byPackage = byPackage
4045
self.current = current
46+
self.nodes = nodes
4147

4248
self.diagnostics = .init()
4349
}
@@ -47,7 +53,7 @@ extension Unidoc
4753
extension Unidoc.Linker
4854
{
4955
public
50-
init(_ currentSnapshot:Unidoc.Snapshot, dependencies:borrowing [Unidoc.Snapshot])
56+
init(_ currentSnapshot:consuming Unidoc.Snapshot, dependencies:borrowing [Unidoc.Snapshot])
5157
{
5258
// Build a combined lookup table mapping upstream symbols to scalars.
5359
// Because module names are unique within a build tree, there should
@@ -83,12 +89,19 @@ extension Unidoc.Linker
8389
byPackage[snapshot.id.package] = snapshot
8490
}
8591

92+
let current:Graph = .init(snapshot: currentSnapshot, upstream: upstream)
93+
8694
self.init(
8795
byPackageIdentifier: byPackageIdentifier,
8896
byPackage: byPackage,
89-
current: .init(
90-
snapshot: currentSnapshot,
91-
upstream: upstream))
97+
current: current,
98+
nodes: current.scalars.decls[current.decls.nodes.indices].reduce(into: [])
99+
{
100+
if let s:Unidoc.Scalar = $1
101+
{
102+
$0.insert(s)
103+
}
104+
})
92105
}
93106
}
94107
extension Unidoc.Linker
@@ -227,8 +240,7 @@ extension Unidoc.Linker
227240
{
228241
for (dependencies, cultures):([Symbol.Package: Set<String>], [Int]) in groups
229242
{
230-
var shared:SymbolGraph.ModuleContext = .init(
231-
nodes: self.current.scalars.decls[self.current.decls.nodes.indices])
243+
var shared:SymbolGraph.ModuleContext = .init()
232244

233245
if let swift:Graph = self[dynamic: .swift]
234246
{

0 commit comments

Comments
 (0)