<label> body => _ body

This commit is contained in:
Dave Abrahams
2016-06-07 14:51:58 -07:00
parent eb27bb65a7
commit b5bc9be6fb
15 changed files with 36 additions and 27 deletions

View File

@@ -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)
}

View File

@@ -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)
@@ -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) {

View File

@@ -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()

View File

@@ -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()
@@ -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()

View File

@@ -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)

View File

@@ -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)
}
@@ -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
@@ -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(

View File

@@ -187,7 +187,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 {

View File

@@ -13,19 +13,19 @@
/// Evaluate `f()` and return its result, ensuring that `x` is not
/// destroyed before f returns.
public func withExtendedLifetime<T, Result>(
_ x: T, _ f: @noescape () throws -> Result
_ x: T, _ body: @noescape () throws -> Result
) rethrows -> Result {
defer { _fixLifetime(x) }
return try f()
return try body()
}
/// Evaluate `f(x)` and return its result, ensuring that `x` is not
/// destroyed before f returns.
public func withExtendedLifetime<T, Result>(
_ x: T, _ f: @noescape (T) throws -> Result
_ x: T, _ body: @noescape (T) throws -> Result
) rethrows -> Result {
defer { _fixLifetime(x) }
return try f(x)
return try body(x)
}
extension String {
@@ -41,10 +41,10 @@ extension String {
/// it is used as the return value of the `withCString(_:)` method.
/// - Returns: The return value of the `f` closure, if any.
public func withCString<Result>(
_ f: @noescape (UnsafePointer<Int8>) throws -> Result
_ body: @noescape (UnsafePointer<Int8>) throws -> Result
) rethrows -> Result {
return try self.nulTerminatedUTF8.withUnsafeBufferPointer {
try f(UnsafePointer($0.baseAddress!))
try body(UnsafePointer($0.baseAddress!))
}
}
}

View File

@@ -124,7 +124,7 @@ public struct StaticString
/// `withUTF8Buffer(invoke:)` method.
/// - Returns: The return value of the `body` closure, if any.
public func withUTF8Buffer<R>(
invoke body: @noescape (UnsafeBufferPointer<UInt8>) -> R) -> R {
_ body: @noescape (UnsafeBufferPointer<UInt8>) -> R) -> R {
if hasPointerRepresentation {
return body(UnsafeBufferPointer(
start: utf8Start, count: Int(utf8CodeUnitCount)))

View File

@@ -103,7 +103,9 @@ extension String {
/// - Parameter body: A closure that takes a character view as its argument.
/// - Returns: The return value of the `body` closure, if any, is the return
/// value of this method.
public mutating func withMutableCharacters<R>(_ body: (inout CharacterView) -> R) -> R {
public mutating func withMutableCharacters<R>(
_ body: (inout CharacterView) -> R
) -> R {
// Naively mutating self.characters forces multiple references to
// exist at the point of mutation. Instead, temporarily move the
// core of this string into a CharacterView.

View File

@@ -183,10 +183,10 @@ public struct Unmanaged<Instance : AnyObject> {
/// }
/// }
public func _withUnsafeGuaranteedRef<Result>(
_ closure: @noescape (Instance) throws -> Result
_ body: @noescape (Instance) throws -> Result
) rethrows -> Result {
let (guaranteedInstance, token) = Builtin.unsafeGuaranteed(_value)
let result = try closure(guaranteedInstance)
let result = try body(guaranteedInstance)
Builtin.unsafeGuaranteedEnd(token)
return result
}

View File

@@ -65,18 +65,18 @@ let _x86_64RegisterSaveWords = _x86_64CountGPRegisters + _x86_64CountSSERegister
/// Invoke `body` with a C `va_list` argument derived from `args`.
public func withVaList<R>(_ args: [CVarArg],
invoke body: @noescape (CVaListPointer) -> R) -> R {
_ body: @noescape (CVaListPointer) -> R) -> R {
let builder = _VaListBuilder()
for a in args {
builder.append(a)
}
return _withVaList(builder, invoke: body)
return _withVaList(builder, body)
}
/// Invoke `body` with a C `va_list` argument derived from `builder`.
internal func _withVaList<R>(
_ builder: _VaListBuilder,
invoke body: @noescape (CVaListPointer) -> R
_ body: @noescape (CVaListPointer) -> R
) -> R {
let result = body(builder.va_list())
_fixLifetime(builder)

View File

@@ -138,7 +138,7 @@ ArrayTraps.test("unsafeLength")
expectCrashLater()
a.withUnsafeBufferPointer {
_ = a.withUnsafeBufferPointer {
UnsafeBufferPointer(start: $0.baseAddress, count: -1)
}
}

View File

@@ -38,7 +38,7 @@
}
// LITERAL4: Begin completions
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: withCString({#(f): (UnsafePointer<Int8>) throws -> Result##(UnsafePointer<Int8>) throws -> Result#})[' rethrows'][#Result#]; name=withCString(f: (UnsafePointer<Int8>) throws -> Result) rethrows{{$}}
// LITERAL4-DAG: Decl[InstanceMethod]/CurrNominal: withCString({#(body): (UnsafePointer<Int8>) throws -> Result##(UnsafePointer<Int8>) throws -> Result#})[' rethrows'][#Result#]; name=withCString(body: (UnsafePointer<Int8>) throws -> Result) rethrows{{$}}
// FIXME: we should show the qualified String.Index type.
// rdar://problem/20788802

View File

@@ -79,7 +79,9 @@ public func ?? <T> (
}
/// Translate the execution of a throwing closure into a Result
func catchResult<Success>(body: () throws -> Success) -> Result<Success> {
func catchResult<Success>(
invoking body: () throws -> Success
) -> Result<Success> {
do {
return try .Success(body())
}