[swift-evolution] [Pitch] Move @noescape

Brent Royal-Gordon brent at architechies.com
Thu Mar 3 16:48:04 CST 2016

> Chris Eidhof noticed an emergent result of removing our currying syntax: it broke some useful code using @noescape, because we only allowed it on parameter declarations, not on general things-of-function-type.  This meant that manually curried code like this:
> func curriedFlatMap<A, B>(x: [A]) -> (@noescape A -> [B]) -> [B] {
>    return { f in
>        x.flatMap(f)
>    }
> }
> Was rejected.  Fixing this was straight-forward (https://github.com/apple/swift/commit/c3c6beac72bc0368030f06d52c46b6444fc48dbd), but required @noescape being allowed on arbitrary function types.  Now that we have that, these two declarations are equivalent:
> 	func f(@noescape fn : () -> ()) {}
> 	func f(fn : @noescape () -> ()) {}
> I propose that we remove the former syntax, migrating code to the later form.  This leads to better consistency between our declarations and types, and follows the precedent of inout.  @autoclosure should also probably move as well.
> Thoughts?

I suppose that makes sense.

While we're here, it actually occurred to me a while ago that `@noescape` could be applied to reference types as well as closures, indicating that the function doesn't keep them alive in the long run. Would that be useful information for the Swift compiler? I could imagine it helping the compiler to pin down the lifetimes of temporary objects, for instance.

Brent Royal-Gordon

More information about the swift-evolution mailing list