Skip to content

Commit 1840690

Browse files
author
Dave Abrahams
authored
Name and label changes for closure parameters (for review only) (#2981)
Implement SE-0118 Name and label changes for closure parameters [SE-0118](https://github.com/apple/swift-evolution/blob/master/proposals/0118-closure-parameter-names-and-labels.md)
1 parent a77539a commit 1840690

File tree

65 files changed

+382
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+382
-350
lines changed

benchmark/single-source/CaptureProp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func benchCaptureProp<S : Sequence
2121

2222
var it = s.makeIterator()
2323
let initial = it.next()!
24-
return IteratorSequence(it).reduce(initial, combine: f)
24+
return IteratorSequence(it).reduce(initial, f)
2525
}
2626

2727
public func run_CaptureProp(_ N: Int) {

benchmark/single-source/MapReduce.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public func run_MapReduce(_ N: Int) {
2020
var c = 0
2121
for _ in 1...N*100 {
2222
numbers = numbers.map({$0 &+ 5})
23-
c += numbers.reduce(0, combine: &+)
23+
c += numbers.reduce(0, &+)
2424
}
2525
CheckResults(c != 0, "IncorrectResults in MapReduce")
2626
}

benchmark/single-source/SortStrings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ func benchSortStrings(_ words: [String]) {
10211021
// Notice that we _copy_ the array of words before we sort it.
10221022
// Pass an explicit '<' predicate to benchmark reabstraction thunks.
10231023
var tempwords = words
1024-
tempwords.sort(isOrderedBefore: <)
1024+
tempwords.sort(by: <)
10251025
}
10261026

10271027
public func run_SortStrings(_ N: Int) {

stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ public struct ${Self}<
229229
}
230230

231231
public func filter(
232-
_ includeElement: @noescape (Base.Iterator.Element) throws -> Bool
232+
_ isIncluded: @noescape (Base.Iterator.Element) throws -> Bool
233233
) rethrows -> [Base.Iterator.Element] {
234234
Log.filter[selfType] += 1
235-
return try base.filter(includeElement)
235+
return try base.filter(isIncluded)
236236
}
237237

238238
public func forEach(
@@ -274,13 +274,13 @@ public struct ${Self}<
274274
public func split(
275275
maxSplits: Int = Int.max,
276276
omittingEmptySubsequences: Bool = true,
277-
isSeparator: @noescape (Base.Iterator.Element) throws -> Bool
277+
whereSeparator isSeparator: @noescape (Base.Iterator.Element) throws -> Bool
278278
) rethrows -> [SubSequence] {
279279
Log.split[selfType] += 1
280280
return try base.split(
281281
maxSplits: maxSplits,
282282
omittingEmptySubsequences: omittingEmptySubsequences,
283-
isSeparator: isSeparator)
283+
whereSeparator: isSeparator)
284284
}
285285

286286
public func _customContainsEquatableElement(

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ internal struct ClosureBasedRaceTest : RaceTestWithPerTrialData {
596596
) {}
597597
}
598598

599-
public func runRaceTest(trials: Int, threads: Int? = nil, body: () -> ()) {
599+
public func runRaceTest(
600+
trials: Int, threads: Int? = nil, invoking body: () -> ()
601+
) {
600602
ClosureBasedRaceTest.thread = body
601603
runRaceTest(ClosureBasedRaceTest.self, trials: trials, threads: threads)
602604
}

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ extension MutableCollection
214214
}
215215

216216
/// Generate all permutations.
217-
public func forAllPermutations(_ size: Int, body: ([Int]) -> Void) {
217+
public func forAllPermutations(_ size: Int, _ body: ([Int]) -> Void) {
218218
var data = Array(0..<size)
219219
repeat {
220220
body(data)
@@ -223,7 +223,7 @@ public func forAllPermutations(_ size: Int, body: ([Int]) -> Void) {
223223

224224
/// Generate all permutations.
225225
public func forAllPermutations<S : Sequence>(
226-
_ sequence: S, body: ([S.Iterator.Element]) -> Void
226+
_ sequence: S, _ body: ([S.Iterator.Element]) -> Void
227227
) {
228228
let data = Array(sequence)
229229
forAllPermutations(data.count) {

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var _seenExpectCrash = false
107107
/// Run `body` and expect a failure to happen.
108108
///
109109
/// The check passes iff `body` triggers one or more failures.
110-
public func expectFailure(${TRACE}, body: () -> Void) {
110+
public func expectFailure(${TRACE}, invoking body: () -> Void) {
111111
let startAnyExpectFailed = _anyExpectFailed
112112
_anyExpectFailed = false
113113
body()
@@ -2228,7 +2228,7 @@ public func expectEqualSequence<
22282228
) where
22292229
Expected.Iterator.Element == Actual.Iterator.Element {
22302230

2231-
if !expected.elementsEqual(actual, isEquivalent: sameValue) {
2231+
if !expected.elementsEqual(actual, by: sameValue) {
22322232
expectationFailure("expected elements: \"\(expected)\"\n"
22332233
+ "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))",
22342234
trace: ${trace})
@@ -2246,9 +2246,9 @@ public func expectEqualsUnordered<
22462246
Expected.Iterator.Element == Actual.Iterator.Element {
22472247

22482248
let x: [Expected.Iterator.Element] =
2249-
expected.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
2249+
expected.sorted(by: compose(compare, { $0.isLT() }))
22502250
let y: [Actual.Iterator.Element] =
2251-
actual.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
2251+
actual.sorted(by: compose(compare, { $0.isLT() }))
22522252
expectEqualSequence(
22532253
x, y, ${trace}, sameValue: compose(compare, { $0.isEQ() }))
22542254
}
@@ -2345,10 +2345,10 @@ public func expectEqualsUnordered<
23452345
}
23462346

23472347
let x: [(T, T)] =
2348-
expected.sorted(isOrderedBefore: comparePairLess)
2348+
expected.sorted(by: comparePairLess)
23492349
let y: [(T, T)] =
23502350
actual.map { ($0.0, $0.1) }
2351-
.sorted(isOrderedBefore: comparePairLess)
2351+
.sorted(by: comparePairLess)
23522352

23532353
func comparePairEquals(_ lhs: (T, T), rhs: (key: T, value: T)) -> Bool {
23542354
return lhs.0 == rhs.0 && lhs.1 == rhs.1

stdlib/private/StdlibUnittest/TypeIndexed.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension TypeIndexed where Value : Strideable {
5959
showFrame: Bool = true,
6060
stackTrace: SourceLocStack = SourceLocStack(),
6161
file: String = #file, line: UInt = #line,
62-
body: () -> R
62+
invoking body: () -> R
6363
) -> R {
6464
let expected = self[t].advanced(by: 1)
6565
let r = body()
@@ -77,7 +77,7 @@ extension TypeIndexed where Value : Equatable {
7777
showFrame: Bool = true,
7878
stackTrace: SourceLocStack = SourceLocStack(),
7979
file: String = #file, line: UInt = #line,
80-
body: () -> R
80+
invoking body: () -> R
8181
) -> R {
8282
let expected = self[t]
8383
let r = body()

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public func withOverriddenLocaleCurrentLocale<Result>(
6565
/// return-autoreleased optimization.)
6666
@inline(never)
6767
public func autoreleasepoolIfUnoptimizedReturnAutoreleased(
68-
_ body: @noescape () -> Void
68+
invoking body: @noescape () -> Void
6969
) {
7070
#if arch(i386) && (os(iOS) || os(watchOS))
7171
autoreleasepool(body)

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ extension Optional {
7676
/// `body` is complicated than that results in unnecessarily repeated code.
7777
internal func _withNilOrAddress<NSType : AnyObject, ResultType>(
7878
of object: inout NSType?,
79-
body: @noescape (AutoreleasingUnsafeMutablePointer<NSType?>?) -> ResultType
79+
_ body:
80+
@noescape (AutoreleasingUnsafeMutablePointer<NSType?>?) -> ResultType
8081
) -> ResultType {
8182
return self == nil ? body(nil) : body(&object)
8283
}
@@ -495,7 +496,9 @@ extension String {
495496
// enumerateLinesUsing:(void (^)(NSString *line, BOOL *stop))block
496497

497498
/// Enumerates all the lines in a string.
498-
public func enumerateLines(_ body: (line: String, stop: inout Bool) -> ()) {
499+
public func enumerateLines(
500+
invoking body: (line: String, stop: inout Bool) -> ()
501+
) {
499502
_ns.enumerateLines {
500503
(line: String, stop: UnsafeMutablePointer<ObjCBool>)
501504
in
@@ -526,7 +529,7 @@ extension String {
526529
scheme tagScheme: String,
527530
options opts: NSLinguisticTagger.Options = [],
528531
orthography: NSOrthography? = nil,
529-
_ body:
532+
invoking body:
530533
(String, Range<Index>, Range<Index>, inout Bool) -> ()
531534
) {
532535
_ns.enumerateLinguisticTags(

0 commit comments

Comments
 (0)