[swift-evolution] Immediately-called closures should be considered @noescape

Jordan Rose jordan_rose at apple.com
Tue Dec 15 18:38:06 CST 2015


> On Dec 15, 2015, at 15:20 , Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Dec 15, 2015, at 3:16 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Here’s a little annoyance I ran across just now:
>> 
>>           let sub: CKSubscription = {
>>               if let ID = self.ID {
>>                   return CKSubscription(recordType: typeName, predicate: predicate, subscriptionID: ID, options: allMutations)
>>               }
>>               else {
>>                   return CKSubscription(recordType: typeName, predicate: predicate, options: allMutations)
>>               }
>>           }()
>> 
>> This closure obviously never leaves the enclosing function, but Swift doesn’t treat it as if it had been passed to a @noescape function, so I have to say “self.ID” instead of “ID” in the condition. That’s a bit irritating, and I’d like to see it improved.
> 
> Seems reasonable, especially because SILGen peepholes { }() so that it doesn't even allocate a closure to begin with.

+1 from me as well. Personally, I would consider this an enhancement to an existing feature and would therefore not need to have it go through formal review. I don't think I get to make this call, though.

Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151215/aad44560/attachment.html>


More information about the swift-evolution mailing list