[swift-evolution] Guaranteed closure execution

Chris Lattner clattner at apple.com
Sat Jan 30 15:55:30 CST 2016


> On Jan 30, 2016, at 12:19 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org> wrote:
> 
> The "noescape + exactly once" guarantee is useful to the compiler because it allows the closure to *initialize* variables that it captures. The way to think about this is that the closure body is effectively inlined.
> 
> "noescape, but not exactly once" is still useful because you can omit references to self, and know that variable modifications in the closure will be visible after the function call. But you can't perform initialization (because the closure might be called more than once), nor can you be sure variables are initialized after the function call (because the closure might not be called at all).
> 
> "exactly once, but escaping" is an important API contract that should be documented, but if the closure can escape the call, then you still can't perform initialization in the closure, because the order it happens in w.r.t. the function call isn't guaranteed. I might be missing something, but I don't see any reason for this feature to exist, because...well, it isn't really a feature if it can't do anything.

+1, exactly right.

-Chris


More information about the swift-evolution mailing list