Skip to content

Commit ace3488

Browse files
authored
[NFC] Fix some of the new Swift main snapshots warnings (#7214)
### Motivation: Swift snapshots off `main` warn about `@retroactive` attribute not present on retroactively added protocol conformance, i.e. when a type and a protocol it conforms to are coming from different modules. ### Modifications: Added `@retroactive` attribute conditionally when built with Swift versions lower than 5.10. Also fixed a few other warnings that were introduced recently with an unused `let` binding and an unused `Comparable` conformance. ### Result: Reduced number of warnings when building with Swift `main` snapshots. New concurrency warnings appearing in Swift `main` are untouched here, as they require much more invasive changes to fix `Sendable` conformances.
1 parent 1341ecd commit ace3488

File tree

17 files changed

+143
-63
lines changed

17 files changed

+143
-63
lines changed

Sources/Basics/Vendor/Triple.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ extension Triple {
426426
}
427427
}
428428

429-
public enum Arch: String, CaseIterable {
429+
public enum Arch: String, CaseIterable, Decodable {
430430
/// ARM (little endian): arm, armv.*, xscale
431431
case arm
432432
// ARM (big endian): armeb

Sources/Commands/PackageTools/Init.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,8 @@ extension SwiftPackageTool {
8383
}
8484
}
8585

86+
#if swift(<5.11)
8687
extension InitPackage.PackageType: ExpressibleByArgument {}
88+
#else
89+
extension InitPackage.PackageType: @retroactive ExpressibleByArgument {}
90+
#endif

Sources/Commands/Utilities/APIDigester.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,14 @@ extension PackageGraph {
322322
}
323323
}
324324

