Required Callback

​I'm not sure about that last question, I guess someone who knows more
about it than me could answer.​

···

*___________________________________*

*James⎥Lead Hustler*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 16 August 2016 at 23:37, James Campbell <james@supmenow.com> wrote:

@noescape is a hint that the callback will only be called once and allows
compiler to optimise, we may or may not be able to combine @required
functionality into that but it looks like it was rejected for now.

@required is a compiler hint / sanity check to enforce that the callback
is actually called once by the developer. There is no focus on any compiler
enhancements other than that.

Why the callback is special ?

The compiler should has a warning for unused parameters of function.

I think this is enough. More works should be leaved for a lint tool.

James Campbell via swift-evolution <swift-evolution@swift.org>于2016年8月17日
周三06:39写道:

···

​I'm not sure about that last question, I guess someone who knows more
about it than me could answer.​

*___________________________________*

*James⎥Lead Hustler*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com
<http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 16 August 2016 at 23:37, James Campbell <james@supmenow.com> wrote:

@noescape is a hint that the callback will only be called once and allows
compiler to optimise, we may or may not be able to combine @required
functionality into that but it looks like it was rejected for now.

@required is a compiler hint / sanity check to enforce that the callback
is actually called once by the developer. There is no focus on any compiler
enhancements other than that.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

​Thats true, my only concern with that is if the user disables that
warning.​

···

*___________________________________*

*James⎥Lead Hustler*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 17 August 2016 at 02:49, Boris Wang <kona.ming@gmail.com> wrote:

Why the callback is special ?

The compiler should has a warning for unused parameters of function.

I think this is enough. More works should be leaved for a lint tool.

James Campbell via swift-evolution <swift-evolution@swift.org>于2016年8月17日
周三06:39写道:

​I'm not sure about that last question, I guess someone who knows more
about it than me could answer.​

*___________________________________*

*James⎥Lead Hustler*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com
<http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 16 August 2016 at 23:37, James Campbell <james@supmenow.com> wrote:

@noescape is a hint that the callback will only be called once and
allows compiler to optimise, we may or may not be able to combine @required
functionality into that but it looks like it was rejected for now.

@required is a compiler hint / sanity check to enforce that the callback
is actually called once by the developer. There is no focus on any compiler
enhancements other than that.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Actually I think that that kind of warning should be left for linters as well; a protocol might define parameters that not all implementations use, or a type may define a method with a parameter that is intended only for future use (to avoid defining an overload later), these aren't necessarily problems.

Also, how do you want to define unused? I suppose a non-escaping closure is unused if it's never called (since it can't be stored), but that doesn't guarantee that it *will* be called, which is the point of this proposal, i.e- a non-escaping closure may be part of a loop that may not execute, which is fine since it has no requirement to be used in every call, only that it isn't stored.

So yeah, even if a warning like this could be done right, I'm not sure it replaces the case put forward for @required.

···

On 17 Aug 2016, at 02:49, Boris Wang via swift-evolution <swift-evolution@swift.org> wrote:

Why the callback is special ?

The compiler should has a warning for unused parameters of function.

I think this is enough. More works should be leaved for a lint tool.

In this case the @required callback is something *all* implementations
should use for the mentioned reasons (memory leaks etc) just to clarify :).

···

*___________________________________*

*James⎥Lead Hustler*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On 17 August 2016 at 11:31, Haravikk <swift-evolution@haravikk.me> wrote:

> On 17 Aug 2016, at 02:49, Boris Wang via swift-evolution < > swift-evolution@swift.org> wrote:
>
> Why the callback is special ?
>
> The compiler should has a warning for unused parameters of function.
>
> I think this is enough. More works should be leaved for a lint tool.

Actually I think that that kind of warning should be left for linters as
well; a protocol might define parameters that not all implementations use,
or a type may define a method with a parameter that is intended only for
future use (to avoid defining an overload later), these aren't necessarily
problems.

Also, how do you want to define unused? I suppose a non-escaping closure
is unused if it's never called (since it can't be stored), but that doesn't
guarantee that it *will* be called, which is the point of this proposal,
i.e- a non-escaping closure may be part of a loop that may not execute,
which is fine since it has no requirement to be used in every call, only
that it isn't stored.

So yeah, even if a warning like this could be done right, I'm not sure it
replaces the case put forward for @required.