Skip to content

Fix two diagnostics when building swift-syntax using pre Swift-6 compilers #2569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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