Skip to content

Commit 7cb0bcd

Browse files
committed
Clean up dead code
I didn't touch any public or codegen'd declarations, only internal or lower declarations that weren't used in anywhere in this project, including tests. These unused declarations were found using a SwiftLint rule that's still in development.
1 parent ef4605b commit 7cb0bcd

File tree

16 files changed

+0
-375
lines changed

16 files changed

+0
-375
lines changed

Sources/SwiftBasicFormat/Utils.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/SwiftParser/Lexer.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ extension Lexer {
227227
return self.pointer.distance(to: other.pointer)
228228
}
229229

230-
func absoluteDistance(to other: Self) -> AbsolutePosition {
231-
return AbsolutePosition(utf8Offset: self.distance(to: other))
232-
}
233-
234230
func peek(at offset: Int = 0) -> UInt8 {
235231
assert(!self.isAtEndOfFile)
236232
assert(offset >= 0)

Sources/SwiftParser/Lookahead.swift

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -244,51 +244,6 @@ extension Parser.Lookahead {
244244

245245
// MARK: Lookahead
246246

247-
extension Parser.Lookahead {
248-
private static let declAttributeNames: [SyntaxText] = [
249-
"autoclosure",
250-
"convention",
251-
"noescape",
252-
"escaping",
253-
"differentiable",
254-
"noDerivative",
255-
"async",
256-
"Sendable",
257-
"unchecked",
258-
"_local",
259-
"block_storage",
260-
"box",
261-
"dynamic_self",
262-
"sil_weak",
263-
"sil_unowned",
264-
"sil_unmanaged",
265-
"error",
266-
"out",
267-
"in",
268-
"inout",
269-
"inout_aliasable",
270-
"in_guaranteed",
271-
"in_constant",
272-
"owned",
273-
"unowned_inner_pointer",
274-
"guaranteed",
275-
"autoreleased",
276-
"callee_owned",
277-
"callee_guaranteed",
278-
"objc_metatype",
279-
"opened",
280-
"pseudogeneric",
281-
"yields",
282-
"yield_once",
283-
"yield_many",
284-
"captures_generics",
285-
"thin",
286-
"thick",
287-
"_opaqueReturnTypeOf",
288-
]
289-
290-
}
291-
292247
extension Parser.Lookahead {
293248
func isStartOfGetSetAccessor() -> Bool {
294249
assert(self.at(.leftBrace), "not checking a brace?")

Sources/SwiftParser/Modifiers.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ extension Parser {
107107
)
108108
}
109109

110-
mutating func parseSingleArgumentModifier() -> RawDeclModifierSyntax {
111-
let keyword = self.consumeAnyToken(remapping: .contextualKeyword)
112-
let detail = self.parseModifierDetail()
113-
return RawDeclModifierSyntax(name: keyword, detail: detail, arena: self.arena)
114-
}
115-
116110
mutating func parseUnownedModifier() -> RawDeclModifierSyntax {
117111
let (unexpectedBeforeKeyword, keyword) = self.expectContextualKeyword("unowned")
118112

Sources/SwiftParser/Patterns.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,6 @@ extension Parser.Lookahead {
325325
return self.consume(if: .rightParen) != nil
326326
}
327327

328-
/// typed-pattern ::= pattern (':' type)?
329-
mutating func canParseTypedPattern() -> Bool {
330-
guard self.canParsePattern() else {
331-
return false
332-
}
333-
334-
if self.consume(if: .colon) != nil {
335-
return self.canParseType()
336-
}
337-
return true
338-
}
339-
340328
/// Determine whether we are at the start of a parameter name when
341329
/// parsing a parameter.
342330
/// If `allowMisplacedSpecifierRecovery` is `true`, then this will skip over any type

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -107,105 +107,6 @@ enum BinaryOperator: RawTokenKindSubset {
107107
}
108108
}
109109

110-
enum CanBeDeclaratinStart: RawTokenKindSubset {
111-
case associatedtypeKeyword
112-
case atSign
113-
case caseKeyword
114-
case classKeyword
115-
case deinitKeyword
116-
case enumKeyword
117-
case extensionKeyword
118-
case fileprivateKeyword
119-
case funcKeyword
120-
case identifier
121-
case importKeyword
122-
case initKeyword
123-
case internalKeyword
124-
case letKeyword
125-
case operatorKeyword
126-
case poundErrorKeyword
127-
case poundIfKeyword
128-
case poundSourceLocationKeyword
129-
case poundWarningKeyword
130-
case precedencegroupKeyword
131-
case privateKeyword
132-
case protocolKeyword
133-
case publicKeyword
134-
case staticKeyword
135-
case structKeyword
136-
case subscriptKeyword
137-
case typealiasKeyword
138-
case varKeyword
139-
140-
init?(lexeme: Lexer.Lexeme) {
141-
switch lexeme.tokenKind {
142-
case .associatedtypeKeyword: self = .associatedtypeKeyword
143-
case .atSign: self = .atSign
144-
case .caseKeyword: self = .caseKeyword
145-
case .classKeyword: self = .classKeyword
146-
case .deinitKeyword: self = .deinitKeyword
147-
case .enumKeyword: self = .enumKeyword
148-
case .extensionKeyword: self = .extensionKeyword
149-
case .fileprivateKeyword: self = .fileprivateKeyword
150-
case .funcKeyword: self = .funcKeyword
151-
case .identifier: self = .identifier
152-
case .importKeyword: self = .importKeyword
153-
case .initKeyword: self = .initKeyword
154-
case .internalKeyword: self = .internalKeyword
155-
case .letKeyword: self = .letKeyword
156-
case .operatorKeyword: self = .operatorKeyword
157-
case .poundErrorKeyword: self = .poundErrorKeyword
158-
case .poundIfKeyword: self = .poundIfKeyword
159-
case .poundSourceLocationKeyword: self = .poundSourceLocationKeyword
160-
case .poundWarningKeyword: self = .poundWarningKeyword
161-
case .precedencegroupKeyword: self = .precedencegroupKeyword
162-
case .privateKeyword: self = .privateKeyword
163-
case .protocolKeyword: self = .protocolKeyword
164-
case .publicKeyword: self = .publicKeyword
165-
case .staticKeyword: self = .staticKeyword
166-
case .structKeyword: self = .structKeyword
167-
case .subscriptKeyword: self = .subscriptKeyword
168-
case .typealiasKeyword: self = .typealiasKeyword
169-
case .varKeyword: self = .varKeyword
170-
default: return nil
171-
}
172-
}
173-
174-
var rawTokenKind: RawTokenKind {
175-
switch self {
176-
case .associatedtypeKeyword: return .associatedtypeKeyword
177-
case .atSign: return .atSign
178-
case .caseKeyword: return .caseKeyword
179-
case .classKeyword: return .classKeyword
180-
case .deinitKeyword: return .deinitKeyword
181-
case .enumKeyword: return .enumKeyword
182-
case .extensionKeyword: return .extensionKeyword
183-
case .fileprivateKeyword: return .fileprivateKeyword
184-
case .funcKeyword: return .funcKeyword
185-
case .identifier: return .identifier
186-
case .importKeyword: return .importKeyword
187-
case .initKeyword: return .initKeyword
188-
case .internalKeyword: return .internalKeyword
189-
case .letKeyword: return .letKeyword
190-
case .operatorKeyword: return .operatorKeyword
191-
case .poundErrorKeyword: return .poundErrorKeyword
192-
case .poundIfKeyword: return .poundIfKeyword
193-
case .poundSourceLocationKeyword: return .poundSourceLocationKeyword
194-
case .poundWarningKeyword: return .poundWarningKeyword
195-
case .precedencegroupKeyword: return .precedencegroupKeyword
196-
case .privateKeyword: return .privateKeyword
197-
case .protocolKeyword: return .protocolKeyword
198-
case .publicKeyword: return .publicKeyword
199-
case .staticKeyword: return .staticKeyword
200-
case .structKeyword: return .structKeyword
201-
case .subscriptKeyword: return .subscriptKeyword
202-
case .typealiasKeyword: return .typealiasKeyword
203-
case .varKeyword: return .varKeyword
204-
}
205-
}
206-
207-
}
208-
209110
enum CanBeStatementStart: RawTokenKindSubset {
210111
case breakKeyword
211112
case continueKeyword

Sources/SwiftParser/Statements.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,6 @@ extension Parser.Lookahead {
12141214
}
12151215
}
12161216

1217-
func isBooleanExpr() -> Bool {
1218-
var lookahead = self.lookahead()
1219-
return !lookahead.canParseTypedPattern() || !lookahead.at(.equal)
1220-
}
1221-
12221217
/// Returns whether the parser's current position is the start of a switch case,
12231218
/// given that we're in the middle of a switch already.
12241219
func isAtStartOfSwitchCase(allowRecovery: Bool = false) -> Bool {

Sources/SwiftParserDiagnostics/SyntaxExtensions.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ extension UnexpectedNodesSyntax {
2121
return self.tokens(satisfying: { $0.tokenKind == kind })
2222
}
2323

24-
/// If this only contains a single item that is a token, return that token, otherwise return `nil`.
25-
var onlyToken: TokenSyntax? {
26-
return onlyToken(where: { _ in true })
27-
}
28-
2924
/// If this only contains a single item, which is a token satisfying `condition`, return that token, otherwise return `nil`.
3025
func onlyToken(where condition: (TokenSyntax) -> Bool) -> TokenSyntax? {
3126
if self.count == 1, let token = self.first?.as(TokenSyntax.self), condition(token) {
@@ -94,11 +89,6 @@ extension SyntaxProtocol {
9489
}
9590
}
9691

97-
/// Returns this node or the first ancestor that satisfies `condition`.
98-
func ancestorOrSelf(where condition: (Syntax) -> Bool) -> Syntax? {
99-
return ancestorOrSelf(mapping: { condition($0) ? $0 : nil })
100-
}
101-
10292
/// Returns this node or the first ancestor that satisfies `condition`.
10393
func ancestorOrSelf<T>(mapping map: (Syntax) -> T?) -> T? {
10494
var walk: Syntax? = Syntax(self)

Sources/SwiftParserDiagnostics/Utils.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
extension String {
14-
/// Remove any leading or trailing spaces.
15-
/// This is necessary to avoid depending SwiftParser on Foundation.
16-
func trimmingWhitespace() -> String {
17-
let charactersToDrop: [Character] = [" ", "\t", "\n", "\r"]
18-
var result: Substring = Substring(self)
19-
result = result.drop(while: { charactersToDrop.contains($0) })
20-
while let lastCharacter = result.last, charactersToDrop.contains(lastCharacter) {
21-
result = result.dropLast(1)
22-
}
23-
return String(result)
24-
}
25-
2614
func withFirstLetterUppercased() -> String {
2715
if let firstLetter = self.first {
2816
return firstLetter.uppercased() + self.dropFirst()

Sources/SwiftSyntax/Raw/RawSyntax.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,6 @@ extension RawSyntax {
156156
kind == .token
157157
}
158158

159-
/// Whether or not this node is a collection one.
160-
var isCollection: Bool {
161-
kind.isSyntaxCollection
162-
}
163-
164-
/// Whether or not this node is an unknown one.
165-
var isUnknown: Bool {
166-
kind.isUnknown
167-
}
168-
169159
var recursiveFlags: RecursiveRawSyntaxFlags {
170160
switch view {
171161
case .token(let tokenView):

Sources/SwiftSyntax/Raw/RawSyntaxTokenView.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,6 @@ public struct RawSyntaxTokenView {
142142
return Trivia(pieces: trailingRawTriviaPieces.map({ TriviaPiece(raw: $0) }))
143143
}
144144

145-
/// Calls `body` with the token text. The token text value must not escape the closure.
146-
@_spi(RawSyntax)
147-
public func withUnsafeTokenText<Result>(
148-
_ body: (SyntaxText?) -> Result
149-
) -> Result {
150-
body(rawText)
151-
}
152-
153145
/// Returns a `RawSyntax` node with the same source text but with the token
154146
/// kind changed to `newValue`.
155147
@_spi(RawSyntax)

Sources/SwiftSyntax/Syntax.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,6 @@ public extension SyntaxProtocol {
295295
return data.indexInParent
296296
}
297297

298-
/// Whether or not this node has a parent.
299-
var hasParent: Bool {
300-
return parent != nil
301-
}
302-
303-
/// Recursively walks through the tree to find the token semantically before
304-
/// this node.
305-
var previousToken: TokenSyntax? {
306-
return self.previousToken(viewMode: .sourceAccurate)
307-
}
308-
309298
/// Recursively walks through the tree to find the token semantically before
310299
/// this node.
311300
func previousToken(viewMode: SyntaxTreeViewMode) -> TokenSyntax? {
@@ -326,12 +315,6 @@ public extension SyntaxProtocol {
326315
return parent.previousToken(viewMode: viewMode)
327316
}
328317

329-
/// Recursively walks through the tree to find the next token semantically
330-
/// after this node.
331-
var nextToken: TokenSyntax? {
332-
return self.nextToken(viewMode: .sourceAccurate)
333-
}
334-
335318
/// Recursively walks through the tree to find the next token semantically
336319
/// after this node.
337320
func nextToken(viewMode: SyntaxTreeViewMode) -> TokenSyntax? {
@@ -370,11 +353,6 @@ public extension SyntaxProtocol {
370353
return nil
371354
}
372355

373-
/// Returns the last token node that is part of this syntax node.
374-
var lastToken: TokenSyntax? {
375-
return self.lastToken(viewMode: .sourceAccurate)
376-
}
377-
378356
/// Returns the last token node that is part of this syntax node.
379357
func lastToken(viewMode: SyntaxTreeViewMode) -> TokenSyntax? {
380358
guard viewMode.shouldTraverse(node: raw) else { return nil }
@@ -472,16 +450,6 @@ public extension SyntaxProtocol {
472450
}
473451
}
474452

475-
/// The length this node's leading trivia takes up spelled out in source.
476-
var leadingTriviaLength: SourceLength {
477-
return raw.leadingTriviaLength
478-
}
479-
480-
/// The length this node's trailing trivia takes up spelled out in source.
481-
var trailingTriviaLength: SourceLength {
482-
return raw.trailingTriviaLength
483-
}
484-
485453
/// Returns a new syntax node with its leading trivia replaced
486454
/// by the provided trivia.
487455
func withLeadingTrivia(_ leadingTrivia: Trivia) -> Self {
@@ -504,11 +472,6 @@ public extension SyntaxProtocol {
504472
return withTrailingTrivia([])
505473
}
506474

507-
/// Returns a new syntax node with all trivia removed.
508-
func withoutTrivia() -> Self {
509-
return withoutLeadingTrivia().withoutTrailingTrivia()
510-
}
511-
512475
/// The length of this node including all of its trivia.
513476
var totalLength: SourceLength {
514477
return raw.totalLength

0 commit comments

Comments
 (0)