[swift-evolution] [Pitch] make @noescape the default

Matthew Johnson musical.matthew at mac.com
Sat Dec 19 19:10:23 CST 2015



Sent from my iPad

> On Dec 19, 2015, at 6:38 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
> On Sat, Dec 19, 2015 at 12:10 PM, Matthew Johnson via swift-evolution
> <swift-evolution at swift.org> wrote:
>> @noescape is safer because it does not require thinking about lifetime issues for captured objects.  My hunch was that @noescape (or @autoclosure with implies @noescape) is also more common.  I had a look through the standard library and this is definitely the case there.
>> 
>> What does everyone think about making @noescape the default and introducing @escaping (or something similar) to annotate function arguments that do escape the call stack?
> 
> @noescape provides additional guarantees and the optimizer can learn
> to rely on it in future.  Thus, it effectively becomes ABI, and you
> can't remove in future versions of the library without breaking the
> ABI.  I think adding it should be an explicit decision because of
> that.
> 

That makes sense.  Still, it would be a shame to have to add it manually if it is actually the right thing a significant majority of the time (Andrew has a good point about looking at app level code to assess this).

One thing to consider - the compiler already detects when function arguments escape the call stack already and provides an error if they are marked @noescape.  Because of this it also detects when they do not escape the call stack.  I don't think it would be possible to forget @escaping when that is your purpose as you would get an error.  

Changing the escaping behavior of a function argument seems like a major change in functionality and thus breaking ABI is probably more acceptable in that case (I'm trying to think of a time when this would even happen - maybe making an synchronous operation asynchronous?).

As the compiler already detects whether the argument escapes or not it seems like the annotation primarily serves a documentation purpose - if you can accept the idea that a change in escaping behavior is significant enough to warrant potentially breaking ABI.


> Dmitri
> 
> -- 
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list