Skip to content

Commit 49f9d95

Browse files
committed
Remove functions that only existed for Swift 5.6 compatibility
1 parent f819f2a commit 49f9d95

File tree

6 files changed

+17
-426
lines changed

6 files changed

+17
-426
lines changed

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public extension Child {
5050
/// function parameter. Otherwise, return `nil`.
5151
var defaultInitialization: InitializerClauseSyntax? {
5252
if isOptional || isUnexpectedNodes {
53-
return InitializerClauseSyntax(value: NilLiteralExprSyntax())
53+
if type.isBaseType && kind.isNodeChoicesEmpty {
54+
return InitializerClauseSyntax(value: ExprSyntax("Optional<\(type.buildable)>.none"))
55+
} else {
56+
return InitializerClauseSyntax(value: NilLiteralExprSyntax())
57+
}
5458
}
5559
guard let token = token, isToken else {
5660
return type.defaultValue.map { InitializerClauseSyntax(value: $0) }

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func syntaxNode(emitKind: String) -> SourceFileSyntax {
7777
"""
7878
)
7979

80-
try! InitializerDeclSyntax("\(node.generateInitializerDeclHeader(optionalBaseAsMissing: false))") {
80+
try! InitializerDeclSyntax("\(node.generateInitializerDeclHeader())") {
8181
let parameters = ClosureParameterListSyntax {
8282
for child in node.children {
8383
ClosureParameterSyntax(firstName: .identifier(child.swiftName))
@@ -149,53 +149,6 @@ func syntaxNode(emitKind: String) -> SourceFileSyntax {
149149
ExprSyntax("self.init(data)")
150150
}
151151

152-
if node.hasOptionalBaseTypeChild {
153-
// TODO: Remove when we no longer support compiling in Swift 5.6. Change the
154-
// above constructor to use `Optional<BaseType>.none` instead.
155-
try! InitializerDeclSyntax(
156-
"""
157-
/// This initializer exists solely because Swift 5.6 does not support
158-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
159-
/// The above initializer thus defaults to `nil` instead, but that means it
160-
/// is not actually callable when either not passing the defaulted parameter,
161-
/// or passing `nil`.
162-
///
163-
/// Hack around that limitation using this initializer, which takes a
164-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
165-
/// the base type would allow implicit conversion from a string literal,
166-
/// which the above initializer doesn't support.
167-
\(node.generateInitializerDeclHeader(optionalBaseAsMissing: true))
168-
"""
169-
) {
170-
FunctionCallExprSyntax(callee: ExprSyntax("self.init")) {
171-
TupleExprElementSyntax(label: "leadingTrivia", expression: ExprSyntax("leadingTrivia"))
172-
for child in node.children {
173-
if child.hasOptionalBaseType {
174-
TupleExprElementSyntax(
175-
leadingTrivia: .newline,
176-
label: .identifier(child.swiftName),
177-
colon: .colonToken(),
178-
expression: ExprSyntax("Optional<\(raw: child.typeName)>.none")
179-
)
180-
} else if child.isUnexpectedNodes {
181-
TupleExprElementSyntax(
182-
leadingTrivia: .newline,
183-
expression: ExprSyntax("\(raw: child.swiftName)")
184-
)
185-
} else {
186-
TupleExprElementSyntax(
187-
leadingTrivia: .newline,
188-
label: .identifier(child.swiftName),
189-
colon: .colonToken(),
190-
expression: ExprSyntax("\(raw: child.swiftName)")
191-
)
192-
}
193-
}
194-
TupleExprElementSyntax(label: "trailingTrivia", expression: ExprSyntax("trailingTrivia"))
195-
}
196-
}
197-
}
198-
199152
for (index, child) in node.children.enumerated() {
200153
// ===================
201154
// Children properties
@@ -353,7 +306,7 @@ private func generateSyntaxChildChoices(for child: Child) throws -> EnumDeclSynt
353306
}
354307

355308
fileprivate extension Node {
356-
func generateInitializerDeclHeader(optionalBaseAsMissing: Bool) -> PartialSyntaxNodeString {
309+
func generateInitializerDeclHeader() -> PartialSyntaxNodeString {
357310
if children.isEmpty {
358311
return "public init()"
359312
}
@@ -363,11 +316,7 @@ fileprivate extension Node {
363316
if !child.kind.isNodeChoicesEmpty {
364317
paramType = "\(raw: child.name)"
365318
} else if child.hasBaseType {
366-
if optionalBaseAsMissing {
367-
paramType = "Missing\(raw: child.typeName)"
368-
} else {
369-
paramType = "some \(raw: child.typeName)Protocol"
370-
}
319+
paramType = "some \(raw: child.typeName)Protocol"
371320
} else {
372321
paramType = "\(raw: child.typeName)"
373322
}

Sources/SwiftParserDiagnostics/DiagnosticExtensions.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,6 @@ extension FixIt {
4242
init(message: FixItMessage, changes: MultiNodeChange) {
4343
self.init(message: message, changes: changes.primitiveChanges)
4444
}
45-
46-
// These overloads shouldn't be needed, but are currently required for the
47-
// Swift 5.5 compiler to handle non-trivial FixIt initializations using
48-
// leading-dot syntax.
49-
// TODO: These can be dropped once we require a minimum of Swift 5.6 to
50-
// compile the library.
51-
init(message: StaticParserFixIt, changes: MultiNodeChange) {
52-
self.init(message: message as FixItMessage, changes: changes.primitiveChanges)
53-
}
54-
init(message: StaticParserFixIt, changes: [MultiNodeChange]) {
55-
self.init(message: message as FixItMessage, changes: MultiNodeChange(combining: changes).primitiveChanges)
56-
}
57-
public init(message: StaticParserFixIt, changes: [Change]) {
58-
self.init(message: message as FixItMessage, changes: changes)
59-
}
6045
}
6146

6247
// MARK: - Make missing

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxExprNodes.swift

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,7 @@ public struct KeyPathExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
27772777
_ unexpectedBeforeBackslash: UnexpectedNodesSyntax? = nil,
27782778
backslash: TokenSyntax = .backslashToken(),
27792779
_ unexpectedBetweenBackslashAndRoot: UnexpectedNodesSyntax? = nil,
2780-
root: (some TypeSyntaxProtocol)? = nil,
2780+
root: (some TypeSyntaxProtocol)? = Optional<TypeSyntax?> .none,
27812781
_ unexpectedBetweenRootAndComponents: UnexpectedNodesSyntax? = nil,
27822782
components: KeyPathComponentListSyntax,
27832783
_ unexpectedAfterComponents: UnexpectedNodesSyntax? = nil,
@@ -2817,41 +2817,6 @@ public struct KeyPathExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
28172817
self.init(data)
28182818
}
28192819

2820-
/// This initializer exists solely because Swift 5.6 does not support
2821-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
2822-
/// The above initializer thus defaults to `nil` instead, but that means it
2823-
/// is not actually callable when either not passing the defaulted parameter,
2824-
/// or passing `nil`.
2825-
///
2826-
/// Hack around that limitation using this initializer, which takes a
2827-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
2828-
/// the base type would allow implicit conversion from a string literal,
2829-
/// which the above initializer doesn't support.
2830-
public init(
2831-
leadingTrivia: Trivia? = nil,
2832-
_ unexpectedBeforeBackslash: UnexpectedNodesSyntax? = nil,
2833-
backslash: TokenSyntax = .backslashToken(),
2834-
_ unexpectedBetweenBackslashAndRoot: UnexpectedNodesSyntax? = nil,
2835-
root: MissingTypeSyntax? = nil,
2836-
_ unexpectedBetweenRootAndComponents: UnexpectedNodesSyntax? = nil,
2837-
components: KeyPathComponentListSyntax,
2838-
_ unexpectedAfterComponents: UnexpectedNodesSyntax? = nil,
2839-
trailingTrivia: Trivia? = nil
2840-
2841-
) {
2842-
self.init(
2843-
leadingTrivia: leadingTrivia,
2844-
unexpectedBeforeBackslash,
2845-
backslash: backslash,
2846-
unexpectedBetweenBackslashAndRoot,
2847-
root: Optional<TypeSyntax> .none,
2848-
unexpectedBetweenRootAndComponents,
2849-
components: components,
2850-
unexpectedAfterComponents,
2851-
trailingTrivia: trailingTrivia
2852-
)
2853-
}
2854-
28552820
public var unexpectedBeforeBackslash: UnexpectedNodesSyntax? {
28562821
get {
28572822
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
@@ -3282,7 +3247,7 @@ public struct MemberAccessExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
32823247
public init(
32833248
leadingTrivia: Trivia? = nil,
32843249
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
3285-
base: (some ExprSyntaxProtocol)? = nil,
3250+
base: (some ExprSyntaxProtocol)? = Optional<ExprSyntax?> .none,
32863251
_ unexpectedBetweenBaseAndDot: UnexpectedNodesSyntax? = nil,
32873252
dot: TokenSyntax = .periodToken(),
32883253
_ unexpectedBetweenDotAndName: UnexpectedNodesSyntax? = nil,
@@ -3330,45 +3295,6 @@ public struct MemberAccessExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
33303295
self.init(data)
33313296
}
33323297

3333-
/// This initializer exists solely because Swift 5.6 does not support
3334-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
3335-
/// The above initializer thus defaults to `nil` instead, but that means it
3336-
/// is not actually callable when either not passing the defaulted parameter,
3337-
/// or passing `nil`.
3338-
///
3339-
/// Hack around that limitation using this initializer, which takes a
3340-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
3341-
/// the base type would allow implicit conversion from a string literal,
3342-
/// which the above initializer doesn't support.
3343-
public init(
3344-
leadingTrivia: Trivia? = nil,
3345-
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
3346-
base: MissingExprSyntax? = nil,
3347-
_ unexpectedBetweenBaseAndDot: UnexpectedNodesSyntax? = nil,
3348-
dot: TokenSyntax = .periodToken(),
3349-
_ unexpectedBetweenDotAndName: UnexpectedNodesSyntax? = nil,
3350-
name: TokenSyntax,
3351-
_ unexpectedBetweenNameAndDeclNameArguments: UnexpectedNodesSyntax? = nil,
3352-
declNameArguments: DeclNameArgumentsSyntax? = nil,
3353-
_ unexpectedAfterDeclNameArguments: UnexpectedNodesSyntax? = nil,
3354-
trailingTrivia: Trivia? = nil
3355-
3356-
) {
3357-
self.init(
3358-
leadingTrivia: leadingTrivia,
3359-
unexpectedBeforeBase,
3360-
base: Optional<ExprSyntax> .none,
3361-
unexpectedBetweenBaseAndDot,
3362-
dot: dot,
3363-
unexpectedBetweenDotAndName,
3364-
name: name,
3365-
unexpectedBetweenNameAndDeclNameArguments,
3366-
declNameArguments: declNameArguments,
3367-
unexpectedAfterDeclNameArguments,
3368-
trailingTrivia: trailingTrivia
3369-
)
3370-
}
3371-
33723298
public var unexpectedBeforeBase: UnexpectedNodesSyntax? {
33733299
get {
33743300
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
@@ -4110,7 +4036,7 @@ public struct PostfixIfConfigExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
41104036
public init(
41114037
leadingTrivia: Trivia? = nil,
41124038
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
4113-
base: (some ExprSyntaxProtocol)? = nil,
4039+
base: (some ExprSyntaxProtocol)? = Optional<ExprSyntax?> .none,
41144040
_ unexpectedBetweenBaseAndConfig: UnexpectedNodesSyntax? = nil,
41154041
config: IfConfigDeclSyntax,
41164042
_ unexpectedAfterConfig: UnexpectedNodesSyntax? = nil,
@@ -4146,37 +4072,6 @@ public struct PostfixIfConfigExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
41464072
self.init(data)
41474073
}
41484074

4149-
/// This initializer exists solely because Swift 5.6 does not support
4150-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
4151-
/// The above initializer thus defaults to `nil` instead, but that means it
4152-
/// is not actually callable when either not passing the defaulted parameter,
4153-
/// or passing `nil`.
4154-
///
4155-
/// Hack around that limitation using this initializer, which takes a
4156-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
4157-
/// the base type would allow implicit conversion from a string literal,
4158-
/// which the above initializer doesn't support.
4159-
public init(
4160-
leadingTrivia: Trivia? = nil,
4161-
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
4162-
base: MissingExprSyntax? = nil,
4163-
_ unexpectedBetweenBaseAndConfig: UnexpectedNodesSyntax? = nil,
4164-
config: IfConfigDeclSyntax,
4165-
_ unexpectedAfterConfig: UnexpectedNodesSyntax? = nil,
4166-
trailingTrivia: Trivia? = nil
4167-
4168-
) {
4169-
self.init(
4170-
leadingTrivia: leadingTrivia,
4171-
unexpectedBeforeBase,
4172-
base: Optional<ExprSyntax> .none,
4173-
unexpectedBetweenBaseAndConfig,
4174-
config: config,
4175-
unexpectedAfterConfig,
4176-
trailingTrivia: trailingTrivia
4177-
)
4178-
}
4179-
41804075
public var unexpectedBeforeBase: UnexpectedNodesSyntax? {
41814076
get {
41824077
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)

0 commit comments

Comments
 (0)