Skip to content

Commit

Permalink
Merge pull request #2569 from ahoppen/ahoppen/fix-old-swift-diags
Browse files Browse the repository at this point in the history
Fix two diagnostics when building swift-syntax using pre Swift-6 compilers
  • Loading branch information
ahoppen authored Mar 27, 2024
2 parents 27e8f91 + 1f0e7d5 commit cfd0487
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
13 changes: 11 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,17 @@ public struct KeywordSpec {
///
/// This is typically used to mark APIs as SPI when the keyword is part of an experimental language feature.
public var apiAttributes: AttributeListSyntax {
guard isExperimental else { return "" }
return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .newline)
let attrList = AttributeListSyntax {
if isExperimental {
let experimentalSPI: AttributeListSyntax = """
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
"""
experimentalSPI.with(\.trailingTrivia, .newline)
}
}
return attrList.with(\.trailingTrivia, attrList.isEmpty ? [] : .newline)
}

/// Initializes a new `KeywordSpec` instance.
Expand Down
26 changes: 26 additions & 0 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,15 @@ extension DeclModifierSyntax {
case `private`
case `public`
case reasync
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _resultDependsOnSelf
case required
case `static`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case transferring
case unowned
case weak
Expand Down Expand Up @@ -2907,11 +2911,17 @@ extension OptionalBindingConditionSyntax {
case `let`
case `var`
case `inout`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _mutating
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _borrowing
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _consuming

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
Expand Down Expand Up @@ -3332,9 +3342,13 @@ extension SimpleTypeSpecifierSyntax {
case _const
case borrowing
case consuming
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case transferring
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _resultDependsOn

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
Expand Down Expand Up @@ -3879,11 +3893,17 @@ extension ValueBindingPatternSyntax {
case `let`
case `var`
case `inout`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _mutating
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _borrowing
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _consuming

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
Expand Down Expand Up @@ -3970,11 +3990,17 @@ extension VariableDeclSyntax {
case `let`
case `var`
case `inout`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _mutating
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _borrowing
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _consuming

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftSyntax/Syntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
public struct Syntax: SyntaxProtocol, SyntaxHashable {
/// We need a heap indirection to store a syntax node's parent. We could use an indirect enum here but explicitly
/// modelling it using a class allows us to re-use these heap-allocated objects in `SyntaxVisitor`.
final class Info: Sendable {
///
/// - Note: `@unchecked Sendable` because `info` is mutable. In Swift 6 and above the variable can be declared as
/// `nonisolated(unsafe)` but that attribute doesn't exist in previous Swift versions and a checked Sendable
/// conformance generates a warning.
final class Info: @unchecked Sendable {
// For root node.
struct Root: Sendable {
private var arena: RetainedSyntaxArena
Expand Down
16 changes: 16 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ public enum Keyword: UInt8, Hashable, Sendable {
case _alignment
case _backDeploy
case _borrow
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _borrowing
case _BridgeObject
case _cdecl
case _Class
case _compilerInitialized
case _const
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _consuming
case _documentation
case _dynamicReplacement
Expand All @@ -39,7 +43,9 @@ public enum Keyword: UInt8, Hashable, Sendable {
case _local
case _modify
case _move
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _mutating
case _NativeClass
case _NativeRefCountedObject
Expand Down Expand Up @@ -104,7 +110,9 @@ public enum Keyword: UInt8, Hashable, Sendable {
case `default`
case `defer`
case `deinit`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case dependsOn
case deprecated
case derivative
Expand Down Expand Up @@ -187,17 +195,23 @@ public enum Keyword: UInt8, Hashable, Sendable {
case renamed
case `repeat`
case required
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _resultDependsOn
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case _resultDependsOnSelf
case `rethrows`
case retroactive
case `return`
case reverse
case right
case safe
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case scoped
case `self`
case `Self`
Expand All @@ -217,7 +231,9 @@ public enum Keyword: UInt8, Hashable, Sendable {
case then
case `throw`
case `throws`
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case transferring
case transpose
case `true`
Expand Down

0 comments on commit cfd0487

Please sign in to comment.