Skip to content

Commit cfd0487

Browse files
authored
Merge pull request #2569 from ahoppen/ahoppen/fix-old-swift-diags
Fix two diagnostics when building swift-syntax using pre Swift-6 compilers
2 parents 27e8f91 + 1f0e7d5 commit cfd0487

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ public struct KeywordSpec {
4343
///
4444
/// This is typically used to mark APIs as SPI when the keyword is part of an experimental language feature.
4545
public var apiAttributes: AttributeListSyntax {
46-
guard isExperimental else { return "" }
47-
return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .newline)
46+
let attrList = AttributeListSyntax {
47+
if isExperimental {
48+
let experimentalSPI: AttributeListSyntax = """
49+
#if compiler(>=5.8)
50+
@_spi(ExperimentalLanguageFeatures)
51+
#endif
52+
"""
53+
experimentalSPI.with(\.trailingTrivia, .newline)
54+
}
55+
}
56+
return attrList.with(\.trailingTrivia, attrList.isEmpty ? [] : .newline)
4857
}
4958

5059
/// Initializes a new `KeywordSpec` instance.

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

+26
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,15 @@ extension DeclModifierSyntax {
802802
case `private`
803803
case `public`
804804
case reasync
805+
#if compiler(>=5.8)
805806
@_spi(ExperimentalLanguageFeatures)
807+
#endif
806808
case _resultDependsOnSelf
807809
case required
808810
case `static`
811+
#if compiler(>=5.8)
809812
@_spi(ExperimentalLanguageFeatures)
813+
#endif
810814
case transferring
811815
case unowned
812816
case weak
@@ -2907,11 +2911,17 @@ extension OptionalBindingConditionSyntax {
29072911
case `let`
29082912
case `var`
29092913
case `inout`
2914+
#if compiler(>=5.8)
29102915
@_spi(ExperimentalLanguageFeatures)
2916+
#endif
29112917
case _mutating
2918+
#if compiler(>=5.8)
29122919
@_spi(ExperimentalLanguageFeatures)
2920+
#endif
29132921
case _borrowing
2922+
#if compiler(>=5.8)
29142923
@_spi(ExperimentalLanguageFeatures)
2924+
#endif
29152925
case _consuming
29162926

29172927
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
@@ -3332,9 +3342,13 @@ extension SimpleTypeSpecifierSyntax {
33323342
case _const
33333343
case borrowing
33343344
case consuming
3345+
#if compiler(>=5.8)
33353346
@_spi(ExperimentalLanguageFeatures)
3347+
#endif
33363348
case transferring
3349+
#if compiler(>=5.8)
33373350
@_spi(ExperimentalLanguageFeatures)
3351+
#endif
33383352
case _resultDependsOn
33393353

33403354
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
@@ -3879,11 +3893,17 @@ extension ValueBindingPatternSyntax {
38793893
case `let`
38803894
case `var`
38813895
case `inout`
3896+
#if compiler(>=5.8)
38823897
@_spi(ExperimentalLanguageFeatures)
3898+
#endif
38833899
case _mutating
3900+
#if compiler(>=5.8)
38843901
@_spi(ExperimentalLanguageFeatures)
3902+
#endif
38853903
case _borrowing
3904+
#if compiler(>=5.8)
38863905
@_spi(ExperimentalLanguageFeatures)
3906+
#endif
38873907
case _consuming
38883908

38893909
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
@@ -3970,11 +3990,17 @@ extension VariableDeclSyntax {
39703990
case `let`
39713991
case `var`
39723992
case `inout`
3993+
#if compiler(>=5.8)
39733994
@_spi(ExperimentalLanguageFeatures)
3995+
#endif
39743996
case _mutating
3997+
#if compiler(>=5.8)
39753998
@_spi(ExperimentalLanguageFeatures)
3999+
#endif
39764000
case _borrowing
4001+
#if compiler(>=5.8)
39774002
@_spi(ExperimentalLanguageFeatures)
4003+
#endif
39784004
case _consuming
39794005

39804006
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {

Sources/SwiftSyntax/Syntax.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
public struct Syntax: SyntaxProtocol, SyntaxHashable {
1717
/// We need a heap indirection to store a syntax node's parent. We could use an indirect enum here but explicitly
1818
/// modelling it using a class allows us to re-use these heap-allocated objects in `SyntaxVisitor`.
19-
final class Info: Sendable {
19+
///
20+
/// - Note: `@unchecked Sendable` because `info` is mutable. In Swift 6 and above the variable can be declared as
21+
/// `nonisolated(unsafe)` but that attribute doesn't exist in previous Swift versions and a checked Sendable
22+
/// conformance generates a warning.
23+
final class Info: @unchecked Sendable {
2024
// For root node.
2125
struct Root: Sendable {
2226
private var arena: RetainedSyntaxArena

Sources/SwiftSyntax/generated/Keyword.swift

+16
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ public enum Keyword: UInt8, Hashable, Sendable {
2020
case _alignment
2121
case _backDeploy
2222
case _borrow
23+
#if compiler(>=5.8)
2324
@_spi(ExperimentalLanguageFeatures)
25+
#endif
2426
case _borrowing
2527
case _BridgeObject
2628
case _cdecl
2729
case _Class
2830
case _compilerInitialized
2931
case _const
32+
#if compiler(>=5.8)
3033
@_spi(ExperimentalLanguageFeatures)
34+
#endif
3135
case _consuming
3236
case _documentation
3337
case _dynamicReplacement
@@ -39,7 +43,9 @@ public enum Keyword: UInt8, Hashable, Sendable {
3943
case _local
4044
case _modify
4145
case _move
46+
#if compiler(>=5.8)
4247
@_spi(ExperimentalLanguageFeatures)
48+
#endif
4349
case _mutating
4450
case _NativeClass
4551
case _NativeRefCountedObject
@@ -104,7 +110,9 @@ public enum Keyword: UInt8, Hashable, Sendable {
104110
case `default`
105111
case `defer`
106112
case `deinit`
113+
#if compiler(>=5.8)
107114
@_spi(ExperimentalLanguageFeatures)
115+
#endif
108116
case dependsOn
109117
case deprecated
110118
case derivative
@@ -187,17 +195,23 @@ public enum Keyword: UInt8, Hashable, Sendable {
187195
case renamed
188196
case `repeat`
189197
case required
198+
#if compiler(>=5.8)
190199
@_spi(ExperimentalLanguageFeatures)
200+
#endif
191201
case _resultDependsOn
202+
#if compiler(>=5.8)
192203
@_spi(ExperimentalLanguageFeatures)
204+
#endif
193205
case _resultDependsOnSelf
194206
case `rethrows`
195207
case retroactive
196208
case `return`
197209
case reverse
198210
case right
199211
case safe
212+
#if compiler(>=5.8)
200213
@_spi(ExperimentalLanguageFeatures)
214+
#endif
201215
case scoped
202216
case `self`
203217
case `Self`
@@ -217,7 +231,9 @@ public enum Keyword: UInt8, Hashable, Sendable {
217231
case then
218232
case `throw`
219233
case `throws`
234+
#if compiler(>=5.8)
220235
@_spi(ExperimentalLanguageFeatures)
236+
#endif
221237
case transferring
222238
case transpose
223239
case `true`

0 commit comments

Comments
 (0)