[swift-evolution] [Pitch] Move @noescape

Chris Lattner clattner at apple.com
Sat Mar 5 01:07:22 CST 2016

On Mar 4, 2016, at 9:32 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> This seems dumb to me :-) you should be able to write the type for any declaration you can produce.  Once you do that, it makes sense to spell the original function as:
>> 	func f(a : @autoclosure () -> ()) {}
>> for consistency.  Yes, I totally get the irony of the fact that @autoclosure used to be on the type in swift 1.
> How much sense does it really make to have a closure with an @autoclosure parameter, though? @autoclosure is meant to be syntactic sugar for when a function needs to control the evaluation of its parameters, like `&&` or `Result(try something())`. Does that feature make sense for closures?

I don’t think that it is wildly “widely useful”, but yes, it certainly makes sense.  Not having it makes the language less orthogonal.

> Even if it does, does it make sense for there to be a type error when you pass a `Foo -> Bar` where an `@autoclosure Foo -> Bar` is expected, or vice versa?

That is orthogonal to my proposal, but yes, these are different function types since they have different behaviors at the use site.

> Even if we decide we have to support @autoclosure on closures, if we turn parameter labels into a feature of the variable's name instead of its type (which I believe I've seen discussed),

I don’t expect that to happen (because, e.g. that would fundamentally change how currying methods works), but if it does, we can certainly re-evaluate this.


More information about the swift-evolution mailing list