Skip to content

Commit aa10fe0

Browse files
committed
take @_exported into account when building codelink resolution trees
1 parent 4f7ac8b commit aa10fe0

File tree

9 files changed

+165
-45
lines changed

9 files changed

+165
-45
lines changed

Sources/SymbolGraphBuilder/Builds/SSGC.PackageBuild.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ extension SSGC.PackageBuild
326326
throw SSGC.PackageBuildError.swift_build(code, invocation)
327327
}
328328

329-
let platform:SymbolGraphMetadata.Platform = try toolchain.platform()
330-
var packages:SSGC.PackageGraph = .init(platform: platform)
329+
var packages:SSGC.PackageGraph = .init(platform: try toolchain.platform())
331330

332331
for pin:SPM.DependencyPin in pins
333332
{
@@ -341,13 +340,17 @@ extension SSGC.PackageBuild
341340
packages.attach(manifest, as: pin.identity)
342341
}
343342

343+
let standardLibrary:SSGC.StandardLibrary = .init(platform: packages.platform,
344+
version: toolchain.splash.swift.version.minor)
345+
344346
let modules:SSGC.ModuleGraph = try packages.join(dependencies: pins,
347+
standardLibrary: standardLibrary,
345348
with: &manifest,
346349
as: self.id.package)
347350

348351
// Dump the standard library’s symbols, unless they’re already cached.
349352
let artifactsCached:FilePath.Directory = try toolchain.dump(
350-
standardLibrary: .init(platform: platform),
353+
standardLibrary: standardLibrary,
351354
cache: cache)
352355
for (module, include):(Symbol.Module, [FilePath.Directory]) in try self.modulesToDump(
353356
among: modules)

Sources/SymbolGraphBuilder/SSGC.PackageGraph.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ extension SSGC.PackageGraph
110110

111111
consuming
112112
func join(dependencies pins:[SPM.DependencyPin],
113+
standardLibrary:SSGC.StandardLibrary,
113114
with sinkManifest:inout SPM.Manifest,
114115
as id:Symbol.Package) throws -> SSGC.ModuleGraph
115116
{
@@ -144,8 +145,6 @@ extension SSGC.PackageGraph
144145
print("\(i + 1). \(package)")
145146
}
146147

