Skip to content

Commit 67a3fcd

Browse files
authored
return to a symbolgraph-extract based model, and pass -fmodule-map (#408)
* return to a symbolgraph-extract based model, and pass -fmodule-map along with includes * we shouldn’t actually need include paths if we have modulemaps * i think we need --no-parallel here * which swift? * the runner uses a different runtime layout * ? * no double dash??? * centralize build planning logic in ModuleGraph * fix failure to dump all stdlib modules * create missing directories * port SymbolGraphPartTests to Swift Testing, and update expectations to reflect bugs that have been fixed in the Swift 6.0 compiler * add a test case for reexported symbols
1 parent 97b2c14 commit 67a3fcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1480
-1377
lines changed

.github/workflows/test.yml renamed to .github/workflows/Test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: |
5858
swift --version
5959
swift build -c release \
60-
--build-tests \
60+
--product ssgc \
6161
--explicit-target-dependency-import-check=error \
6262
-Xcxx -I$SWIFT_INSTALLATION/lib/swift \
6363
-Xcxx -I$SWIFT_INSTALLATION/lib/swift/Block
@@ -71,7 +71,7 @@ jobs:
7171
- name: Validate packages
7272
run: |
7373
swift test -c release \
74-
--skip-build \
74+
--no-parallel \
7575
--filter SymbolGraphValidationTests \
7676
-Xcxx -I$SWIFT_INSTALLATION/lib/swift \
7777
-Xcxx -I$SWIFT_INSTALLATION/lib/swift/Block
@@ -102,4 +102,5 @@ jobs:
102102
- name: Validate packages
103103
run: |
104104
swift test -c release \
105+
--no-parallel \
105106
--filter SymbolGraphValidationTests

Package.resolved

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ let package:Package = .init(
111111
from: "1.33.0")),
112112
.package(url: "https://github.com/apple/swift-markdown", .upToNextMinor(
113113
from: "0.4.0")),
114-
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(
115-
from: "1.4.0")),
116114
.package(url: "https://github.com/apple/swift-syntax",
117115
from: "600.0.1"),
118116
],
@@ -651,10 +649,9 @@ let package:Package = .init(
651649
.target(name: "SymbolGraphLinker"),
652650
]),
653651

