Skip to content

Name and label changes for closure parameters (SE-0118) #2981

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 9 commits into from
Jul 15, 2016
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
2 changes: 1 addition & 1 deletion benchmark/single-source/CaptureProp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func benchCaptureProp<S : Sequence

var it = s.makeIterator()
let initial = it.next()!
return IteratorSequence(it).reduce(initial, combine: f)
return IteratorSequence(it).reduce(initial, f)
}

public func run_CaptureProp(_ N: Int) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/MapReduce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public func run_MapReduce(_ N: Int) {
var c = 0
for _ in 1...N*100 {
numbers = numbers.map({$0 &+ 5})
c += numbers.reduce(0, combine: &+)
c += numbers.reduce(0, &+)
}
CheckResults(c != 0, "IncorrectResults in MapReduce")
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/SortStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ func benchSortStrings(_ words: [String]) {
// Notice that we _copy_ the array of words before we sort it.
// Pass an explicit '<' predicate to benchmark reabstraction thunks.
var tempwords = words
tempwords.sort(isOrderedBefore: <)
tempwords.sort(by: <)
}

public func run_SortStrings(_ N: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ public struct ${Self}<
}

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

public func forEach(
Expand Down Expand Up @@ -274,13 +274,13 @@ public struct ${Self}<
public func split(
maxSplits: Int = Int.max,
omittingEmptySubsequences: Bool = true,
isSeparator: @noescape (Base.Iterator.Element) throws -> Bool
whereSeparator isSeparator: @noescape (Base.Iterator.Element) throws -> Bool
) rethrows -> [SubSequence] {
Log.split[selfType] += 1
return try base.split(
maxSplits: maxSplits,
omittingEmptySubsequences: omittingEmptySubsequences,
isSeparator: isSeparator)
whereSeparator: isSeparator)
}

public func _customContainsEquatableElement(
Expand Down
4 changes: 3 additions & 1 deletion stdlib/private/StdlibUnittest/RaceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@ internal struct ClosureBasedRaceTest : RaceTestWithPerTrialData {
) {}
}

public func runRaceTest(trials: Int, threads: Int? = nil, body: () -> ()) {
public func runRaceTest(
trials: Int, threads: Int? = nil, invoking body: () -> ()
) {
ClosureBasedRaceTest.thread = body
runRaceTest(ClosureBasedRaceTest.self, trials: trials, threads: threads)
}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ extension MutableCollection
}

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

/// Generate all permutations.
public func forAllPermutations<S : Sequence>(
_ sequence: S, body: ([S.Iterator.Element]) -> Void
_ sequence: S, _ body: ([S.Iterator.Element]) -> Void
) {
let data = Array(sequence)
forAllPermutations(data.count) {
Expand Down
12 changes: 6 additions & 6 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var _seenExpectCrash = false
/// Run `body` and expect a failure to happen.
///
/// The check passes iff `body` triggers one or more failures.
public func expectFailure(${TRACE}, body: () -> Void) {
public func expectFailure(${TRACE}, invoking body: () -> Void) {
let startAnyExpectFailed = _anyExpectFailed
_anyExpectFailed = false
body()
Expand Down Expand Up @@ -2228,7 +2228,7 @@ public func expectEqualSequence<
) where
Expected.Iterator.Element == Actual.Iterator.Element {

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

let x: [Expected.Iterator.Element] =
expected.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
expected.sorted(by: compose(compare, { $0.isLT() }))
let y: [Actual.Iterator.Element] =
actual.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
actual.sorted(by: compose(compare, { $0.isLT() }))
expectEqualSequence(
x, y, ${trace}, sameValue: compose(compare, { $0.isEQ() }))
}
Expand Down Expand Up @@ -2345,10 +2345,10 @@ public func expectEqualsUnordered<
}

let x: [(T, T)] =
expected.sorted(isOrderedBefore: comparePairLess)
expected.sorted(by: comparePairLess)
let y: [(T, T)] =
actual.map { ($0.0, $0.1) }
.sorted(isOrderedBefore: comparePairLess)
.sorted(by: comparePairLess)

func comparePairEquals(_ lhs: (T, T), rhs: (key: T, value: T)) -> Bool {
return lhs.0 == rhs.0 && lhs.1 == rhs.1
Expand Down
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/TypeIndexed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension TypeIndexed where Value : Strideable {
showFrame: Bool = true,
stackTrace: SourceLocStack = SourceLocStack(),
file: String = #file, line: UInt = #line,
body: () -> R
invoking body: () -> R
) -> R {
let expected = self[t].advanced(by: 1)
let r = body()
Expand All @@ -77,7 +77,7 @@ extension TypeIndexed where Value : Equatable {
showFrame: Bool = true,
stackTrace: SourceLocStack = SourceLocStack(),
file: String = #file, line: UInt = #line,
body: () -> R
invoking body: () -> R
) -> R {
let expected = self[t]
let r = body()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public func withOverriddenLocaleCurrentLocale<Result>(
/// return-autoreleased optimization.)
@inline(never)
public func autoreleasepoolIfUnoptimizedReturnAutoreleased(
_ body: @noescape () -> Void
invoking body: @noescape () -> Void
) {
#if arch(i386) && (os(iOS) || os(watchOS))
autoreleasepool(body)
Expand Down
9 changes: 6 additions & 3 deletions stdlib/public/SDK/Foundation/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ extension Optional {
/// `body` is complicated than that results in unnecessarily repeated code.
internal func _withNilOrAddress<NSType : AnyObject, ResultType>(
of object: inout NSType?,
body: @noescape (AutoreleasingUnsafeMutablePointer<NSType?>?) -> ResultType
_ body:
@noescape (AutoreleasingUnsafeMutablePointer<NSType?>?) -> ResultType
) -> ResultType {
return self == nil ? body(nil) : body(&object)
}
Expand Down Expand Up @@ -495,7 +496,9 @@ extension String {
// enumerateLinesUsing:(void (^)(NSString *line, BOOL *stop))block

/// Enumerates all the lines in a string.
public func enumerateLines(_ body: (line: String, stop: inout Bool) -> ()) {
public func enumerateLines(
invoking body: (line: String, stop: inout Bool) -> ()
) {
_ns.enumerateLines {
(line: String, stop: UnsafeMutablePointer<ObjCBool>)
in
Expand Down Expand Up @@ -526,7 +529,7 @@ extension String {
scheme tagScheme: String,
options opts: NSLinguisticTagger.Options = [],
orthography: NSOrthography? = nil,
_ body:
invoking body:
(String, Range<Index>, Range<Index>, inout Bool) -> ()
) {
_ns.enumerateLinguisticTags(
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/ObjectiveC/ObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func __pushAutoreleasePool() -> OpaquePointer
func __popAutoreleasePool(_ pool: OpaquePointer)

public func autoreleasepool<Result>(
_ body: @noescape () throws -> Result
invoking body: @noescape () throws -> Result
) rethrows -> Result {
let pool = __pushAutoreleasePool()
defer {
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/Arrays.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ if True:
///
/// You can call any method on the slices that you might have called on the
/// `absences` array. To learn which half had more absences, use the
/// `reduce(_:combine:)` method to calculate each sum.
/// `reduce(_:)` method to calculate each sum.
///
/// let firstHalfSum = firstHalf.reduce(0, combine: +)
/// let secondHalfSum = secondHalf.reduce(0, combine: +)
/// let firstHalfSum = firstHalf.reduce(0, +)
/// let secondHalfSum = secondHalf.reduce(0, +)
///
/// if firstHalfSum > secondHalfSum {
/// print("More absences in the first half.")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Boolean.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public prefix func !<T : Boolean>(a: T) -> Bool {
/// `lhs` evaluates to `true`. For example:
///
/// let measurements = [7.44, 6.51, 4.74, 5.88, 6.27, 6.12, 7.76]
/// let sum = measurements.reduce(0, combine: +)
/// let sum = measurements.reduce(0, +)
///
/// if measurements.count > 0 && sum / Double(measurements.count) < 6.5 {
/// print("Average measurement is less than 6.5")
Expand Down Expand Up @@ -121,7 +121,7 @@ public func || <T : Boolean, U : Boolean>(
/// `lhs` evaluates to `true`. For example:
///
/// let measurements = [7.44, 6.51, 4.74, 5.88, 6.27, 6.12, 7.76]
/// let sum = measurements.reduce(0, combine: +)
/// let sum = measurements.reduce(0, +)
///
/// if measurements.count > 0 && sum / Double(measurements.count) < 6.5 {
/// print("Average measurement is less than 6.5")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Character.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public struct Character :
shift += 8
}

UTF8.encode(scalar, sendingOutputTo: output)
UTF8.encode(scalar, into: output)
asInt |= (~0) << shift
_representation = .small(Builtin.trunc_Int64_Int63(asInt._value))
}
Expand Down Expand Up @@ -297,7 +297,7 @@ public struct Character :
_SmallUTF8(u8).makeIterator(),
from: UTF8.self, to: UTF16.self,
stoppingOnError: false,
sendingOutputTo: output)
into: output)
self.data = u16
}

Expand Down
16 changes: 9 additions & 7 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1484,15 +1484,17 @@ extension Collection {
/// that was originally separated by one or more spaces.
///
/// let line = "BLANCHE: I don't want realism. I want magic!"
/// print(line.characters.split(isSeparator: { $0 == " " })
/// print(line.characters.split(whereSeparator: { $0 == " " })
/// .map(String.init))
/// // Prints "["BLANCHE:", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
///
/// The second example passes `1` for the `maxSplits` parameter, so the
/// original string is split just once, into two new strings.
///
/// print(line.characters.split(maxSplits: 1, isSeparator: { $0 == " " })
/// .map(String.init))
/// print(
/// line.characters.split(
/// maxSplits: 1, whereSeparator: { $0 == " " }
/// ).map(String.init))
/// // Prints "["BLANCHE:", " I don\'t want realism. I want magic!"]"
///
/// The final example passes `false` for the `omittingEmptySubsequences`
Expand Down Expand Up @@ -1523,7 +1525,7 @@ extension Collection {
public func split(
maxSplits: Int = Int.max,
omittingEmptySubsequences: Bool = true,
isSeparator: @noescape (Iterator.Element) throws -> Bool
whereSeparator isSeparator: @noescape (Iterator.Element) throws -> Bool
) rethrows -> [SubSequence] {
// TODO: swift-3-indexing-model - review the following
_precondition(maxSplits >= 0, "Must take zero or more splits")
Expand Down Expand Up @@ -1624,7 +1626,7 @@ extension Collection where Iterator.Element : Equatable {
return split(
maxSplits: maxSplits,
omittingEmptySubsequences: omittingEmptySubsequences,
isSeparator: { $0 == separator })
whereSeparator: { $0 == separator })
}
}

Expand Down Expand Up @@ -1719,11 +1721,11 @@ extension Collection {
Builtin.unreachable()
}

@available(*, unavailable, message: "Please use split(maxSplits:omittingEmptySubsequences:isSeparator:) instead")
@available(*, unavailable, message: "Please use split(maxSplits:omittingEmptySubsequences:whereSeparator:) instead")
public func split(
_ maxSplit: Int = Int.max,
allowEmptySlices: Bool = false,
isSeparator: @noescape (Iterator.Element) throws -> Bool
whereSeparator isSeparator: @noescape (Iterator.Element) throws -> Bool
) rethrows -> [SubSequence] {
Builtin.unreachable()
}
Expand Down
Loading