Skip to content

Commit 4fd8418

Browse files
committed
move the stdlib to put noescape and autoclosure on the type, instead of
the parameter. Progress towards SE-0049.
1 parent ab14e67 commit 4fd8418

37 files changed

+165
-167
lines changed

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public func withInvalidOrderings(_ body: ((Int, Int) -> Bool) -> Void) {
6262

6363
internal func _mapInPlace<C : MutableCollection>(
6464
_ elements: inout C,
65-
@noescape transform: (C.Iterator.Element) -> C.Iterator.Element
65+
transform: @noescape (C.Iterator.Element) -> C.Iterator.Element
6666
) {
6767
for i in elements.indices {
6868
elements[i] = transform(elements[i])

stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ public struct LoggingRangeReplaceableCollection<
218218

219219
@warn_unused_result
220220
public func map<T>(
221-
@noescape transform: (Base.Iterator.Element) throws -> T
221+
transform: @noescape (Base.Iterator.Element) throws -> T
222222
) rethrows -> [T] {
223223
return try base.map(transform)
224224
}
225225

226226
@warn_unused_result
227227
public func filter(
228-
@noescape includeElement: (Base.Iterator.Element) throws -> Bool
228+
includeElement: @noescape (Base.Iterator.Element) throws -> Bool
229229
) rethrows -> [Base.Iterator.Element] {
230230
return try base.filter(includeElement)
231231
}
@@ -440,7 +440,7 @@ public struct Logging${Kind}<Base: ${Kind}> : ${Kind}, LoggingType {
440440

441441
% if Kind == 'MutableCollection':
442442
public mutating func _withUnsafeMutableBufferPointerIfSupported<R>(
443-
@noescape _ body: (UnsafeMutablePointer<Iterator.Element>, Int) throws -> R
443+
_ body: @noescape (UnsafeMutablePointer<Iterator.Element>, Int) throws -> R
444444
) rethrows -> R? {
445445
Log._withUnsafeMutableBufferPointerIfSupported[selfType] += 1
446446
let result = try base._withUnsafeMutableBufferPointerIfSupported(body)
@@ -462,23 +462,23 @@ public struct Logging${Kind}<Base: ${Kind}> : ${Kind}, LoggingType {
462462
}
463463

464464
public func forEach(
465-
@noescape _ body: (Base.Iterator.Element) throws -> Void
465+
_ body: @noescape (Base.Iterator.Element) throws -> Void
466466
) rethrows {
467467
Log.forEach[selfType] += 1
468468
try base.forEach(body)
469469
}
470470

471471
@warn_unused_result
472472
public func map<T>(
473-
@noescape _ transform: (Base.Iterator.Element) throws -> T
473+
_ transform: @noescape (Base.Iterator.Element) throws -> T
474474
) rethrows -> [T] {
475475
Log.map[selfType] += 1
476476
return try base.map(transform)
477477
}
478478

479479
@warn_unused_result
480480
public func filter(
481-
@noescape _ includeElement: (Base.Iterator.Element) throws -> Bool
481+
_ includeElement: @noescape (Base.Iterator.Element) throws -> Bool
482482
) rethrows -> [Base.Iterator.Element] {
483483
Log.filter[selfType] += 1
484484
return try base.filter(includeElement)
@@ -507,7 +507,7 @@ public struct Logging${Kind}<Base: ${Kind}> : ${Kind}, LoggingType {
507507
public func split(
508508
maxSplits: Int = Int.max,
509509
omittingEmptySubsequences: Bool = true,
510-
@noescape isSeparator: (Base.Iterator.Element) throws -> Bool
510+
isSeparator: @noescape (Base.Iterator.Element) throws -> Bool
511511
) rethrows -> [Base.SubSequence] {
512512
Log.split[selfType] += 1
513513
return try base.split(
@@ -546,7 +546,7 @@ public struct Logging${Kind}<Base: ${Kind}> : ${Kind}, LoggingType {
546546
/// `preprocess` on `self` and return its result. Otherwise, return
547547
/// `nil`.
548548
public func _preprocessingPass<R>(
549-
@noescape _ preprocess: () -> R
549+
_ preprocess: @noescape () -> R
550550
) -> R? {
551551
Log._preprocessingPass[selfType] += 1
552552
return base._preprocessingPass { preprocess() }
@@ -579,7 +579,7 @@ public func expectCustomizable<
579579
T.Log == T.Base.Log
580580
>(_: T, _ counters: TypeIndexed<Int>,
581581
//===--- TRACE boilerplate ----------------------------------------------===//
582-
@autoclosure _ message: () -> String = "",
582+
_ message: @autoclosure () -> String = "",
583583
showFrame: Bool = true,
584584
stackTrace: SourceLocStack = SourceLocStack(),
585585
file: String = #file, line: UInt = #line
@@ -597,7 +597,7 @@ public func expectNotCustomizable<
597597
T.Log == T.Base.Log
598598
>(_: T, _ counters: TypeIndexed<Int>,
599599
//===--- TRACE boilerplate ----------------------------------------------===//
600-
@autoclosure _ message: () -> String = "",
600+
_ message: @autoclosure () -> String = "",
601601
showFrame: Bool = true,
602602
stackTrace: SourceLocStack = SourceLocStack(),
603603
file: String = #file, line: UInt = #line

stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
%{
14-
TRACE = '''@autoclosure _ message: () -> String = "",
14+
TRACE = '''_ message: @autoclosure () -> String = "",
1515
showFrame: Bool = true,
1616
stackTrace: SourceLocStack = SourceLocStack(),
1717
file: String = #file, line: UInt = #line'''

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import Glibc
4747
#if _runtime(_ObjC)
4848
import ObjectiveC
4949
#else
50-
func autoreleasepool(@noescape _ code: () -> Void) {
50+
func autoreleasepool(_ code: @noescape () -> Void) {
5151
// Native runtime does not have autorelease pools. Execute the code
5252
// directly.
5353
code()

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public struct SourceLocStack {
8787
}
8888

8989
%{
90-
TRACE = '''@autoclosure _ message: () -> String = "",
90+
TRACE = '''_ message: @autoclosure () -> String = "",
9191
showFrame: Bool = true,
9292
stackTrace: SourceLocStack = SourceLocStack(),
9393
file: String = #file, line: UInt = #line'''

stdlib/private/StdlibUnittest/TypeIndexed.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class TypeIndexed<Value> : Resettable {
5555
extension TypeIndexed where Value : ForwardIndex {
5656
public func expectIncrement<R>(
5757
_ t: Any.Type,
58-
@autoclosure _ message: () -> String = "",
58+
_ message: @autoclosure () -> String = "",
5959
showFrame: Bool = true,
6060
stackTrace: SourceLocStack = SourceLocStack(),
6161
file: String = #file, line: UInt = #line,
@@ -73,7 +73,7 @@ extension TypeIndexed where Value : ForwardIndex {
7373
extension TypeIndexed where Value : Equatable {
7474
public func expectUnchanged<R>(
7575
_ t: Any.Type,
76-
@autoclosure _ message: () -> String = "",
76+
_ message: @autoclosure () -> String = "",
7777
showFrame: Bool = true,
7878
stackTrace: SourceLocStack = SourceLocStack(),
7979
file: String = #file, line: UInt = #line,
@@ -99,7 +99,7 @@ public func <=> <T: Comparable>(
9999

100100
public func expectEqual<V: Comparable>(
101101
_ expected: DictionaryLiteral<Any.Type, V>, _ actual: TypeIndexed<V>,
102-
@autoclosure _ message: () -> String = "",
102+
_ message: @autoclosure () -> String = "",
103103
showFrame: Bool = true,
104104
stackTrace: SourceLocStack = SourceLocStack(),
105105
file: String = #file, line: UInt = #line

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension NSLocale {
2424

2525
public func withOverriddenNSLocaleCurrentLocale<Result>(
2626
_ temporaryLocale: NSLocale,
27-
@noescape _ body: () -> Result
27+
_ body: @noescape () -> Result
2828
) -> Result {
2929
let oldMethod = class_getClassMethod(
3030
NSLocale.self, #selector(NSLocale.current))
@@ -48,7 +48,7 @@ public func withOverriddenNSLocaleCurrentLocale<Result>(
4848

4949
public func withOverriddenNSLocaleCurrentLocale<Result>(
5050
_ temporaryLocaleIdentifier: String,
51-
@noescape _ body: () -> Result
51+
_ body: @noescape () -> Result
5252
) -> Result {
5353
precondition(
5454
NSLocale.availableLocaleIdentifiers().contains(temporaryLocaleIdentifier),
@@ -65,7 +65,7 @@ public func withOverriddenNSLocaleCurrentLocale<Result>(
6565
/// return-autoreleased optimization.)
6666
@inline(never)
6767
public func autoreleasepoolIfUnoptimizedReturnAutoreleased(
68-
@noescape _ body: () -> Void
68+
_ body: @noescape () -> Void
6969
) {
7070
#if arch(i386) && (os(iOS) || os(watchOS))
7171
autoreleasepool(body)

stdlib/public/Platform/Platform.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func _convertDarwinBooleanToBool(_ x: DarwinBoolean) -> Bool {
7979
@warn_unused_result
8080
public func && <T : Boolean>(
8181
lhs: T,
82-
@autoclosure rhs: () -> DarwinBoolean
82+
rhs: @autoclosure () -> DarwinBoolean
8383
) -> Bool {
8484
return lhs.boolValue ? rhs().boolValue : false
8585
}
@@ -88,7 +88,7 @@ public func && <T : Boolean>(
8888
@warn_unused_result
8989
public func || <T : Boolean>(
9090
lhs: T,
91-
@autoclosure rhs: () -> DarwinBoolean
91+
rhs: @autoclosure () -> DarwinBoolean
9292
) -> Bool {
9393
return lhs.boolValue ? true : rhs().boolValue
9494
}

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//
2222

2323
@warn_unused_result
24-
func _toNSArray<T, U : AnyObject>(_ a: [T], @noescape f: (T) -> U) -> NSArray {
24+
func _toNSArray<T, U : AnyObject>(_ a: [T], f: @noescape (T) -> U) -> NSArray {
2525
let result = NSMutableArray(capacity: a.count)
2626
for s in a {
2727
result.add(f(s))
@@ -79,7 +79,7 @@ extension Optional {
7979
/// `body` is complicated than that results in unnecessarily repeated code.
8080
internal func _withNilOrAddress<NSType : AnyObject, ResultType>(
8181
of object: inout NSType?,
82-
body: @noescape AutoreleasingUnsafeMutablePointer<NSType?>? -> ResultType
82+
body: @noescape (AutoreleasingUnsafeMutablePointer<NSType?>?) -> ResultType
8383
) -> ResultType {
8484
return self == nil ? body(nil) : body(&object)
8585
}
@@ -125,7 +125,7 @@ extension String {
125125
/// memory referred to by `index`
126126
func _withOptionalOutParameter<Result>(
127127
_ index: UnsafeMutablePointer<Index>?,
128-
@noescape body: (UnsafeMutablePointer<Int>?) -> Result
128+
body: @noescape (UnsafeMutablePointer<Int>?) -> Result
129129
) -> Result {
130130
var utf16Index: Int = 0
131131
let result = (index != nil ? body(&utf16Index) : body(nil))
@@ -138,7 +138,7 @@ extension String {
138138
/// it into the memory referred to by `range`
139139
func _withOptionalOutParameter<Result>(
140140
_ range: UnsafeMutablePointer<Range<Index>>?,
141-
@noescape body: (UnsafeMutablePointer<NSRange>?) -> Result
141+
body: @noescape (UnsafeMutablePointer<NSRange>?) -> Result
142142
) -> Result {
143143
var nsRange = NSRange(location: 0, length: 0)
144144
let result = (range != nil ? body(&nsRange) : body(nil))

stdlib/public/SDK/ObjectiveC/ObjectiveC.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func __pushAutoreleasePool() -> OpaquePointer
191191
@_silgen_name("_swift_objc_autoreleasePoolPop")
192192
func __popAutoreleasePool(_ pool: OpaquePointer)
193193

194-
public func autoreleasepool(@noescape _ code: () -> Void) {
194+
public func autoreleasepool(_ code: @noescape () -> Void) {
195195
let pool = __pushAutoreleasePool()
196196
code()
197197
__popAutoreleasePool(pool)
@@ -216,15 +216,15 @@ public var NO: ObjCBool {
216216
@_transparent
217217
@warn_unused_result
218218
public func && <T : Boolean>(
219-
lhs: T, @autoclosure rhs: () -> ObjCBool
219+
lhs: T, rhs: @autoclosure () -> ObjCBool
220220
) -> Bool {
221221
return lhs.boolValue ? rhs().boolValue : false
222222
}
223223

224224
@_transparent
225225
@warn_unused_result
226226
public func || <T : Boolean>(
227-
lhs: T, @autoclosure rhs: () -> ObjCBool
227+
lhs: T, rhs: @autoclosure () -> ObjCBool
228228
) -> Bool {
229229
return lhs.boolValue ? true : rhs().boolValue
230230
}

0 commit comments

Comments
 (0)