147-
let standardLibrary:SSGC.StandardLibrary = .init(platform: self.platform)
148-
149148
return try .init(
150149
standardLibrary: standardLibrary.modules.map(SSGC.ModuleLayout.init(toolchain:)),
151150
sparseEdges: self.sparseEdges,

Sources/SymbolGraphBuilder/Standard library/SSGC.StandardLibrary.swift

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import SemanticVersions
12
import SymbolGraphs
23

34
extension SSGC
@@ -18,20 +19,21 @@ extension SSGC
1819
}
1920
extension SSGC.StandardLibrary
2021
{
21-
init(platform:SymbolGraphMetadata.Platform)
22+
init(platform:SymbolGraphMetadata.Platform, version:MinorVersion)
2223
{
23-
switch platform
24+
switch (platform, version)
2425
{
25-
case .macOS: self = .macOS
26-
case .linux: self = .linux
27-
default: fatalError("Unsupported platform: \(platform)")
26+
case (.linux, .v(6, 0)): self = .linux_6_0
27+
case (.linux, _): self = .linux_5_10
28+
case (.macOS, _): self = .macOS_5_10
29+
default: fatalError("Unsupported platform: \(platform)")
2830
}
2931
}
3032
}
3133
// https://forums.swift.org/t/dependency-graph-of-the-standard-library-modules/59267
3234
extension SSGC.StandardLibrary
3335
{
34-
static var macOS:Self
36+
static var macOS_5_10:Self
3537
{
3638
.init(
3739
products: [
@@ -71,7 +73,7 @@ extension SSGC.StandardLibrary
7173
])
7274
}
7375

74-
static var linux:Self
76+
static var linux_5_10:Self
7577
{
7678
.init(
7779
products: [
@@ -130,4 +132,73 @@ extension SSGC.StandardLibrary
130132
dependencies: 0),
131133
])
132134
}
135+
136+
static var linux_6_0:Self
137+
{
138+
.init(
139+
products: [
140+
.init(name: "__stdlib__", type: .library(.automatic),
141+
dependencies: [],
142+
cultures: [Int].init(0 ... 8)),
143+
.init(name: "__corelibs__", type: .library(.automatic),
144+
dependencies: [],
145+
cultures: [Int].init(0 ... 16)),
146+
],
147+
modules: [
148+
// 0:
149+
.toolchain(module: "Swift"),
150+
// 1:
151+
.toolchain(module: "_Concurrency",
152+
dependencies: 0),
153+
// 2:
154+
.toolchain(module: "Distributed",
155+
dependencies: 0, 1),
156+
157+
// 3:
158+
.toolchain(module: "_Differentiation",
159+
dependencies: 0),
160+
161+
// 4:
162+
.toolchain(module: "_RegexParser",
163+
dependencies: 0),
164+
// 5:
165+
.toolchain(module: "_StringProcessing",
166+
dependencies: 0, 4),
167+
// 6:
168+
.toolchain(module: "RegexBuilder",
169+
dependencies: 0, 4, 5),
170+
// 7:
171+
.toolchain(module: "Synchronization",
172+
dependencies: 0),
173+
// 8:
174+
.toolchain(module: "Cxx",
175+
dependencies: 0),
176+
177+
// 9:
178+
.toolchain(module: "Dispatch",
179+
dependencies: 0),
180+
// 10:
181+
.toolchain(module: "DispatchIntrospection",
182+
dependencies: 0),
183+
// 11:
184+
.toolchain(module: "FoundationEssentials",
185+
dependencies: 0, 4, 5, 9),
186+
// 12:
187+
.toolchain(module: "FoundationInternationalization",
188+
dependencies: 0, 4, 5, 9, 11),
189+
// 13:
190+
.toolchain(module: "Foundation",
191+
dependencies: 0, 4, 5, 9, 11, 12),
192+
// 14:
193+
.toolchain(module: "FoundationNetworking",
194+
dependencies: 0, 4, 5, 9, 11, 12, 13),
195+
// 15:
196+
.toolchain(module: "FoundationXML",
197+
dependencies: 0, 4, 5, 9, 11, 12, 13),
198+
199+
// 16:
200+
.toolchain(module: "XCTest",
201+
dependencies: 0, 4, 5, 9, 11, 12, 13),
202+
])
203+
}
133204
}

