Skip to content

Commit 18fb99a

Browse files
author
Dave Abrahams
authored
Merge pull request #3589 from apple/closure-naming-and-labeling
See https://github.com/apple/swift-evolution/blob/master/proposals/0118-closure-parameter-names-and-labels.md * <label> body => _ body * _ isSeparator: => whereSeparator isSeparator: * isOrderedBefore: => by areInIncreasingOrder: * _ includeElement/whereElementsSatisfy predicate => _ isIncluded * initialValue: => makingValueWith factory: (ManagedBuffer) * first/contains(predicate) => first/contains(where: predicate) * isEquivalent: => by areEquivalent: * reduce(_ initial:combine:) => reduce(_ initialResult:_ nextPartialResult) * encode(_:output:) => encode(_:into processCodeUnit:)
2 parents 96399b1 + da2947f commit 18fb99a

File tree

64 files changed

+380
-348
lines changed

Some content is hidden

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

64 files changed

+380
-348
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()
@@ -2244,7 +2244,7 @@ public func expectEqualSequence<
22442244
) where
22452245
Expected.Iterator.Element == Actual.Iterator.Element {
22462246

2247-
if !expected.elementsEqual(actual, isEquivalent: sameValue) {
2247+
if !expected.elementsEqual(actual, by: sameValue) {
22482248
expectationFailure("expected elements: \"\(expected)\"\n"
22492249
+ "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))",
22502250
trace: ${trace})
@@ -2262,9 +2262,9 @@ public func expectEqualsUnordered<
22622262
Expected.Iterator.Element == Actual.Iterator.Element {
22632263

22642264
let x: [Expected.Iterator.Element] =
2265-
expected.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
2265+
expected.sorted(by: compose(compare, { $0.isLT() }))
22662266
let y: [Actual.Iterator.Element] =
2267-
actual.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
2267+
actual.sorted(by: compose(compare, { $0.isLT() }))
22682268
expectEqualSequence(
22692269
x, y, ${trace}, sameValue: compose(compare, { $0.isEQ() }))
22702270
}
@@ -2361,10 +2361,10 @@ public func expectEqualsUnordered<
23612361
}
23622362

23632363
let x: [(T, T)] =
2364-
expected.sorted(isOrderedBefore: comparePairLess)
2364+
expected.sorted(by: comparePairLess)
23652365
let y: [(T, T)] =
23662366
actual.map { ($0.0, $0.1) }
2367-
.sorted(isOrderedBefore: comparePairLess)
2367+
.sorted(by: comparePairLess)
23682368

23692369
func comparePairEquals(_ lhs: (T, T), rhs: (key: T, value: T)) -> Bool {
23702370
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(

stdlib/public/SDK/ObjectiveC/ObjectiveC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func __pushAutoreleasePool() -> OpaquePointer
187187
func __popAutoreleasePool(_ pool: OpaquePointer)
188188

189189
public func autoreleasepool<Result>(
190-
_ body: @noescape () throws -> Result
190+
invoking body: @noescape () throws -> Result
191191
) rethrows -> Result {
192192
let pool = __pushAutoreleasePool()
193193
defer {

stdlib/public/core/Arrays.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ if True:
9999
///
100100
/// You can call any method on the slices that you might have called on the
101101
/// `absences` array. To learn which half had more absences, use the
102-
/// `reduce(_:combine:)` method to calculate each sum.
102+
/// `reduce(_:)` method to calculate each sum.
103103
///
104-
/// let firstHalfSum = firstHalf.reduce(0, combine: +)
105-
/// let secondHalfSum = secondHalf.reduce(0, combine: +)
104+
/// let firstHalfSum = firstHalf.reduce(0, +)
105+
/// let secondHalfSum = secondHalf.reduce(0, +)
106106
///
107107
/// if firstHalfSum > secondHalfSum {
108108
/// print("More absences in the first half.")

stdlib/public/core/Character.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public struct Character :
9292
shift += 8
9393
}
9494

95-
UTF8.encode(scalar, sendingOutputTo: output)
95+
UTF8.encode(scalar, into: output)
9696
asInt |= (~0) << shift
9797
_representation = .small(Builtin.trunc_Int64_Int63(asInt._value))
9898
}
@@ -297,7 +297,7 @@ public struct Character :
297297
_SmallUTF8(u8).makeIterator(),
298298
from: UTF8.self, to: UTF16.self,
299299
stoppingOnError: false,
300-
sendingOutputTo: output)
300+
into: output)
301301
self.data = u16
302302
}
303303

stdlib/public/core/Collection.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,15 +1484,17 @@ extension Collection {
14841484
/// that was originally separated by one or more spaces.
14851485
///
14861486
/// let line = "BLANCHE: I don't want realism. I want magic!"
1487-
/// print(line.characters.split(isSeparator: { $0 == " " })
1487+
/// print(line.characters.split(whereSeparator: { $0 == " " })
14881488
/// .map(String.init))
14891489
/// // Prints "["BLANCHE:", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
14901490
///
14911491
/// The second example passes `1` for the `maxSplits` parameter, so the
14921492
/// original string is split just once, into two new strings.
14931493
///
1494-
/// print(line.characters.split(maxSplits: 1, isSeparator: { $0 == " " })
1495-
/// .map(String.init))
1494+
/// print(
1495+
/// line.characters.split(
1496+
/// maxSplits: 1, whereSeparator: { $0 == " " }
1497+
/// ).map(String.init))
14961498
/// // Prints "["BLANCHE:", " I don\'t want realism. I want magic!"]"
14971499
///
14981500
/// The final example passes `false` for the `omittingEmptySubsequences`
@@ -1523,7 +1525,7 @@ extension Collection {
15231525
public func split(
15241526
maxSplits: Int = Int.max,
15251527
omittingEmptySubsequences: Bool = true,
1526-
isSeparator: @noescape (Iterator.Element) throws -> Bool
1528+
whereSeparator isSeparator: @noescape (Iterator.Element) throws -> Bool
15271529
) rethrows -> [SubSequence] {
15281530
// TODO: swift-3-indexing-model - review the following
15291531
_precondition(maxSplits >= 0, "Must take zero or more splits")
@@ -1624,7 +1626,7 @@ extension Collection where Iterator.Element : Equatable {
16241626
return split(
16251627
maxSplits: maxSplits,
16261628
omittingEmptySubsequences: omittingEmptySubsequences,
1627-
isSeparator: { $0 == separator })
1629+
whereSeparator: { $0 == separator })
16281630
}
16291631
}
16301632

@@ -1719,11 +1721,11 @@ extension Collection {
17191721
Builtin.unreachable()
17201722
}
17211723

1722-
@available(*, unavailable, message: "Please use split(maxSplits:omittingEmptySubsequences:isSeparator:) instead")
1724+
@available(*, unavailable, message: "Please use split(maxSplits:omittingEmptySubsequences:whereSeparator:) instead")
17231725
public func split(
17241726
_ maxSplit: Int = Int.max,
17251727
allowEmptySlices: Bool = false,
1726-
isSeparator: @noescape (Iterator.Element) throws -> Bool
1728+
whereSeparator isSeparator: @noescape (Iterator.Element) throws -> Bool
17271729
) rethrows -> [SubSequence] {
17281730
Builtin.unreachable()
17291731
}

0 commit comments

Comments
 (0)