[swift-evolution] [Pitch] Move @noescape

Jordan Rose jordan_rose at apple.com
Tue Mar 8 17:16:47 CST 2016


This is problematic when there are multiple levels of closure:

fn: (Int) -> (Int) -> (Int, Int) @convention(block)
// without the attribute, equivalent to
fn: (Int) -> ((Int) -> (Int, Int))

Of course neither @noescape nor @autoclosure can apply to an arbitrary function value, but @convention can.

It's also inconsistent with all other attributes in the language. I see the idea of most-to-least important, but I don't think it actually results in a more readable syntax here.

Jordan


> On Mar 5, 2016, at 12:43, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Another point. I prefer lines to be ordered from most important bit of information to least. That is why I prefer trailing ':' type information to C-style declarations. Therefore my preference would be:
> 
>     func f(a: () -> () @autoclosure) {}
> 
> Since the name is the most important, the type the next most, and lastly the annotation is the least important bit of information. 
> 
> On Saturday, 5 March 2016, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> On Mar 4, 2016, at 9:32 PM, Brent Royal-Gordon <brent at architechies.com <javascript:;>> 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.
> 
> -Chris
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <javascript:;>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 
> -- 
> -- Howard.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list