[swift-evolution] [Proposal] Make non-escaping closures the default

Anton Zhilin antonyzhilin at gmail.com
Mon Jun 20 13:24:49 CDT 2016

Trent Nadeau via swift-evolution <swift-evolution at ...> writes:

> https://github.com/tanadeau/swift-evolution/blob/make-noescape-

-1 from me.

1. One must break API and ABI compatibility to add @escaping to an 
existing function
2. @nonescaping case is actually quite as common as @escaping
3. Swift's lifetime system is not powerful enough, I'll explain below

Lazy map and filter will be marked as @escaping. Now consider the 
following code:

func sum<T>(_ array: [T], transform: (T) -> Int) -> Int {
    return array.lazy.map(func).reduce(0, combine: +)

`transform` will be marked as @escaping, despite that `transform` never 
actually escapes `sum`.

I believe that we should not accept nonescaping-by-default until we get 
a powerful lifetime management system, as in Rust.

I think it makes sense to create a mini-proposal just for renaming of 
@noescape to @nonescaping.

- Anton

More information about the swift-evolution mailing list