Skip to content

Commit 1da3972

Browse files
committed
Enable ExistentialAny
1 parent 484dd99 commit 1da3972

16 files changed

+68
-66
lines changed

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ var targets: [Target] = [
129129
do {
130130
let globalSwiftSettings: [SwiftSetting] = [
131131
// Swift 7 mode upcoming features. These must be compatible with 'swift-tools-version'.
132+
.enableUpcomingFeature("ExistentialAny"),
133+
.unsafeFlags(["-Werror", "ExistentialAny"]),
132134
.enableUpcomingFeature("InternalImportsByDefault"),
133135
.enableUpcomingFeature("MemberImportVisibility"),
134136
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),

Sources/SwiftFormat/API/Configuration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public struct Configuration: Codable, Equatable, Sendable {
320320
self = try jsonDecoder.decode(Configuration.self, from: data)
321321
}
322322

323-
public init(from decoder: Decoder) throws {
323+
public init(from decoder: any Decoder) throws {
324324
let container = try decoder.container(keyedBy: CodingKeys.self)
325325

326326
// If the version number is not present, assume it is 1.
@@ -463,7 +463,7 @@ public struct Configuration: Codable, Equatable, Sendable {
463463
?? defaults.rules
464464
}
465465

466-
public func encode(to encoder: Encoder) throws {
466+
public func encode(to encoder: any Encoder) throws {
467467
var container = encoder.container(keyedBy: CodingKeys.self)
468468

469469
try container.encode(version, forKey: .version)

Sources/SwiftFormat/API/Finding.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public struct Finding {
7171
}
7272

7373
/// The category associated with the finding.
74-
public let category: FindingCategorizing
74+
public let category: any FindingCategorizing
7575

7676
/// The finding's message.
7777
public let message: Message
@@ -85,7 +85,7 @@ public struct Finding {
8585
/// Creates a new finding with the given category, message, optional location, and
8686
/// notes.
8787
init(
88-
category: FindingCategorizing,
88+
category: any FindingCategorizing,
8989
message: Message,
9090
location: Location? = nil,
9191
notes: [Note] = []

Sources/SwiftFormat/API/Indent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum Indent: Hashable, Codable, Sendable {
2727
case spaces
2828
}
2929

30-
public init(from decoder: Decoder) throws {
30+
public init(from decoder: any Decoder) throws {
3131
let container = try decoder.container(keyedBy: CodingKeys.self)
3232
let spacesCount = try container.decodeIfPresent(Int.self, forKey: .spaces)
3333
let tabsCount = try container.decodeIfPresent(Int.self, forKey: .tabs)
@@ -57,7 +57,7 @@ public enum Indent: Hashable, Codable, Sendable {
5757
)
5858
}
5959

60-
public func encode(to encoder: Encoder) throws {
60+
public func encode(to encoder: any Encoder) throws {
6161
var container = encoder.container(keyedBy: CodingKeys.self)
6262
switch self {
6363
case .tabs(let count):

Sources/SwiftFormat/Core/DocumentationComment.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public struct DocumentationComment {
5656
///
5757
/// If a brief summary paragraph was extracted from the comment, it will not be present in this
5858
/// collection.
59-
public var bodyNodes: [Markup] = []
59+
public var bodyNodes: [any Markup] = []
6060

6161
/// The structural layout of the parameter descriptions in the comment.
6262
public var parameterLayout: ParameterLayout? = nil
@@ -95,7 +95,7 @@ public struct DocumentationComment {
9595
}
9696

9797
/// Creates a new `DocumentationComment` from the given `Markup` node.
98-
private init(markup: Markup) {
98+
private init(markup: any Markup) {
9999
// Extract the first paragraph as the brief summary. It will *not* be included in the body
100100
// nodes.
101101
let remainingChildren: DropFirstSequence<MarkupChildren>
@@ -144,7 +144,7 @@ public struct DocumentationComment {
144144
/// If parameters were successfully extracted, the provided list is mutated to remove them as a
145145
/// side effect of this function.
146146
private mutating func extractParameterOutline(from list: inout UnorderedList) {
147-
var unprocessedChildren: [Markup] = []
147+
var unprocessedChildren: [any Markup] = []
148148

149149
for child in list.children {
150150
guard
@@ -183,7 +183,7 @@ public struct DocumentationComment {
183183
/// If parameters were successfully extracted, the provided list is mutated to remove them as a
184184
/// side effect of this function.
185185
private mutating func extractSeparatedParameters(from list: inout UnorderedList) {
186-
var unprocessedChildren: [Markup] = []
186+
var unprocessedChildren: [any Markup] = []
187187

188188
for child in list.children {
189189
guard
@@ -232,7 +232,7 @@ public struct DocumentationComment {
232232
///
233233
/// If fields were successfully extracted, the provided list is mutated to remove them.
234234
private mutating func extractSimpleFields(from list: inout UnorderedList) {
235-
var unprocessedChildren: [Markup] = []
235+
var unprocessedChildren: [any Markup] = []
236236

237237
for child in list.children {
238238
guard
@@ -272,19 +272,19 @@ private struct ParameterOutlineMarkupRewriter: MarkupRewriter {
272272
/// Populated if the list item to which this is applied represents a valid parameter field.
273273
private(set) var parameterName: String? = nil
274274

275-
mutating func visitListItem(_ listItem: ListItem) -> Markup? {
275+
mutating func visitListItem(_ listItem: ListItem) -> (any Markup)? {
276276
// Only recurse into the exact list item we're applying this to; otherwise, return it unchanged.
277277
guard listItem.isIdentical(to: origin) else { return listItem }
278278
return defaultVisit(listItem)
279279
}
280280

281-
mutating func visitParagraph(_ paragraph: Paragraph) -> Markup? {
281+
mutating func visitParagraph(_ paragraph: Paragraph) -> (any Markup)? {
282282
// Only recurse into the first paragraph in the list item.
283283
guard paragraph.indexInParent == 0 else { return paragraph }
284284
return defaultVisit(paragraph)
285285
}
286286

287-
mutating func visitText(_ text: Text) -> Markup? {
287+
mutating func visitText(_ text: Text) -> (any Markup)? {
288288
// Only manipulate the first text node (of the first paragraph).
289289
guard text.indexInParent == 0 else { return text }
290290

@@ -316,13 +316,13 @@ private struct SimpleFieldMarkupRewriter: MarkupRewriter {
316316
/// Populated if the list item to which this is applied represents a valid simple field.
317317
private(set) var paragraph: Paragraph? = nil
318318

319-
mutating func visitListItem(_ listItem: ListItem) -> Markup? {
319+
mutating func visitListItem(_ listItem: ListItem) -> (any Markup)? {
320320
// Only recurse into the exact list item we're applying this to; otherwise, return it unchanged.
321321
guard listItem.isIdentical(to: origin) else { return listItem }
322322
return defaultVisit(listItem)
323323
}
324324

325-
mutating func visitParagraph(_ paragraph: Paragraph) -> Markup? {
325+
mutating func visitParagraph(_ paragraph: Paragraph) -> (any Markup)? {
326326
// Only recurse into the first paragraph in the list item.
327327
guard paragraph.indexInParent == 0 else { return paragraph }
328328
guard let newNode = defaultVisit(paragraph) else { return nil }
@@ -331,7 +331,7 @@ private struct SimpleFieldMarkupRewriter: MarkupRewriter {
331331
return newParagraph
332332
}
333333

334-
mutating func visitText(_ text: Text) -> Markup? {
334+
mutating func visitText(_ text: Text) -> (any Markup)? {
335335
// Only manipulate the first text node (of the first paragraph).
336336
guard text.indexInParent == 0 else { return text }
337337

Sources/SwiftFormat/Core/FindingEmitter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class FindingEmitter {
4242
/// related locations in the source file.
4343
public func emit(
4444
_ message: Finding.Message,
45-
category: FindingCategorizing,
45+
category: any FindingCategorizing,
4646
location: Finding.Location? = nil,
4747
notes: [Finding.Note] = []
4848
) {

Sources/SwiftFormat/Core/Pipelines+Generated.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class LintPipeline: SyntaxVisitor {
2424

2525
/// Stores lint and format rule instances, indexed by the `ObjectIdentifier` of a rule's
2626
/// class type.
27-
var ruleCache = [ObjectIdentifier: Rule]()
27+
var ruleCache = [ObjectIdentifier: any Rule]()
2828

2929
/// Rules present in this dictionary skip visiting children until they leave the
3030
/// syntax node stored as their value
31-
var shouldSkipChildren = [ObjectIdentifier: SyntaxProtocol]()
31+
var shouldSkipChildren = [ObjectIdentifier: any SyntaxProtocol]()
3232

3333
/// Creates a new lint pipeline.
3434
init(context: Context) {

Sources/SwiftFormat/Core/RuleBasedFindingCategory.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
/// defaults to the rule's type name).
1919
struct RuleBasedFindingCategory: FindingCategorizing {
2020
/// The type of the rule associated with this category.
21-
private let ruleType: Rule.Type
21+
private let ruleType: any Rule.Type
2222

2323
var description: String { ruleType.ruleName }
2424

2525
/// Creates a finding category that wraps the given rule type.
26-
init(ruleType: Rule.Type) {
26+
init(ruleType: any Rule.Type) {
2727
self.ruleType = ruleType
2828
}
2929
}

Sources/SwiftFormat/Core/SyntaxTraits.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ extension FunctionCallExprSyntax: CallingExprSyntaxProtocol {}
2121
extension SubscriptCallExprSyntax: CallingExprSyntaxProtocol {}
2222

2323
extension Syntax {
24-
func asProtocol(_: CallingExprSyntaxProtocol.Protocol) -> CallingExprSyntaxProtocol? {
25-
return self.asProtocol(SyntaxProtocol.self) as? CallingExprSyntaxProtocol
24+
func asProtocol(_: (any CallingExprSyntaxProtocol).Protocol) -> (any CallingExprSyntaxProtocol)? {
25+
return self.asProtocol((any SyntaxProtocol).self) as? (any CallingExprSyntaxProtocol)
2626
}
27-
func isProtocol(_: CallingExprSyntaxProtocol.Protocol) -> Bool {
28-
return self.asProtocol(CallingExprSyntaxProtocol.self) != nil
27+
func isProtocol(_: (any CallingExprSyntaxProtocol).Protocol) -> Bool {
28+
return self.asProtocol((any CallingExprSyntaxProtocol).self) != nil
2929
}
3030
}
3131

3232
extension ExprSyntax {
33-
func asProtocol(_: CallingExprSyntaxProtocol.Protocol) -> CallingExprSyntaxProtocol? {
34-
return Syntax(self).asProtocol(SyntaxProtocol.self) as? CallingExprSyntaxProtocol
33+
func asProtocol(_: (any CallingExprSyntaxProtocol).Protocol) -> (any CallingExprSyntaxProtocol)? {
34+
return Syntax(self).asProtocol((any SyntaxProtocol).self) as? (any CallingExprSyntaxProtocol)
3535
}
36-
func isProtocol(_: CallingExprSyntaxProtocol.Protocol) -> Bool {
37-
return self.asProtocol(CallingExprSyntaxProtocol.self) != nil
36+
func isProtocol(_: (any CallingExprSyntaxProtocol).Protocol) -> Bool {
37+
return self.asProtocol((any CallingExprSyntaxProtocol).self) != nil
3838
}
3939
}
4040

@@ -49,41 +49,41 @@ extension TryExprSyntax: KeywordModifiedExprSyntaxProtocol {}
4949
extension UnsafeExprSyntax: KeywordModifiedExprSyntaxProtocol {}
5050

5151
extension Syntax {
52-
func asProtocol(_: KeywordModifiedExprSyntaxProtocol.Protocol) -> KeywordModifiedExprSyntaxProtocol? {
53-
return self.asProtocol(SyntaxProtocol.self) as? KeywordModifiedExprSyntaxProtocol
52+
func asProtocol(_: (any KeywordModifiedExprSyntaxProtocol).Protocol) -> (any KeywordModifiedExprSyntaxProtocol)? {
53+
return self.asProtocol((any SyntaxProtocol).self) as? (any KeywordModifiedExprSyntaxProtocol)
5454
}
55-
func isProtocol(_: KeywordModifiedExprSyntaxProtocol.Protocol) -> Bool {
56-
return self.asProtocol(KeywordModifiedExprSyntaxProtocol.self) != nil
55+
func isProtocol(_: (any KeywordModifiedExprSyntaxProtocol).Protocol) -> Bool {
56+
return self.asProtocol((any KeywordModifiedExprSyntaxProtocol).self) != nil
5757
}
5858
}
5959

6060
extension ExprSyntax {
61-
func asProtocol(_: KeywordModifiedExprSyntaxProtocol.Protocol) -> KeywordModifiedExprSyntaxProtocol? {
62-
return Syntax(self).asProtocol(SyntaxProtocol.self) as? KeywordModifiedExprSyntaxProtocol
61+
func asProtocol(_: (any KeywordModifiedExprSyntaxProtocol).Protocol) -> (any KeywordModifiedExprSyntaxProtocol)? {
62+
return Syntax(self).asProtocol((any SyntaxProtocol).self) as? (any KeywordModifiedExprSyntaxProtocol)
6363
}
64-
func isProtocol(_: KeywordModifiedExprSyntaxProtocol.Protocol) -> Bool {
65-
return self.asProtocol(KeywordModifiedExprSyntaxProtocol.self) != nil
64+
func isProtocol(_: (any KeywordModifiedExprSyntaxProtocol).Protocol) -> Bool {
65+
return self.asProtocol((any KeywordModifiedExprSyntaxProtocol).self) != nil
6666
}
6767
}
6868

6969
/// Common protocol implemented by comma-separated lists whose elements
7070
/// support a `trailingComma`.
7171
protocol CommaSeparatedListSyntaxProtocol: SyntaxCollection where Element: WithTrailingCommaSyntax & Equatable {
7272
/// The node used for trailing comma handling; inserted immediately after this node.
73-
var lastNodeForTrailingComma: SyntaxProtocol? { get }
73+
var lastNodeForTrailingComma: (any SyntaxProtocol)? { get }
7474
}
7575

7676
extension ArrayElementListSyntax: CommaSeparatedListSyntaxProtocol {
77-
var lastNodeForTrailingComma: SyntaxProtocol? { last?.expression }
77+
var lastNodeForTrailingComma: (any SyntaxProtocol)? { last?.expression }
7878
}
7979
extension DictionaryElementListSyntax: CommaSeparatedListSyntaxProtocol {
80-
var lastNodeForTrailingComma: SyntaxProtocol? { last }
80+
var lastNodeForTrailingComma: (any SyntaxProtocol)? { last }
8181
}
8282
extension LabeledExprListSyntax: CommaSeparatedListSyntaxProtocol {
83-
var lastNodeForTrailingComma: SyntaxProtocol? { last?.expression }
83+
var lastNodeForTrailingComma: (any SyntaxProtocol)? { last?.expression }
8484
}
8585
extension ClosureCaptureListSyntax: CommaSeparatedListSyntaxProtocol {
86-
var lastNodeForTrailingComma: SyntaxProtocol? {
86+
var lastNodeForTrailingComma: (any SyntaxProtocol)? {
8787
if let initializer = last?.initializer {
8888
return initializer
8989
} else {
@@ -92,7 +92,7 @@ extension ClosureCaptureListSyntax: CommaSeparatedListSyntaxProtocol {
9292
}
9393
}
9494
extension EnumCaseParameterListSyntax: CommaSeparatedListSyntaxProtocol {
95-
var lastNodeForTrailingComma: SyntaxProtocol? {
95+
var lastNodeForTrailingComma: (any SyntaxProtocol)? {
9696
if let defaultValue = last?.defaultValue {
9797
return defaultValue
9898
} else {
@@ -101,7 +101,7 @@ extension EnumCaseParameterListSyntax: CommaSeparatedListSyntaxProtocol {
101101
}
102102
}
103103
extension FunctionParameterListSyntax: CommaSeparatedListSyntaxProtocol {
104-
var lastNodeForTrailingComma: SyntaxProtocol? {
104+
var lastNodeForTrailingComma: (any SyntaxProtocol)? {
105105
if let defaultValue = last?.defaultValue {
106106
return defaultValue
107107
} else if let ellipsis = last?.ellipsis {
@@ -112,7 +112,7 @@ extension FunctionParameterListSyntax: CommaSeparatedListSyntaxProtocol {
112112
}
113113
}
114114
extension GenericParameterListSyntax: CommaSeparatedListSyntaxProtocol {
115-
var lastNodeForTrailingComma: SyntaxProtocol? {
115+
var lastNodeForTrailingComma: (any SyntaxProtocol)? {
116116
if let inheritedType = last?.inheritedType {
117117
return inheritedType
118118
} else {
@@ -121,12 +121,12 @@ extension GenericParameterListSyntax: CommaSeparatedListSyntaxProtocol {
121121
}
122122
}
123123
extension TuplePatternElementListSyntax: CommaSeparatedListSyntaxProtocol {
124-
var lastNodeForTrailingComma: SyntaxProtocol? { last?.pattern }
124+
var lastNodeForTrailingComma: (any SyntaxProtocol)? { last?.pattern }
125125
}
126126

127127
extension SyntaxProtocol {
128128
func asProtocol(_: (any CommaSeparatedListSyntaxProtocol).Protocol) -> (any CommaSeparatedListSyntaxProtocol)? {
129-
return Syntax(self).asProtocol(SyntaxProtocol.self) as? (any CommaSeparatedListSyntaxProtocol)
129+
return Syntax(self).asProtocol((any SyntaxProtocol).self) as? (any CommaSeparatedListSyntaxProtocol)
130130
}
131131
func isProtocol(_: (any CommaSeparatedListSyntaxProtocol).Protocol) -> Bool {
132132
return self.asProtocol((any CommaSeparatedListSyntaxProtocol).self) != nil

Sources/SwiftFormat/Core/WithSemicolonSyntax.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ extension MemberBlockItemSyntax: WithSemicolonSyntax {}
2121
extension CodeBlockItemSyntax: WithSemicolonSyntax {}
2222

2323
extension SyntaxProtocol {
24-
func asProtocol(_: WithSemicolonSyntax.Protocol) -> WithSemicolonSyntax? {
25-
return Syntax(self).asProtocol(SyntaxProtocol.self) as? WithSemicolonSyntax
24+
func asProtocol(_: (any WithSemicolonSyntax).Protocol) -> (any WithSemicolonSyntax)? {
25+
return Syntax(self).asProtocol((any SyntaxProtocol).self) as? (any WithSemicolonSyntax)
2626
}
2727

28-
func isProtocol(_: WithSemicolonSyntax.Protocol) -> Bool {
29-
return self.asProtocol(WithSemicolonSyntax.self) != nil
28+
func isProtocol(_: (any WithSemicolonSyntax).Protocol) -> Bool {
29+
return self.asProtocol((any WithSemicolonSyntax).self) != nil
3030
}
3131
}

0 commit comments

Comments
 (0)