Skip to content

[gardening] Trim trailing whitespace #79459

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ root = true
[*]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 1 addition & 1 deletion SwiftCompilerSources/Sources/AST/SubstitutionMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct SubstitutionMap: CustomStringConvertible {
public init(bridged: BridgedSubstitutionMap) {
self.bridged = bridged
}

public init() {
self.bridged = BridgedSubstitutionMap()
}
Expand Down
8 changes: 4 additions & 4 deletions SwiftCompilerSources/Sources/Basic/StringParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public struct StringParser {
private var s: Substring
private let originalLength: Int

private mutating func consumeWhitespace() {
s = s.drop { $0.isWhitespace }
}
Expand All @@ -23,7 +23,7 @@ public struct StringParser {
s = Substring(string)
originalLength = string.count
}

public mutating func isEmpty() -> Bool {
consumeWhitespace()
return s.isEmpty
Expand All @@ -50,7 +50,7 @@ public struct StringParser {
}
return Int(intStr)
}

public mutating func consumeIdentifier() -> String? {
consumeWhitespace()
var name = ""
Expand All @@ -63,7 +63,7 @@ public struct StringParser {
}
return name.isEmpty ? nil : name
}

public func throwError(_ message: StaticString) throws -> Never {
throw ParsingError(message: message, position: originalLength - s.count)
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftCompilerSources/Sources/Basic/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public struct StringRef : CustomStringConvertible, NoReflectionChildren {
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
}
}

public static func !=(lhs: StringRef, rhs: StaticString) -> Bool { !(lhs == rhs) }
public static func !=(lhs: StringRef, rhs: StringRef) -> Bool { !(lhs == rhs) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct CalleeAnalysis {
guard let callees = getCallees(callee: apply.callee) else {
return .worstEffects.restrictedTo(argument: argument, withConvention: convention)
}

for callee in callees {
let calleeEffects = callee.getSideEffects(forArgument: argument,
atIndex: calleeArgIdx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension BasicBlock {
func dominates(_ other: BasicBlock, _ domTree: DominatorTree) -> Bool {
domTree.bridged.dominates(self.bridged, other.bridged)
}

func strictlyDominates(_ other: BasicBlock, _ domTree: DominatorTree) -> Bool {
dominates(other, domTree) && self != other
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension BasicBlock {
func postDominates(_ other: BasicBlock, _ pdomTree: PostDominatorTree) -> Bool {
pdomTree.bridged.postDominates(self.bridged, other.bridged)
}

func strictlyPostDominates(_ other: BasicBlock, _ pdomTree: PostDominatorTree) -> Bool {
postDominates(other, pdomTree) && self != other
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct BasicBlockRange : CustomStringConvertible, NoReflectionChildren {

/// The inclusive range, i.e. the exclusive range plus the end blocks.
private(set) var inclusiveRange: Stack<BasicBlock>

/// The exclusive range, i.e. not containing the end blocks.
var range: LazyFilterSequence<Stack<BasicBlock>> {
inclusiveRange.lazy.filter { contains($0) }
Expand All @@ -65,7 +65,7 @@ struct BasicBlockRange : CustomStringConvertible, NoReflectionChildren {
private var wasInserted: BasicBlockSet
private var inExclusiveRange: BasicBlockSet
private var worklist: BasicBlockWorklist

init(begin: BasicBlock, _ context: some Context) {
self.begin = begin
self.inclusiveRange = Stack(context)
Expand Down Expand Up @@ -102,7 +102,7 @@ struct BasicBlockRange : CustomStringConvertible, NoReflectionChildren {

/// Returns true if the exclusive range contains `block`.
func contains(_ block: BasicBlock) -> Bool { inExclusiveRange.contains(block) }

/// Returns true if the inclusive range contains `block`.
func inclusiveRangeContains (_ block: BasicBlock) -> Bool {
worklist.hasBeenPushed(block)
Expand Down Expand Up @@ -136,7 +136,7 @@ struct BasicBlockRange : CustomStringConvertible, NoReflectionChildren {
var interiors: LazyFilterSequence<Stack<BasicBlock>> {
inserted.lazy.filter { contains($0) && $0 != begin }
}

var description: String {
return (isValid ? "" : "<invalid>\n") +
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ import SIL
struct DeadEndBlocks : CustomStringConvertible, NoReflectionChildren {
private var worklist: BasicBlockWorklist
private var function: Function

init(function: Function, _ context: FunctionPassContext) {
self.function = function
self.worklist = BasicBlockWorklist(context)

// Initialize the worklist with all function-exiting blocks.
for block in function.blocks where block.terminator.isFunctionExiting {
worklist.pushIfNotVisited(block)
}

// Propagate lifeness up the control flow.
while let block = worklist.pop() {
worklist.pushIfNotVisited(contentsOf: block.predecessors)
}
}

/// Returns true if `block` is a dead-end block.
func isDeadEnd(block: BasicBlock) -> Bool {
return !worklist.hasBeenPushed(block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct FunctionUses {
fileprivate struct FirstUse {
// The head of the use-list.
var first: Int?

// True if the function has unknown uses
var hasUnknownUses: Bool

Expand All @@ -60,7 +60,7 @@ struct FunctionUses {
struct Iterator : IteratorProtocol {
fileprivate let useStorage: [Use]
fileprivate var currentUseIdx: Int?

mutating func next() -> Instruction? {
if let useIdx = currentUseIdx {
let use = useStorage[useIdx]
Expand All @@ -86,20 +86,20 @@ struct FunctionUses {
func makeIterator() -> Iterator {
return Iterator(useStorage: useStorage, currentUseIdx: firstUse.first)
}

var description: String {
var result = "[\n"
if hasUnknownUses {
result += "<unknown uses>\n"
}
for inst in self {
result += "@\(inst.parentFunction.name): \(inst)\n"

}
result += "]"
return result
}

var customMirror: Mirror { Mirror(self, children: []) }
}

Expand All @@ -108,7 +108,7 @@ struct FunctionUses {

// The use-list head for each function.
private var uses: [Function: FirstUse] = [:]

/// Returns the use-list of `function`.
///
/// Note that `collect` must be called before `getUses` can be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import SIL
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
/// destruct this data structure, e.g. in a `defer {}` block.
struct InstructionRange : CustomStringConvertible, NoReflectionChildren {

/// The underlying block range.
private(set) var blockRange: BasicBlockRange

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct BasicBlockSet : IntrusiveSet {

private let context: BridgedPassContext
private let bridged: BridgedBasicBlockSet

init(_ context: some Context) {
self.context = context._bridged
self.bridged = self.context.allocBasicBlockSet()
Expand Down Expand Up @@ -80,7 +80,7 @@ struct ValueSet : IntrusiveSet {

private let context: BridgedPassContext
private let bridged: BridgedNodeSet

init(_ context: some Context) {
self.context = context._bridged
self.bridged = self.context.allocNodeSet()
Expand Down Expand Up @@ -139,7 +139,7 @@ struct SpecificInstructionSet<InstType: Instruction> : IntrusiveSet {

private let context: BridgedPassContext
private let bridged: BridgedNodeSet

init(_ context: some Context) {
self.context = context._bridged
self.bridged = self.context.allocNodeSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ struct Stack<Element> : CollectionLikeSequence {
var index: Int
let lastSlab: BridgedPassContext.Slab
let endIndex: Int

mutating func next() -> Element? {
let end = (slab.data == lastSlab.data ? endIndex : slabCapacity)

guard index < end else { return nil }

let elem = Stack.element(in: slab, at: index)
index += 1

if index >= end && slab.data != lastSlab.data {
slab = slab.getNext()
index = 0
}
return elem
}
}

init(_ context: some Context) { self.bridgedContext = context._bridged }

func makeIterator() -> Iterator {
Expand Down Expand Up @@ -109,15 +109,15 @@ struct Stack<Element> : CollectionLikeSequence {
}

var isEmpty: Bool { return endIndex == 0 }

mutating func pop() -> Element? {
if isEmpty {
return nil
}
assert(endIndex > 0)
endIndex -= 1
let elem = Stack.pointer(in: lastSlab, at: endIndex).move()

if endIndex == 0 {
if lastSlab.data == firstSlab.data {
_ = bridgedContext.freeSlab(lastSlab)
Expand All @@ -132,7 +132,7 @@ struct Stack<Element> : CollectionLikeSequence {

return elem
}

mutating func removeAll() {
while pop() != nil { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Worklist<Set: IntrusiveSet> : CustomStringConvertible, NoReflectionChildr
self.worklist = Stack(context)
self.pushedElements = Set(context)
}

mutating func pop() -> Element? { return worklist.pop() }

/// Pop and allow the popped element to be pushed again to the worklist.
Expand Down
Loading