Skip to content

Commit 9c77951

Browse files
committed
Bump tools version to 6.0 and make the package build in Swift 6 mode
1 parent 0363aac commit 9c77951

28 files changed

+457
-302
lines changed

Package.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the Swift.org open source project
55
//
6-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
77
// Licensed under Apache License v2.0 with Runtime Library Exception
88
//
99
// See https://swift.org/LICENSE.txt for license information
@@ -47,7 +47,11 @@ var targets: [Target] = [
4747
+ swiftSyntaxDependencies([
4848
"SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax", "SwiftSyntaxBuilder",
4949
]),
50-
exclude: ["CMakeLists.txt"]
50+
exclude: ["CMakeLists.txt"],
51+
swiftSettings: [
52+
// TODO: Does not compile with Swift 6 in Swift 6 mode due to Swift concurrency bugs. Remove once swift-tools-version is bumped to 6.1.
53+
.swiftLanguageMode(.v5)
54+
]
5155
),
5256
.target(
5357
name: "_SwiftFormatTestSupport",
@@ -146,9 +150,11 @@ let package = Package(
146150
],
147151
products: products,
148152
dependencies: dependencies,
149-
targets: targets
153+
targets: targets,
154+
swiftLanguageModes: [.v5, .v6]
150155
)
151156

