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

John McCall rjmccall at apple.com
Tue Jun 21 12:19:56 CDT 2016


> On Jun 20, 2016, at 11:24 AM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> Trent Nadeau via swift-evolution <swift-evolution at ...> writes:
> 
>> https://github.com/tanadeau/swift-evolution/blob/make-noescape-
> default/proposals/XXXX-make-noescape-default.md
> 
> -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`.

This is a really good point.  In the short term, we can address this with an unsafe
nonescaping-to-escaping construct, but we'll need a more complete answer eventually.

John.


More information about the swift-evolution mailing list