654-
.executableTarget(name: "SymbolGraphPartTests",
652+
.testTarget(name: "SymbolGraphPartTests",
655653
dependencies: [
656654
.target(name: "SymbolGraphParts"),
657-
.target(name: "Testing_"),
658655
.product(name: "SystemIO", package: "swift-io"),
659656
]),
660657

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<strong><em><code>unidoc</code></em></strong>
44

5-
[![ci build status](https://github.com/tayloraswift/swift-unidoc/actions/workflows/test.yml/badge.svg)](https://github.com/tayloraswift/swift-unidoc/actions/workflows/test.yml)
5+
[![ci build status](https://github.com/tayloraswift/swift-unidoc/actions/workflows/Test.yml/badge.svg)](https://github.com/tayloraswift/swift-unidoc/actions/workflows/Test.yml)
66
[![ci build status](https://github.com/tayloraswift/swift-unidoc/actions/workflows/docs.yml/badge.svg)](https://github.com/tayloraswift/swift-unidoc/actions/workflows/docs.yml)
77
[![ci build status](https://github.com/tayloraswift/swift-unidoc/actions/workflows/Deploy.yml/badge.svg)](https://github.com/tayloraswift/swift-unidoc/actions/workflows/Deploy.yml)
88

Scripts/Linux/GenerateTestSymbolGraphs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,43 @@
33
set -e
44

55
swift --version
6-
swift build \
7-
--package-path TestModules \
8-
-Xswiftc -emit-symbol-graph \
9-
-Xswiftc -emit-symbol-graph-dir -Xswiftc SymbolGraphs \
10-
-Xswiftc -symbol-graph-minimum-access-level -Xswiftc internal \
11-
-Xswiftc -emit-extension-block-symbols \
12-
-Xswiftc -include-spi-symbols \
13-
-Xswiftc -skip-inherited-docs \
14-
-Xswiftc -pretty-print \
15-
-Xswiftc -swift-version -Xswiftc 6
16-
6+
swift build --package-path TestModules
177
swift package --package-path TestModules dump-package > TestModules/Package.swift.json
188

19-
for TARGET in Swift _Concurrency
9+
for output in SymbolGraphs Determinism
2010
do
21-
swift symbolgraph-extract \
22-
-target x86_64-unknown-linux-gnu \
23-
-minimum-access-level internal \
24-
-output-dir TestModules/SymbolGraphs \
25-
-skip-inherited-docs \
26-
-emit-extension-block-symbols \
27-
-include-spi-symbols \
28-
-pretty-print \
29-
-module-name $TARGET
11+
mkdir -p TestModules/$output
12+
for module in Swift _Concurrency _Differentiation
13+
do
14+
swift symbolgraph-extract \
15+
-target x86_64-unknown-linux-gnu \
16+
-minimum-access-level internal \
17+
-output-dir TestModules/$output \
18+
-skip-inherited-docs \
19+
-emit-extension-block-symbols \
20+
-include-spi-symbols \
21+
-pretty-print \
22+
-module-name $module
23+
done
3024
done
3125

32-
swift symbolgraph-extract \
33-
-target x86_64-unknown-linux-gnu \
34-
-minimum-access-level internal \
35-
-output-dir TestModules/Determinism \
36-
-skip-inherited-docs \
37-
-emit-extension-block-symbols \
38-
-include-spi-symbols \
39-
-pretty-print \
40-
-module-name Swift
41-
26+
for include in TestModules/.build/debug/Modules
27+
do
28+
for file in $include/*.swiftmodule
29+
do
30+
swift symbolgraph-extract \
31+
-target x86_64-unknown-linux-gnu \
32+
-minimum-access-level internal \
33+
-output-dir TestModules/SymbolGraphs \
34+
-skip-inherited-docs \
35+
-emit-extension-block-symbols \
36+
-include-spi-symbols \
37+
-pretty-print \
38+
-module-name $(basename $file .swiftmodule) \
39+
-experimental-allowed-reexported-modules=ACL \
40+
-I $include
41+
done
42+
done
4243

4344
.build/release/ssgc -u $SWIFT_INSTALLATION \
4445
-n swift \

Scripts/Linux/TestAll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ swift --version
77
swift build -c release \
88
--explicit-target-dependency-import-check=error \
99
-Xcxx -I$SWIFT_INSTALLATION/lib/swift \
10-
-Xcxx -I$SWIFT_INSTALLATION/lib/swift/Block \
11-
--build-tests
10+
-Xcxx -I$SWIFT_INSTALLATION/lib/swift/Block
1211

1312
Scripts/Linux/GenerateTestSymbolGraphs
1413

@@ -17,7 +16,6 @@ swift test -c release \
1716
-Xcxx -I$SWIFT_INSTALLATION/lib/swift \
1817
-Xcxx -I$SWIFT_INSTALLATION/lib/swift/Block \
1918
--no-parallel \
20-
--skip-build \
2119
--skip SymbolGraphValidationTests \
2220
--disable-testable-imports
2321

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SymbolGraphs
2+
import Symbols
3+
4+
extension PackageNode
5+
{
6+
@frozen public
7+
struct Densified
8+
{
9+
public
10+
let dependencies:[any Identifiable<Symbol.Package>]
11+
public
12+
let products:[SymbolGraph.Product]
13+
public
14+
let modules:[SymbolGraph.Module]
15+
16+
init(dependencies:[any Identifiable<Symbol.Package>],
17+
products:[SymbolGraph.Product],
18+
modules:[SymbolGraph.Module])
19+
{
20+
self.dependencies = dependencies
21+
self.products = products
22+
self.modules = modules
23+
}
24+
}
25+
}

Sources/PackageGraphs/Packages/PackageNode.swift

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ struct PackageNode:Identifiable
1313
public
1414
var dependencies:[any Identifiable<Symbol.Package>]
1515

16+
/// The name of the snippets directory.
17+
public
18+
var snippets:String
1619
public
1720
var products:[SymbolGraph.Product]
1821
public
@@ -26,13 +29,15 @@ struct PackageNode:Identifiable
2629
@inlinable public
2730
init(id:Symbol.Package,
2831
dependencies:[any Identifiable<Symbol.Package>],
32+
snippets:String,
2933
products:[SymbolGraph.Product],
3034
modules:[SymbolGraph.Module],
3135
exclude:[[String]],
3236
root:Symbol.FileBase)
3337
{
3438
self.id = id
3539
self.dependencies = dependencies
40+
self.snippets = snippets
3641
self.products = products
3742
self.modules = modules
3843
self.exclude = exclude
@@ -42,75 +47,72 @@ struct PackageNode:Identifiable
4247
extension PackageNode
4348
{
4449
public consuming
45-
func flattened(dependencies:[PackageNode]) throws -> Self
46-
{
47-
try self.flatten(dependencies: dependencies)
48-
return self
49-
}
50-
51-
mutating
52-
func flatten(dependencies:[PackageNode]) throws
50+
func joined(with dependencies:[PackageNode]) throws -> ([Densified], Densified)
5351
{
54-
var nodes:DigraphExplorer<ProductNode>.Nodes = .init()
55-
for package:PackageNode in dependencies
52+
let nodes:DigraphExplorer<ProductNode>.Nodes = try dependencies.reduce(into: .init())
5653
{
57-
for product:SymbolGraph.Product in package.products
54+
for product:SymbolGraph.Product in $1.products
5855
{
59-
try nodes.index(.init(id: .init(name: product.name, package: package.id),
60-
predecessors: product.dependencies))
56+
let id:Symbol.Product = .init(name: product.name, package: $1.id)
57+
try $0.index(.init(id: id, predecessors: product.dependencies))
6158
}
6259
}
6360

61+
let densifiedUpstream:[Densified] = try dependencies.map
62+
{
63+
try $0.densified(products: nodes, packages: dependencies)
64+
}
65+
let densifiedSink:Densified = try self.densified(
66+
products: nodes,
67+
packages: dependencies)
68+
69+
return (densifiedUpstream, densifiedSink)
70+
}
71+
72+
private consuming
73+
func densified(
74+
products:DigraphExplorer<ProductNode>.Nodes,
75+
packages:[PackageNode]) throws -> Densified
76+
{
6477
var cache:[Symbol.Product: [Symbol.Product]] = [:]
6578

66-
self.products = try self.products.map
79+
for i:Int in self.products.indices
6780
{
68-
.init(name: $0.name, type: $0.type,
69-
dependencies: try nodes.included(by: $0.dependencies, cache: &cache),
70-
cultures: $0.cultures)
81+
try
82+
{
83+
$0 = try products.included(by: $0, cache: &cache)
84+
} (&self.products[i].dependencies)
7185
}
72-
self.modules = try self.modules.map
86+
for i:Int in self.modules.indices
7387
{
74-
.init(name: $0.name, type: $0.type, dependencies: .init(
75-
products: try nodes.included(by: $0.dependencies.products,
76-
cache: &cache),
77-
modules: $0.dependencies.modules),
78-
location: $0.location)
88+
try
89+
{
90+
$0 = try products.included(by: $0, cache: &cache)
91+
} (&self.modules[i].dependencies.products)
7992
}
8093

81-
let declared:[Symbol.Package: any Identifiable<Symbol.Package>] =
82-
self.dependencies.reduce(into: [:]) { $0[$1.id] = $1 }
83-
84-
let actuallyUsed:Set<Symbol.Package> = cache.values.reduce(into: [])
94+
let dependenciesActuallyUsed:Set<Symbol.Package> = cache.values.reduce(into: [])
8595
{
8696
for product:Symbol.Product in $1
8797
{
8898
$0.insert(product.package)
8999
}
90100
}
91101

92-
let directedEdges:[(Symbol.Package, Symbol.Package)] = dependencies.reduce(into: [])
102+
let dependenciesDeclared:[Symbol.Package: any Identifiable<Symbol.Package>] =
103+
self.dependencies.reduce(into: [:]) { $0[$1.id] = $1 }
104+
105+
let dependenciesBlamed:[any Identifiable<Symbol.Package>] = packages.reduce(
106+
into: [])
93107
{
94-
for dependency:any Identifiable<Symbol.Package> in $1.dependencies
108+
if dependenciesActuallyUsed.contains($1.id)
95109
{
96-
$0.append((dependency.id, $1.id))
110+
$0.append(dependenciesDeclared[$1.id] ?? TransitiveDependency.init(id: $1.id))
97111
}
98112
}
99113

100-
// FIXME: in Swift 6, it will be legal to have cyclic package dependencies!
101-
guard
102-
let dependenciesOrdered:[PackageNode] = dependencies.sortedTopologically(
103-
by: directedEdges)
104-
else
105-
{
106-
throw DigraphCycleError<PackageNode>.init()
107-
}
108-
109-
self.dependencies = dependenciesOrdered.compactMap
110-
{
111-
actuallyUsed.contains($0.id)
112-
? declared[$0.id] ?? TransitiveDependency.init(id: $0.id)
113-
: nil
114-
}
114+
return .init(dependencies: dependenciesBlamed,
115+
products: self.products,
116+
modules: self.modules)
115117
}
116118
}

0 commit comments

Comments
 (0)