Sources/SymbolGraphBuilder/Standard library/SSGC.StandardLibraryBuild.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ extension SSGC.StandardLibraryBuild:SSGC.DocumentationBuild
2424
with toolchain:SSGC.Toolchain,
2525
clean _:Bool) throws -> (SymbolGraphMetadata, any SSGC.DocumentationSources)
2626
{
27-
let standardLibrary:SSGC.StandardLibrary = .init(platform: try toolchain.platform())
27+
let standardLibrary:SSGC.StandardLibrary = .init(platform: try toolchain.platform(),
28+
version: toolchain.splash.swift.version.minor)
2829

2930
let artifacts:FilePath.Directory = try toolchain.dump(standardLibrary: standardLibrary,
3031
cache: cache)

Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.SymbolDumpOptions.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ extension SSGC.Toolchain
55
struct SymbolDumpOptions
66
{
77
var minimumACL:Symbol.ACL
8+
var allowedReexportedModules:[Symbol.Module]
89
var emitExtensionBlockSymbols:Bool
910
var includeInterfaceSymbols:Bool
1011
var skipInheritedDocs:Bool
1112

1213
init(minimumACL:Symbol.ACL = .internal,
14+
allowedReexportedModules:[Symbol.Module] = [],
1315
emitExtensionBlockSymbols:Bool = true,
1416
includeInterfaceSymbols:Bool = true,
1517
skipInheritedDocs:Bool = true)
1618
{
1719
self.minimumACL = minimumACL
20+
self.allowedReexportedModules = allowedReexportedModules
1821
self.emitExtensionBlockSymbols = emitExtensionBlockSymbols
1922
self.includeInterfaceSymbols = includeInterfaceSymbols
2023
self.skipInheritedDocs = skipInheritedDocs

Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,15 @@ extension SSGC.Toolchain
216216
{
217217
/// Dumps the symbols for the standard library. Due to upstream bugs in the Swift compiler,
218218
/// this methods disables extension block symbols by default.
219-
func dump(standardLibrary:SSGC.StandardLibrary,
220-
options:SymbolDumpOptions = .init(emitExtensionBlockSymbols: false),
219+
func dump(
220+
standardLibrary:SSGC.StandardLibrary,
221+
options:SymbolDumpOptions = .init(allowedReexportedModules: [
222+
"_Concurrency",
223+
"_StringProcessing",
224+
"FoundationEssentials",
225+
"FoundationInternationalization",
226+
],
227+
emitExtensionBlockSymbols: false),
221228
cache:FilePath.Directory) throws -> FilePath.Directory
222229
{
223230
let cached:FilePath.Directory = cache / "swift@\(self.splash.swift.version)"
@@ -271,6 +278,18 @@ extension SSGC.Toolchain
271278
{
272279
arguments.append("-skip-inherited-docs")
273280
}
281+
if self.splash.swift.version >= .v(6, 0, 0),
282+
// Temporary hack until we have the right stdlib definitions for macOS
283+
self.splash.triple.os.starts(with: "linux"),
284+
!options.allowedReexportedModules.isEmpty
285+
{
286+
let whitelist:String = options.allowedReexportedModules.lazy.map { "\($0)" }.joined(
287+
separator: ",")
288+
289+
arguments.append("""
290+
-experimental-allowed-reexported-modules=\(whitelist)
291+
""")
292+
}
274293

275294
#if os(macOS)
276295
// On macOS, dumping symbols without specifying the SDK will always fail.

Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extension SSGC
1313
class DeclObject
1414
{
1515
let conditions:Set<GenericConstraint<Symbol.Decl>>
16+
var namespaces:Set<Symbol.Module>
1617
var namespace:Symbol.Module
1718
let culture:Symbol.Module
1819
var access:Symbol.ACL
@@ -51,6 +52,7 @@ extension SSGC
5152
value:Decl)
5253
{
5354
self.conditions = conditions
55+
self.namespaces = [namespace]
5456
self.namespace = namespace
5557
self.culture = culture
5658
self.access = access

Sources/SymbolGraphCompiler/Declarations/SSGC.Declarations.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ extension SSGC
2323
}
2424
}
2525
extension SSGC.Declarations
26+
{
27+
var all:LazyFilterSequence<Dictionary<Symbol.Decl, SSGC.DeclObject>.Values>
28+
{
29+
self.decls.values.lazy.filter { $0.access >= self.threshold }
30+
}
31+
}
32+
extension SSGC.Declarations
2633
{
2734
/// Returns the declaration object, or nil if it has already been indexed, or does not meet
2835
/// the minimum visibility threshold.
@@ -41,9 +48,14 @@ extension SSGC.Declarations
4148

4249
let decl:SSGC.DeclObject? =
4350
{
44-
guard case nil = $0
45-
else
51+
if let reexported:SSGC.DeclObject = $0
4652
{
53+
// We have already indexed this declaration!
54+
if reexported.namespace != namespace
55+
{
56+
reexported.namespaces.insert(namespace)
57+
}
58+
4759
return nil
4860
}
4961

0 commit comments

Comments
 (0)