Skip to content

Commit

Permalink
Merge pull request #2644 from ahoppen/5.10/fix-retroactive-warnings
Browse files Browse the repository at this point in the history
[5.10] Fix warnings about retroactive conformances when building swift-syntax 510 with a Swift 6 compiler
  • Loading branch information
ahoppen authored May 7, 2024
2 parents fa8f95c + d60eab9 commit 303e5c5
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ import Utils
let syntaxExpressibleByStringInterpolationConformancesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
DeclSyntax("import SwiftSyntax")

for node in SYNTAX_NODES where node.parserFunction != nil {
DeclSyntax("extension \(node.kind.syntaxType): SyntaxExpressibleByStringInterpolation {}")
}
let typesExpressibleByStringInterpolation =
SYNTAX_NODES
.filter { $0.parserFunction != nil }
.map { $0.kind.syntaxType }
// `SyntaxParsable` conformance for collection nodes is hand-written.
+ [
"AccessorDeclListSyntax",
"AttributeListSyntax",
"CodeBlockItemListSyntax",
"MemberBlockItemListSyntax",
]

// `SyntaxParsable` conformance for collection nodes is hand-written.
// We also need to hand-write the corresponding `SyntaxExpressibleByStringInterpolation` conformances.
DeclSyntax("extension AccessorDeclListSyntax: SyntaxExpressibleByStringInterpolation {}")
DeclSyntax("extension AttributeListSyntax: SyntaxExpressibleByStringInterpolation {}")
DeclSyntax("extension CodeBlockItemListSyntax: SyntaxExpressibleByStringInterpolation {}")
DeclSyntax("extension MemberBlockItemListSyntax: SyntaxExpressibleByStringInterpolation {}")
for type in typesExpressibleByStringInterpolation {
DeclSyntax("extension \(type): SyntaxExpressibleByStringInterpolation {}")
DeclSyntax(
"""
#if compiler(>=6)
extension \(type): @retroactive ExpressibleByStringInterpolation {}
#endif
"""
)
}
}
23 changes: 20 additions & 3 deletions Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension BinaryOperatorExprSyntax {

// MARK: - BooleanLiteralExpr

extension BooleanLiteralExprSyntax: ExpressibleByBooleanLiteral {
extension BooleanLiteralExprSyntax {
public init(_ value: Bool) {
self.init(literal: value ? .keyword(.true) : .keyword(.false))
}
Expand All @@ -77,6 +77,11 @@ extension BooleanLiteralExprSyntax: ExpressibleByBooleanLiteral {
self.init(value)
}
}
#if compiler(>=6)
extension BooleanLiteralExprSyntax: @retroactive ExpressibleByBooleanLiteral {}
#else
extension BooleanLiteralExprSyntax: ExpressibleByBooleanLiteral {}
#endif

// MARK: - CatchClause

Expand Down Expand Up @@ -153,7 +158,7 @@ extension ExprSyntax {

// MARK: - FloatLiteralExprSyntax

extension FloatLiteralExprSyntax: ExpressibleByFloatLiteral {
extension FloatLiteralExprSyntax {
public init(_ value: Float) {
self.init(literal: .floatLiteral(String(value)))
}
Expand All @@ -163,6 +168,12 @@ extension FloatLiteralExprSyntax: ExpressibleByFloatLiteral {
}
}

#if compiler(>=6)
extension FloatLiteralExprSyntax: @retroactive ExpressibleByFloatLiteral {}
#else
extension FloatLiteralExprSyntax: ExpressibleByFloatLiteral {}
#endif

// MARK: - FunctionCallExpr

extension FunctionCallExprSyntax {
Expand Down Expand Up @@ -190,7 +201,7 @@ extension FunctionCallExprSyntax {

// MARK: - IntegerLiteralExpr

extension IntegerLiteralExprSyntax: ExpressibleByIntegerLiteral {
extension IntegerLiteralExprSyntax {
public init(_ value: Int) {
self.init(literal: .integerLiteral(String(value)))
}
Expand All @@ -200,6 +211,12 @@ extension IntegerLiteralExprSyntax: ExpressibleByIntegerLiteral {
}
}

#if compiler(>=6)
extension IntegerLiteralExprSyntax: @retroactive ExpressibleByIntegerLiteral {}
#else
extension IntegerLiteralExprSyntax: ExpressibleByIntegerLiteral {}
#endif

// MARK: - StringLiteralExpr

extension String {
Expand Down
14 changes: 13 additions & 1 deletion Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ extension TokenSyntax: SyntaxExpressibleByStringInterpolation {
}
}

#if compiler(>=6)
// Silence warning that TokenSyntax has a retroactive conformance to `ExpressibleByStringInterpolation` through
// `SyntaxExpressibleByStringInterpolation`.
extension TokenSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

// MARK: - Trivia expressible as string

extension TriviaPiece {
Expand All @@ -466,7 +472,7 @@ struct UnexpectedTrivia: DiagnosticMessage {

}

extension Trivia: ExpressibleByStringInterpolation {
extension Trivia {
public init(stringInterpolation: String.StringInterpolation) {
var text = String(stringInterpolation: stringInterpolation)
let pieces = text.withUTF8 { (buf) -> [TriviaPiece] in
Expand All @@ -484,3 +490,9 @@ extension Trivia: ExpressibleByStringInterpolation {
self.init(stringInterpolation: interpolation)
}
}

#if compiler(>=6)
extension Trivia: @retroactive ExpressibleByStringInterpolation {}
#else
extension Trivia: ExpressibleByStringInterpolation {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,127 @@ import SwiftSyntax

extension AccessorBlockSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension AccessorBlockSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension AccessorDeclSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension AccessorDeclSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension AttributeSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension AttributeSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension CatchClauseSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension CatchClauseSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension ClosureParameterSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension ClosureParameterSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension CodeBlockItemSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension CodeBlockItemSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension DeclSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension DeclSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension EnumCaseParameterSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension EnumCaseParameterSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension ExprSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension ExprSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension FunctionParameterSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension FunctionParameterSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension GenericParameterClauseSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension GenericParameterClauseSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension MemberBlockSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension MemberBlockSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension PatternSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension PatternSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension SourceFileSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension SourceFileSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension StmtSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension StmtSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension SwitchCaseSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension SwitchCaseSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension TypeSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension TypeSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension AccessorDeclListSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension AccessorDeclListSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension AttributeListSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension AttributeListSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension CodeBlockItemListSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension CodeBlockItemListSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

extension MemberBlockItemListSyntax: SyntaxExpressibleByStringInterpolation {}

#if compiler(>=6)
extension MemberBlockItemListSyntax: @retroactive ExpressibleByStringInterpolation {}
#endif

0 comments on commit 303e5c5

Please sign in to comment.