325-
extension SerializedDiagnostics.SourceLocation: DiagnosticLocation {
325+
extension SerializedDiagnostics.SourceLocation {
326326
public var description: String {
327327
return "\(filename):\(line):\(column)"
328328
}
329329
}
330+
331+
#if swift(<5.11)
332+
extension SerializedDiagnostics.SourceLocation: DiagnosticLocation {}
333+
#else
334+
extension SerializedDiagnostics.SourceLocation: @retroactive DiagnosticLocation {}
335+
#endif

Sources/CoreCommands/Options.swift

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,13 @@ public struct LinkerOptions: ParsableArguments {
536536

537537
// MARK: - Extensions
538538

539-
extension BuildConfiguration: ExpressibleByArgument {
539+
extension BuildConfiguration {
540540
public init?(argument: String) {
541541
self.init(rawValue: argument)
542542
}
543543
}
544544

545-
extension AbsolutePath: ExpressibleByArgument {
545+
extension AbsolutePath {
546546
public init?(argument: String) {
547547
if let cwd = localFileSystem.currentWorkingDirectory {
548548
guard let path = try? AbsolutePath(validating: argument, relativeTo: cwd) else {
@@ -564,13 +564,13 @@ extension AbsolutePath: ExpressibleByArgument {
564564
}
565565
}
566566

567-
extension WorkspaceConfiguration.CheckingMode: ExpressibleByArgument {
567+
extension WorkspaceConfiguration.CheckingMode {
568568
public init?(argument: String) {
569569
self.init(rawValue: argument)
570570
}
571571
}
572572

573-
extension Sanitizer: ExpressibleByArgument {
573+
extension Sanitizer {
574574
public init?(argument: String) {
575575
if let sanitizer = Sanitizer(rawValue: argument) {
576576
self = sanitizer
@@ -591,18 +591,34 @@ extension Sanitizer: ExpressibleByArgument {
591591
}
592592
}
593593

594-
extension BuildSystemProvider.Kind: ExpressibleByArgument {}
595-
596-
extension Version: ExpressibleByArgument {}
597-
598-
extension PackageIdentity: ExpressibleByArgument {
594+
extension PackageIdentity {
599595
public init?(argument: String) {
600596
self = .plain(argument)
601597
}
602598
}
603599

604-
extension URL: ExpressibleByArgument {
600+
extension URL {
605601
public init?(argument: String) {
606602
self.init(string: argument)
607603
}
608604
}
605+
606+
#if swift(<5.11)
607+
extension BuildConfiguration: ExpressibleByArgument {}
608+
extension AbsolutePath: ExpressibleByArgument {}
609+
extension WorkspaceConfiguration.CheckingMode: ExpressibleByArgument {}
610+
extension Sanitizer: ExpressibleByArgument {}
611+
extension BuildSystemProvider.Kind: ExpressibleByArgument {}
612+
extension Version: ExpressibleByArgument {}
613+
extension PackageIdentity: ExpressibleByArgument {}
614+
extension URL: ExpressibleByArgument {}
615+
#else
616+
extension BuildConfiguration: @retroactive ExpressibleByArgument {}
617+
extension AbsolutePath: @retroactive ExpressibleByArgument {}
618+
extension WorkspaceConfiguration.CheckingMode: @retroactive ExpressibleByArgument {}
619+
extension Sanitizer: @retroactive ExpressibleByArgument {}
620+
extension BuildSystemProvider.Kind: @retroactive ExpressibleByArgument {}
621+
extension Version: @retroactive ExpressibleByArgument {}
622+
extension PackageIdentity: @retroactive ExpressibleByArgument {}
623+
extension URL: @retroactive ExpressibleByArgument {}
624+
#endif

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,6 @@ public final class ManifestLoader: ManifestLoaderProtocol {
10811081
for toolsVersion: ToolsVersion
10821082
) -> [String] {
10831083
var cmd = [String]()
1084-
let libraryPath = self.toolchain.swiftPMLibrariesLocation.manifestLibraryPath
10851084
let modulesPath = self.toolchain.swiftPMLibrariesLocation.manifestModulesPath
10861085
cmd += ["-swift-version", toolsVersion.swiftLanguageVersion.rawValue]
10871086
// if runtimePath is set to "PackageFrameworks" that means we could be developing SwiftPM in Xcode

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,28 @@ struct SwiftSDKMetadataV4: Decodable {
925925
/// Mapping of triple strings to corresponding properties of such target triple.
926926
let targetTriples: [String: TripleProperties]
927927
}
928+
929+
extension Optional where Wrapped == AbsolutePath {
930+
fileprivate var configurationString: String {
931+
self?.pathString ?? "not set"
932+
}
933+
}
934+
935+
extension Optional where Wrapped == [AbsolutePath] {
936+
fileprivate var configurationString: String {
937+
self?.map(\.pathString).description ?? "not set"
938+
}
939+
}
940+
941+
extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
942+
public var description: String {
943+
"""
944+
sdkRootPath: \(sdkRootPath.configurationString)
945+
swiftResourcesPath: \(swiftResourcesPath.configurationString)
946+
swiftStaticResourcesPath: \(swiftStaticResourcesPath.configurationString)
947+
includeSearchPaths: \(includeSearchPaths.configurationString)
948+
librarySearchPaths: \(librarySearchPaths.configurationString)
949+
toolsetPaths: \(toolsetPaths.configurationString)
950+
"""
951+
}
952+
}

Sources/PackageRegistryTool/PackageRegistryTool+Publish.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,18 @@ extension SwiftPackageRegistryTool {
237237
}
238238
}
239239

240-
extension SignatureFormat: ExpressibleByArgument {
240+
extension SignatureFormat {
241241
public init?(argument: String) {
242242
self.init(rawValue: argument.lowercased())
243243
}
244244
}
245245

246+
#if swift(<5.11)
247+
extension SignatureFormat: ExpressibleByArgument {}
248+
#else
249+
extension SignatureFormat: @retroactive ExpressibleByArgument {}
250+
#endif
251+
246252
enum MetadataLocation {
247253
case sourceTree(AbsolutePath)
248254
case external(AbsolutePath)

Sources/SPMBuildCore/XCFrameworkMetadata.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,3 @@ extension XCFrameworkMetadata.Library: Decodable {
8484
case variant = "SupportedPlatformVariant"
8585
}
8686
}
87-
88-
extension Triple.Arch: Decodable {}

Sources/SPMTestSupport/misc.swift

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,19 @@ extension FileSystem {
375375
}
376376
}
377377

378-
extension URL: ExpressibleByStringLiteral {
378+
extension URL {
379379
public init(_ value: StringLiteralType) {
380380
self.init(string: value)!
381381
}
382382
}
383383

384-
extension URL: ExpressibleByStringInterpolation {
384+
extension URL {
385385
public init(stringLiteral value: String) {
386386
self.init(string: value)!
387387
}
388388
}
389389

390-
extension PackageIdentity: ExpressibleByStringLiteral {}
391-
392-
extension PackageIdentity: ExpressibleByStringInterpolation {
390+
extension PackageIdentity {
393391
public init(stringLiteral value: String) {
394392
self = Self.plain(value)
395393
}
@@ -401,13 +399,13 @@ extension PackageIdentity {
401399
}
402400
}
403401

404-
extension AbsolutePath: ExpressibleByStringLiteral {
402+
extension AbsolutePath {
405403
public init(_ value: StringLiteralType) {
406404
try! self.init(validating: value)
407405
}
408406
}
409407

410-
extension AbsolutePath: ExpressibleByStringInterpolation {
408+
extension AbsolutePath {
411409
public init(stringLiteral value: String) {
412410
try! self.init(validating: value)
413411
}
@@ -429,13 +427,13 @@ extension RelativePath {
429427
}
430428
}
431429

432-
extension RelativePath: ExpressibleByStringLiteral {
430+
extension RelativePath {
433431
public init(_ value: StringLiteralType) {
434432
try! self.init(validating: value)
435433
}
436434
}
437435

438-
extension RelativePath: ExpressibleByStringInterpolation {
436+
extension RelativePath {
439437
public init(stringLiteral value: String) {
440438
try! self.init(validating: value)
441439
}
@@ -458,3 +456,23 @@ extension InitPackage {
458456
)
459457
}
460458
}
459+
460+
#if swift(<5.11)
461+
extension RelativePath: ExpressibleByStringLiteral {}
462+
extension RelativePath: ExpressibleByStringInterpolation {}
463+
extension URL: ExpressibleByStringLiteral {}
464+
extension URL: ExpressibleByStringInterpolation {}
465+
extension PackageIdentity: ExpressibleByStringLiteral {}
466+
extension PackageIdentity: ExpressibleByStringInterpolation {}
467+
extension AbsolutePath: ExpressibleByStringLiteral {}
468+
extension AbsolutePath: ExpressibleByStringInterpolation {}
469+
#else
470+
extension RelativePath: @retroactive ExpressibleByStringLiteral {}
471+
extension RelativePath: @retroactive ExpressibleByStringInterpolation {}
472+
extension URL: @retroactive ExpressibleByStringLiteral {}
473+
extension URL: @retroactive ExpressibleByStringInterpolation {}
474+
extension PackageIdentity: @retroactive ExpressibleByStringLiteral {}
475+
extension PackageIdentity: @retroactive ExpressibleByStringInterpolation {}
476+
extension AbsolutePath: @retroactive ExpressibleByStringLiteral {}
477+
extension AbsolutePath: @retroactive ExpressibleByStringInterpolation {}
478+
#endif

Sources/SwiftSDKTool/Configuration/ShowConfiguration.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,3 @@ struct ShowConfiguration: ConfigurationSubcommand {
4848
print(swiftSDK.pathsConfiguration)
4949
}
5050
}
51-
52-
extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
53-
public var description: String {
54-
"""
55-
sdkRootPath: \(sdkRootPath.configurationString)
56-
swiftResourcesPath: \(swiftResourcesPath.configurationString)
57-
swiftStaticResourcesPath: \(swiftStaticResourcesPath.configurationString)
58-
includeSearchPaths: \(includeSearchPaths.configurationString)
59-
librarySearchPaths: \(librarySearchPaths.configurationString)
60-
toolsetPaths: \(toolsetPaths.configurationString)
61-
"""
62-
}
63-
}
64-
65-
extension Optional where Wrapped == AbsolutePath {
66-
fileprivate var configurationString: String {
67-
self?.pathString ?? "not set"
68-
}
69-
}
70-
71-
extension Optional where Wrapped == [AbsolutePath] {
72-
fileprivate var configurationString: String {
73-
self?.map(\.pathString).description ?? "not set"
74-
}
75-
}

Sources/Workspace/Diagnostics.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ extension Basics.Diagnostic {
195195
}
196196
}
197197

198-
extension FileSystemError: CustomStringConvertible {
198+
extension FileSystemError {
199199
public var description: String {
200200
guard let path else {
201201
switch self.kind {
@@ -246,3 +246,9 @@ extension FileSystemError: CustomStringConvertible {
246246
}
247247
}
248248
}
249+
250+
#if swift(<5.11)
251+
extension FileSystemError: CustomStringConvertible {}
252+
#else
253+
extension FileSystemError: @retroactive CustomStringConvertible {}
254+
#endif

Sources/Workspace/Workspace.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,11 @@ private func warnToStderr(_ message: String) {
14561456
}
14571457

14581458
// used for manifest validation
1459+
#if swift(<5.11)
14591460
extension RepositoryManager: ManifestSourceControlValidator {}
1461+
#else
1462+
extension RepositoryManager: @retroactive ManifestSourceControlValidator {}
1463+
#endif
14601464

14611465
extension ContainerUpdateStrategy {
14621466
var repositoryUpdateStrategy: RepositoryUpdateStrategy {

Sources/swift-bootstrap/main.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
443443
}
444444

445445
// TODO: move to shared area
446-
extension AbsolutePath: ExpressibleByArgument {
446+
extension AbsolutePath {
447447
public init?(argument: String) {
448448
if let cwd: AbsolutePath = localFileSystem.currentWorkingDirectory {
449449
guard let path = try? AbsolutePath(validating: argument, relativeTo: cwd) else {
@@ -465,8 +465,16 @@ extension AbsolutePath: ExpressibleByArgument {
465465
}
466466
}
467467

468-
extension BuildConfiguration: ExpressibleByArgument {
468+
extension BuildConfiguration {
469469
public init?(argument: String) {
470470
self.init(rawValue: argument)
471471
}
472472
}
473+
474+
#if swift(<5.11)
475+
extension AbsolutePath: ExpressibleByArgument {}
476+
extension BuildConfiguration: ExpressibleByArgument {}
477+
#else
478+
extension AbsolutePath: @retroactive ExpressibleByArgument {}
479+
extension BuildConfiguration: @retroactive ExpressibleByArgument {}
480+
#endif

Tests/PackageGraphPerformanceTests/DependencyResolverPerfTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private extension VersionSetSpecifier {
182182
}
183183
}
184184

185-
extension ProductFilter: JSONSerializable, JSONMappable {
185+
extension ProductFilter {
186186
public func toJSON() -> JSON {
187187
switch self {
188188
case .everything:
@@ -200,3 +200,9 @@ extension ProductFilter: JSONSerializable, JSONMappable {
200200
}
201201
}
202202
}
203+
204+
#if swift(<5.11)
205+
extension ProductFilter: JSONSerializable, JSONMappable {}
206+
#else
207+
extension ProductFilter: @retroactive JSONSerializable, @retroactive JSONMappable {}
208+
#endif

Tests/PackageGraphTests/DependencyResolverTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ private let v1_1Range: VersionSetSpecifier = .range("1.1.0" ..< "1.2.0")
4242
private let v1_1_0Range: VersionSetSpecifier = .range("1.1.0" ..< "1.1.1")
4343
private let v2_0_0Range: VersionSetSpecifier = .range("2.0.0" ..< "2.0.1")
4444

45-
extension PackageReference: Comparable {
46-
public static func < (lhs: PackageReference, rhs: PackageReference) -> Bool {
47-
return lhs.identity < rhs.identity
48-
}
49-
}
50-
5145
class DependencyResolverTests: XCTestCase {
5246
func testVersionSetSpecifier() {
5347
// Check `contains`.

0 commit comments

Comments
 (0)