From ed75205bb6c607dfbf42a88b4f258d2137567a09 Mon Sep 17 00:00:00 2001 From: taylorswift Date: Tue, 7 May 2024 02:00:52 +0000 Subject: [PATCH 1/6] test SSGC on macOS --- .github/workflows/ci.yml | 10 +- .../Builds/SSGC.SpecialBuild.swift | 130 ++++++++++++------ 2 files changed, 95 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f792002f4..a585e16b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,15 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Build only + - name: Build debug run: | swift --version swift build + + - name: Build release + run: | + swift build -c release + + - name: Test SymbolGraphBuilder + run: | + swift run -c release SymbolGraphBuilderTests diff --git a/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift b/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift index 7625c055a..d26cb4cfc 100644 --- a/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift +++ b/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift @@ -24,54 +24,96 @@ extension SSGC.SpecialBuild:SSGC.DocumentationBuild with swift:SSGC.Toolchain) throws -> (SymbolGraphMetadata, SSGC.PackageSources) { // https://forums.swift.org/t/dependency-graph-of-the-standard-library-modules/59267 - let sources:[SSGC.NominalSources] = - [ - // 0: - .toolchain(module: "Swift"), - // 1: - .toolchain(module: "_Concurrency", - dependencies: 0), - // 2: - .toolchain(module: "Distributed", - dependencies: 0, 1), + let sources:[SSGC.NominalSources] + switch try swift.platform() + { + case .macOS: + sources = + [ + // 0: + .toolchain(module: "Swift"), + // 1: + .toolchain(module: "_Concurrency", + dependencies: 0), + // 2: + .toolchain(module: "Distributed", + dependencies: 0, 1), + + // 3: + .toolchain(module: "_StringProcessing", + dependencies: 0), + // 4: + .toolchain(module: "RegexBuilder", + dependencies: 0, 3), - // 3: - .toolchain(module: "_Differentiation", - dependencies: 0), + // 5: + .toolchain(module: "Cxx", + dependencies: 0), - // 4: - .toolchain(module: "_RegexParser", - dependencies: 0), - // 5: - .toolchain(module: "_StringProcessing", - dependencies: 0, 4), - // 6: - .toolchain(module: "RegexBuilder", - dependencies: 0, 4, 5), + // 6: + .toolchain(module: "Dispatch", + dependencies: 0), + // 7: + .toolchain(module: "DispatchIntrospection", + dependencies: 0), + // 8: + .toolchain(module: "Foundation", + dependencies: 0, 6), + ] - // 7: - .toolchain(module: "Cxx", - dependencies: 0), + case .linux: + fallthrough + + default: + sources = + [ + // 0: + .toolchain(module: "Swift"), + // 1: + .toolchain(module: "_Concurrency", + dependencies: 0), + // 2: + .toolchain(module: "Distributed", + dependencies: 0, 1), - // 8: - .toolchain(module: "Dispatch", - dependencies: 0), - // 9: - .toolchain(module: "DispatchIntrospection", - dependencies: 0), - // 10: - .toolchain(module: "Foundation", - dependencies: 0, 8), - // 11: - .toolchain(module: "FoundationNetworking", - dependencies: 0, 8, 10), - // 12: - .toolchain(module: "FoundationXML", - dependencies: 0, 8, 10), - // 12: - .toolchain(module: "XCTest", - dependencies: 0), - ] + // 3: + .toolchain(module: "_Differentiation", + dependencies: 0), + + // 4: + .toolchain(module: "_RegexParser", + dependencies: 0), + // 5: + .toolchain(module: "_StringProcessing", + dependencies: 0, 4), + // 6: + .toolchain(module: "RegexBuilder", + dependencies: 0, 4, 5), + + // 7: + .toolchain(module: "Cxx", + dependencies: 0), + + // 8: + .toolchain(module: "Dispatch", + dependencies: 0), + // 9: + .toolchain(module: "DispatchIntrospection", + dependencies: 0), + // 10: + .toolchain(module: "Foundation", + dependencies: 0, 8), + // 11: + .toolchain(module: "FoundationNetworking", + dependencies: 0, 8, 10), + // 12: + .toolchain(module: "FoundationXML", + dependencies: 0, 8, 10), + // 12: + .toolchain(module: "XCTest", + dependencies: 0), + ] + } let metadata:SymbolGraphMetadata = .swift(swift.version, commit: swift.commit, From baa4a0bb33af4697c94e02ca2c61f0878d471d29 Mon Sep 17 00:00:00 2001 From: taylorswift Date: Tue, 7 May 2024 02:15:10 +0000 Subject: [PATCH 2/6] always fill in sdk if unspecified on macOS --- .../SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift b/Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift index 16b0cd34f..ccb226ac1 100644 --- a/Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift +++ b/Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift @@ -355,7 +355,15 @@ extension SSGC.Toolchain "-skip-inherited-docs", ] - if let swiftSDK:SSGC.AppleSDK = self.swiftSDK + #if os(macOS) + // On macOS, dumping symbols without specifying the SDK will always fail. + // Therefore, we always provide a default SDK. + let swiftSDK:SSGC.AppleSDK? = self.swiftSDK ?? .macOS + #else + let swiftSDK:SSGC.AppleSDK? = self.swiftSDK + #endif + + if let swiftSDK:SSGC.AppleSDK { arguments.append("-sdk") arguments.append(swiftSDK.path) From 35c3dca89f9d48f19f818ad8ef983e56b4b5a7cd Mon Sep 17 00:00:00 2001 From: taylorswift Date: Tue, 7 May 2024 02:37:48 +0000 Subject: [PATCH 3/6] remove Cxx module from macOS preset --- .../SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift b/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift index d26cb4cfc..fc66eb5e5 100644 --- a/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift +++ b/Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift @@ -47,18 +47,14 @@ extension SSGC.SpecialBuild:SSGC.DocumentationBuild dependencies: 0, 3), // 5: - .toolchain(module: "Cxx", - dependencies: 0), - - // 6: .toolchain(module: "Dispatch", dependencies: 0), - // 7: + // 6: .toolchain(module: "DispatchIntrospection", dependencies: 0), - // 8: + // 7: .toolchain(module: "Foundation", - dependencies: 0, 6), + dependencies: 0, 5), ] case .linux: From 2bca0def821d5fbd8c2d02ce60bd294c7762a988 Mon Sep 17 00:00:00 2001 From: taylorswift Date: Tue, 7 May 2024 16:34:55 +0000 Subject: [PATCH 4/6] loosen validation for multiple lexical scopes on the same symbol if the symbol is an Objective C symbol --- .../Declarations/SSGC.DeclObject.swift | 20 +++++++++++-------- .../SSGC.TypeChecker.swift | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift b/Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift index 721453089..69bdcaf0e 100644 --- a/Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift +++ b/Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift @@ -18,9 +18,13 @@ extension SSGC /// The type of the superforms tracked by ``\.value.superforms``. var superforms:(any SuperformRelationship.Type)? - /// The symbol this scalar is lexically-nested in. This may - /// be an extension block symbol. - var scope:Symbol.USR? + /// The symbols this scalar is lexically-nested in. This may include an extension block + /// symbol. + /// + /// Remarkably, it is possible for certain (Objective C) declarations to have more than + /// one lexical parent. For example, base class methods can be shared by multiple + /// subclasses in addition to the base class. + var scopes:Set private(set) var value:Decl @@ -35,7 +39,7 @@ extension SSGC self.culture = culture self.superforms = nil - self.scope = nil + self.scopes = [] self.value = value } @@ -77,16 +81,16 @@ extension SSGC.DeclObject throw SSGC.SemanticError.cannot(have: .scope, as: self.value.phylum) } - // It is okay to restate the exact same nesting relationship multiple times. This - // sometimes happens when compiling C modules. - if let scope:Symbol.USR = self.scope, + // Only (Objective) C declarations can have multiple lexical scopes. + if case .s = self.id.language, + let scope:Symbol.USR = self.scopes.first, scope != relationship.scope { throw SSGC.SemanticError.already(has: .scope(scope)) } else { - self.scope = relationship.scope + self.scopes.insert(relationship.scope) self.kinks += relationship.kinks } diff --git a/Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift b/Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift index 2fa10c883..9f9957d45 100644 --- a/Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift +++ b/Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift @@ -194,7 +194,7 @@ extension SSGC.TypeChecker // implementations that implement requirements from protocols in the current module. for decl:SSGC.DeclObject in others { - guard case nil = decl.scope, + guard decl.scopes.isEmpty, let parent:UnqualifiedPath = .init(decl.value.path.prefix), let parent:Symbol.Decl = protocols[parent] else From ba595aecd3e854cd5d63bfc8798c6234b42a3956 Mon Sep 17 00:00:00 2001 From: taylorswift Date: Tue, 7 May 2024 16:49:36 +0000 Subject: [PATCH 5/6] perhaps a newer version of SwiftNIO will not crash swift symbolgraph-extract --- Sources/SymbolGraphBuilderTests/Main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SymbolGraphBuilderTests/Main.swift b/Sources/SymbolGraphBuilderTests/Main.swift index 46e2a151a..453d3f3a1 100644 --- a/Sources/SymbolGraphBuilderTests/Main.swift +++ b/Sources/SymbolGraphBuilderTests/Main.swift @@ -86,7 +86,7 @@ enum Main:TestMain, TestBattery try workspace.build(package: try .remote( package: "swift-nio", from: "https://github.com/apple/swift-nio.git", - at: "2.63.0", + at: "2.65.0", in: workspace), with: toolchain) }) From f097b98733d039f632535c532c3fa51c13da783a Mon Sep 17 00:00:00 2001 From: taylorswift Date: Tue, 7 May 2024 17:01:06 +0000 Subject: [PATCH 6/6] disable swift-nio swift symbolgraph-extract test on macOS --- Sources/SymbolGraphBuilderTests/Main.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/SymbolGraphBuilderTests/Main.swift b/Sources/SymbolGraphBuilderTests/Main.swift index 453d3f3a1..d8d67a825 100644 --- a/Sources/SymbolGraphBuilderTests/Main.swift +++ b/Sources/SymbolGraphBuilderTests/Main.swift @@ -80,6 +80,8 @@ enum Main:TestMain, TestBattery docs.roundtrip(for: tests, in: workspace.artifacts) } + // https://github.com/tayloraswift/swift-unidoc/issues/211 + #if !os(macOS) if let tests:TestGroup = tests / "swift-nio", let docs:SymbolGraphObject = (tests.do { @@ -101,8 +103,8 @@ enum Main:TestMain, TestBattery ]) docs.roundtrip(for: tests, in: workspace.artifacts) - } + #endif // SwiftNIO has lots of dependencies. If we can handle SwiftNIO, // we can handle anything!