Skip to content

Clean up dead code #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Sources/SwiftBasicFormat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ add_library(SwiftBasicFormat STATIC
generated/BasicFormat.swift
SyntaxProtocol+Formatted.swift
Trivia+Indented.swift
Utils.swift
)

target_link_libraries(SwiftBasicFormat PUBLIC
Expand Down
24 changes: 0 additions & 24 deletions Sources/SwiftBasicFormat/Utils.swift

This file was deleted.

4 changes: 0 additions & 4 deletions Sources/SwiftParser/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ extension Lexer {
return self.pointer.distance(to: other.pointer)
}

func absoluteDistance(to other: Self) -> AbsolutePosition {
return AbsolutePosition(utf8Offset: self.distance(to: other))
}

func peek(at offset: Int = 0) -> UInt8 {
assert(!self.isAtEndOfFile)
assert(offset >= 0)
Expand Down
45 changes: 0 additions & 45 deletions Sources/SwiftParser/Lookahead.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,51 +244,6 @@ extension Parser.Lookahead {

// MARK: Lookahead

extension Parser.Lookahead {
private static let declAttributeNames: [SyntaxText] = [
"autoclosure",
"convention",
"noescape",
"escaping",
"differentiable",
"noDerivative",
"async",
"Sendable",
"unchecked",
"_local",
"block_storage",
"box",
"dynamic_self",
"sil_weak",
"sil_unowned",
"sil_unmanaged",
"error",
"out",
"in",
"inout",
"inout_aliasable",
"in_guaranteed",
"in_constant",
"owned",
"unowned_inner_pointer",
"guaranteed",
"autoreleased",
"callee_owned",
"callee_guaranteed",
"objc_metatype",
"opened",
"pseudogeneric",
"yields",
"yield_once",
"yield_many",
"captures_generics",
"thin",
"thick",
"_opaqueReturnTypeOf",
]

}

extension Parser.Lookahead {
func isStartOfGetSetAccessor() -> Bool {
assert(self.at(.leftBrace), "not checking a brace?")
Expand Down
6 changes: 0 additions & 6 deletions Sources/SwiftParser/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ extension Parser {
)
}

mutating func parseSingleArgumentModifier() -> RawDeclModifierSyntax {
let keyword = self.consumeAnyToken(remapping: .contextualKeyword)
let detail = self.parseModifierDetail()
return RawDeclModifierSyntax(name: keyword, detail: detail, arena: self.arena)
}

mutating func parseUnownedModifier() -> RawDeclModifierSyntax {
let (unexpectedBeforeKeyword, keyword) = self.expectContextualKeyword("unowned")

Expand Down
12 changes: 0 additions & 12 deletions Sources/SwiftParser/Patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,6 @@ extension Parser.Lookahead {
return self.consume(if: .rightParen) != nil
}

/// typed-pattern ::= pattern (':' type)?
mutating func canParseTypedPattern() -> Bool {
guard self.canParsePattern() else {
return false
}

if self.consume(if: .colon) != nil {
return self.canParseType()
}
return true
}

/// Determine whether we are at the start of a parameter name when
/// parsing a parameter.
/// If `allowMisplacedSpecifierRecovery` is `true`, then this will skip over any type
Expand Down
99 changes: 0 additions & 99 deletions Sources/SwiftParser/RawTokenKindSubset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,105 +107,6 @@ enum BinaryOperator: RawTokenKindSubset {
}
}

enum CanBeDeclaratinStart: RawTokenKindSubset {
case associatedtypeKeyword
case atSign
case caseKeyword
case classKeyword
case deinitKeyword
case enumKeyword
case extensionKeyword
case fileprivateKeyword
case funcKeyword
case identifier
case importKeyword
case initKeyword
case internalKeyword
case letKeyword
case operatorKeyword
case poundErrorKeyword
case poundIfKeyword
case poundSourceLocationKeyword
case poundWarningKeyword
case precedencegroupKeyword
case privateKeyword
case protocolKeyword
case publicKeyword
case staticKeyword
case structKeyword
case subscriptKeyword
case typealiasKeyword
case varKeyword

init?(lexeme: Lexer.Lexeme) {
switch lexeme.tokenKind {
case .associatedtypeKeyword: self = .associatedtypeKeyword
case .atSign: self = .atSign
case .caseKeyword: self = .caseKeyword
case .classKeyword: self = .classKeyword
case .deinitKeyword: self = .deinitKeyword
case .enumKeyword: self = .enumKeyword
case .extensionKeyword: self = .extensionKeyword
case .fileprivateKeyword: self = .fileprivateKeyword
case .funcKeyword: self = .funcKeyword
case .identifier: self = .identifier
case .importKeyword: self = .importKeyword
case .initKeyword: self = .initKeyword
case .internalKeyword: self = .internalKeyword
case .letKeyword: self = .letKeyword
case .operatorKeyword: self = .operatorKeyword
case .poundErrorKeyword: self = .poundErrorKeyword
case .poundIfKeyword: self = .poundIfKeyword
case .poundSourceLocationKeyword: self = .poundSourceLocationKeyword
case .poundWarningKeyword: self = .poundWarningKeyword
case .precedencegroupKeyword: self = .precedencegroupKeyword
case .privateKeyword: self = .privateKeyword
case .protocolKeyword: self = .protocolKeyword
case .publicKeyword: self = .publicKeyword
case .staticKeyword: self = .staticKeyword
case .structKeyword: self = .structKeyword
case .subscriptKeyword: self = .subscriptKeyword
case .typealiasKeyword: self = .typealiasKeyword
case .varKeyword: self = .varKeyword
default: return nil
}
}

var rawTokenKind: RawTokenKind {
switch self {
case .associatedtypeKeyword: return .associatedtypeKeyword
case .atSign: return .atSign
case .caseKeyword: return .caseKeyword
case .classKeyword: return .classKeyword
case .deinitKeyword: return .deinitKeyword
case .enumKeyword: return .enumKeyword
case .extensionKeyword: return .extensionKeyword
case .fileprivateKeyword: return .fileprivateKeyword
case .funcKeyword: return .funcKeyword
case .identifier: return .identifier
case .importKeyword: return .importKeyword
case .initKeyword: return .initKeyword
case .internalKeyword: return .internalKeyword
case .letKeyword: return .letKeyword
case .operatorKeyword: return .operatorKeyword
case .poundErrorKeyword: return .poundErrorKeyword
case .poundIfKeyword: return .poundIfKeyword
case .poundSourceLocationKeyword: return .poundSourceLocationKeyword
case .poundWarningKeyword: return .poundWarningKeyword
case .precedencegroupKeyword: return .precedencegroupKeyword
case .privateKeyword: return .privateKeyword
case .protocolKeyword: return .protocolKeyword
case .publicKeyword: return .publicKeyword
case .staticKeyword: return .staticKeyword
case .structKeyword: return .structKeyword
case .subscriptKeyword: return .subscriptKeyword
case .typealiasKeyword: return .typealiasKeyword
case .varKeyword: return .varKeyword
}
}

}

enum CanBeStatementStart: RawTokenKindSubset {
case breakKeyword
case continueKeyword
Expand Down
5 changes: 0 additions & 5 deletions Sources/SwiftParser/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,6 @@ extension Parser.Lookahead {
}
}

func isBooleanExpr() -> Bool {
var lookahead = self.lookahead()
return !lookahead.canParseTypedPattern() || !lookahead.at(.equal)
}

/// Returns whether the parser's current position is the start of a switch case,
/// given that we're in the middle of a switch already.
func isAtStartOfSwitchCase(allowRecovery: Bool = false) -> Bool {
Expand Down
10 changes: 0 additions & 10 deletions Sources/SwiftParserDiagnostics/SyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ extension UnexpectedNodesSyntax {
return self.tokens(satisfying: { $0.tokenKind == kind })
}

/// If this only contains a single item that is a token, return that token, otherwise return `nil`.
var onlyToken: TokenSyntax? {
return onlyToken(where: { _ in true })
}

/// If this only contains a single item, which is a token satisfying `condition`, return that token, otherwise return `nil`.
func onlyToken(where condition: (TokenSyntax) -> Bool) -> TokenSyntax? {
if self.count == 1, let token = self.first?.as(TokenSyntax.self), condition(token) {
Expand Down Expand Up @@ -94,11 +89,6 @@ extension SyntaxProtocol {
}
}

/// Returns this node or the first ancestor that satisfies `condition`.
func ancestorOrSelf(where condition: (Syntax) -> Bool) -> Syntax? {
return ancestorOrSelf(mapping: { condition($0) ? $0 : nil })
}

/// Returns this node or the first ancestor that satisfies `condition`.
func ancestorOrSelf<T>(mapping map: (Syntax) -> T?) -> T? {
var walk: Syntax? = Syntax(self)
Expand Down
12 changes: 0 additions & 12 deletions Sources/SwiftParserDiagnostics/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
//===----------------------------------------------------------------------===//

extension String {
/// Remove any leading or trailing spaces.
/// This is necessary to avoid depending SwiftParser on Foundation.
func trimmingWhitespace() -> String {
let charactersToDrop: [Character] = [" ", "\t", "\n", "\r"]
var result: Substring = Substring(self)
result = result.drop(while: { charactersToDrop.contains($0) })
while let lastCharacter = result.last, charactersToDrop.contains(lastCharacter) {
result = result.dropLast(1)
}
return String(result)
}

func withFirstLetterUppercased() -> String {
if let firstLetter = self.first {
return firstLetter.uppercased() + self.dropFirst()
Expand Down
10 changes: 0 additions & 10 deletions Sources/SwiftSyntax/Raw/RawSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@ extension RawSyntax {
kind == .token
}

/// Whether or not this node is a collection one.
var isCollection: Bool {
kind.isSyntaxCollection
}

/// Whether or not this node is an unknown one.
var isUnknown: Bool {
kind.isUnknown
}

var recursiveFlags: RecursiveRawSyntaxFlags {
switch view {
case .token(let tokenView):
Expand Down
8 changes: 0 additions & 8 deletions Sources/SwiftSyntax/Raw/RawSyntaxTokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ public struct RawSyntaxTokenView {
return Trivia(pieces: trailingRawTriviaPieces.map({ TriviaPiece(raw: $0) }))
}

/// Calls `body` with the token text. The token text value must not escape the closure.
@_spi(RawSyntax)
public func withUnsafeTokenText<Result>(
_ body: (SyntaxText?) -> Result
) -> Result {
body(rawText)
}

/// Returns a `RawSyntax` node with the same source text but with the token
/// kind changed to `newValue`.
@_spi(RawSyntax)
Expand Down
35 changes: 0 additions & 35 deletions Sources/SwiftSyntax/SyntaxData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ struct AbsoluteSyntaxPosition {
return .init(offset: newOffset, indexInParent: newIndexInParent)
}

func reversedBySibling(_ raw: RawSyntax?) -> AbsoluteSyntaxPosition {
let newOffset = self.offset - UInt32(truncatingIfNeeded: raw?.totalLength.utf8Length ?? 0)
let newIndexInParent = self.indexInParent - 1
return .init(offset: newOffset, indexInParent: newIndexInParent)
}

func advancedToFirstChild() -> AbsoluteSyntaxPosition {
return .init(offset: self.offset, indexInParent: 0)
}
Expand All @@ -52,12 +46,6 @@ struct AbsoluteSyntaxInfo {
return .init(position: newPosition, nodeId: newNodeId)
}

func reversedBySibling(_ raw: RawSyntax?) -> AbsoluteSyntaxInfo {
let newPosition = position.reversedBySibling(raw)
let newNodeId = nodeId.reversedBySibling(raw)
return .init(position: newPosition, nodeId: newNodeId)
}

func advancedToFirstChild() -> AbsoluteSyntaxInfo {
let newPosition = position.advancedToFirstChild()
let newNodeId = nodeId.advancedToFirstChild()
Expand Down Expand Up @@ -124,11 +112,6 @@ public struct SyntaxIdentifier: Hashable {
return .init(rootId: self.rootId, indexInTree: newIndexInTree)
}

func reversedBySibling(_ raw: RawSyntax?) -> SyntaxIdentifier {
let newIndexInTree = self.indexInTree.reversedBy(raw)
return .init(rootId: self.rootId, indexInTree: newIndexInTree)
}

func advancedToFirstChild() -> SyntaxIdentifier {
let newIndexInTree = self.indexInTree.advancedToFirstChild()
return .init(rootId: self.rootId, indexInTree: newIndexInTree)
Expand All @@ -144,16 +127,6 @@ struct AbsoluteRawSyntax {
let raw: RawSyntax
let info: AbsoluteSyntaxInfo

/// The position of the start of this node's leading trivia
var position: AbsolutePosition {
return AbsolutePosition(utf8Offset: Int(info.offset))
}

/// The end position of this node, including its trivia.
var endPosition: AbsolutePosition {
return position + raw.totalLength
}

/// Returns first `present` child.
func firstChild(viewMode: SyntaxTreeViewMode) -> AbsoluteRawSyntax? {
guard let layoutView = raw.layoutView else { return nil }
Expand Down Expand Up @@ -184,10 +157,6 @@ struct AbsoluteRawSyntax {
let newInfo = AbsoluteSyntaxInfo(position: info.position, nodeId: nodeId)
return .init(raw: newRaw, info: newInfo)
}

static func forRoot(_ raw: RawSyntax) -> AbsoluteRawSyntax {
return .init(raw: raw, info: .forRoot(raw))
}
}

/// SyntaxData is the underlying storage for each Syntax node.
Expand Down Expand Up @@ -228,10 +197,6 @@ struct SyntaxData {
}
}

private var rootArena: SyntaxArena {
rootInfo.arena
}

private var root: SyntaxData {
switch info {
case .root(_): return self
Expand Down
Loading