157+
@MainActor
152158
func swiftSyntaxDependencies(_ names: [String]) -> [Target.Dependency] {
153159
if buildDynamicSwiftSyntaxLibrary {
154160
return [.product(name: "_SwiftSyntaxDynamic", package: "swift-syntax")]

Sources/SwiftFormat/API/Configuration.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -22,7 +22,7 @@ import Foundation
2222
internal let highestSupportedConfigurationVersion = 1
2323

2424
/// Holds the complete set of configured values and defaults.
25-
public struct Configuration: Codable, Equatable {
25+
public struct Configuration: Codable, Equatable, Sendable {
2626

2727
private enum CodingKeys: CodingKey {
2828
case version
@@ -176,7 +176,7 @@ public struct Configuration: Codable, Equatable {
176176
public var noAssignmentInExpressions: NoAssignmentInExpressionsConfiguration
177177

178178
/// Determines how trailing commas in comma-separated lists should be handled during formatting.
179-
public enum MultilineTrailingCommaBehavior: String, Codable {
179+
public enum MultilineTrailingCommaBehavior: String, Codable, Sendable {
180180
case alwaysUsed
181181
case neverUsed
182182
case keptAsWritten
@@ -215,7 +215,7 @@ public struct Configuration: Codable, Equatable {
215215
public var multiElementCollectionTrailingCommas: Bool
216216

217217
/// Determines how multiline string literals should reflow when formatted.
218-
public enum MultilineStringReflowBehavior: String, Codable {
218+
public enum MultilineStringReflowBehavior: String, Codable, Sendable {
219219
/// Never reflow multiline string literals.
220220
case never
221221
/// Reflow lines in string literal that exceed the maximum line length. For example with a line length of 10:
@@ -524,8 +524,8 @@ public struct Configuration: Codable, Equatable {
524524
}
525525

526526
/// Configuration for the `FileScopedDeclarationPrivacy` rule.
527-
public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable {
528-
public enum AccessLevel: String, Codable {
527+
public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable, Sendable {
528+
public enum AccessLevel: String, Codable, Sendable {
529529
/// Private file-scoped declarations should be declared `private`.
530530
///
531531
/// If a file-scoped declaration is declared `fileprivate`, it will be diagnosed (in lint mode)
@@ -547,7 +547,7 @@ public struct FileScopedDeclarationPrivacyConfiguration: Codable, Equatable {
547547
}
548548

549549
/// Configuration for the `NoAssignmentInExpressions` rule.
550-
public struct NoAssignmentInExpressionsConfiguration: Codable, Equatable {
550+
public struct NoAssignmentInExpressionsConfiguration: Codable, Equatable, Sendable {
551551
/// A list of function names where assignments are allowed to be embedded in expressions that are
552552
/// passed as parameters to that function.
553553
public var allowedFunctions: [String] = [
@@ -561,7 +561,7 @@ public struct NoAssignmentInExpressionsConfiguration: Codable, Equatable {
561561
}
562562

563563
/// Configuration for the `OrderedImports` rule.
564-
public struct OrderedImportsConfiguration: Codable, Equatable {
564+
public struct OrderedImportsConfiguration: Codable, Equatable, Sendable {
565565
/// Determines whether imports within conditional compilation blocks should be ordered.
566566
public var includeConditionalImports: Bool = false
567567

Sources/SwiftFormat/API/DebugOptions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -12,7 +12,7 @@
1212

1313
/// Advanced options that are useful when debugging and developing the formatter, but are otherwise
1414
/// not meant for general use.
15-
public struct DebugOptions: OptionSet {
15+
public struct DebugOptions: OptionSet, Sendable {
1616

1717
/// Disables the pretty-printer pass entirely, executing only the syntax-transforming rules in the
1818
/// pipeline.

Sources/SwiftFormat/API/Finding.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -39,7 +39,7 @@ public struct Finding {
3939
/// an `extension` of the `Finding.Message` type and add `static` properties or functions of type
4040
/// `Finding.Message`; these can be initialized using string literals or string interpolations.
4141
public struct Message:
42-
CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByStringInterpolation
42+
CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByStringInterpolation, Sendable
4343
{
4444
/// The message text of the diagnostic.
4545
public var text: String

Sources/SwiftFormat/API/Indent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// Represents an indentation unit that is applied to lines that are pretty-printed.
14-
public enum Indent: Hashable, Codable {
14+
public enum Indent: Hashable, Codable, Sendable {
1515

1616
/// An indentation unit equal to the given number of tab characters.
1717
///

Sources/SwiftFormat/API/Selection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -14,7 +14,7 @@ import Foundation
1414
import SwiftSyntax
1515

1616
/// The selection as given on the command line - an array of offets and lengths
17-
public enum Selection {
17+
public enum Selection: Sendable {
1818
case infinite
1919
case ranges([Range<AbsolutePosition>])
2020

Sources/SwiftFormat/Core/RuleMask.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -124,6 +124,9 @@ enum IgnoreDirective: CustomStringConvertible {
124124
}
125125
}
126126

127+
// This regex is thread-safe.
128+
extension IgnoreDirective.RegexExpression: @unchecked @retroactive Sendable {}
129+
127130
/// A syntax visitor that finds `SourceRange`s of nodes that have rule status modifying comment
128131
/// directives. The changes requested in each comment is parsed and collected into a map to support
129132
/// status lookup per rule name.

Sources/SwiftFormat/Rules/BeginDocumentationCommentWithOneLineSummary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -29,7 +29,7 @@ public final class BeginDocumentationCommentWithOneLineSummary: SyntaxLintRule {
2929
/// even on platforms that support the latter (currently only Apple OSes).
3030
///
3131
/// This allows test runs on those platforms to test both implementations.
32-
public static var _forcesFallbackModeForTesting = false
32+
nonisolated(unsafe) package static var _forcesFallbackModeForTesting = false
3333

3434
/// Identifies this rule as being opt-in. Well written docs on declarations are important, but
3535
/// this rule isn't linguistically advanced enough on all platforms to be applied universally.

Sources/_SwiftFormatTestSupport/DiagnosingTestCase.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ open class DiagnosingTestCase: XCTestCase {
4848
markerLocations: [String: Int],
4949
emittedFindings: [Finding],
5050
context: Context,
51-
file: StaticString = #file,
51+
file: StaticString = #filePath,
5252
line: UInt = #line
5353
) {
5454
var emittedFindings = emittedFindings
@@ -86,7 +86,7 @@ open class DiagnosingTestCase: XCTestCase {
8686
markerLocations: [String: Int],
8787
emittedFindings: inout [Finding],
8888
context: Context,
89-
file: StaticString = #file,
89+
file: StaticString = #filePath,
9090
line: UInt = #line
9191
) {
9292
guard let utf8Offset = markerLocations[findingSpec.marker] else {
@@ -164,7 +164,7 @@ open class DiagnosingTestCase: XCTestCase {
164164
markerLocations: [String: Int],
165165
emittedNotes: inout [Finding.Note],
166166
context: Context,
167-
file: StaticString = #file,
167+
file: StaticString = #filePath,
168168
line: UInt = #line
169169
) {
170170
guard let utf8Offset = markerLocations[noteSpec.marker] else {
@@ -222,7 +222,7 @@ open class DiagnosingTestCase: XCTestCase {
222222
_ actual: String,
223223
_ expected: String,
224224
_ message: String = "",
225-
file: StaticString = #file,
225+
file: StaticString = #filePath,
226226
line: UInt = #line
227227
) {
228228
let actualLines = actual.components(separatedBy: .newlines)

Sources/swift-format/Frontend/ConfigurationLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SwiftFormat
1515

1616
/// Loads formatter configurations, caching them in memory so that multiple operations in the same
1717
/// directory do not repeatedly hit the file system.
18-
struct ConfigurationLoader {
18+
struct ConfigurationLoader: ~Copyable {
1919
/// The cache of previously loaded configurations.
2020
private var cache = [String: Configuration]()
2121

0 commit comments

Comments
 (0)