Skip to content

Commit 431475e

Browse files
authored
Merge pull request #2568 from ahoppen/ahoppen/build-in-swift-6-language-mode
Make swift-syntax build in Swift 6 language mode
2 parents 462e954 + fc47c7b commit 431475e

File tree

81 files changed

+315
-47
lines changed

Some content is hidden

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

81 files changed

+315
-47
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/TokenSpecStaticMembersFile.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ import SyntaxSupport
1616
import Utils
1717

1818
let tokenSpecStaticMembersFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19-
DeclSyntax("@_spi(RawSyntax) import SwiftSyntax")
19+
DeclSyntax(
20+
"""
21+
#if swift(>=6)
22+
@_spi(RawSyntax) internal import SwiftSyntax
23+
#else
24+
@_spi(RawSyntax) import SwiftSyntax
25+
#endif
26+
"""
27+
)
2028

2129
try! ExtensionDeclSyntax("extension TokenSpec") {
2230
for tokenSpec in Token.allCases.map(\.spec) where tokenSpec.kind != .keyword {

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/ChildNameForDiagnosticsFile.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ import SyntaxSupport
1616
import Utils
1717

1818
let childNameForDiagnosticFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19-
DeclSyntax("@_spi(ExperimentalLanguageFeatures) import SwiftSyntax")
19+
DeclSyntax(
20+
"""
21+
#if swift(>=6)
22+
@_spi(ExperimentalLanguageFeatures) internal import SwiftSyntax
23+
#else
24+
@_spi(ExperimentalLanguageFeatures) import SwiftSyntax
25+
#endif
26+
"""
27+
)
2028

2129
try! FunctionDeclSyntax(
2230
"private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String?"

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/SyntaxKindNameForDiagnosticsFile.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ import SyntaxSupport
1616
import Utils
1717

1818
let syntaxKindNameForDiagnosticFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19-
DeclSyntax("@_spi(ExperimentalLanguageFeatures) import SwiftSyntax")
19+
DeclSyntax(
20+
"""
21+
#if swift(>=6)
22+
@_spi(ExperimentalLanguageFeatures) internal import SwiftSyntax
23+
#else
24+
@_spi(ExperimentalLanguageFeatures) import SwiftSyntax
25+
#endif
26+
"""
27+
)
2028

2129
try! ExtensionDeclSyntax("extension SyntaxKind") {
2230
try VariableDeclSyntax("var nameForDiagnostics: String?") {

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparserdiagnostics/TokenNameForDiagnosticsFile.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ import SyntaxSupport
1616
import Utils
1717

1818
let tokenNameForDiagnosticFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19-
DeclSyntax("@_spi(RawSyntax) import SwiftSyntax")
19+
DeclSyntax(
20+
"""
21+
#if swift(>=6)
22+
@_spi(RawSyntax) internal import SwiftSyntax
23+
#else
24+
@_spi(RawSyntax) import SwiftSyntax
25+
#endif
26+
"""
27+
)
2028

2129
try! ExtensionDeclSyntax("extension TokenKind") {
2230
try! VariableDeclSyntax("var nameForDiagnostics: String") {

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ import SyntaxSupport
1616
import Utils
1717

1818
let syntaxExpressibleByStringInterpolationConformancesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19-
DeclSyntax("import SwiftSyntax")
19+
DeclSyntax(
20+
"""
21+
#if swift(>=6)
22+
internal import SwiftSyntax
23+
#else
24+
import SwiftSyntax
25+
#endif
26+
"""
27+
)
2028

2129
let typesExpressibleByStringInterpolation =
2230
SYNTAX_NODES

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ let package = Package(
297297
dependencies: ["_InstructionCounter", "_SwiftSyntaxTestSupport", "SwiftIDEUtils", "SwiftParser", "SwiftSyntax"],
298298
exclude: ["Inputs"]
299299
),
300-
]
300+
],
301+
swiftLanguageVersions: [.v5, .version("6")]
301302
)
302303

303304
// This is a fake target that depends on all targets in the package.

Sources/SwiftCompilerPluginMessageHandling/Diagnostics.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftDiagnostics
15+
internal import SwiftSyntax
16+
#else
1317
import SwiftDiagnostics
1418
import SwiftSyntax
19+
#endif
1520

1621
/// Errors in macro handing.
1722
enum MacroExpansionError {

Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func encodeToJSON(value: some Encodable) throws -> [UInt8] {
1717
}
1818

1919
/// Intermediate representation for serializing JSON structure.
20-
private class JSONReference {
20+
private final class JSONReference {
2121
enum Backing {
2222
case null
2323
case trueKeyword
@@ -60,9 +60,17 @@ private class JSONReference {
6060
backing = .array(arr)
6161
}
6262

63+
#if swift(>=6)
64+
// nonisolated(unsafe) is fine for these properties because they represent primitives
65+
// that are never modified.
66+
nonisolated(unsafe) static let null: JSONReference = .init(backing: .null)
67+
nonisolated(unsafe) static let trueKeyword: JSONReference = .init(backing: .trueKeyword)
68+
nonisolated(unsafe) static let falseKeyword: JSONReference = .init(backing: .falseKeyword)
69+
#else
6370
static let null: JSONReference = .init(backing: .null)
6471
static let trueKeyword: JSONReference = .init(backing: .trueKeyword)
6572
static let falseKeyword: JSONReference = .init(backing: .falseKeyword)
73+
#endif
6674

6775
@inline(__always)
6876
static func newArray() -> JSONReference {

Sources/SwiftCompilerPluginMessageHandling/Macros.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftBasicFormat
15+
internal import SwiftDiagnostics
16+
internal import SwiftOperators
17+
internal import SwiftSyntax
18+
@_spi(MacroExpansion) @_spi(ExperimentalLanguageFeature) internal import SwiftSyntaxMacroExpansion
19+
@_spi(ExperimentalLanguageFeature) internal import SwiftSyntaxMacros
20+
#else
1321
import SwiftBasicFormat
1422
import SwiftDiagnostics
1523
import SwiftOperators
1624
import SwiftSyntax
1725
@_spi(MacroExpansion) @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacroExpansion
1826
@_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros
27+
#endif
1928

2029
extension CompilerPluginMessageHandler {
2130
/// Get concrete macro type from a pair of module name and type name.

Sources/SwiftCompilerPluginMessageHandling/PluginMacroExpansionContext.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftDiagnostics
15+
internal import SwiftOperators
16+
internal import SwiftParser
17+
internal import SwiftSyntax
18+
internal import SwiftSyntaxMacros
19+
#else
1320
import SwiftDiagnostics
1421
import SwiftOperators
1522
import SwiftParser
1623
import SwiftSyntax
1724
import SwiftSyntaxMacros
25+
#endif
1826

1927
/// Manages known source code combined with their filename/fileID. This can be
2028
/// used to get line/column from a syntax node in the managed source code.

Sources/SwiftIDEUtils/SyntaxClassification.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
public enum SyntaxClassification: Sendable {
1620
/// An attribute starting with an `@`.

Sources/SwiftIDEUtils/Utils.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftSyntax
15+
#else
1316
import SwiftSyntax
17+
#endif
1418

1519
extension Range<AbsolutePosition> {
1620
/// Shift the range `utf8Offset` bytes to the right, ie. add `utf8Offset` to the upper and lower bound.

Sources/SwiftOperators/OperatorError+Diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
#if swift(>=6)
1414
public import SwiftDiagnostics
15-
import SwiftParser
16-
import SwiftSyntax
15+
internal import SwiftParser
16+
internal import SwiftSyntax
1717
#else
1818
import SwiftDiagnostics
1919
import SwiftParser

Sources/SwiftOperators/OperatorTable+Defaults.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftSyntax
15+
#else
1316
import SwiftSyntax
17+
#endif
1418

1519
/// Prefabricated operator precedence graphs.
1620
extension OperatorTable {

Sources/SwiftOperators/OperatorTable.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftSyntax
15+
#else
1316
import SwiftSyntax
17+
#endif
1418

1519
/// Maintains and validates information about all operators in a Swift program.
1620
///

Sources/SwiftOperators/PrecedenceGraph.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
internal import SwiftSyntax
15+
#else
1316
import SwiftSyntax
17+
#endif
1418

1519
/// Describes the relative precedence of two groups.
1620
enum Precedence: Sendable {

Sources/SwiftParser/Attributes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension Parser {
1620
mutating func parseAttributeList() -> RawAttributeListSyntax {

Sources/SwiftParser/Availability.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension Parser {
1620
/// Parse a list of availability arguments.

Sources/SwiftParser/Declarations.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension DeclarationModifier {
1620
var canHaveParenthesizedArgument: Bool {

Sources/SwiftParser/Directives.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension Parser {
1620
private enum IfConfigContinuationClauseStartKeyword: TokenSpecSet {

Sources/SwiftParser/ExpressionInterpretedAsVersionTuple.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) public import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension ExprSyntax {
1620
/// Parse the source code of this node as a `VersionTupleSyntax`.

Sources/SwiftParser/Expressions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension TokenConsumer {
1620
mutating func atStartOfExpression() -> Bool {

Sources/SwiftParser/IsValidIdentifier.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
/// Context in which to check if a name can be used as an identifier.
1620
///

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) @_spi(BumpPtrAllocator) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) @_spi(BumpPtrAllocator) import SwiftSyntax
17+
#endif
1418

1519
extension SyntaxText {
1620
fileprivate func containsPlaceholderEnd() -> Bool {

Sources/SwiftParser/Lexer/LexemeSequence.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) @_spi(BumpPtrAllocator) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) @_spi(BumpPtrAllocator) import SwiftSyntax
17+
#endif
1418

1519
extension Lexer {
1620
/// A sequence of ``Lexer/Lexeme`` tokens starting from a ``Lexer/Cursor``

Sources/SwiftParser/Lexer/RegexLiteralLexer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) @_spi(BumpPtrAllocator) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) @_spi(BumpPtrAllocator) import SwiftSyntax
17+
#endif
1418

1519
/// A separate lexer specifically for regex literals.
1620
fileprivate struct RegexLiteralLexer {

Sources/SwiftParser/Lookahead.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
extension Parser {
1620
/// Token lookahead for the parser.

Sources/SwiftParser/LoopProgressCondition.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if swift(>=6)
14+
@_spi(RawSyntax) internal import SwiftSyntax
15+
#else
1316
@_spi(RawSyntax) import SwiftSyntax
17+
#endif
1418

1519
/// A type that can be used to make sure that a loop in the parser makes process.
1620
///

0 commit comments

Comments
 (0)