Skip to content

Commit bb6dfba

Browse files
committed
Remove functions that only existed for Swift 5.6 compatibility
1 parent b36fbc3 commit bb6dfba

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("\(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
@@ -3148,7 +3148,7 @@ public struct KeyPathExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
31483148
_ unexpectedBeforeBackslash: UnexpectedNodesSyntax? = nil,
31493149
backslash: TokenSyntax = .backslashToken(),
31503150
_ unexpectedBetweenBackslashAndRoot: UnexpectedNodesSyntax? = nil,
3151-
root: (some TypeSyntaxProtocol)? = nil,
3151+
root: (some TypeSyntaxProtocol)? = TypeSyntax?.none,
31523152
_ unexpectedBetweenRootAndComponents: UnexpectedNodesSyntax? = nil,
31533153
components: KeyPathComponentListSyntax,
31543154
_ unexpectedAfterComponents: UnexpectedNodesSyntax? = nil,
@@ -3188,41 +3188,6 @@ public struct KeyPathExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
31883188
self.init(data)
31893189
}
31903190

3191-
/// This initializer exists solely because Swift 5.6 does not support
3192-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
3193-
/// The above initializer thus defaults to `nil` instead, but that means it
3194-
/// is not actually callable when either not passing the defaulted parameter,
3195-
/// or passing `nil`.
3196-
///
3197-
/// Hack around that limitation using this initializer, which takes a
3198-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
3199-
/// the base type would allow implicit conversion from a string literal,
3200-
/// which the above initializer doesn't support.
3201-
public init(
3202-
leadingTrivia: Trivia? = nil,
3203-
_ unexpectedBeforeBackslash: UnexpectedNodesSyntax? = nil,
3204-
backslash: TokenSyntax = .backslashToken(),
3205-
_ unexpectedBetweenBackslashAndRoot: UnexpectedNodesSyntax? = nil,
3206-
root: MissingTypeSyntax? = nil,
3207-
_ unexpectedBetweenRootAndComponents: UnexpectedNodesSyntax? = nil,
3208-
components: KeyPathComponentListSyntax,
3209-
_ unexpectedAfterComponents: UnexpectedNodesSyntax? = nil,
3210-
trailingTrivia: Trivia? = nil
3211-
3212-
) {
3213-
self.init(
3214-
leadingTrivia: leadingTrivia,
3215-
unexpectedBeforeBackslash,
3216-
backslash: backslash,
3217-
unexpectedBetweenBackslashAndRoot,
3218-
root: Optional<TypeSyntax> .none,
3219-
unexpectedBetweenRootAndComponents,
3220-
components: components,
3221-
unexpectedAfterComponents,
3222-
trailingTrivia: trailingTrivia
3223-
)
3224-
}
3225-
32263191
public var unexpectedBeforeBackslash: UnexpectedNodesSyntax? {
32273192
get {
32283193
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
@@ -3653,7 +3618,7 @@ public struct MemberAccessExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
36533618
public init(
36543619
leadingTrivia: Trivia? = nil,
36553620
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
3656-
base: (some ExprSyntaxProtocol)? = nil,
3621+
base: (some ExprSyntaxProtocol)? = ExprSyntax?.none,
36573622
_ unexpectedBetweenBaseAndDot: UnexpectedNodesSyntax? = nil,
36583623
dot: TokenSyntax = .periodToken(),
36593624
_ unexpectedBetweenDotAndName: UnexpectedNodesSyntax? = nil,
@@ -3701,45 +3666,6 @@ public struct MemberAccessExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
37013666
self.init(data)
37023667
}
37033668

3704-
/// This initializer exists solely because Swift 5.6 does not support
3705-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
3706-
/// The above initializer thus defaults to `nil` instead, but that means it
3707-
/// is not actually callable when either not passing the defaulted parameter,
3708-
/// or passing `nil`.
3709-
///
3710-
/// Hack around that limitation using this initializer, which takes a
3711-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
3712-
/// the base type would allow implicit conversion from a string literal,
3713-
/// which the above initializer doesn't support.
3714-
public init(
3715-
leadingTrivia: Trivia? = nil,
3716-
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
3717-
base: MissingExprSyntax? = nil,
3718-
_ unexpectedBetweenBaseAndDot: UnexpectedNodesSyntax? = nil,
3719-
dot: TokenSyntax = .periodToken(),
3720-
_ unexpectedBetweenDotAndName: UnexpectedNodesSyntax? = nil,
3721-
name: TokenSyntax,
3722-
_ unexpectedBetweenNameAndDeclNameArguments: UnexpectedNodesSyntax? = nil,
3723-
declNameArguments: DeclNameArgumentsSyntax? = nil,
3724-
_ unexpectedAfterDeclNameArguments: UnexpectedNodesSyntax? = nil,
3725-
trailingTrivia: Trivia? = nil
3726-
3727-
) {
3728-
self.init(
3729-
leadingTrivia: leadingTrivia,
3730-
unexpectedBeforeBase,
3731-
base: Optional<ExprSyntax> .none,
3732-
unexpectedBetweenBaseAndDot,
3733-
dot: dot,
3734-
unexpectedBetweenDotAndName,
3735-
name: name,
3736-
unexpectedBetweenNameAndDeclNameArguments,
3737-
declNameArguments: declNameArguments,
3738-
unexpectedAfterDeclNameArguments,
3739-
trailingTrivia: trailingTrivia
3740-
)
3741-
}
3742-
37433669
public var unexpectedBeforeBase: UnexpectedNodesSyntax? {
37443670
get {
37453671
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
@@ -4481,7 +4407,7 @@ public struct PostfixIfConfigExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
44814407
public init(
44824408
leadingTrivia: Trivia? = nil,
44834409
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
4484-
base: (some ExprSyntaxProtocol)? = nil,
4410+
base: (some ExprSyntaxProtocol)? = ExprSyntax?.none,
44854411
_ unexpectedBetweenBaseAndConfig: UnexpectedNodesSyntax? = nil,
44864412
config: IfConfigDeclSyntax,
44874413
_ unexpectedAfterConfig: UnexpectedNodesSyntax? = nil,
@@ -4517,37 +4443,6 @@ public struct PostfixIfConfigExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
45174443
self.init(data)
45184444
}
45194445

4520-
/// This initializer exists solely because Swift 5.6 does not support
4521-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
4522-
/// The above initializer thus defaults to `nil` instead, but that means it
4523-
/// is not actually callable when either not passing the defaulted parameter,
4524-
/// or passing `nil`.
4525-
///
4526-
/// Hack around that limitation using this initializer, which takes a
4527-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
4528-
/// the base type would allow implicit conversion from a string literal,
4529-
/// which the above initializer doesn't support.
4530-
public init(
4531-
leadingTrivia: Trivia? = nil,
4532-
_ unexpectedBeforeBase: UnexpectedNodesSyntax? = nil,
4533-
base: MissingExprSyntax? = nil,
4534-
_ unexpectedBetweenBaseAndConfig: UnexpectedNodesSyntax? = nil,
4535-
config: IfConfigDeclSyntax,
4536-
_ unexpectedAfterConfig: UnexpectedNodesSyntax? = nil,
4537-
trailingTrivia: Trivia? = nil
4538-
4539-
) {
4540-
self.init(
4541-
leadingTrivia: leadingTrivia,
4542-
unexpectedBeforeBase,
4543-
base: Optional<ExprSyntax> .none,
4544-
unexpectedBetweenBaseAndConfig,
4545-
config: config,
4546-
unexpectedAfterConfig,
4547-
trailingTrivia: trailingTrivia
4548-
)
4549-
}
4550-
45514446
public var unexpectedBeforeBase: UnexpectedNodesSyntax? {
45524447
get {
45534448
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)

0 commit comments

Comments
 (0)